Wrong normals when object is rotated and using custom world aligned shader?

I have a little problem with my custom world aligned shader. It uses world position as UV for normalmap. This is probably the reason is misbehaves. When I rotate the object it flips rotation of normal map. Is there a way to fix this? I’m using Unity 5.4b10.

My code for normal:o.Normal = UnpackNormal(tex2D(_NormalTex,IN.worldPos.xz));

same problem…

Any news to solve it?

Yes, go into photoshop, go into channels tab, select green channel and press ctrl+i to invert it.

…Revert and try other channels if doesn’t work

Without looking at your shader code I am not sure where it is breaking. When trying to implement my own world map shader I found two places where my normals were getting messed up. I’ll try my best to explain my two errors, and what I did to fix them. From your screenshots, I think it is issue 2. @IgorAherne, this would work, but if the object gets rotated back the normals will be flipped again.

  1. In my implementation, I was using a series of floor pieces that snapped together, but when I rotated any piece the lighting on the normals would not rotate. My coworker found this post very helpful in fixing this issue: Forum post, specifically this section of code:

                // reorient normals to their world axis
                xNorm = xNorm.zyx; // hackily swizzle channels to match unity "right"
                yNorm = yNorm.yzx; // hackily swizzle channels to match unity "up"
                zNorm = zNorm.xyz; // no swizzle needed
     
                // blend normals together
               normal = xNorm * projNormal.x + yNorm * projNormal.y + zNorm * projNormal.z;
    
  2. After fixing issue one I realized that on any given cube the normals would be correct on all the positive sides, and incorrect on all the negative sides. I fixed this by doing some preprocessing on the normal data to make all the normal directions positive. When I combined the x, y, and z channels I used the absolute normals to calculate the red, and green channels of the normal map, but the initial normal direction to get the blue channel. If we used the absolute normal directions for the blue channel as well lighting would be flipped.