Advertisement

find point between two points which intersects with plane

Started by January 11, 2018 03:29 PM
1 comment, last by recp 7 years, 1 month ago

I want to split view frustum for shadows mapping ( CSM/PSSM ). I need to get corners of each frustum split. I already have 8 corners of view frustum and view frustum planes. So I thought that maybe I don't need to create new invViewProj matrix and get corners using clip space method, it is too expensive ( for each split )

To get center of two point/vector we use this: center = ( V1 + V2 ) * 0.5

So, using same information could give us splitted frustum corner by this:

newNearTopLeft = ( nearTopLeft + farTopLeft ) * ( near / planeDistance ) /* this plane is between far and near points */
/* repeat this for each 8 corner  */

Does the math correct? If it is correct then this will save my engine from many calculations

I think I found it! Here the code it may help someone else who don't want to use re-extract new frustum corners to split frustum.

v                       = normalize(Far - Near)
d                       = distance(Far, Near)
size                  = d * C / Far
newCorner.    = nearCorner + v * size
 

Code:


/* this is for one point between NEAR and FAR planes, others get calculated same */

vec3  corner;
float dist;

dist = glm_vec_distance(corners[j + 4], corners[j]);
glm_vec_sub(corners[j + 4], corners[j], corner);
glm_vec_scale_as(corner, dist * C / f, corner);

glm_vec_add(corners[j], corner, subFrustum.corners[j + 4]);

 

This topic is closed to new replies.

Advertisement