Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
renderer: fix normalmap dark blotches #260
I discovered that bug while toying with
I was like:
As you can see the bug is also visible when diffuse and everything is rendered properly.
So I clamped normal Z component between 0 and 1… and magically the bug disappeared!
I don't know why this bug happens, and why this fix works, but it works. This is a fix I first discovered when I faced similar bug while generating normalmap from heightmap (see #258). This is why I implemented the fix after all the available ways to load normalmaps, and not only at the end of the Z reconstruction: the fix will be used later by normalmap generation too.
Note that an
Edit: the depicted texture is
In any way, it's good to have an engine that is able to automatically fix compression artifacts, even if we patch every software on the planet and beyond to not produce problematic compression artifacts.
That said, I'm not against a crunch fix if that's doable.
This GLSL code is downstream from texture decompression, so it doesn't matter how the image was obtained. You just get some RGBA values from 0 to 1.
So in the z-reconstruction case, the code would work regardless of the input texture format. And in the non-z-reconstruction case, there is no taking the square root of a possibly negative number, so the problem could never occur at all.