How do I get the Skybox Lighting settings value "Ambient Intensity" in the frag/vert?

Hello everyone,

Here’s the value i want - I pasted both Unity 5.6 and 5.5 pictures, because they are different. I need Ambient Intensity or (in 5.6) Intensity Multiplier.

I know that in surface shader, this value is easily available, but what shader variable or function do I use to access this value in frag/vert?

Any tips or tricks to doing this would be greatly appreciated!

Thankyou

FYI Here’s the shader I am using (basically just a typical specular diffuse shader):

Shader "Custom/texturePsuedoSpecularLit_Ambientsupport" {
    Properties {
        _Color("Main Color", Color) = (1,1,1,1)
        _MainTex ("Main Texture", 2D) = "white" {}
        _SpecColor ("Specular Color", Color) = (1,1,1,1)
        _SpecShininess ("Specular Shininess", Range(1.0,100.0)) = 2.0
    }
    SubShader {
        Pass {
            Tags { "LightMode" = "ForwardBase" }
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            fixed4 _Color;
            sampler2D _MainTex;
            float4 _LightColor0;
            float4 _SpecColor;
            float _SpecShininess;
            float4 _MainTex_ST;

            struct appdata {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float2 texcoord : TEXCOORD0; 
            };

            struct v2f {
                float4 pos : SV_POSITION;
                float3 normal : NORMAL;
                float2 texcoord : TEXCOORD0;
                float4 posworld : TEXCOORD1;
            };

            v2f vert(appdata IN) {
                v2f OUT;
                OUT.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
                OUT.posworld = mul(unity_ObjectToWorld, IN.vertex);
                OUT.normal = mul(unity_ObjectToWorld, float4(IN.normal, 0.0)).xyz; 
               
                OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
                return OUT;
            }

            fixed4 frag(v2f IN) : COLOR {
                float3 ambientLight = unity_AmbientSky.xyz * _Color * _LightColor0.rgb; 
                fixed4 texColor = tex2D(_MainTex, IN.texcoord);
               
                float3 normalDirection = normalize(IN.normal);
                float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); 
                float3 viewDirection = normalize(_WorldSpaceCameraPos - IN.posworld.xyz);
                float3 diffuse = _LightColor0.rgb * max(0.0, dot(normalDirection, lightDirection)); 
               
                float3 specular;

               
                //specular calculation
                if(dot(normalDirection, lightDirection) < 0.0) {
                    specular = float3(0.0, 0.0, 0.0);
                } else {
                    specular = _LightColor0.rgb * _SpecColor.rgb * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), _SpecShininess);
                }
               
                float3 diffuseSpecular = ambientLight + diffuse + specular;

                return float4(diffuseSpecular, 1) * texColor * _Color;
            }
           
            ENDCG
        }
    }
}

Is it? If so it’ll be the same in a vertex fragment shader, though I’m unaware of any way to get the intensity in a surface shader.

If you write a surface shader that uses it, select it in the editor and click on the “Show generated code” button to see the vertex fragment shader that’s actually being used, and thus how it’s getting the value.

I am trying to obtain this value as well on a surface shader. The closest I can get is unity_AmbientSky, which gives me color but not the Intensity Multiplier. My current workaround is to have a C# script pass RenderSettings.ambientIntensity to the shader using Shader.SetGlobalFloat and make it execute in edit mode.

I’d love to to this in a more elegant way, though. But I have not been able to find a way to obtain the intensity value directly in the shader.