Trying to implement normal map in my custom lighting pipeline I use for my game's shaders. I'm NOT using shader graph (for multiple reasons that are completely irrelevant to this post) so keep that in mind.
I'm using triplanar mapping for this specific shader, and I use this to triplanar map the normal map:
float3 wall_normal = triplanar_normal(IN.positionWS,IN.normalWS,_BumpMap,1.0,_RockTexture_ST.xy, IN);
triplanar_normal is just a reimplementation of the shader graph node using the code from the documentation https://docs.unity3d.com/Packages/com.unity.shadergraph@6.9/manual/Triplanar-Node.html
float3 triplanar_normal(float3 position, float3 normal, sampler2D t, float blend, float2 tile, Varyings IN)
{
float3 node_uv = position * float3(tile.xxx);
float3 node_blend = max(pow(abs(normal), blend), 0);
float3 node_x = UnpackNormalmapRGorAG(tex2D(t, node_uv.zy));
float3 node_y = UnpackNormalmapRGorAG(tex2D(t, node_uv.xz));
float3 node_z = UnpackNormalmapRGorAG(tex2D(t, node_uv.xy));
node_x = float3(node_x.xy + normal.zy, abs(node_x.z) * normal.x);
node_y = float3(node_y.xy + normal.xz, abs(node_y.z) * normal.y);
node_z = float3(node_z.xy + normal.xy, abs(node_z.z) * normal.z);
float4 Out = float4(normalize(node_x.zyx * node_blend.x + node_y.xzy * node_blend.y + node_z.xyz * node_blend.z), 1);
float3x3 node_transform = float3x3(IN.tangentWS, IN.bitangentWS, IN.normalWS);
Out.rgb = TransformWorldToTangent(Out.rgb, node_transform);
return Out;
}
In my vertex shader, I calulate the world space tangent, bitangent, and normal like this:
half3 wNormal = normal_inputs.normalWS;
half3 wTangent = normal_inputs.tangentWS;
half3 wBitangent = normal_inputs.bitangentWS;
OUT.normalWS = wNormal;
OUT.tangentWS = wTangent;
OUT.bitangentWS = wBitangent;
I then mix the normals like this:
lerp(IN.normalWS, wall_normal, mask)
The results from this look incorrect (this is the result from a simple NDotL calculation w/ the scene's directional light) and I'm not entirely sure why.