Recently been trying to implement volumetric lighting. The alphaness texture comes out perfectly on Renderdoc, however a strange glitch occurs whenever I either try to directly render the texture through a quad to the screen, or through multiplying the alphaness component with my regular texture. A strange static pattern (as shown in the image below) appears on the texture. The texture also periodically turns completely black, and in some frames the image comes out perfectly.

The volumetric lighting texture is rendered to a framebuffer with the settings below:

The fragment shader which samples from the god rays texture (my HDR shader) is shown below. When I comment out the * texture(godRaysTex, TexCoords).r it renders perfectly, however without the god rays.

1 Answer
1

Through trial and error I spotted the issue. I was using the output variable FragColor in my god rays shader to perform the calculations. As a result, OpenGL probably would think a fragment was finished being written to on its first assignment, while it was in fact in the process of a calculation in the loop.

Changing FragColor += occlusionSample; into color += occlusionSample;, where color is a vec4 defined in the scope of the main() and then setting FragColor = color at the end of the calculations solved the issue.