200 likes | 306 Views
Chalmers University of Technology Advanced computer graphics – DAT205. Procedural terrain on the GPU. David Sundelius Adam Scott. Introduction. Generating terrain is a task fitted well for parallelization and thus for the GPU
E N D
Chalmers University ofTechnology Advanced computer graphics – DAT205 Procedural terrain on the GPU David Sundelius Adam Scott
Introduction • Generating terrain is a task fittedwell for parallelization and thus for the GPU • A techniqueto generate terrain, withtextures and lightingduringruntime. • Divides the worldintocubic blocks containingvoxels
Agenda • Overview • Densityfunction and noisegeneration • Marchingcubesalgorithm • Texturing, shadingand lighting • Demo • Questions
Terrain generation overview • Divideenvironment in blocks ofvoxels • Parallelize block calculation by usingpixelshaders • Use a densityfunctiontocreate the basicenvironment • Applynoiseto the generateddensityfunction • Use the marchingcubesalgorithmto generate geometry • Addtextures and texturecoordinates • Renderscene
Densityfunction • Functionusedtocreatethe basicenvironment • A threedimensionalfunction • Positive and negative values • float density = -1; • float density = -ws.y; • float density = rad – length(ws- float3(0,rad,0));
Noise generation • Generate somenoise 3d texturerepeating • Modify the densityfunctionwithrandom sampling from ournoisetexture • Use interpolation towarp the area • Abletocreate a hard floor or flat areas, just clamp the densityfunction • Possibilitytouse hand madetextures • Generate cavestructure
Marchingcubes - Blocks • Marchthroughvoxels in blocks • For eachvoxelwecreate an arraywithinformation ofcornersfrom the densityfunction
Marchingcubes – Lookuptables • Lookupconstructedarray • Pregeneretedlookuptables
Marchingcubes - geometry • Geometryshader • Calculate position ofvertex • Calculate normal • Three different methodsto generate blocks
Block generation method 1 • 1. Fillvolume • 2. Generate vertices • The slowestmethod
Block generation method 2 • 1. Filldensityvolume • 2. Lightweight marker point • 3. Generate vertices
Block generation method 3 • 1. Fillvolume • 2. List non-empty cells • 3. List verticesto generate • 4. Generate vertices • 5. Splatvertices • 6. Make triangles
Lighting and ambient occlusion • Easytoimplement • Calculatingnormals • Ray casting • Long/short rays
Premadetextures • Pros and cons • Loadingtextures (such as photographs) • Triplanartexturing – project on axiswithleastdistorted normal
Generating textures • Generating textures • Marbletextures
Pros and cons • Requires a lotofmemory on the GPU • Cancompromizevalitityof data (not exact), ambiguity in model • Canhaveholes • Fast wayto generate procedural environments • Easy and fast to manipulate environment • High resolution (easytoextendusetoLoD)
Applications • Levelofdetail • Collisions • Lighting • Otheruse: create 3d models from sampling i.e. MRI
Demonstration • Video
Further research • http://undergraduate.csse.uwa.edu.au/units/CITS4241/Project/references/Lorensen-Cline-brief.pdf • http://code-freeze.blogspot.se/2012/04/rebuilding-world-one-iteration-at-time.html • The CD to GPU gems 3 – Interactive demo