Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Convert Diffuse (Lambert) shader in Standard with alpha cutout

Discussion in 'Shaders' started by OldHarryMTX, Mar 22, 2020.

  1. OldHarryMTX

    OldHarryMTX

    Joined:
    Sep 18, 2018
    Posts:
    45
    Hi all
    I'm trying to convert a Diffuse Shader i got in a Standard one. Here's my code, with the commented lines that are the one i have tryed to add for the conversion:

    Code (CSharp):
    1. Shader "Custom/Diffuse Fog" {
    2.  
    3.     Properties
    4.     {
    5.         _Color("Main Color", Color) = (1,1,1,1)
    6.         _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
    7.         _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
    8.     }
    9.  
    10.         SubShader
    11.         {
    12.             Cull Off
    13.             Tags {"Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout"}          
    14.             LOD 200
    15.  
    16.         CGPROGRAM
    17.         #pragma target 3.0
    18.         #pragma surface surf Lambert alphatest:_Cutoff addshadow
    19.         //#pragma surface surf Standard alphatest:_Cutoff addshadow
    20.  
    21.         sampler2D _MainTex;
    22.         fixed4 _Color;
    23.  
    24.         UNITY_INSTANCING_BUFFER_START(Props)
    25.         UNITY_INSTANCING_BUFFER_END(Props)
    26.  
    27.         struct Input
    28.         {
    29.             float2 uv_MainTex;
    30.         };
    31.  
    32.         void surf(Input IN, inout SurfaceOutput o)
    33.         //void surf(Input IN, inout SurfaceOutputStandard o)
    34.         {
    35.             fixed4 color = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    36.             /*
    37.             here some code, not interesting at the moment
    38.             */
    39.             o.Albedo = color;
    40.             o.Alpha = color.a;
    41.         }
    42.         ENDCG
    43.         }
    44.  
    45.             Fallback "Transparent/Cutout/VertexLit"
    46. }
    In the immages below you can see the difference between the two versions:

    upload_2020-3-22_21-28-13.png
    Diffuse

    upload_2020-3-22_21-28-35.png
    Standard

    I can't understand why the Standard version returns color so desaturated.

    Do you know why it happens?

    Thankyou in advance
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    The Standard shader assumes every material has some specularity (because in the real world it does). If you don’t set a Smoothness in a Standard Surface Shader it’ll default to a Smoothness of 0.0, or a fully rough surface. Rough surfaces tend to be fairly desaturated in appearance (think powder) and the Standard shader with a Smoothness of 0.0 mimics some of this look. You probably want to actually set the Smoothness to something between 0.25 ~ 0.75. If it still doesn’t look how you want, you might want to try using the StandardSpecular shading model with the Surface Shader and additionally Specular color values to something very dark or black. Though if you choose to use black, at that point you probably want to switch back to Lambert.
     
  3. OldHarryMTX

    OldHarryMTX

    Joined:
    Sep 18, 2018
    Posts:
    45
    Thank you for the reply. I will try adding the smoothness but, considering what you are saying, probably is better if I still use the Lambert Diffuse as the game have a toon like graphic.

    Thank you again!