Lighting artifact caused by Point Lights

Whenever I use any point lights in my scenes, I have discovered a very noticeable lighting artifact. When the pixel color output by the .frag shader (gl_FragColor) is a certain shade of gray, then you will begin to notice that point lights light up the entire geometry, even if the vertex is outside of the radius of the point light - and the artifact is worse for pixels as they become more gray.

I discovered the artifact using the fog library contributed by @jayfella , however after further testing, I was able to reproduce the issue by creating a .frag shader with a single line that sets gl_FragColor to a light shade of gray - so the artifact is not directly caused by the fog shader code (or any other specific shader, as i have reproduced the error with both the stock phong and stock pbr shaders)

So this lighting artifact is only apparent to the naked eye when the final pixel color is a light shade of gray, which is why I was only able to discover the issue by setting a high fog value and moving the camera far away.

Has anyone else who is using the fog library by @jayfella experienced anything similar when you set high fog values near point lights?

Note: we don’t know what that picture is supposed to look like so I’m not sure we can spot what’s wrong with it. Might need some additional pointers.

You might need to provide more information on that. If you have a frag shader with only a single line that sets gl_FragColor to gray then the whole object will be gray… you’ve bypassed all lighting at that point.

I should elaborate on this, and state that I did not actually create a new blank shader - but I bypassed the frag shader lighting in the PBRLighting.frag (and Lighting.frag as well) shader by adding gl_FragColor.rgb = vec3(0.3); as the very last line in the shader, with the intention of simulating the same colors that appear from heavy gray fog, in order to rule out Jayfella’s fog library as the cause.

Here is a (hopefully) better video showing the artifacts, as well as a comparison screenshot showing how the map normally looks in the same area, and a second screenshot that shows how it looks if i turn off fog and hardcode the shader to make the terrain and trees gray.

At the start of the video, you can see a purlple point light up close - then I zoom out and show the lighting effects from multiple point lights scattered around the map. Then at the end of the video, I cast a spell that spawns a small blue point light for a short duration, and you can see that it lights up the entire 256 size terrain patch until it despawns and the light is removed. It also looks like multiple point lights overlapping a single geometry will cause an even more drastic whitening effect to the entire geometry. And it also flickers at times, depending on the camera angle and position.

How the scene normally looks with point lights and no fog
https://i.imgur.com/jWutf2a.png

Here is a screenshot showing the reoccurence of the error when I turn off fog, and instead add gl_FragColor.rgb = vec3(0.3); to the end of the shaders (tested on terrain, tree, and leaf shaders) to simulate a similar color that fog naturally causes at far distances.
https://i.imgur.com/dnKwUqW.png

So it does seem as though some type of post fragment shader lighting is occurring from my findings so far, but it is only apparent to the naked eye when the output pixel is a very light gray or close to white.

I’m still kind of confused. If you put that line in your shader then the whole object is going to be the same color. Near, far, middle… all the same color. Lighting was overridden.

As for the video, I’m still making a lot of assumptions about what I’m seeing but I’d be curious to know what the radius of the point light was, etc… is it just a child of that area of the map and so on. Single pass lighting or multipass lighting?

1 Like

All of the point lights in the example video have a radius of less than 20.

The point lights are all attached to the rootNode in my game.

I also am using single passing (or I atleast believe this to be the case, as all of my PBR shaders im using have

LightMode SinglePassAndImageBased

in their .j3md file

This was also what I thought should happen, but the only way to get those results is if I remove the point lights.

But there appears to be some full-geometry lighting occuring on parts of the geometry that are not within the set radius of the point light. And the lighting effect seems to stack as more lights overlap a terrainPatch or geometry, resulting in some terrain patches being brighter or darker than others.

Heres an edited version of the last screenshot, where I circled the position of each point light, and wrote a number on each terrain patch to designate how many point lights have that patch caught in their radius (even if it is only 1 vertex).

https://i.imgur.com/kHopkgi.png

Strange in many ways.

Fog density is calculated by the distance from the camera - but in your screenshot it appears as if the distance calculation is wrong from material to material. It actually looks like the distance is fixed across the entire geometry.

Out of interest, what are your near and far frustum values? Does the issue go away when you set near to say 1 and the far to 1000?

That screenshot was actually taken without using fog - I just hard coded my shaders with gl_FragColor.rgb = vec3(0.3); to demonstrate how the effect occurs even without using fog.

So the error is not directly caused by your fog library - the artifact seems to occurr whenever the final fragment shader output color is a shade of gray close to white - or whenever there is a lot of fog.

The video I posted above shows in more detail how the artifact occurs when I am using fog.

Sorry You ninja’d me. Please read the post above about frustum distances.

1 Like

I tried setting the near and far frustum values to these, and the lighting artifact still occurrs.

I also think I may have mislead you with my screenshot, as that was a screenshot taken when I turned fog off, and instead simulated the color by hard coding the shader. The issue is not caused by any of your fog code, but appears to be a byproduct of the near-white gray color that fog naturally becomes at far distances.

In this video I posted where I am using fog, it appeared (to my knowledge) as though the fog was rendering properly on a few terrain patches, but is causing the artifact on patches or geometries near point lights. At the very end of my video, you can see the fog intensity flicker for the entire terrain patch when the light is removed.

Bumping to see if anyone else has experienced this bug once more, before I move on to finding an indirect workaround.

I am unsure if others are unwilling to trust that I’ve actually found a major bug with point lights, and instead think I am just doing something wrong - but if anyone has any interest I will gladly make a test case for you to run to confirm if it is indeed a bug.

I also suspect that this bug is diminishing the results of normal maps and AO maps to a degree that is very subtle, as these both frequently result in fragment shaders outputting pixel colors that are within the grayscale range that receives improper lighting from point lights post frag shader.

If it is a bug then that’s the single quickest way to get it fixed… make a simple test case.

Also it would help you confirm that it is not something specific to your setup.

1 Like