Advertisement Jump to content
Sign in to follow this  

Light Volume Rendering Optimization

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

Hi everyone:

I saw an optimization for light volume rendering online and tried implementing one by myself. The basic idea of that algorithm is culling all the lights which are either invisible or having no influence on the surface. It is a two pass algorithm with the following state changes:

Pass I:
[color="#333333"]- Front faces only;
- Colour write disabled;
- No Z-write;
- Z function = Less/Equal;
- Z-Fail writes non-zero value to stencil buffer (increment-saturate);
- Stencil pass & fail don’t modify stencil buffer;

[color="#333333"]Pass II:
[color="#333333"]- Back-faces only;
- Colour write enabled;
- No Z-write;
- Z function = Greater/Equal;
- Stencil function = Equal (stencil ref = zero);
- Always writes zeo to stencil;

[font="Lucida Grande"][color="#333333"]But when I implemented the algorithm, I got a black screen. I think the algorithm itself is correct but I do not know what is wrong with my code. Here is my code for state changes:[/font]
[font="Lucida Grande"][color="#333333"]Pass I[/font]
[font="Lucida Grande"][color="#333333"]
gd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); //front face
gd3dDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL); //z-test -> less/equal
gd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,0); //disable color write
gd3dDevice->SetRenderState(D3DRS_STENCILREF, 1);
gd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false); //disable z write
gd3dDevice->SetRenderState(D3DRS_STENCILZFAIL,D3DSTENCILOP_REPLACE); //replace if z fails
gd3dDevice->SetRenderState(D3DRS_STENCILFAIL,D3DSTENCILOP_KEEP); //otherwise keep stencil buffer value unchanged
[font="Lucida Grande"][color="#333333"]Pass II[/font]
[font="Lucida Grande"][color="#333333"]
gd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW); //back face
gd3dDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_GREATEREQUAL); //z-test -> greater/equal
gd3dDevice->SetRenderState(D3DRS_STENCILREF, 0); //ref = 0
gd3dDevice->SetRenderState(D3DRS_STENCILZFAIL,D3DSTENCILOP_REPLACE); //always write zero to stencil

[font="Lucida Grande"][color="#333333"]After the light volume rendering pass I reset the z buffer and stencil buffer.[/font]

[font="Lucida Grande"][color="#333333"]Could anyone please tell me what is wrong with the above code?[/font]
[font="Lucida Grande"] [/font]
[font="Lucida Grande"][color="#333333"]Note: DrawFont is also not working after the above state changes.[/font]

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!