Adding Normalmap to shader

Hi! I have this shader:

Shader "Custom/WallB" 
{
    Properties {
        _Color ("Color", Color)     = (1,1,1,1)
        _MainTex ("Base Color", 2D) = "white" {}
        _BumpMap ("Normal Map", 2D) = "bump" {}
        _UVs ("UV Scale", float)    = 1.0
        _Offset ("Offset", Vector)  = (0,0,0,0)
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
        CGPROGRAM
        #pragma surface surf StandardSpecular fullforwardshadows
        #pragma target 3.0
        sampler2D _MainTex;
        sampler2D _BumpMap;
        fixed4 _Color;
        float _UVs;
        float4 _Offset;
        struct Input {
            float2 uv_MainTex;
            float2 uv_BumpMap;
            float3 worldPos;
            float3 worldNormal;
            INTERNAL_DATA
        };
        UNITY_INSTANCING_BUFFER_START(Props)
        UNITY_INSTANCING_BUFFER_END(Props)
        void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
            float3 Pos = (IN.worldPos + _Offset) / (-1.0 * abs(_UVs));
            float3 c1 = tex2D(_MainTex, Pos.yz).rgb;
            float3 c2 = tex2D(_MainTex, Pos.xz).rgb;
            float3 c3 = tex2D(_MainTex, Pos.xy).rgb;
            float alpha21 = abs(IN.worldNormal.x);
            float alpha23 = abs(IN.worldNormal.z);
            float3 c21 = lerp(c2, c1, alpha21).rgb;
            float3 c23 = lerp(c21, c3, alpha23).rgb;
            o.Albedo = c23 * _Color;

            float3 normalTex1 = UnpackNormal(tex2D(_BumpMap, Pos.yz));
            float3 normalTex2 = UnpackNormal(tex2D(_BumpMap, Pos.xz));
            float3 normalTex3 = UnpackNormal(tex2D(_BumpMap, Pos.xy));
            float3 normal21 = lerp(normalTex2, normalTex1, alpha21);
            float3 normal23 = lerp(normal21, normalTex3, alpha23);
            //o.Normal = normalize(normal23);
        }
        ENDCG
    }
    FallBack "Mobile/VertexLit"
}

And when I uncomment //o.normal side walls don’t work properly.


I would be happy if someone would fix this. I completely can’t understand shaders, and maybe shader graph could be better, but then I would need to change everything in project, and I don’t want to do it especially when I want to publish this on mobiles so I want to keep things simple.

Hi, the problem might be because you are using all 3 normals on each side of cube. and this stripes can be result of sampling normal which mustn’t be used on this side of cube. So probably one of the solutions i see here is to sample the right normal map according to existing normals of this mesh.
Here is an example on how to implement such thing: https://www.gamedev.net/blogs/entry/2250761-triplanar-texturing-and-normal-mapping/

This is too hard for me. Im reading this and even don’t know if this is my case :frowning:

I tried with copilot with different results, some of them work, some not. If one wall is correct, another not :smiley: last thing what i would do is to divide walls to planes, and give them different materials… but this is some option. But maybe someone want to try himself making one, good working shader? :wink:
Im surprised, that noone ever was in need with similar shader.