Search Unity

Water Shader - Different depth values between windows and mac.

Discussion in 'Shaders' started by Hjeldnes, Apr 20, 2014.

  1. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Update:
    Ok, so there were two issues.
    1. Very silly bug. When I tested the windows version, the camera was set to player settings, ie. not deferred.
    So, naturally, the depthtexture was empty.

    2. ScreenPos.Z, which I used to compare depth, needed to be adjusted, like so: Linear01Depth(normScreenPos.z);

    Then I could do a comparison between depth screen, and depth water.



    I'm working on a water/river shader, and I had it working fine on mac, but on windows the depth buffer looks wrong.
    Does anyone know what is causing it, and how to fix? I would like to use surface shaders so that I can easily get proper lighting on the material.

    Here are two screenshots showing the difference. Depth is fine on mac, all black on windows.

    $Screen Shot 2014-04-20 at 22.11.51.png $Screen Shot 2014-04-20 at 22.11.47.png



    And here is the depth part of the code:

    Code (csharp):
    1. void surf (Input IN, inout SurfaceOutput o)
    2. {  
    3.     float depth = LinearEyeDepth(tex2D(_CameraDepthTexture, IN.screenPos.xy / IN.screenPos.w).r);  
    4.     depth = depth/_ProjectionParams.z;
    5.     o.Emission = depth;    
    6. }

    Still working on this water, but currently it looks something like this. I will use the depth value to fade the water towards a depth color, as it gets deeper (as well as increasing distortion amount).




    $Screen Shot 2014-04-20 at 22.27.07.png
     
    Last edited: Apr 21, 2014