Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rendering everything outside of a object with a shader darker

Discussion in 'Shaders' started by Prokopis-Petros, Jun 29, 2017.

  1. Prokopis-Petros

    Prokopis-Petros

    Joined:
    Jun 8, 2016
    Posts:
    24
    So i've managed to setup one object (like a filter in front of the camera) with a stencil mask, and set everything else to use a stencil object shader, when a material with the stencil object shader attatched passes under the stencil mask filter it is drawn in the game, simple. Now I want to expand this and create annother shader that is going to instead of not being drawn outside the stencil mask filter, just turn darker creating a simple fog of war effect, any idea on how to do this? I get that you can't achive this effect using the stencil buffer, could anyone point me in the right direction? When trying to find a solution to this it just turned up with overly complicated tutorials, using the shadow effect in unity pro and such
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Using a stencils for this is an option, depending on exactly what you want to do. If you just want something darker you could have the objects you want to appear darker write to a stencil mask, then render another object that tests for that mask, then renders using a multiply or alpha blend. Kind of the inverse of what you're currently doing with the "camera filter" drawing after the objects rather than before. The other way if you need a more complex effect is to have the objects you want to render darker actually be two shader passes, one that only renders outside of the mask, and one that only renders inside the mask.
     
  3. Prokopis-Petros

    Prokopis-Petros

    Joined:
    Jun 8, 2016
    Posts:
    24
    Thanks! I will look into that, im still new to shaders in unity