I’m happily using Panda3D from 1 year now and I like it a lot
Now I have a small issue with transparency, I think it should be easy to solve but I lack the required knowledge.
I have a few flat ‘ribbons’ (all have zero Z) overlapping / com-penetrating each other. They all have the same color, only alpha is changing along with the distance from a point. The goal is to have a simple fading effect: the higher distance, the more transparent the ribbon is, until it completely fades away.
It works ok, but in the overlapping parts the color is brighter and it flicker like in the picture below: red regions not ok.
My goal is to ‘fuse’ the ribbons together so that it looks like a unique surface and the color changes smootly; the overlapping regions not visible.
The ribbons are generated at runtime from a live datastream I have no control on. I used GeomTriangles and GeomVertexData to create the geometry; color and alpha are assigned to each vertex.
I tried to use
ColorBlendAttrib::make(blend_mode, operat_a, operat_b, alpha_blend_mode, alpha_op_a, alpha_op_b)
but it seems that only the rgb part was having effect while the alpha part was not having any visible effect.
I also tried the
DecalRenderAttrib again with no visible differences.
As a bonus, I’d like those ribbons to be able to ‘receive’ shadows from other objects over it, but not to cast shadows themselves: yellow region in the picture.
Any help would be appreciated.
Hmm… it’s odd that the overlapping regions are brighter than expected. If I may ask, could you show us the code that sets up these objects, please? Specifically, anything that alters how they’re rendered (e.g. making them additive, or disabling depth-testing, etc.)
Transparency can get tricky when transparent objects may interpenetrate. You see, standard transparency depends on having its elements rendered from furthest to nearest–if they’re not, one can end up with unexpected results. Panda3D does by default automatically sort transparent objects for this reason, I do believe–but it sorts objects, not each pixel, meaning if it’s possible to have some parts of an object behind and other parts in front of some other object, the results again might not be as expected.
This can be further complicated by depth-testing: if a more-distant object is rendered after a less-distant one, depth-testing may result in it not being rendered at all. Now, one can disable depth-testing for specific objects–as long as doing so doesn’t cause other problems.
One fairly easy solution–as long as the results are suitable to your intentions–is to render your transparent objects additively. With additive rendering, the order in which objects are rendered no longer matters, allowing both for interpenetration and unsorted objects.
Otherwise, depending on your specific situation, there might be other blending modes (such as the “max” blending-mode) that work for you.
You should find a bit more information on this topic on the manual page below:
thanks for your reply.
I’m trying to create a minum example to reproduce the effect.
In the meanwhile, I can answer you the options I use on each ‘ribbon’ are the following:
I think that Panda is doing a good job trying to achieve a correct real-world result.
I agree that using something like the ‘max’ blending should provide the result I want, but I was not able to achieve it.
I tried different variations of
ColorBlendAttrib::make(add, one, zero, max, O_incoming_alpha, O_fbuffer_alpha)
but while modifying the first three params did produced visible changes, modifying the latter three did not produce any visible effects. Seems like they were ignored. Shall I do something to enable it? Like calling
set_transparency( 'something') or other ?
That could well be very helpful, so thank you!
Hmm, okay, that seems reasonable I do think.
Part of the reason that the last three parameters seem to be ignored may simply be that the “max” blending-mode doesn’t actually use any parameters aside from the blending-mode itself, so the last two parameters at least should be ignored, I believe.
That said, if the “max” blending-mode itself is being ignored, I’m not sure of why that is. It might be that the use of additive blending for the RGB channels (as you’re specifying by the first three parameters there, I believe) is resulting in it being ineffective–but I’m really not sure.
Have you tried “simple” max-blending, without separating the RGB and alpha channels, such as shown below?