Rendering Light Geometry for Deferred Shading/Lighting

Interesting idea from Call Of Juarez 2 about rendering deferred light geometry. When deferred light geometry intersects with camera you need to switch culling and turn off zbuffer. In COJ2, instead of testing intersection on CPU and switching states, they just push out light geometry vertices:

// vertex shader
float3 posCS = mul( in.pos, worldToCamera ).xyz;
posCS.z = max( posCS.z, nearPlaneZ + offset );
out.pos = mul( float4( posCS, 1. ), cameraToScreen );

Could be a win if You are CPU bound.

This entry was posted in Graphics. Bookmark the permalink.

3 Responses to Rendering Light Geometry for Deferred Shading/Lighting

  1. Anonymous says:

    Thanks for the interesting bit. But why are you actually using the minimum? The coordinates are in clip space (0 >= z <= w) after the matrix multiplication, right? Or are you using GL conventions?


  2. KriS says:

    Thanks, I fixed example code. Now min/max is in camera (view) space (previously it was erroneously done in screen space).


  3. Anonymous says:

    Thanks for fixing this quickly, should be correct now.

    Another thing to be aware of when using this technique is that you also push forward light sources that are completely behind you. This should not be an issue though if you do proper frustum culling for lights.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s