Framework for Real-Time Editing of Endless Procedural Terrains
Total Page:16
File Type:pdf, Size:1020Kb
Framework for Real-Time Editing of Endless Procedural Terrains Johan Klokkhammer Helsing Master of Science in Computer Science Submission date: July 2014 Supervisor: Anne Cathrine Elster, IDI Norwegian University of Science and Technology Department of Computer and Information Science Problem description Game developers commonly re-implement terrain generating code for each project they are working on, thus using up valuable development time. Furthermore, terrain generating code is often written in compiled languages, and this usually requires the code to be recompiled and the application relaunched each time a change has been made to the generator. Games and other virtual environments often use terrains generated using the implicit procedural techniques of Perlin and Musgrave. These techniques have also been applied to heightmap-generating software and 3D-modeling software. Such programs commonly offer a node editor letting the user visually edit an expression tree consisting of common procedural algorithms and mathematical functions. The results of the changes can often be viewed in real time. These packages, however, do not let you run the generation on the client. A heightmap has to be generated in its entirety first; and can then be imported by the game or application as a non-procedural model. Hence, many of the desirable properties of procedural generation are lost in the process, such as the ability to generate infinite worlds or a new world each time a game is started. The goal of this project is to combine the ease of use of visually editing an expression tree in a node editor with the ability to generate terrain on demand at the player's computer. An open-source library capable of serializing and de- serializing graphs of functions will be developed, as well as a visual node editor interfacing with the library. The node editor should be capable of displaying generated terrains in real time. This will enable non-programmers to edit terrain efficiently, while retaining the ability to perform generation in-game. A reference plug-in for a real-time engine will be developed to demonstrate the potential of the framework. Existing game engines as well as the NTNU HPC-Lab Snow Simulator will be considered as candidates for the reference plug-in. Assignment given: 15 January 2014 Advisor: Anne C. Elster, IDI, NTNU Abstract Procedural content generation is the act of creating video game content auto- matically, through algorithmic means. In online procedural generation, content is generated as the game is running on the consumer's computer. Online procedural generation of terrains has become an important feature in many recent video games. The technique enhances the replayability and vastness of virtual worlds by offering a unique and endless terrain for each play session. Procedural terrain generation is commonly achieved through noise synthesis. Adding, multiplying and filtering layers of noise at different frequencies and am- plitudes, can lead to complex and realistic terrain models. This process of filtering and combining noise and other functions to create a final terrain function is usually done by issuing calls to a noise generating library in a programming or scripting language, such as C++ or Lua. The process requires a programmer to write code, compile the code, run the program, observe the results, and then start over editing the code. This is a tedious, non-intuitive and time-consuming design process. Consequently, game designers are often forced to accept sub-optimal results because of time constraints or lack of control over the generation process. Our framework, Noise Modeler, consists of a GUI application and a library for modeling terrains for endless-world creation. In this project, noise and other functions are composited through a visual flow-graph editor similar to the ones used by procedural shader editors and offline terrain generators. This novel framework enables non-programmers to edit models for procedural heightmap terrains while observing the effect of changes immediately in a real-time preview. Designed terrains can be serialized to human-readable text files, consuming only a few kilobytes. By using our library, a game engine can load these text files in order to generate terrain data on-demand on the GPU. To our knowledge the Noise Modeler framework is therefore unique in its cause. It may be limited in features, and rough around the edges in terms of usability, but it clearly outperforms existing noise libraries, and has terrain specific features and heightmap previews not present in procedural shader editors. Sammendrag Prosedyrisk innholdsgenerering (procedural content generation) er et begrep for det˚agenerere spillinnhold automatisk ved hjelp av algoritmer. I online prosedyrisk generering genereres innholdet mens spillet kjører p˚aspillerens datamaskin. Online prosedyrisk generering av terreng har blitt en viktig del av mange nylige dataspill. Teknikken kan forlenge levetiden og størrelsen til et spill ved ˚atilby en unik og uendelig virtuell verden hver gang spillet startes. Prosedyrisk terrenggenerering oppn˚asvanligvis ved˚asyntetisere og filtrere syn- tetisk støy. Ved ˚alegge sammen, multiplisere og kombinere støy ved forskjellige frekvenser og amplituder, er det mulig ˚alage komplekse og realistiske terrengmo- deller. Denne prosessen | best˚aendeav filtrering og kombinering av støy og andre funksjoner for ˚alage det endelige terrenget | blir ofte opn˚addved hjelp av funk- sjonskall mot et bibliotek for syntetisering av støy gjennom et programmerings- eller script-spr˚ak. Prosessen krever at en programmerer skriver kode, kompilerer koden, kjører programmet, observerer resultatet, og deretter redigerer kode igjen. Dette er tid- krevende, tungvindt, og ikke intuitivt. Resultatet er at spilldesignere ofte blir tvun- get til ˚agodta terrengmodeller de ikke er helt fornøyd med grunnet tidsnød, eller manglende kontroll over genereringsprossessen. V˚artrammeverk, Noise Modeler, best˚arav et grafisk brukergrensesnitt og et bibliotek for modellering av terreng for uendelige prosedyriske verdener. I det- te prosjektet blir støy og andre funksjoner kombinert gjennom et visuelt redige- ringsverktøy for grafer ikke ulikt tilsvarende verktøy for design av prosedyriske teksturer. Dette nye rammeverket gjør det mulig for ikke-programmerere ˚alage modeller for prosedyrisk generering av høydedata-terreng. Endringer p˚amodellen kan observeres i en forh˚andsvisning som oppdateres i sanntid. Designede terreng kan serialiseres til et tekstformat som er forst˚aeligfor men- nesker. Formatet bruker kun et par kilobyte for ˚arepresentere et terreng. Ved ˚a bruke v˚artbibliotek, kan en spillmotor laste disse tekstfilene for ˚agenerere terreng- data n˚ardet etterspørres. Genereringen blir utført ved hjelp av klientens grafikk- prosessor. Noise modeler, er derfor | s˚avidt vi vet | et unikt verktøy. Det mangler riktignok en del funksjoner, og har et brukergrensesnitt som trenger justeringer i forhold til brukervennlighet, men rammeverket er klart raskere enn eksisterende støygenererende biblioteker og har terrengspesifikke funksjoner man ikke finner i prosedyriske shader-verktøy. ii Acknowledgments I wish to thank my supervisor Dr. Anne C. Elster for her valuable assistance and advice during the project. Gratitude is also given to Colt McAnlis for letting me use one of his screenshots of a vector displacement terrain in this thesis, and Philip Trettner for his screenshot of the Upvoid Engine. I would also like to thank NTNU and NVIDIA's CUDA Research Center and NVIDIA CUDA Teaching Center program for their contributions to the IDI/NTNU HPC-Lab. Finally, I wish to thank Hanna H. Kamperud for her support throughout my study. iii Contents Abstracti Sammendrag ii Acknowledgments iii List of Tables ix List of Figuresx Listings xii Glossary xiii 1 Introduction1 1.1 Benefits of generating terrains procedurally..............2 1.2 Current approaches...........................2 1.3 Thesis goals...............................3 1.4 Research questions...........................4 1.5 Thesis outline..............................4 2 Background5 2.1 Procedural content generation.....................6 2.2 Terrain models.............................8 2.2.1 Heightmaps...........................8 2.2.2 Vector displacement fields...................9 2.2.3 Layered heightmap....................... 10 2.2.4 3D meshes............................ 10 2.2.5 Voxel grid............................ 10 2.2.6 Overview of common game engines and their supported ter- rain models........................... 11 2.3 Fractal terrains............................. 13 iv CONTENTS 2.3.1 Stochastic interpolation.................... 13 2.3.2 Implicit procedural techniques................. 14 2.3.3 Noise............................... 15 2.3.4 Value noise........................... 16 2.3.5 Perlin noise and other types of gradient noise........ 16 2.3.6 Simplex noise.......................... 19 2.3.7 Approximating fBm with noise................ 20 2.3.8 Other uses of noise....................... 21 2.4 Simulating erosion........................... 23 2.5 Noise libraries.............................. 25 2.5.1 libnoise............................. 25 2.5.2 Accidental Noise Library.................... 25 2.6 Offline terrain generators with procedural features.......... 26 2.6.1 World Machine......................... 26 2.6.2 Lithosphere........................... 26 2.7 GeoGen................................. 27 2.8 Procedural shader editors....................... 28 2.9 OpenGL................................