Wednesday, February 19, 2020

graphics - How can I easily create cloud texture maps?


I am making 3d planets in my game; these will be viewed as "globes". Some of them will need cloud layers. I looked at various Blender tutorials for creating "earth", and for their cloud layers they use earth cloud maps from NASA.


However I will be creating a fictional universe with many procedurally-generated planets. So I would like to use many variations.


I'm hoping there's a way to procedurally generate cloud maps such as the NASA link. I will also need to create gas giants, so I will also need other kinds of cloud texture maps.


If that is too difficult, I could fall back to creating several variations of cloud maps. For example, 3 for earth-like, 3 for gas giants, etc.



So how do I statically create or programmatically generate such cloud maps?



Answer



Cloud generation is fun! I'll cover both offline and runtime methods.


Pre-rendered clouds


If you want to pre-render your cloud textures offline, look no further than Photoshop (or Gimp, if you prefer). Both programs can easily generate cloud patterns. Menu items tend to move around between releases, but as of Gimp 2.8.2 the core command you're looking for is Filters -> Render -> Clouds -> Solid Noise. You'll need to create a new blank image before the command is enabled. I encourage you to experiment with the noise parameters, but just as one example, here's what happens if you set "Random Seed" to 1, "Detail" to 4, "X Size" to 4.0, "Y Size" to 8.0, disable "Randomize" and "Turbulent", and enable "Tilable": Raw output of Gimp


One further step I definitely recommend is editing the image's levels (Colors -> Levels... in Gimp). By dragging the endpoints around, you can effectively change the level of cloud cover from "fully overcast" to "not a cloud in the sky". Thresholded clouds


Other interesting possibilities:



  • Use the "Dodge" and "Burn" tools to manually brighten/darken portions of the image.

  • Warp the cloud image to suggest wind patterns. Try Gimp's Filters -> Distorts -> Whirl and Pinch... command, or for more control use Filters -> Distorts -> IWarp... with the Deform Mode set to "Swirl". Keep it subtle, though -- too much warping tends to blur the high-frequency detail out of the image.


  • Add multiple independent cloud layers to simulate different types of clouds, from thin and wispy to big & chunky (I'm sure they have proper scientific names, but damnit Jim, I'm a programmer, not a meteorologist!). In this case, you'd probably want to save each layer as a separate image so you can animate them independently at runtime.


It really depends on your artistic vision. Go nuts! When you're finished, remember to export the texture as a single-channel grayscale image, so you can use the same cloud data for your color and alpha channel at runtime.


Runtime cloud generation


Generating unlimited cloud patterns at runtime is a bit more involved, but still totally feasible. It's a huge topic, and this will only cover the broad strokes.


Basically you're going to replicate Gimp's "Solid Noise" command in your shader code, using a noise function like the canonical Perlin Noise to generate infinite, smooth, deterministic, (optionally) periodic noise volumes. Your question didn't specify which rendering API you're targeting, so I can't get too specific here; chapter 26 of "GPU Gems 2" covers a variant of Perlin noise in (somewhat dated) HLSL and CgFX, or you can use this drop-in GLSL noise function. By sampling a 2D slice of a 3D noise volume, you get something like the Gimp "Solid Noise" command with Detail=0. The lower the distance between your noise volume samples, the lower-frequency ("smoother") your noise will be. To increase the level of high-frequency detail, start with a base low-frequency noise pattern and add additional higher-frequency "octaves" of noise, where each "octave" is a different slice of the 3D noise volume with a larger sampling distance and lower amplitude. A visual example of this process (which I found by Googling "multi-octave Perlin noise") can be found here.


As a huge added bonus, cloud textures generated in this fashion can very easily be animated! Add a time-based offset to your 3D noise function sample coordinates, and you'll get extremely convincing cloud motion (as seen in this video, for example). This is because the noise function is smooth in all three dimensions; scrolling the texture in the U/V direction causes the clouds to move around the planet, while scrolling in the W (perpendicular) direction has the effect of slowly "evolving" the clouds.


Warping clouds at runtime is possible as well, for hurricane-like effects. Results can actually be much higher quality than the naïve Gimp warp filters, which (as mentioned earlier) can lead to an overly blurry texture. One technique you definitely want to look into is "flow maps", as described by Alex Vlachos of Valve (SIGGRAPH 2010 slides) or Carlos Gonzalez of Naughty Dog (GDC 2012 slides). The basic idea is that you paint a vector field (the "flow map") and use it to distort and scroll the cloud texture at runtime, while periodically cross-fading between two different cloud textures when the distortion distance gets too high.


Which method to use?


Pre-rendering cloud textures in Gimp/Photoshop is extremely easy; you can generate a new texture in a few seconds once you get the hang of it. The runtime code is trivial, and very fast. However, more unique cloud textures means higher disk space requirements (also, a larger/slower download) and more VRAM usage at runtime.



Runtime cloud generation is much more difficult at first, but once you get it working it has several clear advantages over pre-rendered cloud textures. You can generate an infinite variety of realistic animated cloud patterns without using any additional disk space or VRAM. However, the runtime cost of evaluating multiple 3D noise functions per-pixel can be steep; your cloud pixel shaders will be much slower than they in the pre-rendered case.


TL;DR: definitely start by using pre-rendered clouds, and switch to runtime procedural clouds if you need the extra variety (or want an extra programming challenge).


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...