Skip to content

Commit

Permalink
Tigher fit of shadow map.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Lejeune committed Jun 21, 2014
1 parent 32e6942 commit 1e959a0
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/graphics/render.cpp
Expand Up @@ -748,8 +748,32 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
core::aabbox3df box = smallcambox; core::aabbox3df box = smallcambox;
box = box.intersect(trackbox); box = box.intersect(trackbox);



float xmin = INFINITY, xmax = -INFINITY;
SunCamViewMatrix.transformBoxEx(trackbox); float ymin = INFINITY, ymax = -INFINITY;
float zmin = INFINITY, zmax = -INFINITY;
const vector3df vectors[] =
{
frustrum->getFarLeftDown(),
frustrum->getFarLeftUp(),
frustrum->getFarRightDown(),
frustrum->getFarRightUp(),
frustrum->getNearLeftDown(),
frustrum->getNearLeftUp(),
frustrum->getNearRightDown(),
frustrum->getNearRightUp()
};
for (unsigned j = 0; j < 8; j++)
{
vector3df vector;
SunCamViewMatrix.transformVect(vector, vectors[j]);
xmin = MIN2(xmin, vector.X);
xmax = MAX2(xmax, vector.X);
ymin = MIN2(ymin, vector.Y);
ymax = MAX2(ymax, vector.Y);
zmin = MIN2(zmin, vector.Z);
zmax = MAX2(zmax, vector.Z);
}
/* SunCamViewMatrix.transformBoxEx(trackbox);
SunCamViewMatrix.transformBoxEx(box); SunCamViewMatrix.transformBoxEx(box);
core::vector3df extent = box.getExtent(); core::vector3df extent = box.getExtent();
Expand All @@ -759,12 +783,12 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
// Snap to texels // Snap to texels
const float units_per_w = w / 1024; const float units_per_w = w / 1024;
const float units_per_h = h / 1024; const float units_per_h = h / 1024;*/


float left = box.MinEdge.X; float left = xmin;
float right = box.MaxEdge.X; float right = xmax;
float up = box.MaxEdge.Y; float up = ymin;
float down = box.MinEdge.Y; float down = ymax;


core::matrix4 tmp_matrix; core::matrix4 tmp_matrix;


Expand All @@ -777,8 +801,8 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
} }


tmp_matrix.buildProjectionMatrixOrthoLH(left, right, tmp_matrix.buildProjectionMatrixOrthoLH(left, right,
up, down, down, up,
30, z); 30, zmax);
m_suncam->setProjectionMatrix(tmp_matrix, true); m_suncam->setProjectionMatrix(tmp_matrix, true);
m_suncam->render(); m_suncam->render();


Expand Down

0 comments on commit 1e959a0

Please sign in to comment.