Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Applying AO to ground plane that is invisible to camera

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

  1. max_at_newgameplus

    max_at_newgameplus

    Joined:
    Apr 24, 2016
    Posts:
    35
    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_at_newgameplus

    max_at_newgameplus

    Joined:
    Apr 24, 2016
    Posts:
    35
    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:
    46
    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:
    717
    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_at_newgameplus

    max_at_newgameplus

    Joined:
    Apr 24, 2016
    Posts:
    35
    @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?
     
unityunity