Thanks for the reply. I've tried it, but I do not seem to get any shadows. Here is an image:
I tried it with the following code, as per your suggestions:
for (const RenderableLighting::DirectionalLight& directionalLight : lighting.mDirectionalLights)
{
Vec3 lightDir = directionalLight.mLightDirection; // = Vec3(0.0f, 1.0f, 1.0f)
Vec3 perpVec1(1.0f, 0.0f, 0.0f);
Vec3 perpVec2(0.0f, 1.0f, -1.0f);
Mat3 rotationMatrix; // using glm, so matrices are column-major
rotationMatrix[0] = perpVec1;
rotationMatrix[1] = perpVec2;
rotationMatrix[2] = lightDir;
assert(glm::cross(perpVec1, perpVec2) == lightDir);
Vec3 corners[8] = {Vec3(-25.0f, -25.0f, 25.0f), Vec3(-25.0f, -25.0f, -25.0f), Vec3(-25.0f, 25.0f, 25.0f), Vec3(-25.0f, 25.0f, -25.0f),
Vec3(25.0f, -25.0f, 25.0f), Vec3(25.0f, -25.0f, -25.0f), Vec3(25.0f, 25.0f, 25.0f), Vec3(25.0f, 25.0f, -25.0f) };
for (uint32_t i = 0; i < 8; i++)
corners[i] = corners[i] * rotationMatrix;
float minX = corners[0].x, minY = corners[0].y, minZ = corners[0].z, maxX = corners[0].x, maxY = corners[0].y, maxZ = corners[0].z;
for (uint32_t i = 0; i < 8; i++)
{
if (corners[i].x < minX)
minX = corners[i].x;
if (corners[i].x > maxX)
maxX = corners[i].x;
if (corners[i].y < minY)
minY = corners[i].y;
if (corners[i].y > maxY)
maxY = corners[i].y;
if (corners[i].z < minZ)
minZ = corners[i].z;
if (corners[i].z > maxZ)
maxZ = corners[i].z;
}
Mat4 viewMatrix(rotationMatrix);
viewMatrix[3][0] = -(minX + maxX) * 0.5f;
viewMatrix[3][1] = -(minY + maxY) * 0.5f;
viewMatrix[3][2] = -(minZ + maxZ) * 0.5f;
viewMatrix[0][3] = 0.0f;
viewMatrix[1][3] = 0.0f;
viewMatrix[2][3] = 0.0f;
viewMatrix[3][3] = 1.0f;
Mat4 lightVP = glm::ortho(minX, minX, minY, maxY, minZ, maxZ) * viewMatrix;
GLCALL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDirectionalShadowMap.mFramebuffer));
GLCALL(glDrawBuffer(GL_NONE));
DirLightShadowPass(directionalLight, lightVP, renderQueue);
GLCALL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mGBuffer.mFramebuffer));
GLCALL(glDrawBuffer(GBuffer::GBUFFER_COLOR_ATTACHMENT_FINAL));
DirLightLightingPass(directionalLight, gNDCBiasMatrix * lightVP, lighting.mGamma, lighting.mScreenSize);
}
Do you spot anything that stands out? Besides the view/projection calculations, the rest should be fine