10

Is there a way to set a transparancy channel in a raster image used for a texture in 3d graphics?

this creates a raster image with a transparency channel:

img = SetAlphaChannel[Image@Table[0, {400}, {400}], 
        Graphics[{GrayLevel[0], Disk[]}]];

This works just fine in a 2D graphic:

Graphics[{Thick , Red, Line[{{0, 0}, {1, 1}}], Inset[img], Thick , Blue,
        Line[{{1, 0}, {0, 1}}]}]

Mathematica graphics

But in 3D my transparent region is just white..

Graphics3D[{Line[{{1/2, 1/2, 1/2}, {1/2, 1/2, 3/2}}], Texture@img, 
    Polygon[{{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}, 
    VertexTextureCoordinates ->
        {{0, 0, 1}, {1, 0, 1}, {1, 1, 1},{0,1, 0}}]}, Lighting -> "Neutral"]

Mathematica graphics

Any ideas?

Ive already treid the rendering options here with no joy: Transparent textures don't show

-- the point of this is to import real raster images and set a transparancy mask by the way.

george2079
  • 38,913
  • 1
  • 43
  • 110

1 Answers1

8

As usual seconds after posting I figured it out...

The Raster needs to be three channels to start:

         img = SetAlphaChannel[Image@Table[{0, 0, 0}, {400}, {400}], 
                  Graphics[{GrayLevel[0], Disk[]}]]

And Texture needs to operate on the image data rather than directly on the image..:

        Graphics3D[{Line[{{1/2, 1/2, 1/2}, {1/2, 1/2, 3/2}}], 
           Texture@ImageData@img, 
           Polygon[{{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}}, 
           VertexTextureCoordinates -> {{0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 
               1, 0}}]}, Lighting -> "Neutral"]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
george2079
  • 38,913
  • 1
  • 43
  • 110