diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 8ca6e45bc7..8b95b86a46 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -639,6 +639,22 @@ core::matrix4 getTighestFitOrthoProj(const core::matrix4 &transform, const std:: return tmp_matrix; } +static +core::matrix4 makeFrustrum(float left, float right, float top, float bottom, float n, float f) +{ + core::matrix4 projmat; + float *M = projmat.pointer(); + // http://msdn.microsoft.com/en-us/library/windows/desktop/bb205353(v=vs.85).aspx + M[0] = 2 * n / (right - left); + M[5] = 2 * n / (top - bottom); + M[10] = 1 / (f - n); + M[12] = (left + right) / (left - right); + M[13] = (top + bottom) / (bottom - top); + M[14] = n / (n - f); + M[15] = 1.; + return projmat; +} + // From http://advancedgraphics.marries.nl/presentationslides/11_light_space_perspective_shadow_maps.pdf static @@ -673,18 +689,16 @@ core::matrix4 test(const scene::ICameraSceneNode &B, const core::vector3df &Ligh zmin = MIN2(zmin, Vz); zmax = MAX2(zmax, Vz); } - float n = 100.; + float n = 1.; const core::vector3df PinLightSpace(-Borig.dotProduct(axisX), zmin - n, (ymin + ymax) / 2.); const core::vector3df PinWorldSpace = PinLightSpace.X * axisX + PinLightSpace.Y * axisY + PinLightSpace.Z * axisZ; core::matrix4 viewmat; viewmat.setTranslation(-PinLightSpace); -// viewmat.buildCameraLookAtMatrixLH(PinWorldSpace, PinWorldSpace + 1000. * axisZ, core::vector3df(0., 0., 1.)); - core::matrix4 projmat; - projmat.buildProjectionMatrixOrthoLH(-10., 10., n + 100., n, -1000., 1000.); + core::matrix4 projmat;// = makeFrustrum(-1., 1., 10., -10, -1, 1.); + projmat.buildProjectionMatrixOrthoLH(-10., 10, n + 100, n, -1000, 1000); core::matrix4 NewLightView; NewLightView.buildCameraLookAtMatrixLH(axisY, core::vector3df(0., 0., 0.), axisZ); - // delete P; return projmat * viewmat * NewLightView; }