Skip to content

Commit

Permalink
It works ! But need cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Lejeune committed Dec 25, 2014
1 parent fe9fe08 commit 3843a27
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/graphics/render.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3843a27

Please sign in to comment.