I’ve got a tri-planar shader in my game, that applies diffuse and normal maps to an object based on fragment position and normal. The code of the shader is at pastebin.com/ySFYG5Ka .
The shader takes the incoming fragment position and uses the X and Z coordinates to calculate a texture coordinate for the detail textures and normal maps. Then it uses the normal to blend between three mappings of the detail shader, projecting the detail along each of the 3 axes. So far, it has worked well.
My issue now is that I am attempting to provide a variation of the shader that combines the detail normal map with a model-specific normal map. In the shader code posted above, I have enclosed the model-normal specific sections in #ifdef MODELNORMAL blocks, with the MODELNORMAL being defined in the technique. For objects that want to use the model’s normal map, I use a technique with MODELNORMAL defined, and provide a normal
The problem is that, while the shader works as expected with MODELNORMAL undefined, when MODELNORMAL is defined, somehow the fog coordinate gets stomped on. Here is a shot of the shader with MODELNORMAL not defined:
http://i.imgur.com/R6QD7El.jpg
Here is a shot with MODELNORMAL defined:
http://i.imgur.com/yieq5Ur.png
You can see that in the second shot, the mountain model has the detail from its normal map, as well as the detail from the detail texture. However, the fog color is incorrect. The fog shading on the model stays constant, regardless of distance from the camera.
I have tried using TEXCOORD11 and TEXCOORD9 semantics for the input model normal, with no change. I’m not really a graphics programmer or shader expert, so I’m not really sure how to fix this, or even what exactly is going wrong. Anyone have any ideas?