ShapeNet / shapenet-viewer

ShapeNet Viewer
MIT License
188 stars 25 forks source link

Fix PNG transparency (Fixes #2) #22

Open baudm opened 6 years ago

baudm commented 6 years ago

This is a JME issue. Since the modified code is internal to JME, a new class with the same interface is created instead.

There are two problems:

  1. Renderer.readFrameBuffer() fills the output ByteBuffer with the wrong transparency information. Instead of setting the background to be fully transparent (0x00), the alpha channel bits are set to 0xff, or fully opaque.
  2. When an image of type BufferedImage.TYPE_INT_BGR is written, the alpha channel information is lost and is never written. Hence, we end up with 3-channel PNGs instead of 4.

This is a quick fix which should address the issue without waiting for JME to fix the issue on their end.

ghost commented 6 years ago

When I Render bowl,maybe the part of the bowl become transparency,how to solve it?

5f2ef71aa9b94edbb84959963148f2a2-0

baudm commented 6 years ago

Is this the result from my branch?

ghost commented 6 years ago

yes ,it is.I guess the channel of the alpha has a little problem

baudm commented 6 years ago

Ok, looking at my code, I think I'm making all white pixels transparent. The problem is: how to determine whether a white pixel is truly transparent (i.e. background) or still part of the rendered image?

ghost commented 6 years ago

I don't know whether to adjust the color of the light to decide to set the pixel to be transparent or not ? Always the direct zone of the ray or the brightest part seem to be wrongly decided. or applying Affine Transformation to decide to the transparent part if getting the motion info of the camera

baudm commented 6 years ago

I've read some comments before that the transparency is fine on OS X, but doesn't work in Linux and Windows. This is actually harder to fix because the actual rendered image doesn't contain proper values for the alpha channel.

ghost commented 6 years ago

Your advice is very important for me,thank you!