Upcoming Events
Southwest Gaming Expo
11/20 - 11/22 @ Dallas, TX

Workshop on Network and Systems Support for Games (NetGames 2009)
11/23 - 11/25 @ Paris, France

ICIDS 2009 Interactive Storytelling
12/9 - 12/11 @ Guimarães, Portugal

Global Game Jam
1/29 - 1/31  

More events...


Quick Stats
7109 people currently visiting GDNet.
2341 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

Link to us

  Intel sponsors gamedev.net search:   

Real-Time Realistic Cloud Rendering and Lighting


7. From Impostors to Full 3D Models

A visual improvement can be obtained by changing between rendering impostors and rendering the full 3D cloud. This helps when objects pass through clouds as they won't simply show up as clipping the cloud impostor billboard but they will appear to really travel through the cloud.

First of all we need to determine below which distance the cloud should look fully 3D and above which distance the cloud should appear only as an impostor taking into account the size of the cloud. Through experimentation good values for these distances are 2 times the radius of the cloud and 4 times the radius respectively. In between these distances we will fade the impostor out from fully opaque to fully transparent. The 3D will also be faded but it will go from transparent to opaque as the camera draws nearer.

To calculate the alpha value when the impostor and the 3D model are fading we use:

alpha = (Clouds[i].DistanceFromCamera - dist_3D) / (dist_impostor - dist_3D);

The main problem is that the texture already contains an alpha channel and we need to blend it with the GL_ONE, GL_ONE_MINUS_SRC_ALPHA factors. Thus we cannot simply use the alpha value of the color to fade. Setting the all the components of the color to the color will achieve this. Thus in the impostor rendering function we use:

glColor4f(alpha, alpha, alpha, alpha);

The 3D rendering function looks very similar to the impostor creation function, excluding the viewport and camera changes. To fade the particles we must multiply their colors by the alpha value and then send it to OpenGL.

ParticleColor.R = (0.3f + Puff->Color.R * phase) * alpha;
ParticleColor.G = (0.3f + Puff->Color.G * phase) * alpha;
ParticleColor.B = (0.3f + Puff->Color.B * phase) * alpha;
ParticleColor.A = Puff->Color.A * Puff->Life * alpha;

The conditions for determining which way to draw the cloud are:

//beyond this render only the impostor
dist_impostor = Clouds[i].Radius * 4;
//square this since the camera distance is also squared
dist_impostor *= dist_impostor;
//closer than this render only the 3D model
dist_3D = Clouds[i].Radius * 2;
//square 
dist_3D *= dist_3D;

if (Clouds[i].DistanceFromCamera > dist_impostor)
  RenderCloudImpostor(&Clouds[i], 1.0f);
else
  if (Clouds[i].DistanceFromCamera < dist_3D)
    RenderCloud3D(&Clouds[i], Camera, Sun, 1.0f);
  else
  {
    alpha = (Clouds[i].DistanceFromCamera - dist_3D) / (dist_impostor - dist_3D);
    RenderCloudImpostor(&Clouds[i], alpha);
    RenderCloud3D(&Clouds[i], Camera, Sun, 1.0f - alpha);
  }

8. Conclusion

Harris' method for cloud rendering is suitable for real-time applications requiring a realistic model for clouds which one can fly through. With the added advantage of impostors the performance is good even for a large number of clouds. However the method does present some disadvantages:

  1. If the light direction changes the whole lighting algorithm has to be executed again which is expensive if it is to be done in real-time. This can be alleviated by distributing the calculations over several frames and storing intermediate results in a separate texture. Loading the texture from the framebuffer is a rather inexpensive operation and can be performed each frame to store the calculations. Another advantage of using such a texture is that it can be used as a lightmap, projecting it on geometry underneath to achieve correct shading.
  2. The time required by the lighting algorithm is significant and for many clouds the processing time can slow down the loading of the game. This is however a fair trade-off for having realistic clouds.
  3. Using the splat texture the clouds always look very fluffy, there is a lack of detail. Niniane Wang proposes a different, artistically based method, used in Microsoft Flight Simulator 2004, which gives better detail on the clouds and uses less particles which comes as a trade-off to physically correct lighting.

A problem arises when objects are in the clouds as sharp edges will be visible. This can be solved, as Harris shows, by splitting the impostor with a plane on which the object resides. For further details refer the original paper.

9. References

[1]  Mark J. Harris and Anselmo Lastra, Real-Time Cloud Rendering. Computer Graphics Forum (Eurographics 2001 Proceedings), 20(3):76-84, September 2001.

[2] Niniane Wang, Realistic and Fast Cloud Renderin, Journal of graphics tools, 9(3):21-40, 2004

[3] Matt Pharr, Greg Humphreys, Physically Based Rendering: From Theory to Implementation, Morgan Kaufmann, Hardcover, August 2004, ISBN 012553180X





Contents
  Introduction
  The phase function
  From Impostors to Full 3D Models

  Source code
  Printable version
  Discuss this article