Working on the night mode
This commit is contained in:
1 parent
e6bfe85e2e
commit
442d3a7945
18 files changed
+1060
-2
No files matched your search
@@ -133,6 +133,29 @@ namespace ZL {
|
||||
lightSpaceMatrix = lightProjectionMatrix * lightViewMatrix;
|
||||
}
|
||||
|
||||
static Eigen::Matrix4f perspective(float fovY, float aspect, float zNear, float zFar) {
|
||||
float t = std::tan(fovY * 0.5f);
|
||||
Eigen::Matrix4f m = Eigen::Matrix4f::Zero();
|
||||
m(0, 0) = 1.0f / (aspect * t);
|
||||
m(1, 1) = 1.0f / t;
|
||||
m(2, 2) = -(zFar + zNear) / (zFar - zNear);
|
||||
m(2, 3) = -(2.0f * zFar * zNear) / (zFar - zNear);
|
||||
m(3, 2) = -1.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
void ShadowMap::updateSpotlightMatrix(const Eigen::Vector3f& lightPos,
|
||||
const Eigen::Vector3f& lightDir,
|
||||
float fovY, float nearZ, float farZ) {
|
||||
Eigen::Vector3f d = lightDir.normalized();
|
||||
Eigen::Vector3f up(0.f, 1.f, 0.f);
|
||||
if (std::abs(d.dot(up)) > 0.99f)
|
||||
up = Eigen::Vector3f(1.f, 0.f, 0.f);
|
||||
lightViewMatrix = lookAt(lightPos, lightPos + d, up);
|
||||
lightProjectionMatrix = perspective(fovY, 1.0f, nearZ, farZ);
|
||||
lightSpaceMatrix = lightProjectionMatrix * lightViewMatrix;
|
||||
}
|
||||
|
||||
void ShadowMap::bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glViewport(0, 0, resolution, resolution);
|
||||
|
||||
Reference in new issue
Block a user