• Advertisement
Sign in to follow this  

CSM min and max calculation for orthogonal projection

This topic is 718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two ways to calculate min and max vectors, which are later used to create light's orthogonal projection. Lets name them A and B, so A looks like this:

// Calculate min and max vectors, using viewer's camera frustum slice centroid and radius
minOrtho.set(0, 0, 0, 1).assign(centroid).sub(frustumRadius, frustumRadius, -frustumRadius, 0);
maxOrtho.set(0, 0, 0, 1).assign(centroid).add(frustumRadius, frustumRadius, -frustumRadius, 0);
// Transform min and max vectors into light's eye space
Matrix4f.transform(lightTransforms[i].view, minOrtho, tmpVector);
Matrix4f.transform(lightTransforms[i].view, maxOrtho, tmpVector);

and B:

minOrtho.set(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE, 1.0f);
maxOrtho.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, 1.0f);
// Transform viewer's frustum slice points into light's eye space, then find mins and maxes
for(int j=0; j<8; j++){
	Matrix4f.transform(lightTransforms[i].view, tmpCamera.frustum.points[j].xyzw(), tmpVector);
	if(tmpCamera.frustum.points[j].x < minOrtho.x)
		minOrtho.x = tmpCamera.frustum.points[j].x;
	if(tmpCamera.frustum.points[j].y < minOrtho.y)
		minOrtho.y = tmpCamera.frustum.points[j].y;
	if(tmpCamera.frustum.points[j].z < minOrtho.z)
		minOrtho.z = tmpCamera.frustum.points[j].z;

	if(tmpCamera.frustum.points[j].x > maxOrtho.x)
		maxOrtho.x = tmpCamera.frustum.points[j].x;
	if(tmpCamera.frustum.points[j].y > maxOrtho.y)
		maxOrtho.y = tmpCamera.frustum.points[j].y;
	if(tmpCamera.frustum.points[j].z > maxOrtho.z)
		maxOrtho.z = tmpCamera.frustum.points[j].z;

Now what gives me headache is that I can't understand one thing. When I was writing graphics engine I used A code because shadows looked much softer than using B, but now I'm rewriting my graphics engine (old one was static and now I'm writing object-oriented) from scratch and now B gives better results than A, but I can't understand why?


I think myself that calculating min and max by fitting frustum into sphere and using that sphere radius is better solution, than finding min and max using frustum points. Maybe I did a mistake in A technique?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement