Shader produces bad texture

Viewed 40

I'm trying to make a shader that will draw a tile on the roof (a mesh object generated point by point in the code).

It looks pretty good on the CUBE, but it's very bad on my mesh.

What am I doing wrong?

For the tile I have:

  • texture
  • height map
  • normal map

Code:

Shader "Custom/RoofShader"
{
    Properties{
        _MainTex("Texture", 2D) = "white" {}
        _BumpMap("Bumpmap", 2D) = "bump" {}
    }

        SubShader{
            Tags { "RenderType" = "Opaque" }

            CGPROGRAM
            #pragma surface surf Standard

            sampler2D _MainTex;
            sampler2D _BumpMap;

            struct Input {
                float3 worldNormal;
                float3 worldPos;
                float2 uv_MainTex;
                float2 uv_BumpMap;
                INTERNAL_DATA
            };

            fixed4 _Color;


            void surf(Input IN, inout SurfaceOutputStandard o) {

                if (abs(IN.worldNormal.x) > 0.5)
                {
                    o.Albedo = tex2D(_MainTex, IN.worldPos.xy);
                    
                }
                if (abs(IN.worldNormal.y) > 0.5)
                {
                    o.Albedo = tex2D(_MainTex, IN.worldPos.yx);
                }
                if (abs(IN.worldNormal.z) > 0.5)
                {
                    o.Albedo = tex2D(_MainTex, IN.worldPos.yx);
                }

                o.Albedo = tex2D(_MainTex, IN.uv_MainTex);
                o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

            }

            ENDCG
    }
        FallBack "Diffuse"
}

enter image description here

0 Answers
Related