1

I have a mesh (plane with some modifiers) with a material assigned to it in Blender, and the texture of the material uses a semi-transparent PNG image.

When exporting to POD file, the mesh still looks semi-transparent in PVRShaman as it does in Blender, but when I import it in Cocos3D as CC3DPODMeshNode it appears as the image itself is still semi-transparent, but it also has a blueish color behind it, in the background.

Any idea why this happens?

The settings seem to be OK in Blender, because I can visualize it correctly after export, but what's wrong on the Cocos3D side?

NirMH
  • 4,769
  • 3
  • 44
  • 69
Andrei Marincas
  • 446
  • 5
  • 13

1 Answers1

1

You might be dealing with pre-multiplied alpha. For efficiency, Xcode (and the iOS image loaders) assume that alpha is to be pre-multiplied into the colors within each texture, and actually modifies the textures during app packaging and texture loading. This is a well-known issue with Xcode and iOS.

Try changing the name of the PNG file to give it a ppng file extension. That will cause Xcode to skip the file manipulation at build time and will cause Cocos3D to use a non-Apple file loader for the image.

See the notes for the CC3Texture class or the texture property of CC3Material or CC3MeshNode for more on this.

[Edit]:

This turned out to be an issue with the rendering order of two nodes that contain transparency. The bluish color was coming from the scene backdrop, which was behind the skybox. The object of interest was being rendered before the skybox, which also had a texture containing transparency. Normally, Cocos3D will automatically render opaque objects first, then translucent object in reverse order of distance from the camera. In this case, the skybox contained transparency (had an alpha channel), and was being rendered after the object of interest. It's generally good practice to make sure the texture used for skyboxes is opaque and contains no alpha transparency.

It's also possible to force the skybox (even a translucent skybox) to be rendered first by setting its zOrder property to a positive value (it defaults to zero). The zOrder property can be used to fix the rendering order of transparent objects. It is not required (and has no effect) on fully opaque objects.

Bill Hollings
  • 2,344
  • 17
  • 25
  • Changing the extension to 'ppng' will actually throw an error because it can't find the original 'png' image, and as a result no image will be loaded and the material's diffuse color will be visible instead (even though the material uses z transparency with alpha 0) – Andrei Marincas Jul 21 '14 at 08:21
  • I can use 'ppng' directly in Blender or load the material texture as [CC3Texture textureFromFile:@"myimage.ppng"], but it behaves exactly like 'png' – Andrei Marincas Jul 21 '14 at 08:50
  • Almost working with ppng... I moved the plane higher on the y axis, and rotating the camera around the y axis and looking down to the plane, but the plane is semi-transparent only for half of the rotation; for the other half it becomes blueish again. – Andrei Marincas Jul 21 '14 at 12:55
  • If the problem is happening dynamically (eg- as it rotates), then it won't be an issue with the texture content itself. Where is the bluish tint coming from? Do you have another object behind your plane that is providing it? Are you encountering Z-fighting by having two co-planar surfaces? If you are still having an issue, ZIP up a small Xcode project that demos it, send it to support@brenwill.com, and I'll have a look at it. – Bill Hollings Jul 21 '14 at 18:31
  • The bluish color comes from the scene's backdrop but I don't know how is that possible, because the semi-transparent plane is inside a sphere, which is opaque (uv mapped to a jpeg image). I'm already preparing a demo project, I would appreciate if you could investigate the problem. – Andrei Marincas Jul 23 '14 at 08:35