Transparency issues. Bah!

Searched the forums for this rookie problem but nothing seems to work.

I started up an old panda project of mine and working on getting it up to speed with 1.7 (I think I last touched it with panda 1.6.0). I copySubImage a PNMImage from a 256 color bitmap image, addAlpha() to it, and then setAlpha() anytime the pixel is white.

On the model I set setTransparency(TransparencyAttrib.MDual). Put the PNM into a texture, put the texture on the model, but no transparency. All the white parts are still visible.

What alpha value are you setting where you want to have transparency? The convention is that alpha = 0 means fully transparent, while alpha = 1 means fully opaque.

David

Manual says addAlpha() fills with 0 (transparent), and then whenever the pixel is not white, alpha is set to 1.
The maddening thing is the code use to work, so I am flabbergasted.

def Tile(sourceImgPath = '', alphaColor = (None, None, None), tileSize = (0, 0), location = (0,0)):
    sourceImage = PNMImage()
    textureFile = Filename(sourceImgPath)
    sourceImage.read(textureFile)
    tile = PNMImage(tileSize[0], tileSize[1])
    tile.copySubImage(tiles, 0, 0, location[0], location[1])
    tile.addAlpha()
    for x in range(tile.getXSize()):
        for y in range(tile.getYSize()):
            if tile.getXel(x,y) == VBase3D(alphaColor[0], alphaColor[1], alphaColor[2]):
                pass
            else:
                tile.setAlpha(x,y,1) 
    return tile

Are you sure that this condition is ever returning True?

if tile.getXel(x,y) == VBase3D(alphaColor[0], alphaColor[1], alphaColor[2]):

Relying on floating-point equivalences is spotty at best.

David

Yup, I’ve done print statements, and even written the image as png to disk with alpha is present as intended.

Well, I have to make stabs in the dark, please bear with me.

Are you sure the TransparencyAttrib is sticking? Try specifying it with an override. Also try the simpler TransparencyAttrib.MAlpha for now:

model.setTransparency(TransparencyAttrib.MAlpha, 1)

Do you have a shader applied? A custom shader will override all of your state, including transparency settings.

When you apply the texture, you aren’t setting it on a custom TextureStage with custom texture modes, right?

Do other textures you load from disk work properly?

Do other models you load from disk, with transparency built into the model, work properly?

David

I do have a custom shader applied. That would also explain the odd texture scale too. I’ll need to fix up my node tree, thank you!