Standard Shader vs (identical?) Standard Surface Shader

Hi,

since we need to get rid of the no-secondary-maps-on-mobile-Restriction we’ve create a custom Standard Surface Shader.

However the custom shader (which just sets some basic vars) does not work like intended. First issue, is that the _BumpScale is not applied like in the Standard Shader (a “fine grained” value like 0.26 is the same as if set to 1, but 2 is stronger, 3 etc. - but the value is a float?)

o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)) * _BumpScale;

Is this the correct way to apply the BumpScale?

The second issue is that - even without bump - the detail albedo is much brighter when using the Standard Shader.

Standard Shader: Dropbox

Custom Shader: Dropbox

Here is the full source of the shader (Note that for simplification / performance i use the UV of MainTex for Metallic and Bump):

Shader "Custom Colorable Object" {
    Properties {
        _Color("Color", Color) = (1,1,1,1)

        _MainTex("Albedo", 2D) = "white" {}

        _MetallicGlossMap("Metallic", 2D) = "white" {}

        _GlossMapScale("Smoothness", Range(0, 1)) = 0

        _MetallicFactor("Metallic Factor",Range(0, 1)) = 0

        _BumpMap("Normal Map", 2D) = "bump" {}

        _BumpScale("Scale", Float) = 1.0
   
        _DetailAlbedoMap("Detail Albedo x2", 2D) = "white" {}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
       
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _DetailAlbedoMap;
        sampler2D _BumpMap;
        sampler2D _MetallicGlossMap;

        float _MetallicFactor;
        float _BumpScale;
        float _GlossMapScale;

        struct Input {
            float2 uv_MainTex;
            //float2 uv_BumpMap;
            float2 uv2_DetailAlbedoMap;

        };

        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutputStandard o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * tex2D(_DetailAlbedoMap, IN.uv2_DetailAlbedoMap) * _Color;
            //fixed4 c = tex2D(_DetailAlbedoMap, IN.uv2_DetailAlbedoMap) * _Color;
            o.Albedo = c.rgb;
            // Bump
            o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)) * _BumpScale;
            // Metallic
            fixed4 mc = tex2D(_MetallicGlossMap, IN.uv_MainTex);
            o.Metallic = mc.r * _MetallicFactor;
            o.Smoothness = mc.a * _GlossMapScale;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

I’d appreciate any help on these issues!

Best regards
zkw

No. That’s the way to scale bumps:

o.Normal = UnpackScaleNormal(tex2D(_BumpMap, IN.uv_BumpMap), _BumpScale);

Also you are correct in saying detail is brighter that’s because if _DETAIL_MULX2 is defined (which it is normally) detailalbedo is multiplied by a constant:

detailAlbedo * unity_ColorSpaceDouble.rgb

Overall you’ll need to refer to UnityStandardInput.cginc and probably the rest of the standard shader source as the documentation does a really poor job explaining anything.

1 Like

Perfect! Thank you very much! Just one thing: If i use unity_ColorSpaceDouble.rgb the shader can’t compile. I now just use 2 as a constant. Any idea how to get this Unity constant in my shader?

Don’t know the value but then again this should compile. Are you sure you don’t have a typo?