Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Post processing effect to a 'depth only' camera.

Discussion in 'Shaders' started by lvictorino, Sep 3, 2014.

  1. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Hi,

    I want to apply a post processing effect to a Camera with a culling mask set as Depth only.
    My configuration is :
    • Camera 1: renders the game, depth set to 0, culling mask set to SolidColor
    • Camera 2: renders the UI, depth set to 1, culling mask sef to Depth Only

    I'd like to apply a simple "Grayscale mode" shader (renders everything in grayscale) to the content of Camera 2 because I want this effect applied only to the UI.
    But as the Camera 2 is rendered after the Camera 1, the post-processing effect is also applied to Camera 1' content.

    How could I do something as simple as this?

    Thanks in advance for your help.
     
  2. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    Are you rendering second camera to a render texture ? or just applying effect to the screen ?
     
  3. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    The second camera is directly used as a camera... I'm not using a render texture... Should I?
     
  4. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    I just did a test with my post fx asset and I had to make the overlay ( gui ) clear solid with alpha as zero then use a transparent blend mode in post fx shader to overlay gui properly ( so only overlay is grey )

    I guess u could render a depth texture and pass that to the post fx shader too ( might be slower than above method )

    If there is a better way id really like to know myself
     
  5. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    And yes for an overlay to have a different effect then main cam .. that camera would have to render to a rendertexture otherwise the gui and game scene are already rendered in the screen buffer
     
  6. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Ok so you suggest that Camera2 renders to a Render Texture.
    This texture will be used with a material using my grayscale shader.
    But what should I do after that? How to apply this material to see my overlay displayed above Camera1?

    Sorry I'm very new to post-processing effects :(
     
  7. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    It would basically be a transparent shader that adds greyscale.. taking the rendertexture and drawing it to screen ( so you have to clear the camera 2 solid black with alpha 0 )
     
  8. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    Ive actually done all this work already and there is nothing faster

    Post FX Studio

    Can make just about any effect
     
  9. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Ho that's nice!

    About what you suggested earlier (solid black + alpha 0)... what about semi-transparent pixels? In my overlay I use semi transparent sprites, and setting solid color + black + alpha 0 on camera overlay make these semi-transparent pixels not visible :(
     
  10. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    r u setting a transparent blend mode in the shader ? can u pastebin your shader ?

    and the gui elements are using a shader that writes to alpha channel as well ?
     
  11. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    Another option would be make it additive then u wont have to worry about alpha channel
     
  12. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
  13. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    here try this .. i changed a few things to make it faster as well in frag part

    http://pastebin.com/wQUpVxZa

    This is untested ... but it should work
     
  14. lvictorino

    lvictorino

    Joined:
    Jul 9, 2012
    Posts:
    31
    Thanks a lot for your help... but... there is a problem here.



    As you can see, there is a clear problem on game view :)
    Any idea?
    I just render the camera overlay in a render texture and then I use Graphics.DrawTexture on repaint event on Camera1.
    Is it the right thing to do ?

    Thanks again.
     
  15. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    I use Graphics.DrawMeshNow ( i think DrawTexture is basically same thing just uses its own quad )

    mymaterial.SetPass(0);
    Graphics.DrawMeshNow ( _mesh, icamtrans.position, icamtrans.rotation );

    is the problem those extra lines ?

    are you clearing the bottom camera as well to solid black ?
     
    Last edited: Sep 4, 2014
  16. echologin

    echologin

    Joined:
    Apr 11, 2010
    Posts:
    1,078
    If you PM me a link to a simple project that shows all this .. i can take a look real quick