Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Issue with reflection in custom standard shader

Discussion in 'Shaders' started by PrisedRabbit, Jun 9, 2020.

  1. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    62
    Hi all!

    Tried to make custom standard shader, but have issues with reflections in windows build (Unity 5.4.5, 2017.4.40), in Unity Editor all fine:

    The video https://monosnap.com/file/TMBd3h909eFC8aMjp2cbppUqciOCRi

    Shader code:

    Code (JavaScript):
    1. Shader "Custom/Custom_Standard" {
    2.     Properties {
    3.         [NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
    4.         [NoScaleOffset] _BumpMap ("Normalmap", 2D) = "bump" {}
    5.         [NoScaleOffset] _MetallicGlossMap("Metallic (R)", 2D) = "white" {}
    6.         [NoScaleOffset] _Roughness("Roughness (R)", 2D) = "white" {}
    7.         [NoScaleOffset] _LightMap ("LightMap", 2D) = "white" {}
    8.         [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
    9.         _Scale ("Scale", Vector) = (1.0, 1.0, 0.0, 0)
    10.     }
    11.  
    12.     CGINCLUDE
    13.         #define UNITY_SETUP_BRDF_INPUT MetallicSetup
    14.     ENDCG
    15.  
    16.     SubShader {
    17.         Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
    18.  
    19.         CGPROGRAM
    20.         #pragma surface surf CustomStandard
    21.         #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
    22.         #pragma shader_feature __ UNWRAPED_UV
    23.         #pragma target 3.0
    24.         #include "./shared_standard.cginc"
    25.         ENDCG
    26.     }
    27.     FallBack "Standard"
    28.     CustomEditor "CustomShaderGUI"
    29. }
    the part of shared_standard.cginc:

    Code (JavaScript):
    1. inline half4 LightingCustomStandard (CustomSurfaceOutput s, half3 viewDir, UnityGI gi)
    2.         {
    3.             half4 c = 1;
    4.             c.rgb = gi.indirect.specular;
    5.        
    6.             return c;
    7.         }
    8.  
    9.         inline void LightingCustomStandard_GI (CustomSurfaceOutput s, UnityGIInput data, inout UnityGI gi)
    10.         {
    11.             Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(s.Smoothness, data.worldViewDir, s.Normal, lerp(unity_ColorSpaceDielectricSpec.rgb, s.Albedo, s.Metallic));
    12.             gi = UnityGlobalIllumination(data, s.Occlusion, s.Normal, g);
    13.         }
    14.  
    15.         void surf (Input IN, inout CustomSurfaceOutput o)
    16.         {
    17.             half4 albedo = tex2D (_MainTex, IN.customUV);
    18.             half3 metallic = tex2D (_MetallicGlossMap, IN.customUV).rgb;
    19.             half3 roughness = tex2D(_Roughness, IN.customUV).rgb;
    20.             half3 lm = tex2D(_LightMap, IN.uv2_LightMap).a * 0.75 + 0.25;
    21.  
    22.             o.Albedo = albedo.rgb;
    23.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.customUV));
    24.  
    25.             o.Metallic = metallic.r;
    26.             o.Smoothness = 1 - roughness.r;
    27.             o.Alpha = albedo.a;
    28.             o.Occlusion = 1.0;
    29.             o.LightMap = lm;
    30.         }
     
  2. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    62
    Hm, if I set null to _BumpMap - no problem