Adaptive GPU-based terrain rendering Adaptives GPU basiertes Terrain Rendering Diploma thesis Timo Schmiade Lehrstuhl f¨r Computergraphik und Multimediasysteme u Fachbereich 12 Elektrotechnik und Informatik Universit¨t Siegen a Erstgutachter: Prof. Dr. Andreas Kolb Zweitgutachter: Dr.-Ing. Christof Rezk Salama Betreuer: Dipl. Math. Martin Lambers 23rd May 2008 Eidesstaatliche Erkl¨rung a Ich erkl¨re hiermit, dass ich die vorliegende Arbeit selbstst¨ndig angefera a tigt habe. Die aus fremden Quellen direkt oder indirekt ubernommenen ¨ Gedanken sind als solche kenntlich gemacht. Die Arbeit wurde bisher keiner anderen Pr¨ fungsbeh¨rde vorgelegt und auch nicht ver¨ffentlicht. Ich bin u o o mir bewusst, dass eine unwahre Erkl¨rung rechtliche Folgen haben kann. a Ort, Datum Vorname, Name II Abstract The diploma thesis at hand presents a survey on the development of terrain rendering algorithms during the past ten years and examines to which extent Shader model 4 can contribute to terrain rendering algorithms. Therefore, a new approach based on the features of Shader model 4 named RAG is introduced. RAG is a purely GPUbased terrain rendering algorithm which refines a coarse input mesh by recursively employing the new geometry shader stage introduced with Shader model 4. Each triangle is directly tesselated within the rendering pipeline, depending on how well it approximates the given height map texture. RAG provides fast CPU-independent terrain refinement, but guarantees to the mesh’s accuracy can only be given to a certain extent. This is due to the purely edge-based refinement decisions which are applied to each triangle and guarantee a consistent mesh topology. Zusammenfassung Die vorliegende Diplomarbeit veranschaulicht die Entwicklung von Terrain Rendering Algorithmen innerhalb der vergangenen zehn Jahre und untersucht inwiefern Shader Modell 4 f¨r das Terrain Rendering u verwendet werden kann. Dazu wird ein neuer, auf den M¨glichkeiten o von Shader Modell 4 basierender Algorithmus names RAG vorgestellt. RAG ist ein vollst¨ndig GPU-basierter Algorithmus, der ein grobes a Mesh rekursiv verfeinert, indem er die mit Shader Modell 4 eingef¨hrte u Geometry Shader Stage ausnutzt. Jedes Dreieck wird direkt innerhalb der Rendering Pipeline abh¨ngig davon, wie gut es die gegebene a H¨hentextur bereits approximiert, tesseliert. RAG stellt eine schnelle o und CPU unabh¨ngige Terrain Verfeinerungstechnik dar, kann aber a nur begrenzt Garantien uber die Exaktheit der H¨hentextur-Approo ¨ ximation geben. Dies liegt daran, dass rein kantenbasierte Verfeinerungsentscheidungen getroffen werden m¨ssen, um eine konsistente u Meshtopologie zu garantieren. III Contents 1 Introduction 2 Terrain rendering algorithms 2.1 Real-time Optimally Adapting Meshes (ROAM) 2.2 Batched Dynamic Adaptive Meshes (BDAM) . . 2.3 Geometry clipmaps . . . . . . . . . . . . . . . . 2.4 Geometry Image Warping . . . . . . . . . . . . 2.5 Generic Adaptive Mesh Refinement (GAMeR) . 2.6 Recapitulation . . . . . . . . . . . . . . . . . . . 3 Shader model 4 4 Recursive Adaptive Geometry shader 4.1 Motivation . . . . . . . . . . . . . . . 4.2 Realisation . . . . . . . . . . . . . . . 4.2.1 Tesselation . . . . . . . . . . . 4.2.2 Recursion . . . . . . . . . . . 4.3 Preprocessing . . . . . . . . . . . . . 4.4 Frame-wise updates . . . . . . . . . . 4.5 Problems . . . . . . . . . . . . . . . . 4.5.1 Under-refined triangles . . . . 4.5.2 Over-refined triangles . . . . . 4.5.3 Oblique triangles . . . . . . . 4.6 Error metrics . . . . . . . . . . . . . 4.7 Parallel research . . . . . . . . . . . . 4.7.1 Comparison . . . . . . . . . . 4.7.2 Conclusion . . . . . . . . . . . 5 Results 5.1 Implementation . . . . . . . . . 5.1.1 Graphical user interface 5.1.2 Internals . . . . . . . . . 5.2 Measurements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 4 5 8 12 16 19 22 24 26 26 27 28 33 34 34 37 37 38 41 42 44 46 48 49 49 49 51 54 6 Conclusions 57 6.1 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 1 1 Introduction Since the early 90’s, terrain rendering has been one of the intensely developed subjects in the domain of computer graphics. New algorithms to performantly display digital landscapes have emerged with every new generation of hardware in general and graphic cards in particular. The desire to display more and more detailed landscapes is the central reason that this topic is far from being ultimately explored. The fields of application are numerous and versatile. For example, an exactly rendered surface can help a pilot to safely land an airplane in a situation of poor visibility. Landscape measurements can be conducted at the computer rather than on location. Finally, virtual reality projects and video games are able to arouse a higher state of immersion for the user. But with improved presentation, higher demands for computer develop. More detail means more complexity for the processor, the graphic card and the system memory. Each new generation of hardware increases the performance and functional range of these components, but it takes more than mere hardware improvements to compensate today’s fast-growing data sizes and increasing demands to detail and accuracy. Therefore, algorithms that exhaust the full potential of every available computer component are required to fulfil a user’s demands. During the past ten years, many terrain rendering technologies have been developed and tested. Some of them are outdated in the meantime, some others are still used and improved. To provide an overview of the research that has been done so far, I present some of the most important algorithms in the following section 2 of this work. The first two presented approaches in that chapter are not GPU-based, but are yet important to illustrate the development of terrain rendering during the past years. As implied by the title, this thesis deals with the display of terrain using GPU features, which are introduced along with Shader models. Section 3 reviews what such a Shader model is, and which features are supported by the newest Shader model with the version number 4 in comparison to its predecessor. Section 4 begins by discussing the problems of adapting a classical CPUbased terrain rendering algorithm to a GPU implementation. This reveals some of the limitations of GPU-based approaches. Following this, a new algorithm, based on Shader model 4, named Recursive Adaptive Geometry Shader (RAG) is developed and its workflow is described in detail. The main objectives of RAG are to be fast, accurate and efficient and to avoid the waste of resources. This approach transports almost all work traditionally conducted by the 2 CPU to the GPU, exploiting the new geometry shader stage. Following a discussion of problems caused by the new approach, I will compare RAG to an algorithm that has been developed in parallel to it in the last part section 4. The following section 5 first details my implementation of RAG. All important aspects will be covered to clarify how an implementation can look like and which points are to be considered. Following this, performance measurements recorded with this implementation are presented. An evaluation of this thesis follows in the final section 6. I will discuss the extent to which my set goals have been reached and which improvements can be pursued in future research. 3 2 Terrain rendering algorithms This section presents a selection of terrain rendering algorithms from the past 15 years. Summarising all the algorithms that have been developed during that time is by far beyond the scope of this work, however the selected algorithms presented here give a good overview of the technological history of terrain rendering. Each algorithm has very different characteristics. For instance, the first algorithm (ROAM) has no support for the features of programmable graphic hardware, due to such hardware not being available at the time of its development. On the other side, Geometric Clipmaps makes vast use of those possibilites, to the degree that the processor is hardly stressed at all. Bearing this in mind, a comparative evaluation of the presented approaches is very difficult. Nevertheless, my summary of each algorithm will attempt to rate it according to the following criteria: Input data Older algorithms are often based on a fine triangle mesh which is then reduced for better display performance, while new approaches mostly take a texture with encoded height values as an input. 01101001 IN 10100110 00011010 01101001 11010001 10100110 00011010 01101001 11010001 10100110 00011010 11010001 elements::value_type* for( int i=0; i 1 ) discardFragmentStage(true); setVertexBufferTarget( VB0 ); renderCoarseMesh(); for( i=1; i