Volume displacement method for clouds using fluids

By -
Duration
6 mins

I was recently asked how to convert a cloud displacement map to bring it into Maya fluids. Displacement is rather incomplete for clouds.. even if one assumes the cloud bottom is flat, however it can look good in some cases. Also infrared images of clouds from space tend to nicely code for cloud height, because it gets cooler with altitude. Here is one of many sites that have nice infrared cloud images: National Geophysical Data Center 2D Fluid Displacement method (shown above) There are a few methods where one can import the data into a fully 3D fluid grid, although it is also possible to directly apply the 2d displacement image to a 2d fluid and volumetrically render it. The "useAsHeightField" toggle on a 2d fluid will interpret its opacity as displacement. It renders as a flat bottomed volume with continuous density between the bottom and the top or surface of displacement. The "pond" feature uses this toggle, but uses a surface render method. For clouds it is better to use a volume render method with self shadowing. In the examples I've attached I've mapped a texture to the opacity and edited the opacity graph to get good shape on the clouds. If one instead wishes to use a map then instead make the opacityInput = density, and make the density grid static. Make the opacity graph the default linear 0-1 ramp to start with. Set the fluid resolution to your displacement map resolution, then use the fluid paint tool import function to load the image into the fluid density grid. One can then adjust the the opacityInputBias and transparency to get the best effect. Also the edgeDropoff can be used to soften the bottoms of the clouds( although it also softens all 6 boundaries of the fluids container ). The fluid's size "z" value will determine the maximum displacment while the opacity determines the displacement relative to the range. The transparency attribute determines how opaque the clouds are. Here is a 2D fluid heightfield that uses noise on the opacity to create the clouds:

displacementClouds.ma (find this at the bottom)

Here is the same scene but with the addition of a second fluid for the atmosphere. (Create a 3D fluid and then select the SkyFog preset in the attribute editor)

displacementCloudsWithSkyFog.ma (find this at the bottom)

This next file uses a hurricane infra-red image loaded into a 2D fluid initial state for a more realistic cloud shape:

