+ All Categories
Home > Documents > MARCHING CUBES - Chalmers

MARCHING CUBES - Chalmers

Date post: 16-Feb-2022
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
19
MARCHING CUBES Johan Elvek & Bartolomeus Jankowski
Transcript

MARCHING CUBESJohan Elvek & Bartolomeus Jankowski

BRIEF HISTORYIn the Beginning...

•Medical Imaging

• CT, MR, SPECT

• Data – Stacked 2D Slices(Think: Volume Texture)

• 2D Slices ➙ 3D Mesh

• Calculate Normals, Shade – Cut with Textured Plane(Medical Term: Reformatting)

TERRAINWhy Marching Cubes?

• Classic Terrain Generation: Height Maps

• Pros: Fast and Simple – Texture Lookup in Vertex Shader

• Cons: height(u,v) – 2D-Function, Cannot Produce Caves, Overhangs, etc.

TERRAINWhy Marching Cubes?

• Classic Terrain Generation: Height Maps

• Pros: Fast and Simple – Texture Lookup in Vertex Shader

• Cons: height(u,v) – 2D-Function, Cannot Produce Caves, Overhangs, etc.

?

TERRAINDensity Function

•Marching Cubes

• Medical Imaging – Density Data

• In General – Density Function f

•Density at Some Point p

Determines whether p Is Inside or Outside Terrain• Threshold Is Domain-Dependent

f : R3 → R

Density function f —given a point p in space,calculate the density at p.

THE ALGORITHMWhy Cubes?

• Grid of Cubes (Voxels)• Medical Imaging –

Cubes Between 2 Slices –Density at each Cube Vertex Corresponds to Pixel in Slice

• Terrain –Cubes Fill Entire Scene –f(p) Gives Density for Any Given Point p

• Cube Vertices Marked Inside (1) or Outside (0)• For Each Cube Edge with

(0,1) or (1,0) ➙ Vertex of a Triangle

THE ALGORITHMFinding Triangles

• 8-Bit Binary Values Formed from the Corners of each Cube ➙ Index into Lookup Table

• Symmetry/Rotation ➙ Distinct Cases (Visualization)

• Exact Point of Intersection Found by Linear Interpolation

THE ALGORITHMFinding Normals

•Normal of Each Point Is Equal to Gradient of f

• Easily Obtained by Calculating Independent Rate of Change in Density along x, y, and z Directions

THE ALGORITHMFinding Normals Cont’d

xixi−1

xi+1

n̂ = normalize(dx, dy, dz)

f(xi+1)− f(xi−1) = dx

d

GPU GENERATIONGPU Gems 3 — Overview

•World Divided into Blocks• Each Block Divided into 323 Cubes• Each Non-Empty Block Dynamically

Assigned a Vertex Buffer (from Pool of ~300)

• For Each Frame• Sort Blocks Front-to-Back• Generate Terrain for New Blocks in View

Frustum• Evict or Reuse (Vertex Buffers of) No

Longer Visible, or Faraway, Blocks• One Block at a Time

GPU GENERATIONGPU Gems 3 — Overview

• For Each Vertex in Each Triangle, We Need:• World-Space Coordinates• Normals• Ambient Occlusion Value

•Multi-Pass Algorithm• We Focus On Second of Three Presented

Methods

GPU GENERATIONGPU Gems 3 — Pass 1: Build Densities

• In Pixel Shader• Store Density at Each Cube Corner (333

in Total) in a Texel of a Volume Texture

•Density Function• Ground (density = –ws.y)

• Add Noise Layers (density += ...)• Sample Volume Textures of Noise• Different Frequencies and Amplitudes

Produce Different Kinds of Detail• Possibly Some Manual Influence• Expensive Due to Many Lookups &

Computations

GPU GENERATIONGPU Gems 3 — Pass 2: Gen. Triangle List

• In Geometry Shader• Stream out “Lightweight Marker”

Containing Cube Position and Edges for Each Triangle (a 32-bit Unsigned Integer)• (Use the Lookup Tables)

• Stream-out Queries Can Be Used to Skip Remaining Passes(If Triangle Count Is 0)• (No Vertex Buffer Assigned)

• Maximum Number of Markers Is 5 per Cube• First Method Streams out up to 105

Floats (Coordinates, Normals, and Occlusion for Each Vertex)

GPU GENERATIONGPU Gems 3 — Pass 3: Gen. Vertices & Draw

• In Vertex Shader• For Each Vertex in Triangle, Calculate:• Coordinates (Covered)• Normals (Covered)• Ambient Occlusion Value (Next Slide)

• Pass-Through Geometry Shader & Draw Geometry

GPU GENERATIONGPU Gems 3 — Pass 3: Gen. Vertices & Draw

• Ambient Occlusion• 32 Rays per Vertex• 16 Short-Range Samples (Sample

Block’s Volume Texture)• 4 Long-Range Samples (Use More

Expensive Density Function)

GPU GENERATIONGPU Gems 3 — Method 3 (Briefly)

•More Complex, but Faster

• Avoid Duplication of Vertices• For Each Cube – Only Vertices Lying on

Edges 0, 3, and 8 Are Created• An Index Buffer Is Also Created to

Describe Triangles0

3

8

GPU GENERATIONGPU Gems 3 — Textures + Extra

• Textures

• Triplanar

• Striation

•Other Things

• Collision

• Lighting (Of Other Stuff)

QUESTIONS???


Recommended