The clouds in Minecraft are semi-transparent and are rendered on both sides. If you fly into the cloud you can see inside of the cloud. If I render clouds the inside faces would be visible on the outside. How can I prevent that? Z-Ordering the faces and render near to far with depth test on? There must be a better, easier way. Could the accum or stencil buffers be used somehow?

UPDATE : I think the crucial point everyone is forgetting is that these clouds and semi-transparent and "blended" into the scene as each face is rendered. If two faces are rendered on top of each other the "white" texture will double up which is undesired. The faces also seem to have slight lighting variations which would rule out using a stencil.

UPDATE2: Just another note. Each cloud is 12x12x4 blocks (roughly). Larger clouds are just a group of the base clouds stuck together.

Here's showing clouds from above. They are translucent and the chunks below can be seen. enter image description here

And here's the view from inside them. enter image description here

  • 5
    \$\begingroup\$ I don't play Minecraft and I'm having some trouble visualising the situation. Do you have a representative screenshot? \$\endgroup\$ – Anko Aug 17 '15 at 2:54
  • \$\begingroup\$ thanks for the screenshots, I had no idea what you were talking about \$\endgroup\$ – jhocking Aug 17 '15 at 13:54

Set culling to cull front faces first, then render your clouds. This will render the backfaces. After that, switch culling to cull backfaces, and render the clouds, which will render the front faces on top of the back faces.

This will prevent rendering your backfaces on top of the front faces, but still keep back faces visible all times.

Update: From the pictures, I see that the backfaces are only visible when you are inside. Just switch the order of the above instructions: Render front faces first, backfaces later so they are discarded by the z buffer if you are outside. Just render with culling disabled in that case.

  • \$\begingroup\$ Why not just render without any culling? - That would do the same as you're suggesting but with one less draw call I think \$\endgroup\$ – Elva Aug 17 '15 at 8:37
  • \$\begingroup\$ Yes, the first solution would require the 2-pass approach but the updated answer would not, you're right. I'll correct it. \$\endgroup\$ – János Turánszki Aug 17 '15 at 9:25
  • \$\begingroup\$ Your first answer I think will work, but I'll have to still Z-Order my clouds or else one cloud behind another would be visible. \$\endgroup\$ – Peter Quiring Aug 17 '15 at 12:38
  • \$\begingroup\$ But at least you won't have to sort faces, only the clouds. And keep in mind, if you do it by my first method, you will see the inside at all times, even if you are outside. The second method resemles the images more. \$\endgroup\$ – János Turánszki Aug 17 '15 at 14:04
  • \$\begingroup\$ My clouds are vertex buffers (OpenGL 2.x) so I can't sort the faces. I tried just disabling culling and clouds overlap, even if they are z-ordered. Your first answer is so far the best solution. \$\endgroup\$ – Peter Quiring Aug 19 '15 at 0:12

Sounds like the clouds have both inside and outside faces. Make your cloud double sided but don't turn off backface culling.

  • \$\begingroup\$ Because the clouds are semi-transparent and blended into the scene this will not work. You will still see the inside faces even from outside the cloud. \$\endgroup\$ – Peter Quiring Aug 17 '15 at 12:35

I think there's a special shader for that. To lighten the alpha calculation, it might only consider the first alpha from the mesh from the POV, and blend everything else behind it that has no alpha (or that is not clouds).

From the inside of a cloud, other clouds are no longer visible.

  • \$\begingroup\$ Is this an OpenGL extension? Can you give me more details? \$\endgroup\$ – Peter Quiring Aug 18 '15 at 23:50
  • \$\begingroup\$ A fragment shader defines how pixels are rendered on the screen. It's basically a little program that you load into your graphic card and that processes every pixel shown on the screen before display. It's written in a specific language (GLSL for openGL). You can find more on internet. I never made such a shader, so I won't be able to help you more. Fragment shader is also called Pixel shader. Vertex shader is another thing, so be careful. \$\endgroup\$ – Crazyrems Aug 19 '15 at 10:11
  • \$\begingroup\$ I use pixel shaders already which gives the developer more control, but I don't see how they could help in this case. Each face is passed thru the shaders and the only way to avoid double exposure is to z-order the clouds. \$\endgroup\$ – Peter Quiring Aug 19 '15 at 12:54

I think the only solution is to do a 2 pass rendering (as Janos said). But the clouds first need to be Z-Ordered. Then render the outside faces of all clouds (back culling), and then render all inside faces (front culling). This will prevent seeing the inside faces from outside, and the sorting will prevent seeing a cloud behind another cloud. Remember the clouds and semi-transparent and "blended" into the scene as each face is rendered.

UPDATE : "Each" cloud must be rendered in 2 passes individually. Do outside faces, then inside faces. Then repeat that for each cloud. Clouds must still be z-ordered.

Here is some pseudo code:

void renderClouds() {
  Cloud clouds[] = getClouds();
  clouds = sortClouds(clouds);
  for(int a=0;a<clouds.length;a++) {
    clouds[a].render();  //render outside faces
    clouds[a].render();  //render inside faces

That works for me now. But I'm open to better ideas.


I suggest another approach:

First you render your world and sky, etc. just like you would do normally.

Then you have to sort the clouds (or the vertices of the clouds) from closest to the camera to furthest from the camera. You then test if the camera is inside a cloud, if this is the case, you will have to turn off back face culling so that the insides of the cloud will be rendered.

Then you render your clouds (from near to far) and if you have depth test enabled you will not have any clouds overlapping.

This is my theory. If it is wrong, please let me know so I can learn from it.

  • \$\begingroup\$ It's close , but will not work in every case. Sometimes the view can be half inside a cloud and half outside. That's why a 2 pass approach outside then inside is needed. \$\endgroup\$ – Peter Quiring Aug 25 '15 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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