• Advertisement
Sign in to follow this  

How To Calculate The World Area For The Texel Of A Shadow Map

This topic is 641 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

Is there anybody knows how to calculate the area of world coordinates for one texel in a shadow map (for dir-light or spot-light)? I just remember some paper has given some MAGIC formula to calculate this, such as:

 

float calculateSurfelAreaLight(vec3 lightPos)
{
    return (4.0 * lightPos.z * lightPos.z * f_tanFovXHalf * f_tanFovYHalf) / (i_RSMsize * i_RSMsize);
}

 

But i can't find the full induction process about its formula. How can I get this induced formula? What is the relationship between the area and the light-fov? Any suggestions or paper-references about this would be greatly appreciated!

Edited by neoragex

Share this post


Link to post
Share on other sites
Advertisement

The process is to figure out the size of the projection window in world space (the part of your projection matrix's projection plane which makes up your shadow map) and then divide by texel count in x and y direction.

 

You can do this analytically (draw diagrams and do the math) or you can get the four intersection points (although you only need the 'upper left' and 'lower right' ones) of the projection plane with the lines of the view frustum running through it and transform them with the inverse of your viewProjection matrix which the lights use, and figure out width/height from those.

Share this post


Link to post
Share on other sites

The process is to figure out the size of the projection window in world space (the part of your projection matrix's projection plane which makes up your shadow map) and then divide by texel count in x and y direction.

 

You can do this analytically (draw diagrams and do the math) or you can get the four intersection points (although you only need the 'upper left' and 'lower right' ones) of the projection plane with the lines of the view frustum running through it and transform them with the inverse of your viewProjection matrix which the lights use, and figure out width/height from those.

 

Thanks for your hints @agleed! Your reply about projection window makes the answer far more clear. But maybe I still find some little bugs in the explanation.

 

I do think that the world area relative to a single texel in a shadow-map may not be constant, considering the perspective projection. It depends on the linear depth (in the light's coordination system) for every single texel in the shadow map. So the 'lightPos.z' in above code does not stand for the distance between the light and a FIXED PROJECTION WINDOW. It is the linear depth (in the light's coordination system) for its corresponding texel in the shadow map.

 

What do you think? :)

Edited by neoragex

Share this post


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

  • Advertisement