Procedural terrain on the GPU Chalmers University of Technology Advanced computer graphics – DAT205 David Sundelius Adam Scott
Introduction Generating terrain is a task fitted well for parallelization and thus for the GPU A technique to generate terrain, with textures and lighting during runtime. Divides the world into cubic blocks containing voxels
Agenda Overview Density function and noise generation Marching cubes algorithm Texturing, shading and lighting Demo Questions
Terrain generation overview Divide environment in blocks of voxels Parallelize block calculation by using pixelshaders Use a density function to create the basic environment Apply noise to the generated density function Use the marching cubes algorithm to generate geometry Add textures and texture coordinates Render scene
Density function Function used to create the basic environment A three dimensional function Positive and negative values float density = -1; float density = -ws.y; float density = rad – length(ws- float3(0,rad,0));
Noise generation Generate some noise 3d texture repeating Modify the density function with random sampling from our noise texture Use interpolation to warp the area Able to create a hard floor or flat areas, just clamp the density function Possibility to use hand made textures Generate cave structure
Marching cubes - Blocks March through voxels in blocks For each voxel we create an array with information of corners from the density function
Marching cubes – Lookup tables Lookup constructed array Pregenereted lookuptables
Marching cubes - geometry Geometry shader Calculate position of vertex Calculate normal Three different methods to generate blocks
Block generation method 1 1. Fill volume 2. Generate vertices The slowest method
Block generation method 2 1. Fill density volume 2. Lightweight marker point 3. Generate vertices
Block generation method 3 1. Fill volume 2. List non-empty cells 3. List vertices to generate 4. Generate vertices 5. Splat vertices 6. Make triangles
Lighting and ambient occlusion Easy to implement Calculating normals Ray casting Long/short rays
Premade textures Pros and cons Loading textures (such as photographs) Triplanar texturing – project on axis with least distorted normal
Generating textures Marble textures
Pros and cons Requires a lot of memory on the GPU Can compromize valitity of data (not exact), ambiguity in model Can have holes Fast way to generate procedural environments Easy and fast to manipulate environment High resolution (easy to extend use to LoD)
Applications Level of detail Collisions Lighting Other use: create 3d models from sampling i.e. MRI
Demonstration Video
Further research references/Lorensen-Cline-brief.pdf references/Lorensen-Cline-brief.pdf iteration-at-time.html iteration-at-time.html The CD to GPU gems 3 – Interactive demo
Questions ?