Sign in to follow this  

Light Volume Rendering Optimization

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]

[color="#333333"]Pass II:[/color]
[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;[/color]

[font="Lucida Grande"][size="2"][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:[/color][/size][/font]
[font="Lucida Grande"][size="2"][color="#333333"]Pass I[/color][/size][/font]
[font="Lucida Grande"][size="2"][color="#333333"][code]
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"][size="2"][color="#333333"]Pass II[/color][/size][/font]
[font="Lucida Grande"][size="2"][color="#333333"][code]
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"][size="2"][color="#333333"]After the light volume rendering pass I reset the z buffer and stencil buffer.[/color][/size][/font]

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this