Cloud generator (POV-Ray)

by Oyonale
Media based on density files (df3) tend to render much faster than procedural-based media and still interact nicely with lighting. For this reason, df3 files can be used to create realistic cloudscapes, and particularly ones impossible to create with other methods.In the download section below you will find complete scenes (written in pure POV-Ray script) and the corresponding df3 files. These scenes took between 3 and 6 hours to render at 1600x600 or 800x600 on my P4 1.7Gz (with the exception of "Sunset 2" which took 35 hours, probably because it uses an extra light source), which is quite fast considering that they all use radiosity and many "slow" features such as other media and isosurfaces. The clouds themselves took 1-2 hours depending on the scene.The MakeCloud macros help create df3 files such as the ones used in these scenes. These macros work as follows: they create a 3-dimensional black and white pigment in the x-y plane that defines the shape of a single cloud. This pigment is moved along the z axis, so that, when the macro is rendered as an animation, each frame (in TGA format) corresponds to a "slice" of the pigment (like in a tomography scan), as shown in the picture below (10 frames, z axis in red)The main difficulty consists in creating a credible cloud shape and the two macros use different methods:Makecloud1.pov uses a procedural pigment (a function with some turbulence). It is quite fast and can be used for very fluffy, turbulent clouds.Makecloud2.pov first creates a 3d cloud object (a blob) and then uses this object as a pigment. It is slower than Makecloud1 but much more flexible, and it gives more compact clouds.See the macros' headers for usage and meaning of parameters.To produce the df3 file from the TGA bitmaps, the tga2df3 utility is required:tga2df3 for Windows (courtesy of PodD)tga2df3 for Linux (courtesy of ZeSly)The df3 file is put in a box as follows (the scattering and absorption values are just examples):#declare C_Cloud=White*0.7;#declare C_Scattering=C_Cloud*0.004;#declare C_Absorption=(1-C_Cloud)*0.0005;#declare Cloud=box{-0.5,0.5    texture{pigment{Clear}finish{ambient 0 diffuse 0}}    hollow    interior{        media{            scattering{1,C_Scattering extinction 0.3}            absorption C_Absorption            intervals 3            density{                density_file df3 "cloud2_1.df3"                turbulence 0.15 // mostly useful for MakeCloud2 clouds, which are not created turbulent                lambda 2.1                omega 0.8                interpolate 1                translate -0.5                scale <1,-1,1>            }        }    }    scale <4/3,1,1>} NotesThe df3 files in the demo scenes have been rendered with 90 or 99 frames at 512*384 pixels:  +w512 +h384 +ft +a +kff99When testing the clouds, use intervals = 1. It should be quite fast but will look a little rough. Use intervals 2 to 4 for smoother results in the final (slower) render.POV-Ray reads df3 files upside down, so it is necessary to scale them by <1,-1,1>Using different light_groups for the clouds and the rest of the scene may be necessary (see the makecloud2 demo scenes).For MakeCloud1 clouds, turbulence is part of the df3. For MakeCloud2 clouds, turbulence is added in the media statement.LimitationsOne of the reasons why df3 clouds are fast is (probably) that the density values are precomputed. The other is that each cloud is in its own box. In fact, it should be possible to get more speed by using a smaller container, at least if the cloud isn't too turbulent. The cloud box technique has 2 important drawbacks though:Boxes must not overlap: if you see vertical lines in the middle of a cloud, it is probable that another cloud is overlapping. This is (very slightly) the case with the MakeCloud1 demo scene. This prevents the df3 cloud boxes from being used for dense cloud covers where they should be overlapping. One could theoretically put several media df3 in a bigger box, but then the render times start climbing up.The clouds projects shadows on the objects below, but as the media is constrained in the cloud box it is not currently possible to have beautiful rays of light passing through the cloud. Of course, one can see what happens by putting a cloud in a larger box filled with scattering media, but again the render times won't be very nice. In fact, I even tried to fake this by putting a simple half-transparent box under the cloud (see the Makecloud2_demo_rain.pov file) but it just clogged my computer...Also, the cloud shapes in Makecloud1 and Makecloud2 are still far from optimal and people are invited to experiment with other methods. One particular issue is to keep the bottom of the cloud flat... In real life, the top of a cloud can get quite turbulent and fluffy even when its bottom is completely flat. MakeCloud2 can extend the cloud vertically but it doesn't work very well.Brief summary of the available methods to create clouds in POV-RayMethodPros (1)ConsPhoto backgroundFast ; easy to set up ; realistic by definition ; all types of cloudsPoorly scalable (2) because limited by the size of the photo ; requires photos that match the scene ; partial environments only ; doesn't interact with lighting (3) ; possible mismatch with 3D objectsTerragen backgroundFast ; scalable (Terragen images can be very large) ; relatively easy to set up for simple situations ; quite realistic ; possibility to model an entire environmentRequires a good knowledge of Terragen ; can be difficult to set up for complex situations ; limited to the skies Terragen can do (which can be quite recognisable) ; doesn't interact with lightingPigment on plane or sky sphere (entire sky)Fast ; very scalable ; can be realistic enough in certains situationsDifficult to set up ; doesn't interact with lighting ; useless for many cloud environmentsPigment on polygon (mimics a single cloud)Fast ; scalable ; realistic enough for some large cloudscapes of isolated clouds seen from a certain angleDifficult to set up ; doesn't interact with lighting ; useless for most cloud environmentsStacked planes with a partially transparent pigmentFast and scalable at screen resolution ; usually more realistic than the pigment method ; interacts with lighting ; good for dense cloud coversCan be slow to very slow when high resolutions are needed ; not very good for isolated clouds, like fair weather cumulusMedia (procedural using a pattern such as bozo or granite)Scalable ; can be very photorealistic, particularly when used in combination with other atmospheric media ; near-perfect interaction with lightingPainfully slow (too slow for large renders) ; very difficult to set up and test due to slowness ; not very goof for isolated clouds, like fair weather cumulusMedia (density file)Quite fast ; can be photorealistic ; partial interaction with lighting ; good for isolated fluffy clouds, like fair weather cumulusNot fully scalable ; can be difficult to set up ; requires the generation of df3 files and an external utility ; not usable for dense cloud covers(1) Pros and cons are relative, and counter-examples can certainly be found.(2) Scalable in this context means that the object or texture retains its aspect independently of the render size.(3) A cloud interacting with lighting should change its aspect according to the sun position, colour and intensity, and project shadows both on the media and objects below. All this can obviously be faked somehow when the basic technique doesn't support it.