displacementHurricane.mb, fluid initial state (you'll find these at the bottom)

Here is the same file but with some added procedural noise to give it more detail than there is in the fluid grid:

hurricaneDetailNoise.mb (you'll find this at the bottom)

To animate the fluid One can simple set the initial state to a rotating velocity and simulate. (make sure to set density buoyancy to zero) You could paint velocity with the paint fluids tool or use a vortex field. Another method that can be very controllable is to keyframe the rotation of a drag field that has a magnitude around 10 and inherit motion set to 1.0.

hurricaneDynamic.mb (you'll find this at the bottom)

3D Fluid Method If you want to instead map a displacement to a 3d fluid grid there are a variety of possible methods, although they are generally harder to implement than the 2D method above and will require more memory. First off you should create a fluid that has the resolution set to cloud image resolution in x and z and the y resolution set based on the relative height of the cloud layer. Adjust the fluid size to the desired cloud bank size, but make sure the size value is always proportional to the resolution. Thus for a resolution of 1000, 500, 10 one might have a size of 20.0, 10.0, 0.2. The total memory used will be proportional to xres*yres*zres. Here are a couple of methods for initializing the fluid density values from the displacement image: 1. In the paint fluids tool Import the cloud image as density starting from the bottom fluid slice or layer(click on the light blue dial next to the fluid to set the layer.. the view initially rotates the layer unless on hit the lock icon). As one moves upward import the same (displacement style) texture, but threshold it so that only the peak intensities remain. The import remaps the image based on the min/max values in the paint attributes block, so I think one could use this to do the desired thresholding by making the min negative. 2. Write a script that loops over the image pixels, getting the color using either bonus tools iffPixelCmd or perhaps using colorAtPoint on a file texture with the image. For each pixel do setFluidAttr on the voxels where intensity from the image would be considered height, so for a given pixel if the intensity was one, one would set the density of all the fluid voxels in that column. If the intensity was 0.5 one would only set the bottom half of the voxels in that column, etc.. 3. Apply the texture as a displacement to a surface. Convert this displacement to polys. Then emit from this mesh into the fluid over a few frames moving the mesh downward during the emission until it is totally below the fluid. 4. Write a standalone program that converts the image to a fluids cache using the technique in #2 above. A Dynamic Cloud texture In some cases you may wish to texture a cloud layer on a planet yet dynamically animate it as a fluid. In this case one can simply apply a 2D fluid texture as a transparency and color map on a cloud layer shader, and initializes it with the paint fluids tool. This is useful when you need to have clouds wrap around curvature of the earth.

editPfxOnPolyPath.mel parentToSurface.mel nClothBook.ma dynamicFollow.mel cameraFollow.mel cameraFollowScene.ma lightOcclusion.ma fireball.ma itsSlinky.ma TunShu_BindClothSkin.zip confettiFall.mb simpleConfetti.ma roundConfetti.ma partyStreamers.ma waterTank.ma nClothWater2.ma nClothWater.ma waterPlayground.ma sunsetLeaf.zip oakBigLeaf.mel + oakBigLeaf.mel.icon ribbonTwist.ma bagOfMarbles.ma toonOcean.ma buckySphere.ma thickSlab.ma phoneChord.ma forestRoad.ma bark.iff basicLeafHC.jpg birchBark.gif grassRoad.jpg leafSerrate.tif WhiteBark.tif sideleaf.rgb atmosphere.ma writeHello.ma zipper.ma nClothVertexEditor.mel equalizer.ma slidingCurtain.ma inkDrop.ma orangeDye.ma displacementClouds.ma displacementCloudsWithSkyFog.ma displacementHurricane.mb fluid initial state hurricaneDetailNoise.mb hurricaneDynamic.mb
Posted By
Published In
Tags
  • Tutorials
21 Comments
To post a comment please login or register
| 2 years ago
Could I download files? I cannot access.
But I can not download the files
thanks a lot.It was a very beautiful expression
| 5 years ago
I STILL CAN"T UNDERSTAND HOW TO. Can anyone please give me a more step by step insight on how to map or attach an image into the Opasity of a fliud container. Thank you
Edited by yCETcXj7 5 years ago
| 5 years ago
I STILL CAN"T UNDERSTAND HOW TO. Can anyone please give me a more step by step insight on how to map or attach an image into the Opasity of a fliud container. Thank you
Edited by yCETcXj7 5 years ago
Hi Duncan, Hope all good. Just an idea : It would be great if we can deform the 2D fluid container using non-linear reformers, 2 bends will do a nice spherical surface. I feel its not a complected feature, what do u think? waiting your blog posts. Best, Firas.
Edited by w4ixA90t 6 years ago
| 8 years ago
Thanks much Duncan. I'll try that---and keep in mind what you said about the incompressible motion. Sounds like this might be exactly what I needed! Jeff
| 8 years ago
Also you might look into having a dynamic temperature grid, then emitting temperature and density into the simulation to drive the motion. It will get quite involved for the kind of simulation you describe. Check out cgtalk threads on fluids in the Maya dynamics section for some help.
| 8 years ago
The paint fluids tool is the one you use to load the image. This tool by default auto sets the initial state of the fluid after edits. If you look in the paint fluids tool options attributeMaps:import is used to bring in image data. when you paint a 3d fluid the brush is always working on a slice of the fluid, but there is stamp depth, which if large then the imported image will project down the entire fluid. ( or you could use different images for different slices ) In the options "min/max value" determines the min/max range the image is mapped to. You also can use the different operations and opacity when importing depending on how you want to apply the image. The initial state is saved as an old style fluids cache file and appears in a node that is created called initialState_fluidShape1 ( or your fluid name). To push the fluid around with a field, assign the field to the fluid. Make sure the fluid has a dynamic density and velocity grid or it won't move. Also remember that the fluid solves for incompressible motion, so the motion may not be as you would think. (it is not like particles) Some motion like converging to a point is not allowed. Also note that some fields are applied to all fluid voxels uniformly while others like gravity are applied more in voxels with higher density. Another way of giving a push would be to paint the initial state of the fluid velocity(paint fluids tool:velocity).
| 8 years ago
Hi Duncan. I have two questions. Can your method above of loading an IR image into the fluid's initial state be applied to a 3d fluid? Also...where would I find the initial state?--apologies...I'm still very new to fluids. Second, If I wanted to connect an air field to a cloud and have that field distort the cloud, what might be a process for that? I attempted simply connecting them, set attenuation to 0 and pumped up the speed and magnitude but I still get no movement. Suggestions? Is adjusting the velocity and rotation the only way to achieve fluid movement? I'm trying to simulate a mezzocyclone within a thunderstorm (anvil, rotation, etc). Thanks!
| 8 years ago
Sorry Duncan: I was so obsessed in my clouds. I noticed in your previous comment. The sun is still pending. Apreciated.
| 8 years ago
Hi Duncan: Why is it so difficult to create clouds over the globe of the earth using fluid? On the other hand, As emulating of real way the solar fluids? Thanks
| 8 years ago
There is no easy way to use this technique for a sphere. One could use an extremely high resolution 3D fluid and initialize its values from the source cloud info using a spherical projection, although import doesn't support projections so you would need to set the fluid values with a script. The fluid resolution would need to be too high to model a good earth, however. One could use the built in texturing on the fluid, but it would not have vortice shapes. A more efficient method might be to use a lot of lower resolution 2d fluids. Each fluid would be treated as a slightly overlapping tile on the earth (create a default poly sphere... each quad could be replaced by a 2d fluid). One can sue the edge dropoff to feather the overlaps. One would initialize each fluid with a different region from the spherical map. It would be a bit of work to setup and likely would involve a bit of scripting, but it should work. The problem might be the sheer number of fluid nodes for a good tiling with a smooth edge. Even though the individual nodes would be low res it would be cumbersome to edit and manage so many nodes. There could be render issues as well.
| 8 years ago
hi is there a way to map it on sphere(earth) to make it appear a part of earths environment.
| 9 years ago
One thing that that helps a lot if you are following this workflow is to set the 2d fluid texture Z resolution to 1. This attribute is there but does not appear in the UI, so you need to set it by hand: setAttr fluidTexture2DShape1.resolutionD 1 Note that the attribute is D (Height, Width, Depth) which is Z in local space of the fluid. This attribute defaults to 10 and actually affects things like the size of the cache. (When I created this tutorial I wondered why it took so long to set initial state from the image, and the reason is that the initial state file was 10 times bigger than it needed to be ) It is probably confusing that there is a depth resolution on a 2d fluid. In actuality one can make the fluid 3D by setting the attribute "is2d" false on the fluid. All fluid nodes have this attribute but we don't currently expose it because occasionally changing it can trigger a crash. In the case of a 2D fluid texture it probably doesn't make much sense to make it 3d, as it will always just shade the center slice of the fluid. In can be useful, however , to make fluidTexture3D into 2d textures. This is done for the ocean wake textures so they can take advantage of the built in projection of the 3D fluids instead of using a 2d fluid with a separate projection node. Note that any future versions of Maya will have the 2D fluid texture default to a depth resolution of 1 instead of 10, fixing the problem. Duncan
| 9 years ago
I thought i'd offer my 2 cents on how to load the infared image into a 2d fluid. You can go to the paint fluid tool and towards the bottom in the attribute editor there is a section called Attribute Maps. Within the attribute maps section, there is a section for import. If you have paintable attributes set to density, the imported infared clouds file will be applied as density within the 2d fluid. This has worked for me, but there may be another way as well. If so, please share. Duncan, thank you again for another great blog post and tutorial!
| 11 years ago
im having trouble mapping an infra red image to the initial state also... i was wondering if a third request will encourage you to elaborate a bit on the process of mapping the image to the fluid. ive tried a few ways but cant get rid of the perlin noise.
| 11 years ago
these methods produce decent looking clouds, but how would a person go about implementing them if they wanted them to look good from below instead of from above?
| 11 years ago
Hmmm. I am not sure my previous post made it so here I go again. First of all, thanks very much for the tutorials Duncan, they are always great and offer new possibilities. I was wondering if you could go into a little bit more details on the approach of mapping the image to the 2d container. I assume that you plugged the image as a projected file texture into the opacity input bias. Is this correct? I am asking because when I try it I only get a decent image when rendering from above. As soon as I go down toward a side or eye level view it breaks down, sometimes not rendering any fluid density at all. This does not occur when I do it with your sample scene. Thanks much Duncan. jim
| 11 years ago
Hi there, Great tutorials. Thanks very much. I am currently trying to create a simliar effect using a 2d fluid mapped onto a sphere to create a globe. I need to get up close to the clouds and would like to have a volumetric effect. The problem is, the 2d fluid acts as the texture placement for the phong shader. How do I place, or is there a work around so that the fluid wraps around the globe correctly. I am using a cloud mp designed to be applied to a sphere as the density. Any help or ideas you can provide would be greatly appreciated. Regards Martin Waters
| 11 years ago
I don't have understand where is load the file hurricane infra-red.. Can help me??
*Save $66 per month on Autodesk's Suggested Retail Price (SRP) when purchasing 1 year term 3ds Max or Maya subscription.