Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. 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

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:
    54
    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:
    165
    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.             }
     
unityunity