Issue with <Texture> blocks that use the same file

I seem to have found an issue with how blocks in egg files that use the same file act.

I have something like this:

<Texture> A {
  "./thetexture.png" //this png only has RGB
}

<Texture> B {
  "./thetexture.png"
  <Scalar> alpha-file { "./alpha.png" } //this file also has rgb, but it represents an alpha channel
  <Scalar> format { rgba }
  <Scalar> alpha { blend_no_occlude }
  <Scalar> draw_order { 1 }
}

Now the problem I have with this is the following:
If polygons that use Texture B are defined first in the Egg their appearance is correct, but polygons with Texture A also look transparent unless I add a alpha { off } to the declaration of A.
The real problem is when polygons that use Texture A are defined first, because then, no matter what I do I can’t get the Texture B polygons to look transparent.

Right. Textures that reference the same filename are collapsed into the same Texture objects, for efficiency reasons. This happens even if they have different properties, which is unfortunate if you really meant for them to have different properties (though experience shows that usually, they have different properties only by mistake).

The cheesiest workaround is to make a copy of your texture file, under a different name, so your two objects can load different filenames. Of course, this would mean that your texture would now be resident in texture memory twice, which would be necessary if you truly had different texture properties.

But in fact, you don’t really need different texture properties in this case; you’re really setting different polygon properties (transparency type, draw order). By convention, egg lets you set these properties in a entry, since that’s often a convenient place to put them; and then the egg loader knows to apply these properties to any polygons that use this texture. So the alpha and draw-order are not actually texture properties, and therefore they can be set differently for both textures A and B.

What can’t be different between textures A and B is the alpha channel. If you really need the alpha channel to be different, then yeah, you really need two different textures. But because in your case you just want the polygons that reference texture A not to be transparent, in that case it’s OK if texture A has an alpha channel, you just won’t be using it.

So, bottom line: change your entries to look like this:

<Texture> A {
  "./thetexture.png"
  <Scalar> alpha-file { "./alpha.png" }
  <Scalar> format { rgba }
  <Scalar> alpha { off }
}

<Texture> B {
  "./thetexture.png"
  <Scalar> alpha-file { "./alpha.png" }
  <Scalar> format { rgba }
  <Scalar> alpha { blend_no_occlude }
  <Scalar> draw_order { 1 }
} 

David

Thank you very much for taking the time to clear that up.