Search Unity

standard metallic shader map

Discussion in 'Shaders' started by ghiboz, May 10, 2017.

  1. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi all!
    I need to do somethings on a custom shader: I created a standard shader and looks like this:

    Code (CSharp):
    1. Shader "gRally/grsCarTemporary2"
    2. {
    3.     Properties {
    4.         _Color ("Color", Color) = (1,1,1,1)
    5.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    6.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    7.         _Metallic ("Metallic", Range(0,1)) = 0.0
    8.     }
    9.     SubShader {
    10.         Tags { "RenderType"="Opaque" }
    11.         LOD 200
    12.        
    13.         CGPROGRAM
    14.         // Physically based Standard lighting model, and enable shadows on all light types
    15.         #pragma surface surf Standard fullforwardshadows
    16.  
    17.         // Use shader model 3.0 target, to get nicer looking lighting
    18.         #pragma target 3.0
    19.  
    20.         sampler2D _MainTex;
    21.         struct Input {
    22.             float2 uv_MainTex;
    23.         };
    24.  
    25.         half _Glossiness;
    26.         half _Metallic;
    27.         fixed4 _Color;
    28.  
    29.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    30.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    31.         // #pragma instancing_options assumeuniformscaling
    32.         UNITY_INSTANCING_CBUFFER_START(Props)
    33.             // put more per-instance properties here
    34.         UNITY_INSTANCING_CBUFFER_END
    35.  
    36.         void surf (Input IN, inout SurfaceOutputStandard o) {
    37.             // Albedo comes from a texture tinted by color
    38.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    39.             o.Albedo = c.rgb;
    40.             // Metallic and smoothness come from slider variables
    41.             o.Metallic = _Metallic;
    42.             o.Smoothness = _Glossiness;
    43.             o.Alpha = c.a;
    44.         }
    45.         ENDCG
    46.     }
    47.     FallBack "Diffuse"
    48. }
    49.  
    now I need to add a separate texture that contains the metallic map... is not a problem, but how can I pass to the standard pipeline to get the metallic not by _Metallic slider but by the alpha channel of the metallic texture?

    thanks in advance
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The "real" Standard shader stores the metallic value in the red channel of the Metallic texture, and the smoothness in the alpha, btw. There's no reason you have to stick to that convention for Surface shaders though, if storing the metallic in the alpha is what you want to do.

    However the answer to your question is "the same way you would in any other shader". Not helpful, I know, but if that's the question you're asking then you probably need to start reading up on shaders.
    http://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/
     
  3. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    thank again @bgolus
    I've solved, using this code:
    Code (CSharp):
    1. // spec
    2. fixed4 cSpec = tex2D(_MetallicGlossMap, IN.uv_MainTex);
    3. o.Metallic = cSpec.rgb;
    4. o.Smoothness = _Glossiness * cSpec.a;
    my error was that I think that I was able to use the code inside the standard shader just adding some defines like
    Code (CSharp):
    1. #pragma shader_feature _METALLICGLOSSMAP
    but no, I needed to write the code..

    thanks:rolleyes: