Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Stencil Buffer

Discussion in 'General Discussion' started by HolBol, Aug 20, 2014.

  1. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Just reading over the 4.6 beta patch notes, and suddenly :

    Also known as YAY.
     
    angrypenguin likes this.
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Yay. Well that's one piece of more than 10-year-old technology sorted out, now just for those render textures ;D

    Actually you can do some kinda cool stuff with the stencil buffer, beyond just masking.
     
    bluescrn likes this.
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,315
    I TAKE BACK LITERALLY EVERYTHING BAD I HAVE EVER SAID ABOUT UNITY EVER.
     
  4. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,488
    What about stuff like for hair shading :)
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Hair shading? Isn't that typically just a shader with Kajiya-Kay or somesuch shading model? (i.e. does not need Pro)
     
  6. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,315
    My guess is they mean something like GPU particles for hair shading, ie TressFX. Which is even more confusing because that's something you can do in Free too, as long as you're targeting DX11.
     
  7. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,488
    I mean when I use alphas for hair, and I don't want to use AlphaTest because it looks unnatural. I would hope transparent surfaces would cast shadows properly... and plus clip maps don't use the full range of the alpha.
     
  8. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    So, now as i understand, uGUI is fully free ;) previously Unity said that stencil-related features in uGUI (but was small part though) will be PRO-only. I glad that they decide to make uGUI fully free.
     
  9. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,315
    Here's what I want to use the stencil buffer for. I want to test against the radius of a sphere and cull everything inside that sphere. Can I do this in Free?
     
  10. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    It says the stencil buffer access is now free.
     
  11. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,315
    ...Yes.

    I know.

    But I want to know if I can accomplish this specific thing with the stencil buffer.

    edit:



    This is an effect I was previously handling in an alpha clip shader, but handling it with stencil buffers would be better, I think. If it's possible.
     
  12. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,404
    It's possible yes (doing stencil depthtesting operations).
    Edited: I mean "depth test" (not ztest).
     
    Last edited: Aug 21, 2014
    Deleted User likes this.
  13. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,058
    Not sure that is actually possible with stencils, i'm unsure exactly how you could fill the stencil to get that exact effect, at least for the top part, not sure what is going on at the bottom.

    For example if you rendered a sphere with a stencil value and then excluded a cube where-ever the sphere was rendered it would not generate the same results as the sphere is solid so you would only get the corners of the cube. I guess rendering 6 circles with stencil on each side of the cube should work, but that doesn't seem to be much of an elegant solution, its essentially doing the same as your single shader solution, but with increased rendering operations, increased meshes.It may give a small performance boost, but I wouldn't count on it for that simple example.

    If you want to explore it though, check out the project in my sig that was designed to show off using the stencil buffer. Its a bit dated now and was only tested with pro, but it should still work.
     
  14. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,628
    Not stencil buffer but you can easily do that with a depth mask and Unity free, and it performs well on mobile... http://wiki.unity3d.com/index.php?title=DepthMask
     
  15. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,315
    There's not much special going on there. I'm just rendering backfaces on the mesh:

    https://dl.dropboxusercontent.com/u...er/WebPlayerRainFall3/WebPlayerRainFall3.html
     
  16. Alkanine9

    Alkanine9

    Joined:
    Mar 5, 2014
    Posts:
    11
    bool aprilFoolsJoke = false;
    bool reliableSource = true;
    bool checkedMyself = true;

    void Start() {
    if(!aprilFoolsJoke && reliableSource && checkedMyself) {
    party();
    }
    }

    void party() {
    Application.LoadLevel("clubhouse");
    }
     
    Ostwind, 8bitCartridge and HolBol like this.
  17. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    HAHAHAHAHAHA! :D :D :D LOL!

    This is the best thing i've heard all day! BTW, not April, ye fool! (Pun entirely intended! ;))