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.
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?
LikeLike
Thanks, I fixed example code. Now min/max is in camera (view) space (previously it was erroneously done in screen space).
LikeLike
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.
LikeLike