I finished a simple module to make photorealistic volumic cloud.
We use it as a SceneNode.
Code: Select all
// Before creating any cloud, we have to initialize the material of clouds:
setup_cloud_material(driver, driver->getTexture("clouds-group.png"), 4, 4); // texture, and number of texture by line and by row (see clouds.h)
// parent, ... position scale
CloudNode * cloud = new CloudNode(scenemgr->getRootSceneNode(), scenemgr, vector3df(1,0,0), vector3df(10,8,12));
You can download the archive at google drive
The maximum number of faces by cloud is 100 and can be changed in cloud.h. The effective cound depend on the camera distance to the cloud.
Screenshot of a scene mith 3 lamps: a big white, a small blue and a small red: 100 faces
As you see, the high number of faces makes a good effect for the light diffusion in the cloud.
With around 60 faces (~2 times farther)
With around 40 faces (~4 times farther)
KNOWN ISSUES:
* Alpha sorting problems with 2 differents clouds:
Faces are sorted before each render, to have a good alpha rendering. The sorting is done for each cloud before each frame, but only for the faces of the cloud. So when a cloud cover an other, there is sometimes transparency bugs. It appends when a cloud cover a more recently created cloud (render order of irrlicht)
* Very short bugs in alpha sorting when the camera moves fast
Faces are sorted during the method OnRegisterSceneNode called before every render, but maybe before the update of the camera position. A offset can appear sometimes between the orientation of the faces and the camera direction.
THE GEOMETRY
At the creationg time of the cloud, A tuple of points is determined to represent the cloud's geometry: its poles (by default it is a 5-uple, but can be changed in the header)
When the distance to the camera has changed a lot, the geometry is adapted: if the camera is farther than before, faces are removed around each pole.
When the distance have decreased, faces are added around each pole.
This way the cloud keep allways the same form.
THE ALPHA SORTING
At contrary of the way of the engine, faces haven't to be sorted by distance to the camera. Each face is orthogonal to the camera direction vector, and so are parallel. The only way is to sort it with the algebric distance to the camera, on the focal axis: