Search Unity

Applying AO to ground plane that is invisible to camera

Discussion in 'Image Effects' started by max_coding13, Oct 27, 2018.

  1. max_coding13

    max_coding13

    Joined:
    Apr 24, 2016
    Posts:
    34
    Hello,
    I'm attempting to apply the Post Stack v2 AO on a scene with an invisible (transparent or culled) ground plane, but still retain the AO "shadow" of objects intersecting with the ground plane as if it were opaque. Is this possible? I am truly stumped on how to go about achieving this effect.

    Here's a breakdown of what I'm trying to do:
     
  2. max_coding13

    max_coding13

    Joined:
    Apr 24, 2016
    Posts:
    34
    My best crack at this has been applying something similar to a tri-planar shader onto the ground plane, which maps a render texture from the main camera onto its uv in screen space coords.
    If you then cull out the ground plane on that camera, the render texture when applied to the shader will effectively make the ground "see through". Now you just have to nest secondary camera which doesn't cull the ground plane and make that your new main camera. Now you can apply AO on the cube and ground (with the shader), and the AO will look like it's floating on nothing.

    This sort of works, but I'm having a bit of trouble pinning down how to effectively write the shader to always write the texture exactly in screen space coords.

    Anyone ever write something like this before?
     
  3. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    105
    Maybe this could help? There seems to be a whole thread regarding shadow (well, not AO) on fully transparent surfaces (matte shadow)...
     
  4. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    AO is a depth-reliant effect. If you have no depth (aka. transparent shaders), you have no AO. The simplest solution would be to make your transparent shader write to the Z-Buffer, but then you run into the issue of how to render stuff that's behind it.
     
  5. max_coding13

    max_coding13

    Joined:
    Apr 24, 2016
    Posts:
    34
    @ivank yes I actually have managed to have normal shadows appear on the transparent ground using similar methods, but I appreciate the thread link.
    @GoGoGadget Right, that was what I was attempting to do (rendering stuff behind the shader) in my second post by mapping the main camera's rendertexture (with shader culled) to the shader's uv - making the shader "transparent" while still writing to depth buffer. I can't quite get the rendertexture to render exactly in screen-space coords on the shader however. Perhaps there is a simpler technique?