Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
Interestingly, the original code works just fine in my case under Mma 10.0.1. –  kirma Sep 23 at 18:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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