Forum begins after the advertisement:


[Part 10] Getting errors when I use ambient in code

Home Forums Video Game Tutorial Series Creating an Underwater Survival Game in Unity [Part 10] Getting errors when I use ambient in code

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15562
    Layla
    Participant
    Helpful?
    Up
    0
    ::

    I’m getting an error that says “undeclared identifier ‘ambient'” This is my code.

               fixed4 frag (v2f i) : SV_Target
                {
                    fixed4 col = tex2D(_MainTex, i.screenPos);
                    if (i.screenPos.y > _WaterLevel.x * i.screenPos.x + _WaterLevel.y - _WaterLevel.x * 0.5) return col;
        
                    float depth = LinearEyeDepth(tex2D(_DepthMap, i.screenPos.xy));
        
                    depth = saturate((depth - _DepthStart) / _DepthEnd);
                    
                    return lerp(col, (0.5 * ambient + _DepthColor * 0.5) * ambient.w, depth);
    #15566
    Terence
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you try adding this to your code?

    fixed4 frag(v2f i) : SV_Target
    {
        fixed4 col = tex2D(_MainTex, i.screenPos);
        if (i.screenPos.y > _WaterLevel.x * i.screenPos.x + _WaterLevel.y - _WaterLevel.x * 0.5) return col;
    
        float depth = LinearEyeDepth(tex2D(_DepthMap, i.screenPos.xy));
        depth = saturate((depth - _DepthStart) / _DepthEnd);
    
        // Use Unity's ambient light
        fixed4 ambient = UNITY_LIGHTMODEL_AMBIENT;
    
        return lerp(col, (0.5 * ambient + _DepthColor * 0.5) * ambient.w, depth);
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: