Simple metalness and glossiness standard light shader.

I want to make a simle shader that used a metalness and glossiness map on it. With minimum code. I wrote this, but it doesnot work:

Shader "Custom/StructShader" {
    Properties {
        _MainTex ("A (RGB)", 2D) = "white" {}
        _MS ("MS", 2D) = "black" {}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM

        #pragma surface surf Standard fullforwardshadows

        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _MS;

        struct Input {
            float2 uv_MainTex;
            float2 uv_MS;
        };

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_CBUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_CBUFFER_END

        void surf (Input IN, inout SurfaceOutputStandard o) {

            fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;

            fixed4 ms = tex2D(_MainTex, IN.uv_MS);
            o.Metallic = ms.r;
            o.Smoothness = ms.g;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

What is wrong?

You’re sampling the _MainTex texture twice, that should be _MS there.

1 Like