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. Let us know your feedback about the Global Illumination changes in the 2023.2 beta.
    Dismiss Notice
  3. Dismiss Notice

A way to set the stencil buffer through shader graph?

Discussion in 'Graphics Experimental Previews' started by Desoxi, Jul 16, 2018.

  1. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Well the question is as the title says :D
    Is there a way i dont know to set the stencil buffer via the shader graph?
     
    tomekkie2 likes this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,652
    Not yet
     
  3. albertjames

    albertjames

    Joined:
    Aug 11, 2018
    Posts:
    16
    What about now ? :)
     
  4. alexhessler

    alexhessler

    Joined:
    Oct 16, 2017
    Posts:
    1
    How about now?
     
    AladinoTrent likes this.
  5. AladinoTrent

    AladinoTrent

    Joined:
    Nov 7, 2016
    Posts:
    3
    Are there new News or solution for this?
     
  6. Blarghle

    Blarghle

    Joined:
    Aug 19, 2014
    Posts:
    19
    I would also like to know when this feature is coming
     
  7. koonm

    koonm

    Joined:
    Jan 5, 2016
    Posts:
    11
    How about now? It's 2021,still can't use stencil buffer?
     
  8. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    251
    want
     
    tomekkie2 and Desoxi like this.
  9. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    946
    Generally you can set stencil overrides using RenderObjects in urp.
    Unfortunately there is no use of that for me. If I were using just Pass or Comp that would work. But I need PassFront, PassBack, CompFront, CompBack and RenderObjects have no these face selection options.
     
  10. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    2022 ... is this possible yet?
     
    Prodigga likes this.
  11. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    And a few months later.. ??
     
  12. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    251
    still want
     
  13. KCGames47

    KCGames47

    Joined:
    Nov 3, 2014
    Posts:
    34
    Maybe I'm stupid, but is this really that hard for Unity to implement? like making a new .... node that generates a .... block of code? please correct me if I'm wrong...
     
    X28 likes this.
  14. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    196
    I could probably use this as well. Trying to use the stencil buffer to do some masking. Trying to use the base mesh to mask a submesh and this came up as a possible solution.

    Could this be done with a custom function in Shader Graph?
     
  15. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    86
    This is just unbelievable that something trivial like that is not implemented yet. That's the only reason why I keep using Amplify Shader Editor.
     
    X28, Ruchir and Mehrdad995 like this.
  16. Mehrdad995

    Mehrdad995

    Joined:
    Jul 17, 2013
    Posts:
    46
    Bump, what about now?
    After 4 years has it been implemented yet?
    ---------------------------------------------------------
     
    KCGames47 and Ruchir like this.
  17. vx4

    vx4

    Joined:
    Dec 11, 2012
    Posts:
    179
    yes it can be done since 2 years ago.
     
  18. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    86
    How?
     
  19. vx4

    vx4

    Joined:
    Dec 11, 2012
    Posts:
    179
    implement native plug-in. lol
     
  20. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    86
    I have not idea what are you talking about
     
  21. vx4

    vx4

    Joined:
    Dec 11, 2012
    Posts:
    179
    first you have to understand you cant change stencil buffer ot it state during shader excu this due to limation in Graphics API like DX11 or whatever you using. Everything shuld be set before excustion Draw cmd.

    Second, stencil buffer is couple depth buffer which also couple with RenderTexture in most cases. So,if you want set stencil buffer you can use for ex Graphics.SetRenderTarget or CommandBuffer.SetRenderTarget.

    3. you can change stencl state all of them like, stencil value Ref and othe link but RenderObjects in urp does not show them all so you have to craete your own Scriptable Renderer Feature.

    4.you can use Unordered Access View (UAV) or RenderTexture with RenderTexture.enableRandomWrite is enable to act like stencil buffer,where you can read write and mod pixel in inside shader.also you bind more than one if you want.

    5 if all of this does not work for you can create your own low-level rendering plugin where you can Graphics API.
     
  22. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    86
    There are many complex ways to use stencil buffers but that is not the topic of this thread:
    upload_2022-7-16_13-7-34.png

    If you're Implying that it should not be possible to add Stencil buffer settings to the shader graph I recommend you to take a look at Amplify Shader Editor. It's just a line of code in the final shader such as in the build-in pipeline.
     

    Attached Files:

  23. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,770
    Ahh damn! I was hoping there might be some built in solution to this :(
    I'm so bad at making shaders outside of the shader graph, and stencil stuff is so interesting!
    Has anyone managed to script anything for it yet?
     
  24. pixelChisel

    pixelChisel

    Joined:
    May 19, 2016
    Posts:
    17
    Well then, I guess I'll switch to Amplify for future projects...
     
  25. Ofenkatze

    Ofenkatze

    Joined:
    Aug 14, 2013
    Posts:
    15
    Well, that's unfortunate, because Amplify shaders don't work with the Visual Effects Graph. So I'm stuck with making shaders in shader graph, copying them, then editing the stencil stuff in code. Which is not overly efficient. It would be a really handy feature to have in shader graph.
    Edit: Scratch that, can't use the modified shader in visual effects graph...
     
    Last edited: Aug 28, 2023