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

Started by
1 comment, last by neoragex 7 years, 9 months ago

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!

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.

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? :)

This topic is closed to new replies.

Advertisement