Saturday, June 17, 2017

Procedural Clouds in Tiled Terrain

I've shown tiled terrain clouds in many screenshots over various blog posts, but I've never had a post that shows off the different types/layers of clouds. The 3DWorld sky is rendered back to front as several layers:
  • Blue sky with gradient for atmospheric scattering effect (day) / starfield (night)
  • Sun flare when the sun is in view (day) / moon (night)
  • Fog/haze layer that increases in intensity with distance to blend the terrain with the sky
  • Procedural 2D wispy cloud plane layer that casts shadows on the ground
  • Procedural volumetric 3D clouds that move with the wind
Both cloud layers are drawn using screen aligned quads and noise evaluation in shaders on the GPU. The 2D cloud layer casts shadows on the terrain and grass by tracing a ray from the sun to the point on the ground and intersecting it with the cloud plane to compute light intensity. I haven't figured out how to efficiently produce shadows for the 3D cloud layer. The two types of clouds use different lighting calculations because the shaders have access to different types of data. For example, the cloud plane doesn't have local cloud density information, so it can't compute volumetric lighting like the 3D cloud system can. They don't always blend together perfectly, but in most cases it looks good enough.

3DWorld has a set of config file parameters, key bindings, and UI sliders to control the amount of clouds on the 2D and 3D layers. Clouds are also affected by weather conditions such as wind, rain, and snow. I've added an "auto" mode with day/night cycle that dynamically varies the weather and cloud cover over time to simulate a real environment.

Here is a set of screenshots showing the various weather and cloud conditions that can be selected. I've turned off the birds in the sky for most of these images so that the clouds can be seen clearly.

Sunny day with sun lens flare and minimal cloud cover.

Light, wispy, high clouds, with distant fog.

Medium wispy clouds and haze. These clouds cast dynamic shadows on the ground.

High, dense clouds, with small areas where the sun peeks out.

Scattered small 3D cloud puffs.

Mixed 3D low lying volumetric clouds and high 2D cloud layers.

Heavy cloud cover with mixed cloud types. The lighting doesn't really match between cloud types.

Storm clouds with rain. Are those city buildings in the background?

Clouds colored red at sunset.

Night time clouds in a starry sky.

Thursday, June 15, 2017

Assorted Images and Videos

I'm currently working on procedural building generation, but it's not yet finished. I don't want to show off unfinished work, at least not until I get closer. So here are some images and videos on assorted 3DWorld topics that I've been working on.

Dynamic Light Sources + Shadows + Reflections + Indirect Lighting

I did some experimenting with dynamic lighting with shadows, reflections, and indirect light. Adding shadows works just fine - see the screenshot near the end of my earlier post. I've also had horizontal plane reflection support for a while. Indirect lighting of dynamic objects is new. It works the same way as indirect sun and sky lighting, using multi-threaded ray/path tracing. Unfortunately, the performance vs. quality trade-off isn't there yet. I need at least 50K rays for a noise-free image, and that only runs at around 8 FPS with 4 ray bounces. Maybe this isn't the right approach? At least it looks cool. Here is a blue light casting shadows and (difficult to see) indirect light.

Blue dynamic light source casting shadows at night in the Sponza atrium.

Blue light source with floor reflections and indirect light from multiple sources.

Procedural 3D Clouds

Last month I went back to working on procedural 3D volumetric clouds in tiled terrain mode. I've had static 3D clouds for a while now. It was time to make them animated. There are between 400 and 600 active clouds in the visible area of the scene, with a user controlled cloud density parameter. Clouds move in the direction of the wind and change shape over time using 4D procedural noise in the shader (x, y, z, and time). [It's actually 3D noise; time is added as a vertex offset.] Cloud speed and the rate of shape change for individual clouds increases with wind speed. When a cloud floats outside the view distance, another cloud is generated on the opposite side just out of view distance, so that it floats into the scene. I don't have enough material for a full post, only one video.

I took some screenshots, which look like all of my previous tiled terrain cloud screenshots because you can't see the clouds moving.

Mandelbrot Set Viewer

I implemented a Mandelbrot Set fractal viewer in 3DWorld's "overhead map view" mode for fun. I spent some time coming up with a custom color mapping that shows off the fractal pattern well. The user can pan around and zoom in and out with the mouse and arrow keys. It's implemented using double precision math so that you can zoom in further before running into precision problems. I don't think I can get good results with double precision on the GPU, so I made this run on multiple threads on the CPU. I normally get around 30 FPS at 1080p resolution, but it competes with video recording for CPU cores and ends up running at only 15 FPS in this video. A 16s video recorded at 60 FPS appears to play back at 4x the speed and lasts for only 4s. Oh well.