Ambient occlusion and dynlight shaders with point light math
Posted: Sat Sep 24, 2016 19:50
Pull request: https://github.com/coelckers/gzdoom/pull/112
Okay, here's the 'lightmath' branch as a PR. As it is a little big I'll try summarize what it is changing:
Okay, here's the 'lightmath' branch as a PR. As it is a little big I'll try summarize what it is changing:
- Adds three new settings in the menus. A light math setting for the dynamic lights, and two for configuring the SSAO pass.
- Renames FShaderManager to FShaderCollection and adds a new FShaderManager class. The purpose of this is to allow two families of scene shaders: normal shaders that only output to a single color buffer, and gbuffer shaders that use multiple render targets (MRT). This is needed by the AO pass to get the fog information for each pixel into a second color buffer.
A bonus of this change is that it will enable the post processing shaders to get a more natural home in the future instead of being members of FGLRenderer. I'll probably make a follow up PR at some point where I move all the post processing shaders to be members of FShaderManager. That would mean that any kind of shader would always come from the shader manager (like it did in the past). - Changes the dynamic light position in the storage buffers uploaded to the GPU to be in eye/view coordinates instead of world. This is to simplify the math a bit in the main.fp shader.
- Moves the dynamic light position a bit upwards. This is needed for flasks/vials that have their current center beneath the floor, but I'm not sure if the way I did it is a good way to deal with it. Maybe the lights.pk3 just needs to be fixed. Suggestions here are very welcome as it feels like a bit of a hack to just move them up in the code where I'm doing it (in gl_GetLight).
- The SSAO pass itself runs as part of FGLRenderer::DrawScene. It sets up the shaders for MRT output, then draws the opaque stuff, then applies SSAO on top, switches back to normal shaders, and draws the transparent and portals. For each portal with SSAO it does the same thing. For performance reasons I added a gl_ssao_portals setting that controls how many portals it will do it for and allowed the user to adjust it in the menus. The portals.wad is very good for testing the trade off here between frame rate and visuals.
- In GLPortal::End it outputs 0 into the alpha channel using a slightly modified stencil.fp. That allows the SSAO shader to know which pixels it should ignore the depth information with and is the primary way it avoids ssao'ing the sky geometry. We can make the primary main.fp also output 0 in the alpha channel if we have some parts of the scene that we don't want to be "seen" by the AO pass.
- I left a comment in the code for main.fp saying what needs to be remarked/changed to start using model normals, when those become available.