# CSM min and max calculation for orthogonal projection

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

## 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

// Transform min and max vectors into light's eye space
Matrix4f.transform(lightTransforms[i].view, minOrtho, tmpVector);
minOrtho.assign(tmpVector);
Matrix4f.transform(lightTransforms[i].view, maxOrtho, tmpVector);
maxOrtho.assign(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);
tmpCamera.frustum.points[j].assign(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?

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013277
×