Playing around with God-Rays in my framework, I was greeted with the following artifacts on my laptop:


The artifacts themselves act almost like noise, flickering around the image rapidly. They also appear in colors that are not in the source image whatsoever.

Running the program on a PC yielded the correct results with no artifacts whatsoever. The program also experienced the same artifacts on another identical laptop (these laptops are distributed by my faculty, so they are going to be as identical in hardware and software as you can get).

I'm just not sure how to approach an issue like this one. I imagine the source of this issue will be very tricky to find, so I am just hoping someone can offer some advice to put me on the right track to isolating the issue.

Some potential clues:

  • In Nvidia's Nsight frame capture system, the artifacts are not static! Even though I should be viewing a "screenshot" of the current frame-buffer, the artifacts are still dynamic and moving around like noise on an old TV.
  • Multiplying the final result of the GodRay directly influences the amount of artifacts. If multiplied by zero, they no longer appear.
  • The seam between the two triangles of the full-screen quad can be seen running from the top left to the bottom right.
  • I have up to date Drivers. Version 347.52 on the NVS 5400M. I have also tried 347.25, but there was no difference.
  • OpenGL is not generating any errors
  • I am using an OpenGL 4.5 Core profile
  • I have never had any graphical issues in other programs running on my laptop.

Fragment Shader

#version 450 core
#define NUM_SAMPLES 128

uniform float Exposure;
uniform float Decay;
uniform float Density;
uniform float Weight;
uniform vec2 LightPositionOnScreen;
uniform sampler2D uTex;

in vec2 texcoord;

out vec3 outColor;

void main()
    vec2 texCoord = texcoord;
    vec2 deltaTextCoord = LightPositionOnScreen - texcoord;
    deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * Density;

    float illuminationDecay = 1.0;

    for (int i = 0; i < NUM_SAMPLES; i++)
        texCoord += deltaTextCoord;
        vec3 tap = texture(uTex, texCoord).rgb;
        tap *= illuminationDecay * Weight;

        outColor += tap;

        illuminationDecay *= Decay;

    outColor *= Exposure;

Thanks for taking the time to read my post! I will update if the source of the issue is found.

Edit: Issue solved by: chipgw

Initializing outColor to vec3(0.0, 0.0, 0.0) before the loop removed the artifacts.

  • \$\begingroup\$ What's your depth value and depth-clear? \$\endgroup\$ Feb 17 '15 at 0:17
  • \$\begingroup\$ Depth had been working correctly, and had been cleared to 1.0. I was able to confirm this with Nsight. \$\endgroup\$ Feb 17 '15 at 4:36

My first thought is the += to an uninitialized outColor. I think it'd be better to do the math on a temporary variable and put it in outColor once it's done.

  • 1
    \$\begingroup\$ Good catch! That instantly fixed it! That won't be a mistake I make again :P \$\endgroup\$ Feb 17 '15 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.