Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Stencil ONLY works in Scene view, how?

Discussion in 'Shaders' started by ChadrickEvans, Sep 9, 2019.

  1. ChadrickEvans

    ChadrickEvans

    Joined:
    Mar 14, 2015
    Posts:
    38
    I was creating a stencil shader a while back that worked like a charm for the first few hours.

    I noticed that one object was having issues. The mesh trail was rendering above it regardless of having the same reference value as the object. After carefully examining the material and ensuring the reference value was exactly as it should be... All of the materials using my stencil shader stopped working in play mode.

    So now I'm faced with Unity doing exactly what I want it to do, only in edit mode.



    I'm not using TrailRenderer, I'm using a mesh with a custom shader for the trail.

    Here is the stencil code applied to the trail

    Code (CSharp):
    1. Stencil{
    2.   Ref[_StencilRef]
    3.   Comp NotEqual
    4. }
    Here is the stencil code applied to the object

    Code (CSharp):
    1. Stencil{
    2.   Ref[_StencilRef]
    3.   Comp Always
    4.   Pass Replace
    5. }
     
  2. ChadrickEvans

    ChadrickEvans

    Joined:
    Mar 14, 2015
    Posts:
    38
    After testing more I realized that my stencil shader DOES work properly but not when using Graphics.DrawMesh.

    Graphics.DrawMesh is very important for the trail I'm rendering. Is there a reason that stencils don't work properly with Graphics.DrawMesh rendered materials?
     
unityunity