Transparency Object Depth Sorting

Hey, it has been some time, look, normally this is not a issue for me as it is only cosmetic and I have gotten used to it, however I recently joined a game jam and decided to rebuild my Vortex The Pretty Game for it as a Magical Girl Game.

Now, I just showed some of the progress that I was doing recently, and it seems people are not comfortable with the fact then when the character spins, her insides show up as her human character model disappears, if you played Whirligig Willies, you may have noticed this issue, and yes it does bother me, but I never found a really good reason to ask why that happens.

If you don’t know what I,am talking about here is a small picture of the issue in action.
Screen Shot 2021-02-15 at 4.14.01 PM
it is obvious you can see her eyeballs, mouth, and petticoats, all show up out of her as she starts to disappear, and those objects all belong inside her, now is that time to ask, why? I read somewhere in the manual that using multisample or dual transparency fixes this, I,am using dual transparency, so I was wondering what I did wrong to get this sort of result.

Anyway Thank You to anyone with advice, or who can help me solve this issue, thanks.

Could you post the code that loads this character, please? (Including any settings that you apply to the NodePath(s) of the character, like setting “dual transparency”.)

Furthermore, what happens if you activate the “show-transparency” config-option? (By either including “show-transparency 1” in your “prc” file or running the following at the start of your program:

from panda3d.core import loadPrcFileData
loadPrcFileData("", "show-transparency 1")

If you do this, what elements of your model do you see flashing?

The “dual transparency” mode, if I’m not much mistaken, helps in certain specific circumstances, but isn’t a fix for all.

To quote the manual:

This only works well if the flats are typical cutouts, where there is a big solid part (alpha == 1.0) and a big transparent part (alpha == 0.0), and not a lot of semitransparent parts (0.0 < alpha < 1.0).

If you want to respect transparency, use

mymodel.setTransparency(TrasnparencyAttrib.MAlpha)

So the transparency is visible. If you want nothing to be transparent, just do:

mymodel.setColor(r, g, b, 1)

Is this in fact a transparency issue or is the model meant to be solid? If the models (or parts of it) are meant to be solid, then you should not enable transparency on those parts at all.

It’s hard to tell from the screenshot, but could it be that the model geometry is inside-out? Calling model.setTwoSided(True) is a quick way to check (but the right way to fix this is by flipping the faces in the modelling program).

sorry for the long response guys, I kinda overslept heh heh heh, anyway, thaumaturge you asked for the code bit, here it is,

        self.pactor = 0
        self.frobj.extend([Actor("actor/fr_"+str(self.pactor)+".egg", {"Walk": "actor/fr_"+str(self.pactor)+"-ani/walk.egg",
        "Stand": "actor/fr_"+str(self.pactor)+"-ani/Stand.egg", "Fall": "actor/fr_"+str(self.pactor)+"-ani/Fall.egg",
        "Swim": "actor/fr_"+str(self.pactor)+"-ani/swim.egg", "Defeat": "actor/fr_"+str(self.pactor)+"-ani/hurt.egg",
        "Jump": "actor/fr_"+str(self.pactor)+"-ani/jump.egg", "ShinnyHold": "actor/fr_"+str(self.pactor)+"-ani/Shinnyhold.egg",
        "ShinnyUp": "actor/fr_"+str(self.pactor)+"-ani/shinnyup.egg", "Slide": "actor/fr_"+str(self.pactor)+"-ani/Slide.egg",
        "RoleA": "actor/fr_"+str(self.pactor)+"-ani/taunt.egg"})])
        self.frobj[0].reparentTo(self.render)
        self.frtex[0] = loader.loadTexture("actor/tex/actx_"+str(self.pactor)+".png")
        self.mixtex["fr0"] = loader.loadTexture("actor/tex/actx_"+str(self.pactor)+".png")
        self.frobj[0].setTexture(self.frtex[0])
        self.frobj[0].setTwoSided(True)
        self.frobj[0].enableBlend()
        self.frobj[0].loop("Walk")
        self.frobj[0].setPos(0.0, 0.0, 6.3)
        self.frobj[0].setTransparency(TransparencyAttrib.M_dual, 1)
        self.frobj[0].setShaderOff() #temporary solution to the shadows on this

give me a chance to test you loadprc trick and I will get back to you.


@panda3dmastercoder I will give it try and get back to you hold on.
Edit: it gives a error, “r” is not defined.


@rdb how would that be done? I just enable transparency on the actor, should I try a get get paren or child? but would that effect all the children too? model.setTwoSided is always set to true for each model loaded, but I also go out of my way to make sure each face is flipped in the right direction.

the whole scene is flashing red, save for a few actors that are simple boxes

Okay, that indicates that all of those flashing elements are being treated as “transparent” (even if they’re not visibly so), which may be part of your problem.

(I’m not sure that it is the source of your problem, but it seems like it might be.)

You see, transparency generally calls for proper sorting. When the two transparent objects overlap significantly, then a shift in position can change which is calculated to be “nearer”, and thus the order in which they render.

In general, it’s wise, I think, to limit how many objects are treated as being transparent.

If you don’t intend for all of that to be transparent, then check your textures: it may be that some of them have alpha-channels, and are thus being considered to have transparency.

but the scene never goes transparent and it flashes
EDIT: wait, I just checked my load code, and yes I added a feature for glass

I wasn’t saying that it would become transparent–I was saying that it was being treated as though it were transparent: the elements are presumably being assigned to the “transparent” culling bin, and being sorted as transparent items are.

As to the flashing, if you mean the red, that’s the result of the “show-transparency” option, I believe: it’s using the red flashing to indicate which objects are considered to have transparency.

my apologies, I have a glass feature in place for some objects, in that case, is there a way to manually sort the object’s culling during the transparency like “setBin”?

What I’d suggest, rather, is that you limit your glass feature to only those things that are glass. (And again, to check your textures for the presence of an alpha channel.) Let Panda sort things automatically.

As to doing it manually, “setBin” is exactly the thing to use, I believe.

well I have a cutscene feature that needs everything to be dynamic, I am looking at the issue more, and it seems the transparency is not sync which is causing the issue, like the outside model goes invisible before the insides, maybe if I do it by child to child basis, it might work?

Looks like you misunderstood. The setColor method takes for arguments, r, g, b and a. It sets the color with the rgba format, where r stands for red, g stands for green, b stands for blue and a stands for alpha. If you set the alpha to 1, it won’t be transparent at all. But as you keep on decreasing the number (0.9, 0.8, 0.7…), it becomes more transparent. 0 means that it is completely transparent and the color isn’t visible at all. So I gave r, g, b, 1 so that you could give your own rgb values but keep 1 for the alpha for no transparency. If you don’t know rgba color values, please read the following tutorial: Colors RGB and RGBA.
Note: The tutorial is actually to apply RGB colors to a web page, but you can see how rgb gets rendered and use the same knowledge in Panda3D

EDIT: You can use the rgb calculator and find the colors. The calculator is in the same link. Only for alpha you have to do your own testing, seeing which alpha value works.

okay, fair enough, but I do not want change any colors, does all 1s work?

One works when you want no transparency. So if you want it to be half transparent, you have to set a to 05. A can be values from 0 to 1 (Including decimals between)

Note that calling “setColor” won’t change whether Panda treats an object as “transparent”, I believe.

Could you describe the feature, please?

It will if he calls the setTransparency(TransparencyAttrib.MAlpha) method.

It won’t, I believe. Calling “setColor” and “setTransparency” won’t change which culling bin the object is sorted into. An object placed in the “transparent” bin will still be there, and so the object will be treated as though it were transparent–even if there are no pixels with an alpha-value below 1.

if you played whirligig willies, there is a scene where one of the amendments (a magic stamp) commands a solid wall of vines to disappear to let you through to the first level, I use transparency to achieve this. so that is way it is always on.

Well, why not apply transparency only to the wall of vines, then? That way the effect should still work, without affecting anything else.