Search Unity

Zdepth underneath object

Discussion in 'Shaders' started by emilmeiton, Sep 2, 2015.

  1. emilmeiton

    emilmeiton

    Joined:
    Apr 8, 2014
    Posts:
    15
    Hi, I'm trying to get the z-depth of the objects "behind" my object.

    To bring some context.., I've tried to do a custom fog shader as a camera effect. This looks nice in the editor but when exporting to webgl it only shows my z-depth and not the original colors of the objects in the scene. To try and remedy this I'm hoping to do the effect on an object in the scene instead (I've tried and grabpass works with objects in the scene but not as a camera effect in webgl).

    The explaining text above is maybe a bit intricate but the important thing for me right now is to get the z-buffer of objects behind an object I'm rendering right now.., Anybody got any ideas?
     
  2. emilmeiton

    emilmeiton

    Joined:
    Apr 8, 2014
    Posts:
    15
    ok, so I got it working as can be seen here
    http://emilmeiton.com/Aqua2/index.html

    But now I'm stuck with trying to turn on SSAO

    I have a gameobject (a plane) that has the fog and atmospheric effects on it. And I understand that the camera effect SSAO is rendered after everything else (hence after my plane with the fog etc).., Is there a way to render the plane (with the fog etc) after my camera effect SSAO?

    I can't seem to get the fog shader to be a camera effect since it breaks in webgl somehow.

    Anybody got any ideas?
     
  3. jistyles

    jistyles

    Joined:
    Nov 6, 2013
    Posts:
    34
    So it sounds like a platform specific bug/limitation is preventing you from doing what you intend. I'm not familiar with webgl, so I can't offer anything concrete as a solution. Are you able to post a screenshot of what it's supposed to look like in the editor before exporting to webgl?

    What I can offer however is maybe something you hadn't considered to address this bit:
    "I can't seem to get the fog shader to be a camera effect since it breaks in webgl somehow."

    If you can't get your fog working under a camera image effect, maybe replace the concept of an image effect with an object which is attached and covers the camera using the following shader settings:
    - cull off (so the backfaces of the object are visible)
    - Ztest always (so it draws on top of everything regardless of depth)
    - Zwrite off (so it doesn't write to the depth buffer)
    - "Queue"="Transparent - 100" (so it draws after all opaques but before all other transparencies)
    Generate your screen space coordinates and treat it like a full screen postprocess from there on out.
     
  4. emilmeiton

    emilmeiton

    Joined:
    Apr 8, 2014
    Posts:
    15
    Thanks!, that's what I'm doing right now with everything except SSAO. And it works very nice.., I'm probably going to add a few of those shader settings though since I'm missing some.

    I'm thinking of adding the SSAO into the object (that's covering the view) instead of as an image effect on the camera. This way I have more control.., the con would be that it's probably a quite complex thing to implement considering I don't have that much experience.., but it's worth a try I think!