Skip to main content
gamedev.net
🔒 Locked

Light Volume Rendering Optimization

Started by IMYT 0 replies 1.2k views
Original Post
IMYT
IMYT
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
gd3dDevice->SetRenderState(D3DRS_STENCILPASS,D3DSTENCILOP_KEEP);
[/font]
[font="Lucida Grande"][color="#333333"]Pass II[/font]
[font="Lucida Grande"][color="#333333"]
gd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW); //back face
gd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_ALPHA); //enable color write
gd3dDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_GREATEREQUAL); //z-test -> greater/equal
gd3dDevice->SetRenderState(D3DRS_STENCILREF, 0); //ref = 0
gd3dDevice->SetRenderState(D3DRS_STENCILFUNC,D3DCMP_EQUAL);
gd3dDevice->SetRenderState(D3DRS_STENCILZFAIL,D3DSTENCILOP_REPLACE); //always write zero to stencil
gd3dDevice->SetRenderState(D3DRS_STENCILFAIL,D3DSTENCILOP_REPLACE);
gd3dDevice->SetRenderState(D3DRS_STENCILPASS,D3DSTENCILOP_REPLACE);
[/font]

[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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.