Search Unity

Simple metalness and glossiness standard light shader.

Discussion in 'Shaders' started by tr1te, Jul 4, 2017.

  1. tr1te

    tr1te

    Joined:
    Sep 5, 2012
    Posts:
    38
    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:

    Code (CSharp):
    1. Shader "Custom/StructShader" {
    2.     Properties {
    3.         _MainTex ("A (RGB)", 2D) = "white" {}
    4.         _MS ("MS", 2D) = "black" {}
    5.     }
    6.     SubShader {
    7.         Tags { "RenderType"="Opaque" }
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.  
    12.         #pragma surface surf Standard fullforwardshadows
    13.  
    14.         #pragma target 3.0
    15.  
    16.         sampler2D _MainTex;
    17.         sampler2D _MS;
    18.  
    19.         struct Input {
    20.             float2 uv_MainTex;
    21.             float2 uv_MS;
    22.         };
    23.  
    24.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    25.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    26.         // #pragma instancing_options assumeuniformscaling
    27.         UNITY_INSTANCING_CBUFFER_START(Props)
    28.             // put more per-instance properties here
    29.         UNITY_INSTANCING_CBUFFER_END
    30.  
    31.         void surf (Input IN, inout SurfaceOutputStandard o) {
    32.  
    33.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
    34.             o.Albedo = c.rgb;
    35.  
    36.             fixed4 ms = tex2D(_MainTex, IN.uv_MS);
    37.             o.Metallic = ms.r;
    38.             o.Smoothness = ms.g;
    39.             o.Alpha = c.a;
    40.         }
    41.         ENDCG
    42.     }
    43.     FallBack "Diffuse"
    44. }
    45.  
    What is wrong?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You're sampling the _MainTex texture twice, that should be _MS there.
     
    neoshaman likes this.