10
$\begingroup$

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.

$\endgroup$
7
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Interestingly, the original code works just fine in my case under Mma 10.0.1. $\endgroup$ – kirma Sep 23 '14 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.