# Is frustum corner calculation used in all forms of deferred shading?

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

## Recommended Posts

There are lots of posts on this forum and elsewhere about calculating frustum corners in order to reconstruct position when doing deferred shading. Most of these examples also tend to render the final result to a fullscreen quad. Which makes sense, as the quad corners match up to the frustum corners you just calculated.

But what if you are rendering your lighting using a light volume rather than a quad? Do you still need to calculate the frustum corners to extrapolate position in view space, or can you use the position of the light volume itself to accomplish this?

I've seen people hint at being able to use some other method when using light volumes instead of fullscreen quads, but I haven't been able to find what it is...

##### Share on other sites
All you really need in most cases is the direction from the camera to the pixel, either in world space or in view space. With a full screen quad you can directly map the quad vertices to the frustum corners, and interpolate that. With a volume you can instead transform vertex positions to view space, interpolate that, and then normalize to get the ray direction in view space. You can also transform the coordinates to world space, subtract the camera position, and then interpolate that vector to get the ray in world space. You can even calculate the view-space ray direction from the pixel coordinates, if you know a bit about the projection and the size of the viewport. I go through all of the math (with shader code) in this blog post. Anything with the #if PointLight || SpotLight is meant for use with a spherical or conical bounding volume rather than a full screen quad.

On a side note, if you're using D3D10 or higher you can disable perspective-correct interpolation for any vertex shader output. This lets you interpolate in screen space, which means you can do anything you would do with a fullscreen quad with a 3D light volume.

##### Share on other sites

I go through all of the math (with shader code) in this blog post. Anything with the #if PointLight || SpotLight is meant for use with a spherical or conical bounding volume rather than a full screen quad.

Thank you for your reply, and for the awesome blog post! After reading it for probably the 10th time, I think it is starting to click. There is just one point that is vague to me. In each of your shader examples, you have a line that samples from the distance buffer:

float normalizedDepth = DepthTexture.Sample(PointSampler, texCoord).x;
What coordinates is texCoord set to? I assume it is not the vertex texture coordinates of the light volume surface. And I'm assuming it isn't the screen space coordinates of the current pixel, since we're doing everything in view space. You don't talk about calculating any texture coordinates, so I'm uncertain where you get those coordinates from.

##### Share on other sites
It's the UV coordinate computed from the screen space pixel coordinate. So screenPos.xy / RenderTargetSize. You could also just use Load, and pass the pixel coordinates directly (if you're using D3D10). By sampling the depth buffer at the pixel that you're shading, you essentially get the view-space depth Z of of the ray going from the camera to the pixel. Then with a little math you can get the length of the ray, which is what you use to calculate the final pixel position.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 44