Dienstag, 18. November 2014

Multiple Clouds

A realistic sky is composed of many individual clouds, so the present single distorted sphere is not enough. Instead of creating multiple cloud objects, the current information stored in the spheres (i.e. vertices, normals, texture coordinates and indices) can be reused with only minimum additional storage and calculations.

Instancing clones

Each new cloud will simply use the data stored for the vertices and translate the whole shape by a given offset. Hence, the shader programs can repeatedly operate on the same buffers (including the information from the standard sphere) to create multiple clouds with the addition that for each new cloud an offset has to be specified. As a consequence, the vertex and fragment shaders can be used with only minor adaptations and in parallel as opposed to expensive generations of spheres, buffers and further shaders.
The distortion of the shape (cf. previous post) is only based on the time. Therefore, a second parameter has to be passed to the shaders and has to be incorporated into the noise and turbulence functions in order to obtain different shapes for each cloud. In avoidance of similar-looking clouds, a scale factor is also introduced as the third parameter an instance depends on. Furthermore, all parameters for blending (see the previous post on rendering a single cloud) have to be passed to the shaders as well.
These additional parameters are passed to the shaders per sphere instance using the function glVertexAttribDivisor. The draw call changes from glDrawElements to the function glDrawElementsInstanced with another parameter specifying how many instances should be drawn. Figure 1 displays the result of the instanced rendering described above. Obviously, size and distortion vary between the clouds and the regularly updated offsets make the objects float over the screen as if wind was driving them.

Figure 1 multiple instances of rendered spheres

Using the approach of instanced rendering, several clouds can be glued together to create more complex shapes such as cumulus clouds.

Performance

All subsequent performance measurements were performed on a machine operating on 64 bit Windows 8 with an Intel i7-3667U processor and 4 GB RAM. The testing machine did not have a graphics board so the program is likely to perform better on other machines. With all the adjustments made for instanced rendering, the program runs at a speed of 30 frames per second with 187 different cloud objects (1152 triangles each) as opposed to approximately 300 frames per second for only one.
The following screenshots (Figure 2 to Figure 5) display the maximum number of clouds that could smoothly be rendered at 30 frames per second for different resolutions of the clouds. Although, it would be possible to create a sky that is entirely covered with clouds, a resolution of 25 x 25 triangles per sphere was chosen in subsequent demonstrations because the clouds do not appear edgy.

Figure 2 10x10 (200 triangles): 30 FPS: 740 clouds

Figure 3 25x25 (1152 triangles): 30 FPS: 187 clouds
+
Figure 4 50x50 (15000 triangles): 30 FPS: 51 clouds

Figure 5 100x100 (20000 triangles): 30 FPS: 8 clouds

References


Keine Kommentare:

Kommentar veröffentlichen