5
\$\begingroup\$

I'm working on a friends engine project and my task is to construct a new frustum from the light direction that overlaps the view frustum and possible shadow casters. The project already has a function that creates a frustum for this but its way to big and includes way to many casters (shadows) which can't be seen in the view frustum. Now the only parameter of this function are the normalized light direction vector and a view class which lets me extract the 8 view frustum points in world space. I don't have any additional infos about the scene. I have read some of the related Questions here but non seem to fit very well to my problem as they often just point to cascaded shadow maps. Sadly i can't use DX or openGl functions directly because this engine has a dedicated math library.

From what i've read so far the steps are: Transform view frustum points into light space and find min/max x and y values (or sometimes minima and maxima of all three axis) and create a AABB using the min/max vectors.

But what comes after this step? How do i transform this new AABB back to world space?

What i've done so far:

CVector3 Points[8], MinLight = CVector3(FLT_MAX), MaxLight = CVector3(FLT_MAX);
for(int i = 0; i<8;++i){
    Points[i] = Points[i] * WorldToShadowMapMatrix;
    MinLight = Math::Min(Points[i],MinLight);
    MaxLight = Math::Max(Points[i],MaxLight);
}

AABox box(MinLight,MaxLight);
box.GetPoints(Points); //save new aabb points to the array
CMat4 ShadowMapToWorld = WorldToShadowMapMatrix.Inverse();

for(int i = 0; i<8;++i){
    Points[i] = Points[i] * ShadowMapToWorld;
}

I don't think this is the right way to do it. The near plain probably has to extend into the direction of the light source to include potentional shadow casters.

I've read the Microsoft article about cascaded shadow maps http://msdn.microsoft.com/en-us/library/windows/desktop/ee416307%28v=vs.85%29.aspx which also includes some sample code. But they seem to use the scenes AABB to determine the near and far plane which I can't since i cant access this information from the funtion I'm working in.

Could you guys please link some example code which shows the calculation of such frustum?

Thanks in advance!

Additional question: is there a way to construct a WorldToFrustum matrix that represents the above transformation?

\$\endgroup\$
  • \$\begingroup\$ "How do i transform this new AABB back to world space?" Why do you need to transform it back to world space? The AABB in light space is the frustum for the directional light, i.e. the region that will be visible when you render the shadow map. \$\endgroup\$ – Nathan Reed Aug 20 '14 at 2:17
  • \$\begingroup\$ This frustum wont be used for rendering the shadow map, i guess it's supposed to be renderd for debugging. My guess would be multiplying each point of the new AABB with the Inverse of the WorldToShadowMapMatrix. But it looks like only to points were really transformed back. \$\endgroup\$ – Fabian Aug 20 '14 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.