Thursday, June 20, 2019

Real Time Cloud Algorithm


I want to know how the algorithm works in this game: http://www.gametrailers.com/user-movie/cloud-the-game/45068



Especially how the game generates the real time cloud, and be able to merge with other clouds dynamically.


I tried to google some info, but was unable to find the useful information. Probably because I used to wrong keywords



Answer



Cloud rendering is hard task. But those clouds in video are just couple of "cloudy" particles. I don't think that that is something nice :)


For nice clouds problem is not the cloud simulation, but the cloud rendering, which is impossible to handle to be photo realistic in realtime for scene with dynamic lighting. What happens in participating media like cloud is: enter image description here


Light emission exist only when participating media emits light (like hot gas or fire) or when they are lighted (this is simalar part to normal rendering), absorption mean that light is absorbed and scattering is the biggest computational problem. Light is scattered inside the volume. Then you want to have self shadowing and shadow emmiting to the ground and opaque scene. How to do it?


Where to obtain cloud? Clouds can be simulated by perlin noise. It is very common and looks nice. Perlin noise can be 4D, where 4th dimension is time to create nice dynamic clouds. If you want to specify cloud shapes: you have to do volumetrization over the desired shapes, save it as density 3D grid and multiply it with perlin.


How to render it


By rendering particles?. Particle clouds are possible. It is most simple method. However, simulation of any light propagation between particles is pretty hard. It is very typical that you have to sort particles in the view direction of camera ( or in so called half-axis between camera-dir and light-dir). This is impossible in realtime application unless your target platform doesn't support shader model 4 or better shader model 5 - and gpgpu computing (like cuda, openCl or direct compute) - so you could write Parallel radix sort and sort particles every frame (that will be realtime). Sorting is needed for alpha blending and also for smart shadow mapping.


I'll guide you to some articles:




By volumetric raycasting. Volumetric raycasting means, that you have grid where you did fluid simulation (typicaly Navier-Strokes, but voxelized cloud shape is ok too). And shoot ray for every pixel through volume and integrate radiance across the ray. This is suprisingly OK for realtime applications. Raycasting on wiki. You don't have to have gpgpu computing. Volumetric raycasting can be done on pixel shader, because it doesn't need any synchronization between threads (rays). Having grid in 3D texture is perfect on graphics hardware, because you can benefit from native tri-linear interpolation of the texture unit. Self shadowing can be done by shooting ray from every sample to light and counting the density of light shadowing volume. This is slow. You could use some shadow mapping with transitions (like deep shadow maps). The light scattering is also not possible in realtime (with gpgpu it is).


Volumetric raycasting is fast and it is easier to implement than particle sorting and work fast even on older HW.


Something to study:



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...