<p>I wrote a simple Phong shader with two directional lights for a project, and noticed an unpleasant artifact in the lighting. Where both lights are illuminating the same region, dark bands appear at the light terminators where N.L reaches zero. At first I thought it must be a bug in my code, but a quick test revealed the Unity standard shader has the exact same problem.</p>

<p><a href="https://i.sstatic.net/RKu8H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RKu8H.png" alt="my shader"></a>
<a href="https://i.sstatic.net/YJesJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YJesJ.png" alt="unity shader"></a></p>

<p>My best guess is that this is some form of the Mach effect, and our retinas are overshooting where the brightness plateaus. Does anyone know any tricks to mitigate this effect?</p>

<p>EDIT FOR CLARITY:</p>

<p>Here are two more images to illustrate the effect better - one with my shader, and one with Unity's diffuse shader, with the lights at 90 degrees and all specular and ambient contributions removed. </p>

<p><a href="https://i.sstatic.net/Dyaw5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Dyaw5.png" alt="mine"></a><a href="https://i.sstatic.net/T5PCZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/T5PCZ.png" alt="unity"></a></p>

<p>You can clearly see the dark bands around the top right quadrant where one light's terminator intersects the other's area of effect (well, I can anyway, YMMV). I've run an eyedropper over it and confirmed it's a perceptual effect, the pixels do not in fact get darker.</p>

CC BY-SA 3.0
2017-12-20T12:46:38.250Z
Is it rendered in linear colour space ?
PaulHK
CC BY-SA 3.0
2017-12-20T13:28:43.523Z
Do you actually have two lights 180 degrees apart? It *should* get dark at the light terminator but it wouldn't normally get light again on the other side unless you have two-sided lighting turned on and shadows turned off, or two lights on opposite sides.
Dan Hulme
CC BY-SA 3.0
2017-12-20T13:32:58.507Z
PaulHK, tried it with both and the effect persists, although it's a little less pronounced in linear.
russ
CC BY-SA 3.0
2017-12-20T13:35:01.193Z
Dan, check out the pics. The lights are more like 60 degrees apart, the problem is when one light's contribution reaches zero, it appears to have a negative contribution to the other light - probably just a perceptual artifact but still annoying.
russ
<shader><artifacts>
Avoiding Mach band effect when using multiple lights
russ
# Avoiding Mach band effect when using multiple lights

(Asked by: username_0 on 2017-12-20)

I wrote a simple Phong shader with two directional lights for a project, and noticed an unpleasant artifact in the lighting. Where both lights are illuminating the same region, dark bands appear at the light terminators where N.L reaches zero. At first I thought it must be a bug in my code, but a quick test revealed the Unity standard shader has the exact same problem.

[![my shader](https://i.sstatic.net/RKu8H.png)](https://i.sstatic.net/RKu8H.png)
[![unity shader](https://i.sstatic.net/YJesJ.png)](https://i.sstatic.net/YJesJ.png)

My best guess is that this is some form of the Mach effect, and our retinas are overshooting where the brightness plateaus. Does anyone know any tricks to mitigate this effect?

EDIT FOR CLARITY:

Here are two more images to illustrate the effect better - one with my shader, and one with Unity's diffuse shader, with the lights at 90 degrees and all specular and ambient contributions removed.

[![mine](https://i.sstatic.net/Dyaw5.png)](https://i.sstatic.net/Dyaw5.png)[![unity](https://i.sstatic.net/T5PCZ.png)](https://i.sstatic.net/T5PCZ.png)

You can clearly see the dark bands around the top right quadrant where one light's terminator intersects the other's area of effect (well, I can anyway, YMMV). I've run an eyedropper over it and confirmed it's a perceptual effect, the pixels do not in fact get darker.

**Tags:** shader, artifacts

> **Comments:**
> **username_1**: Is it rendered in linear colour space ?  
> **username_2**: Do you actually have two lights 180 degrees apart? It *should* get dark at the light terminator but it wouldn't normally get light again on the other side unless you have two-sided lighting turned on and shadows turned off, or two lights on opposite sides.  
> **username_0**: username_1, tried it with both and the effect persists, although it's a little less pronounced in linear.  
> **username_0**: Dan, check out the pics. The lights are more like 60 degrees apart, the problem is when one light's contribution reaches zero, it appears to have a negative contribution to the other light - probably just a perceptual artifact but still annoying.  

---

## 0 answers

