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

A way to set the stencil buffer through shader graph?

Discussion in 'Shader Graph' 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?
     
    SanyaBane and tomekkie2 like this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    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:
    12
    How about now? It's 2021,still can't use stencil buffer?
     
  8. RR7

    RR7

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

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    972
    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:
    254
    still want
     
  13. KCGames47

    KCGames47

    Joined:
    Nov 3, 2014
    Posts:
    39
    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...
     
    SanyaBane and X28 like this.
  14. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    225
    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:
    88
    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.
     
    funkyCoty, SanyaBane, X28 and 2 others 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:
    181
    yes it can be done since 2 years ago.
     
  18. CogumeloSoft

    CogumeloSoft

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

    vx4

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

    CogumeloSoft

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

    vx4

    Joined:
    Dec 11, 2012
    Posts:
    181
    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:
    88
    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,817
    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
  26. SanyaBane

    SanyaBane

    Joined:
    Nov 22, 2016
    Posts:
    6
    Any updates?
     
  27. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    still want
     
    petey likes this.
  28. skatecastorGP

    skatecastorGP

    Joined:
    Jul 22, 2012
    Posts:
    2
    the reality of Unity in 2024... this is sad
     
  29. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,817
    Yeah this really seems like something they should add. Maybe they've stopped working on it altogether, who knows. Maybe look into the stencil options in Render Features in URP?
     
  30. SorAxel

    SorAxel

    Joined:
    Sep 3, 2018
    Posts:
    1
    How about now?
     
  31. theghostronaut

    theghostronaut

    Joined:
    Jul 27, 2018
    Posts:
    41
    We really need this.
     
    vanyfilatov likes this.
  32. nz2develop

    nz2develop

    Joined:
    Oct 5, 2017
    Posts:
    7
    So there is a code in the ShaderGraph package source code mirroring repo, that I believe generates the stencil equivalent of the ShaderLab Stencil block.

    There is also a note in the Changelog to version 10.0.0 under the Fixed list, that states
    "Added StencilOverride support"

    But I can't find anywhere in the versions above the specified package functionality that would let Unity users set or override the Stencil behavior to be generated into ShaderLab code, as the latest version 17.0 does with DepthTest for example.

    Is it a work in progress, or is there any limitation related to this feature?

    Знімок екрана 2024-01-21 о 22.16.05.png
     
  33. theghostronaut

    theghostronaut

    Joined:
    Jul 27, 2018
    Posts:
    41
    I got around it by just setting the stencil via a custom render pass (render objects) instead.
     
    termway likes this.
  34. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    154
    really, still nothing?! this would be trivial to implement on unity's side
     
    LeekAndRibs likes this.
  35. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    77
    You can do it for FullScreen shader since Unity 2022.2 and URP 14.

    upload_2024-2-12_10-51-16.png

    I have no idea why we can't do this for the other material modes.
     
  36. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    88
    This is unacceptable that we don't have this simple thing exposed in the Shader Graph yet. Maybe they are just forcing us to keep using Amplify Shader Editor forever?
     
  37. s4lt3d

    s4lt3d

    Joined:
    Nov 21, 2014
    Posts:
    14
    How about now? Is it supported yet? Would be incredibly useful as UI Elements also don't support shaders.... I guess unity just wants us to have boring UI in games.
     
  38. firdiar

    firdiar

    Joined:
    Aug 2, 2017
    Posts:
    25
    im waiting for it too
     
  39. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,293
    @BenCloward could you give us some insight why stencil is available only via renderer feature?
     
  40. BenCloward

    BenCloward

    Unity Technologies

    Joined:
    Jul 15, 2021
    Posts:
    137
    All of the settings in the Graph Inspector are added and maintained by the SRP teams (URP and HDRP) - so if you're looking for features that need Graph Inspector settings, it's best to ask in the forums for those teams instead of here. The Shader Graph team doesn't have control over those.
     
    Qriva likes this.