Forum begins after the advertisement:


Pink Texture Error with Underwater Effect

Home Forums Video Game Tutorial Series Creating an Underwater Survival Game in Unity Pink Texture Error with Underwater Effect

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #13759
    Spencer Truett
    Participant

    I am using Unity version 2022.3.17 and I have been implementing a top down underwater survival game. I wished to use your underwater effect to achieve the desired aesthetic. I have followed the section of part 10 that addresses the water effect and have found that the shader texture is pink and seems to be having some kind of error the issue only appears when I change the return lerp in the shader from:

    (col, _DepthColor, depth)

    To:

    (col, (0.5 * ambient + _DepthColor * 0.5) * ambient.w, depth)

    for context here is the segment of code from the shader:

    //frag function (ran on every pixel seen by camerea and where post processing effects are applied)
    fixed4 frag (v2f i) : SV_Target
    {
        //sample all pixels in i.screenPos from the _CameraDepthTexture, then convert to //linear depth (typical depth is non linear) then clamp between zero and 1
        float depth = LinearEyeDepth(tex2D(_CameraDepthTexture, i.screenPos.xy));
        //clip the depth between 0 and 1 where 1 is if a pixel is further then depth End
        depth = saturate((depth - _DepthStart) / _DepthEnd);
    
        //scale intensity of blue based on depth value lerp
        fixed4 col = tex2D(_MainTex, i.screenPos);
        return lerp(col, (0.5 * ambient + _DepthColor * 0.5) * ambient.w, depth);
    }

    and here is a screenshot of my game when playing in the unity editor I have included the Main Camera subwindow so you can see the intended view.

    View post on imgur.com

    #13762
    Terence
    Keymaster

    Hi Spencer, I suspect one of the operations you have done might be incorrect, or one of the variables is empty / is the wrong type. To find out which it is, you can try is to incrementally change your code. Since this code works:

    return lerp(col, _DepthColor, depth);

    You can first try adding the ambient color and test to see if the texture turns pink:

    return lerp(col, ambient + _DepthColor, depth);

    Then add the multiplier and test it, etc.:

    return lerp(col, 0.5 * ambient + _DepthColor, 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: