discard overlapping transparent pixels?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
andrea_i
Posts: 2
Joined: Thu Mar 08, 2018 4:56 pm

discard overlapping transparent pixels?

Post 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
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: discard overlapping transparent pixels?

Post by CuteAlien »

Maybe https://en.wikipedia.org/wiki/Alpha_compositing can help a little bit. It's a tricky problem.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
andrea_i
Posts: 2
Joined: Thu Mar 08, 2018 4:56 pm

Re: discard overlapping transparent pixels?

Post 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 : )
Post Reply