I’ve asked more questions about this darned shader on the internet in the past couple weeks than I have about just about anything in the last several years. Anyway…
As I have posted about before, I am using a custom tri-planar shader in my RPG game, to apply terrain textures from a texture array to terrain geometry. Shortly before my Windows installation died, I had converted the tri-planar shader to a “quad”-planar shader; ie, a variant that projects the terrain textures against the top/bottom and against all 6 sides (1 projection per 2 sides) of a hexagonal cell. The shader was working quite well on D3D11 before the crash. I talk about it at gamedev.net/blog/33/entry-22 … rojection/ and include some screenshots. I had not yet gotten around to modifying it for OpenGL before the crash (the original tri-planar version was working well, though). Also, there have been some changes involving lights (the addition of normal bias to shadowing) committed since I last was able to test the shader on D3D11.
Here I am post-crash, and the world has changed completely. I am now developing on Linux and OpenGL. Managed to get everything building correctly, but now I have an issue with lights with my shader. The shader projects both a diffuse map and a normal map against the geometry, and the normal map is used as a tangent-space normal map on the object. However, whenever normal-mapping is enabled in the shader, I get incorrect lighting from both point and directional lights.
Here is a shot with diffuse set to gray, and with normal-mapping disabled:
As you can see, the lighting is correct.
Here is a shot with gray diffuse, but with normal-mapping enabled:
It looks as if the normals on the cap geometry are inverted for 1/2 of the light radius.
Here is a more distant above shot:
The strange thing is that the vertical portion of the hex cell receives lighting correctly. Also, if I enable translucent on the shader, then I get a result that is nearer to what I expect, albeit with a dimly-shaded bar through the center of the light:
Note that in the original case, the directional light does not illuminate the hex cap geometry, but in the translucent version it does. When diffuse is not set to gray, the diffuse component maps correctly to the geometry, and with normal-mapping disable, the result looks pretty good.
I’ve gone through the shader multiple times trying to figure this out. I’ve re-exported the geometry multiple times, played with the normals, etc… Just can’t seem to figure out what’s going wrong.
I’ve put together a small example demonstrating the behavior, which can be found at drive.google.com/file/d/0B_HwlE … sp=sharing
I have seen that it is not necessarily a problem with my quad-conversion; the original tri-planar shader for GLSL also exhibits the behavior; that version was working correctly under Windows/OpenGL.
If anyone can see something I’m missing, I’d appreciate it. And sorry for spamming the forum with questions about this thing.