Wednesday, June 8, 2011

Screen-Space Ambient

Currently, I'm still doing a lot of this using multiple forward-rendering geometry passes, when they could instead be using screen-space techniques. I have done this so far as the performance for what I'm trying is fine, and it aids debugging greatly to be able to easily turn off entire passes.

However since the lighting was added in, with arbitrary numbers of lights (5 shadow-mapped lights now being used), then engine has slowed down greatly. Time to revisit the render channels.

Ambient Lighting is an obvious task here. Currently, I draw the depth/normals map, create the ambient cube map, calculate SSDO, and then - using forward-pass geometry - draw the ambient lighting into the scene, looking up SSDO and the ambient cube map.

However the screen-space data is all there ready to be used - screen space normals and SSDO. Additionally, the screen-space fogging that fades the scene out to the ambient cube map is almost identical to what I want to do. So hell, let's do it!

Adding Screen-space Ambient

1. Add a new RenderChannel and generateSSAmbient() to CameraScene.py
2. Create data/screen_space_ambient.xml - copied from data/fog.xml as the effect is similar
3. Create shaders2/post/ssambient.vs3 and .ps3

NOT SURE WHY : can't blend in the SSDO results in texture stage 3. Just cant seem to be able to read the texture map

4. Remove old ambient lighting path

Difference
==========
old way : 3098 / 34134 draw commands 99.1msec
new way : 2564 / 31921 draw commands 89.9msec

Apart from the issue mentioned above, the new screen-space ambient lighting looks exactly like the old forward-render ambient lighting, except the number of draw-calls drops by about 20% and the render time drops by 10%. And there are many more instances of this kind of rendering optimisation just waiting to be done..

1 comment:

  1. As usual with DirectX issues, turning on DirectX Debug highlights the cause of the problem. When Vertex Shaders are in use, the tex coord index must equal the stage. Fixing this issue fixed the problem setting the SSDO texture on stage 3.

    ReplyDelete