hello! I am having a hard time to setup combined normals on a triplanar shader. I have been able to reconstruct normals with RG and BA channels. Also setting up correct UV to make sure that the texture is correct wrapped. Now this causes that normals are flipped. I am super confused how to fix this. Anyone can shine some light on it?
You need to pass in special tangents and binormals for your triplanar maps. This took me a while to figure out. In the vertex shader: Code (csharp): fixed3 worldTangentXZ = float3( 1.0, 0.0, 0.0 ); fixed3 worldTangentY = float3( 1.0, 0.0, 0.0 ); // don't try to figure out tangents on flat surfaces if( abs( worldNormal.y ) != 1 ){ worldTangentXZ = normalize( cross( worldNormal, float3( 0.0, -1.0, 0.0 ) ) ); } if( abs( worldNormal.z ) != 1 ){ worldTangentY = normalize( cross( worldNormal, float3( 0.0, 0.0, -1.0 ) ) ); } o.tSpaceXZ = float4(worldTangentXZ.xyz, 0.0); o.tSpaceY = float4(worldTangentY.xyz, 0.0); o.bSpaceXZ = float4( normalize( cross( v.normal.xyz, worldTangentXZ.xyz ) ), 0.0); o.bSpaceY = float4( normalize( cross( v.normal.xyz, worldTangentY.xyz ) ), 0.0); In the pixel shader: Code (csharp): // make some mildly random uv coords float2 worldUVx = worldPos.zy * _Tiling.xy * 1.17; float2 worldUVy = worldPos.xz * _Tiling.xy * 1.37; float2 worldUVz = worldPos.xy * _Tiling.xy; // sample normal maps half4 worldNormalX= UnpackNormal( tex2D(_BumpTex,worldUVx) ); half4 worldNormalY= UnpackNormal( tex2D(_BumpTex,worldUVy) ); half4 worldNormalZ= UnpackNormal( tex2D(_BumpTex,worldUVz) ); // flip x on opposite side of mapping worldNormalX.x *= ( step( worldNormal.x, 0 ) * 2 - 1 ); worldNormalY.x *= ( step( worldNormal.y, 0 ) * 2 - 1 ); worldNormalZ.x *= -( step( worldNormal.z, 0 ) * 2 - 1 ); // the vertex normal that unity always passes in float3 vertWorldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z ); // convert normals to world space worldNormalX = ( worldNormalX.x * IN.tSpaceXZ.xyz ) + ( worldNormalX.y * IN.bSpaceXZ.xyz ) + ( worldNormalX.z * vertWorldNormal ); worldNormalY = ( worldNormalY.x * IN.tSpaceY.xyz ) + ( worldNormalY.y * IN.bSpaceY.xyz ) + ( worldNormalY.z * vertWorldNormal ); worldNormalZ = ( worldNormalZ.x * IN.tSpaceXZ.xyz ) + ( worldNormalZ.y * IN.bSpaceXZ.xyz ) + ( worldNormalZ.z * vertWorldNormal ); now you should have 3 normal maps facing the correct direcection.