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.

I recently encountered a problem when combining multiple texture layers in an graphics object when the texture comes from an image with alpha channel. Apparently the alpha channel of the image passed to Texture[] as an argument is not represented as it should be in the obtained Graphics object. Instead of delivering true transparent texels I just get non transparent white ones. The same issue applies to usage of Texture[] with Graphics3D.

Here is a simple test case:

I first create two images, the second one containing an alpha channel:

layer1 = Image[RandomReal[1, {12, 12, 3}]];
layer2 = SetAlphaChannel[Image[RandomReal[1, {12, 12, 3}]], 
   Image[Join[ConstantArray[0, {6, 12}], ConstantArray[1, {6, 12}]]]];

Then I lay layer2 on top of layer1 and create a Graphics object of each layer using a Texture on a polygon:

Graphics[{Texture[layer1], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}], 
  Texture[layer2], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]

Unfortunately I only get white pixels where layer2 should be transparent. enter image description here

If I just pass the ImageData of layer2 things work, but the rest of the image information is lost (notice the additional blurring):

Graphics[{Texture[layer1], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}], 
  Texture[layer2//ImageData], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}]

enter image description here

Is this a bug or am I missing something?

share|improve this question
    
why don't you use ImageCompose[Image[layer1], Image[layer2]]. –  Rorschach Oct 22 '13 at 18:11
    
@Blackbird: Don't be fooled by the example above. This is just a simple example that everyone can use to reproduce the problem. I actually use the above procedure with Graphics3D and mapping of the texture on different planes. The same problem appears there. –  Wizard Oct 22 '13 at 20:27
    
You can check the Heike's answer here. You may find it useful. stackoverflow.com/questions/8458675/… –  s.s.o Oct 22 '13 at 22:03
    
@s.s.o: Unfortunately the link does not help with the problem at hand. Setting the alpha channel is not the problem here. The problem seems to be using an image object that contains an alpha channel with Texture[]. –  Wizard Oct 23 '13 at 8:53

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.