setShaderAuto() on transparent texture

Hello,

I has 2 hair textures.

  • hair.jpg : RGB texture
  • hair_trans.jpg : Grayscale texture (tell alpha channel)
    My egg code show below.
<Texture> Tex3 {
  hair_trans.jpg
  <Scalar> format { alpha }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
  <Scalar> alpha { dual }
}
<Texture> Tex2 {
  hair.jpg
  <Scalar> format { rgb }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
  <Scalar> envtype { modulate }
}

And combine them to make a transparent hair.

   <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { Tex2 }
      <TRef> { Tex3 }
      <VertexRef> { 5 1 0 <Ref> { hair_00.verts } }
    }

When I load the hair model it’s work fine.
But when I use self.hair.setShaderAuto() the texture show black.
Do I miss something?
What is the absolute method to use setShaderAuto on transparent texture.
Please give me an advise.

Thanks in advance.

  • Ola -

I don’t know why your shader isn’t working, but you can combine the two images more efficiently into a single texture, like this:

<Texture> Tex2 {
  hair.jpg
  <Scalar> alpha-file { hair_trans.jpg }
  <Scalar> format { rgba }
  <Scalar> wrapu { repeat }
  <Scalar> wrapv { repeat }
  <Scalar> minfilter { linear_mipmap_linear }
  <Scalar> magfilter { linear }
  <Scalar> envtype { modulate }
  <Scalar> alpha { dual }
}

And then apply only the one texture:

   <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { Tex2 }
      <VertexRef> { 5 1 0 <Ref> { hair_00.verts } }
    }

Perhaps this will make it easier on your shader hardware.

David

Thank you David.
I will try. :slight_smile:

I have a related question. First I had the same problem with the black texture when alpha is defined as a second texture in the egg-file. Combining it to ine texture did the trick, its colored and transparent as it should be.

Now my question: I have to change the color-texture at runtime. When I do this with self.hair.setTexture(…) I loose the alpha-component.
How do I provide the alpha-part in python? Especially the alpha { dual } part?

You can load a texture with a separate alpha channel like this:

loader.loadTexture("rgb.png", "transp.png")

You can specify the “dual” part using this:

nodePath.setTransparency(TransparencyAttrib.MDual)

Thank you :slight_smile: