Page 1 of 1

discard overlapping transparent pixels?

Posted: Thu Mar 08, 2018 5:07 pm
by andrea_i
Hi! I'm pretty new to irrlicht and loving it so far, I'm making a brush sketching tool and I got stuck on this issue:

I'd like for each of my strokes to never show overlapping alpha with itself, thus avoid the artifacts visible in this image:
Image

What I'd like to achieve instead, is having each stroke to overlap only with subsequent or previous strokes, based on Z depth, because it's a 3d paint app.
Also, in this app there's no shading or lights, all flat. Not sure if it helps solving the issue or not.

I've read it might be necessary to use the stencil buffer, but to be honest I'm no openGL expert, I can pretty much work my way around a GLSL shader but I can't write one of my own, especially with advanced techniques, so I'm hoping someone will be able to help here!

Thanks!
Andre

Re: discard overlapping transparent pixels?

Posted: Fri Mar 09, 2018 12:44 pm
by CuteAlien
Maybe https://en.wikipedia.org/wiki/Alpha_compositing can help a little bit. It's a tricky problem.

Re: discard overlapping transparent pixels?

Posted: Fri Mar 09, 2018 12:51 pm
by andrea_i
Thanks!
It looks like someone figured it out in Unity using a vertex+fragment shader and stencil buffers, here's the post:
https://mispy.me/unity-alpha-blending-overlap/

What I desperately need from this community is guidelines to do the following (because I really can't find my way around this):
1) add a CG shader that uses the stencil buffer
2) set the blend function to this: SrcAlpha OneMinusSrcAlpha

Eventually I guess I'll figure it out, looking at the shadows implementation in irrlicht, but it might take me a while...please help : )