Top Banner
Building Worlds Filipe Varela [email protected]
40
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building Worlds - Codebits

Building Worlds

Filipe Varela [email protected]

Page 2: Building Worlds - Codebits

Overview

• Topographic Datasets

• Geometry partitioning

• Tesselating meshes

• Level of Detail (LOD)

• Data structures for geometry

• Projections

• Efficient Out of Core fetches

• Lighting

• Shaders

• Procedural detail

Page 3: Building Worlds - Codebits

Basics - drawing path

Topography Normals

Bathymetry

Textures

Shaders

Page 4: Building Worlds - Codebits

Topography

Shuttle Radar Topography Mission

(SRTM)

Blue Marble Next Generation

(BMNG)

Page 5: Building Worlds - Codebits

SRTM

Resolution: 90m/pixel

Coverage: 60ºS to 60ºN Lat, 360º Long

Samples: 144000x432000, 16 bit

~115 GiB

Much higher resolutions available for limited areas

Page 6: Building Worlds - Codebits

Others

Mars: MOLA + Viking

Moon: LOLA + Clementine

Mercury: Messenger + Mariner

Venus: Magellan + Venera

A couple more...

Page 7: Building Worlds - Codebits

Back to Basics

432000x144000 samples (not counting poles)

16bit/sample topography+bathy

24bit/sample textures (+ 173GB)

24bit/sample normals (+ 173GB)

Add specular byte to topo+bathy

Totals 3x173 GB = 519 GB @ 90m/sample

Page 8: Building Worlds - Codebits

Preparing the Data

What exactly do you need to achieve?

How much effort are you willing to put in?

Page 9: Building Worlds - Codebits

• Data is but height samples - Mesh tesselation

• Too much data to draw everything every frame - Level of Detail

Terrain Rendering 101

Page 10: Building Worlds - Codebits

• Realtime Optimally Adapting Meshes

• Geomipmapping

• Chunked Level of Detail (LOD)

• Geometry Clipmaps

Common Methods

Page 11: Building Worlds - Codebits

Chunked LOD

Page 12: Building Worlds - Codebits

Tesselating Meshes

Several options - I picked triangle strips

Page 13: Building Worlds - Codebits

LOD - Level of Detail

Split each chunk into 4 when LOD increases

Chunk side vertex count must be 2^n

Page 14: Building Worlds - Codebits

LOD - Level of DetailConnect patches by copying:

left of right to right of left

new count is (2^n)+1

Page 15: Building Worlds - Codebits

LOD - Tricks

Optimize patch side vertex count for performance

You want few GPU ops with a lot of data

You don’t want the GPU to ‘swap’ from VRAM to RAM

Page 16: Building Worlds - Codebits

Meet the Quadtree

Page 17: Building Worlds - Codebits

Quadtree Basics

• vertex buffer object

• exactly 4 children per node (1-NE, 2-NW, 3-SE, 4-SW)

• index [1-4]

• last drawn timestamp

• vertex buffers for geometry, textures, normals

• Search: O(n), n = LOD level (follow pointers)

Page 18: Building Worlds - Codebits

Cylindrical #FAIL

Linear sample density Non linear perimeter

Page 19: Building Worlds - Codebits

6 Gnomonic Projections

Wolfram is your friend http://mathworld.wolfram.com/GnomonicProjection.html

Page 20: Building Worlds - Codebits

Cube to Sphere

Normalize each vertex Add altitude

v = normalize(v) * (planet radius + altitude)

Page 21: Building Worlds - Codebits

So Far

• Dealt with LOD, splitting

• Found a suitable projection system

• Triangulated the terrain meshes

• Each patch of terrain - Vertex Buffer Object

Page 22: Building Worlds - Codebits

Redundancy

• Several representations of the same data

• Increased dataset size, up to 2x

• No way around for textures

• EP + 1 for everything else

Page 23: Building Worlds - Codebits

EP + 1

Page 24: Building Worlds - Codebits

EP + 1 Storage

• Reprocess the entire dataset

• Write all samples as chunks

• Arrange by LOD levels

• Don’t write duplicate samples

• Reading a chunk is now fseek+fread

Page 25: Building Worlds - Codebits

Eye Candy 1 - Lighting

• Normals are crucial

• Light intensity directly proportional to LoN

Page 26: Building Worlds - Codebits

Calculating Normals

• Use a single chunk of vertexes

• Rotate and scale accordingly

• Attach heightmap as texture

• Morph (planet radius + texture height)

• Sample neighboring heights for normal

Page 27: Building Worlds - Codebits

Normal MapHeights stored in 16bit: Red+Green channels

Non spherical coordinate system

Page 28: Building Worlds - Codebits

Planetary NormalsGet rotation from unit vector to the vertex position

Apply same rotation to normal vector

Page 29: Building Worlds - Codebits

• Extract watermask from BMNG

• Single bit, store in blue component of heightmap (24 bit total)

Water Specular

Page 30: Building Worlds - Codebits

Eye Candy 2 - Atmosphere

• Two types of scattering, Mie & Rayleigh

• Small molecules, O2, O3, etc - Rayleigh

• Aerosols - Mie (gray when it rains, pollution haze, etc)

Page 31: Building Worlds - Codebits

Atmospheric ShaderPhase function - Amount of scattering for camera angle

Outscattering - Optical depth of ray from entry point to camera

Inscattering - Amount of light added by scattering on planet surface into camera

Page 32: Building Worlds - Codebits

Atmospheric Shader

Page 33: Building Worlds - Codebits

Atmospheric Shader

Page 34: Building Worlds - Codebits

Atmospheric Shader

Page 35: Building Worlds - Codebits

Fractal NoiseAdding in missing detail

Page 36: Building Worlds - Codebits

Fractal NoiseAdding in missing detail

Height = dataset height + noise heightmap

Page 37: Building Worlds - Codebits

Fun!

• Add gravity, each object is a node, it’s easy

• Export from SketchUp to .obj, auto triangulate + auto normals

• Write a script to convert .obj into a vertex buffer object

• Drop in a dead simple shader

Page 38: Building Worlds - Codebits

Just for Fun

Page 39: Building Worlds - Codebits

Final Results

Page 40: Building Worlds - Codebits

Thanks!