Search Unity

Shader that remains the same transparency when overlapping, using for shadows

Discussion in 'Shaders' started by celaeno, Jun 25, 2015.

  1. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Hello,

    I'm looking for a shader to use for the projection of shadows. Problem is when 2 shadows overlap each other the overlapping part get's darker as you can see in the image. Is there a shader that prevents the overlapping part so that it remains the same transparency?

    Thanks

     
  2. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    you can use stencil buffer.
    For area that has been rendered by shadow,any other shadow will skip it's rendering.
    Code (CSharp):
    1. //use Stencil Buffer to prevent multi Blending            
    2.             Stencil
    3.              {
    4.                 Ref 1
    5.                 Comp NotEqual
    6.                 Pass Replace
    7.                 Fail Keep
    8.                 ZFail Keep
    9.                 ReadMask 1
    10.                 WriteMask 1
    11.             }