Search Unity

Still see reflections when Smoothness & Metallic set to 0

Discussion in 'Shaders' started by SpookyCat, Nov 12, 2018.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,765
    I am just playing around with the basic Unity shader but I can't get it to completely turn of reflections. If Smoothness and Metallic are set to 0 I would expect to see no reflections at all in the sphere but yet I do, how does one stop that?
    Code (CSharp):
    1.  
    2. Shader "Custom/Test" {
    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.  
    22.         struct Input {
    23.             float2 uv_MainTex;
    24.         };
    25.  
    26.         half _Glossiness;
    27.         half _Metallic;
    28.         fixed4 _Color;
    29.  
    30.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    31.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    32.         // #pragma instancing_options assumeuniformscaling
    33.         UNITY_INSTANCING_BUFFER_START(Props)
    34.             // put more per-instance properties here
    35.         UNITY_INSTANCING_BUFFER_END(Props)
    36.  
    37.         void surf (Input IN, inout SurfaceOutputStandard o) {
    38.             // Albedo comes from a texture tinted by color
    39.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    40.             o.Albedo = c.rgb;
    41.             // Metallic and smoothness come from slider variables
    42.             o.Metallic = 0;    // _Metallic;
    43.             o.Smoothness = 0;    // _Glossiness;
    44.             o.Alpha = c.a;
    45.         }
    46.         ENDCG
    47.     }
    48.     FallBack "Diffuse"
    49. }
    50.  
    The shader above gives this result:
    reflect.jpg
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    The GGX specular model unity uses clamps the smoothness at a minimum value, so you’d have to use an alternate lighting model.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,351
    A metallic of zero does not mean zero specular, it means a specular color of RGB 56, 56, 56. If you want to remove reflections entirely, use the StandardSpecular lighting model and use a specular color of RGB 0, 0, 0.
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Do you know why they clamped it at this minimum value rather than just having a metallic of 56/255 be the current result?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,351
    The specular color isn't "clamped". Metallic in the default metallic setup Standard material is just a lerp factor used for determining the albedo and specular colors from the diffuse texture. Full metallic means use the diffuse texture's color as the specular color, and black for albedo. A metallic of zero means use the default average specularity for real world dielectric (non-metal) materials, which is roughly 56/255 in gamma space.
     
    AshwinMods likes this.
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    So physically correct, but not really what people sometimes want when they set smoothness and metallic to 0, which is no specular response what so ever. (This comes up a lot for people with terrain shaders).
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,351
    Physically correct*, but doesn't account for macro scale self occlusion / reflection shadowing which makes everything look like it's glowing where you're not using screen space reflections unless you have a lot of localized reflection probes. This is especially problematic for terrain and forward rendering since usually it's one probe for the entire terrain, hence the need to crush the specular.

    * ish.