Search Unity

Unity 5 Surface Shaders and Realtime Shadows issue

Discussion in 'Global Illumination' started by Project-Mysh, Jan 27, 2015.

  1. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi there,

    Testing Surface Shaders with Unity 5 I have found an issue that I dont know how to resolve.
    Its about Realtime Shadows and how they affect the surface. Screenshot comparison:

    Realtime Shadows and Realtime GI (marked as static):
    U5b21Comp1.jpg
    Without Realtime Shadows but with Realtime GI (marked as static):
    U5b21Comp2.jpg

    Surface Shader code:
    Code (CSharp):
    1. Shader "Custom/Vcol" {
    2.     Properties {
    3.         [LM_Metallic] [LM_Glossiness] _Meta ("Metalness and Gloss", Color) = (128,128,128,0)
    4.     }
    5.    
    6.     CGINCLUDE
    7.         #define _GLOSSYENV 1
    8.         #define UNITY_SETUP_BRDF_INPUT MetallicSetup
    9.     ENDCG
    10.    
    11.     SubShader {
    12.         Tags { "RenderType"="Opaque" }
    13.         LOD 200
    14.        
    15.         CGPROGRAM
    16.         #include "UnityPBSLighting.cginc"
    17.         #pragma surface surf Standard addshadow
    18.         #pragma target 3.0
    19.  
    20.         fixed4 _Meta;
    21.  
    22.         struct Input {
    23.             fixed4 color : COLOR;
    24.         };
    25.  
    26.         void surf (Input IN, inout SurfaceOutputStandard o) {
    27.             o.Albedo = IN.color.rgb*IN.color.rgb;
    28.             o.Metallic = _Meta.rgb;
    29.             o.Smoothness = _Meta.a;
    30.         }
    31.         ENDCG
    32.     }
    33.     FallBack "Diffuse"
    34. }
    What I have to include to get the same results as Standard shader? What im doing worng?
     
  2. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi there unity team,

    This is from a converstaion with larsbertram1, creator of LUX, that have the same issue with surface shaders.

     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    just to add some more info about this:
    missing "ao" in custom surface shaders using the standard lighting is caused by the fact that the shader compiler always adds "nodirlightmap" to all passes although this is not defined in the surface shader.
    so when using directional lightmaps (even if those are just used for the gi) those will look different using the standard shader compared with a custom surface shader using the standard lighting functions.

    having a closer look using the frame debugger gives you the following results (forward rendering):

    Shader: Standard (Specular setup) pass #0 DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_OFF DIRLIGHMAP_COMBINED DYNAMICLIGHTMAP_ON _NORMALMAP

    Shader: Custom (Specular setup) pass #0 DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_OFF DIRLIGHMAP_OFF DYNAMICLIGHTMAP_ON

    lars
     
    Project-Mysh likes this.