0
votes

In this game im writing I tried to render ice with transparency. Below the ice there is a solid block (a gray one). The light blue planes you can see are the sky sphere you can see through the stone. As you can also see it only doesn't work in one direction. My question is why those planes appear. I'm not drawing any qauds there. The only ones im drawing (the ice blocks) are the ones that face to the air. and the stone below.

I check if a face is drawn like this: check if neighbour cube is transparent AND NOT the same one as the cube which face should be drawn itself

the last check is to prevent that the ice cubes see each other as air and draw all faces where something is transparent.

I read something about transparency order on the internet but I dont't understand exactly what's the problem here.

enter image description here

1

1 Answers

2
votes

If you are using transparency you have to take care about the order of drawing objects. If you don't care about the order, following might happen:

  1. Sky is rendered far away and the buffer now contains the depth information of the sky for each fragment
  2. Transparent ice is rendered, depth information is updated since ice is closer to the camera than the sky
  3. Attempt to draw rock: Depth information is behind the ice for some fragments. As the renderer does not know about transparency it "assumes" you cannot see through the ice. So there is no need to render the rocks.

You can avoid that on object base by sorting objects. First draw solid objects from front to back. After that draw the transparent ones. However, if you have transparent objects near each other or stacked upon each others, you need a more sophisticated algorithm (e.g. order independent transparency) to avoid artifacts.