Computer Graphics

Triangle Meshes

Prof. Dr. David Bommes
Computer Graphics Group

Last Time: Lighting

images/ray-tracing-pipeline-3.svg images/ray-tracing.svg

images/spheres-0.pngno illumination images/spheres-2.pnglocal illumination images/spheres-4.pngglobal illumination

Phong Lighting Model

  • Ambient lighting
    • approximate global light transport / exchange
    • uniform in, uniform out
images/spheres-0.png
  • Diffuse lighting
    • dull / matt surfaces
    • directed in, uniform out
images/spheres-1.png
  • Specular lighting
    • shiny surfaces
    • directed in, directed out
images/spheres-2.png

Wikipedia

Phong Lighting Model

images/torus-a.pngambient: \(I_a m_a\) images/torus-d.pngdiffuse: \(I_l m_d \left( \vec{n} \cdot \vec{l} \right)\) images/torus-s.pngspecular: \(I_l m_s \left( \vec{r} \cdot \vec{v} \right)^s\)

images/torus-ads.png
\[ I \;=\; I_a m_a + I_l \left( m_d \left( \vec{n} \cdot \vec{l} \right) + m_s \left( \vec{r} \cdot \vec{v} \right)^s \right) \]

Real or Rendered?

images/rendering_vs_photo_quiz/pancakes_cg.jpg images/rendering_vs_photo_quiz/blueberry_muffin_real.jpg images/rendering_vs_photo_quiz/mms_cg.jpg images/rendering_vs_photo_quiz/bread_cg.jpg images/rendering_vs_photo_quiz/lizard_real.jpg images/rendering_vs_photo_quiz/car_cg.jpg images/rendering_vs_photo_quiz/buildings_cg.jpg

Fake Images and Videos

Today: Ray Tracing Meshes

  • Extend ray tracing to triangle meshes
    • Mesh data structures
    • Lighting computations
    • Efficient ray intersections

images/ray-tracing-pipeline.svg images/ray-tracing.svg

Triangle Meshes

What is a triangle mesh?

  • Connectivity / Topology
    • Vertices \(\mathcal{V} = \{ v_1, \dots, v_n \}\)
    • Edges \(\mathcal{E} = \{ e_1, \dots, e_k \}\), \(e_i \in \mathcal{V} \times \mathcal{V}\)
    • Faces \(\mathcal{F} = \{ f_1, \dots, f_m \}\), \(f_i \in \mathcal{V} \times \mathcal{V} \times \mathcal{V}\)
images/triangle-mesh-0.png

  • Geometry
    • Vertex positions \(\{ \vec{p}_1, \dots, \vec{p}_n \}\), \(\vec{p}_i \in \R^3\)
images/triangle-mesh-1.png

Triangle Meshes

  • Triangle meshes can represent arbitrary surfaces
images/vw.png

Triangle Meshes

  • Triangle meshes can represent arbitrary surfaces
  • Piecewise linear approximation → error is \(\mathcal{O}(h^2)\)
images/approximation.png

Triangle Meshes

  • Triangle meshes can represent arbitrary surfaces
  • Piecewise linear approximation → error is \(\mathcal{O}(h^2)\)
  • Approximation error inversely proportional to #triangles
images/octagon-subdivision.png

Triangle Meshes

  • Triangle meshes can represent arbitrary surfaces
  • Piecewise linear approximation → error is \(\mathcal{O}(h^2)\)
  • Approximation error inversely proportional to #triangles
  • Adaptive tesselation can adapt to surface curvature

images/adaptive-sampling-1.pngadaptive meshing images/adaptive-sampling-2.pngcurvature visualization

Triangle Meshes

  • Triangle meshes can represent arbitrary surfaces
  • Piecewise linear approximation → error is \(\mathcal{O}(h^2)\)
  • Approximation error inversely proportional to #triangles
  • Adaptive tesselation can adapt to surface curvature
  • Simple primitives can be processed efficiently by CPU/GPU

images/euler-trimesh.png images/geforce.png

Example: Stanford Bunny

  • Observation:
    • roughly twice as many faces as vertices
    • roughly three times as many edges as vertices
  • Coincidence?
  • No!
    • Euler Formula for meshes of genus 0 \[V - E + F = 2\]
    • more on this in the course 3D Geometry Processing (spring)
images/bunny-flat.png
34835 vertices, 69666 faces, 104499 edges

Mesh Data Structures

Face Set

  • Face Set is a standard file format for triangle meshes (e.g. STL format)
  • Memory consumption
    36 B/f = 72 B/v
    • recall: ~twice as many faces as vertices
images/data-structure-1.svg

Indexed Face Set

  • Indexed Face Sets are used for many file formats (e.g. OFF, OBJ, VRML)
  • Memory consumption
    12 B/v + 12 B/f = 36 B/v
images/data-structure-2.svg

Face-Based Connectivity

  • Store connectivity per face
  • Memory consumption
    16 B/v + 24 B/f = 64 B/v
  • Non-constant element size for general polygonal meshes
  • Edges not represented
images/data-structure-3.svg

Edge-Based Connectivity

  • Store connectivity per edge
  • Memory consumption
    16 B/v + 4 B/f + 32 B/e = 120 B/v
  • Edges explicitly represented
  • Missing edge orientation leads to case distinctions during traversal
images/data-structure-4.svg

Halfedge-Based Connectivity

  • Store connectivity per halfedge
  • Memory consumption
    16 B/v + 4 B/f + 20 B/h = 144 B/v
    (can be reduced to 96 B/v)
  • Edges & halfedges explicitly represented
  • No case distinctions during traversal!
images/data-structure-5.svg

One-Ring Traversal

  • Simple one-ring traversal without case distinctions:
  1. Start at vertex
  2. Outgoing halfedge
  3. Opposite halfedge
  4. Next halfedge
  5. Opposite halfedge
  6. Next halfedge
images/data-structure-6.svg

Half-Edge navigation demo

Halfedge-Based Libraries

Lighting & Shading

Ray Tracing Meshes

images/bunny-phong.pngWe want this… images/bunny-flat.png…but we get this

Flat Shading vs. Phong Shading

  • Flat shading
    • Use constant face normal for lighting
    • Yields facetted appearence
    • Mach band effect emphasizes this even more
images/teapot-flat.png

images/mach-band.pngMach band effect images/Mach_bands_animation.gifsource Wikipedia

Flat Shading vs. Phong Shading

  • Flat shading
    • Use constant face normal for lighting
    • Yields facetted appearence
    • Mach band effect emphasizes this even more
images/teapot-flat.png

  • Phong shading
    • Use smooth normal field for lighting
    • Compute normal vectors per vertex
    • Barycentric interpolation of normal vectors
images/teapot-phong.png

Normal Vectors

  • Triangle normal

\[ \vec{n}(T) = \frac{\left(\vec{b}-\vec{a}\right) \times \left(\vec{c}-\vec{a}\right)} {\norm{\left(\vec{b}-\vec{a}\right) \times \left(\vec{c}-\vec{a}\right)}} \]

images/normal-triangle.png

  • Vertex normal
    • Average of incident triangles’ normals \(\vec{n}(T_i)\)
    • Weighted by area or opening angle \(w(T_i)\)

\[ \vec{n}(V) = \frac{ \sum_{T_i \ni V} w(T_i) \, \vec{n}(T_i)} { \norm{ \sum_{T_i \ni V} w(T_i) \, \vec{n}(T_i)} } \]

images/normal-vertex.png

Vertex Normals

images/vertex-normals-1.pngtriangulation (flat shading) images/vertex-normals-2.pngno weighting images/vertex-normals-3.pngangle-weighted

Interpolate Vertex Normals

  • Intersection point with barycentric coordinates \[ \vec{x} = \alpha\vec{A} + \beta\vec{B} + \gamma\vec{C}\]
  • Linearly interpolate vertex normals \[ \vec{n}\of{\vec{x}} = \alpha\vec{n}\of{\vec{A}} + \beta\vec{n}\of{\vec{B}} + \gamma\vec{n}\of{\vec{C}} \]
  • Use \(\vec{n}(\vec{x})\) to light point \(\vec{x}\)
  • Normalize for lighting calculations!
images/ray-triangle-shading.png

Ray Tracing Meshes

images/bunny-flat.pngFlat Shading images/bunny-phong.pngPhong Shading

Ray Tracing Meshes

images/bunny_flat_low.pngFlat Shading images/bunny_smooth_low.pngPhong Shading

Efficient Ray-Mesh Intersections

Ray-Mesh Intersections

  • Brute-Force
    • Intersect ray with all \(n\) mesh triangles
    • Select intersection with smallest positive ray parameter \(t\)
    • Computational cost: \(\mathcal{O}(n)\) for single ray
    • Many unnecessary ray-triangle intersection tests
images/plants_sunflowerfield.png
Image courtesy of Oliver Deussen

Spatial Data Structures

  • Improve efficiency of ray-surface intersections by pre-sorting of primitives → spatial data structures
  • Tradeoffs
    • Applicability
    • Performance
    • Resources
    • Implementation
  • Examples
    • uniform grids, adaptive grids, kd-trees, bsp-trees, bounding volume hierarchies

Spatial Data Structures

  • Fundamental in computer science
  • Other applications
    • robotics, motion planning, simulation
    • geographical information systems (GIS)
    • sensor networks, routing, etc.
  • In computer graphics:
    • visibility, transparency rendering, physics-based animation & simulation, collision detection, morphing, geometric modeling, etc.

KD-Trees

  • Construction

KD-Trees

  • Construction
    • compute bounding box

KD-Trees

  • Construction
    • compute bounding box
    • recursively split cell using axis-aligned plane until maximum depth or minimum number of remaining objects is reached
      • Only leaf nodes store reference to geometry!

KD-Trees

  • Construction
    • compute bounding box
    • recursively split cell using axis-aligned plane until maximum depth or minimum number of remaining objects is reached
      • Only leaf nodes store reference to geometry!
    • choosing the split plane
      • midpoint
      • median cut
      • advanced strategies
    • builds a binary tree structure
root internal nodes leaf nodes

KD-Trees

  • Internal nodes store
    • split axis: \(x\)-, \(y\)-, or \(z\)-axis
    • split position: coordinate of split plane along axis
    • children: reference to child nodes
  • Leaf nodes store
    • list of primitives
    • mailboxing information

KD-Trees

  • Traversal
    • top-down recursion
t max t min t split

KD-Trees

  • Traversal
    • top-down recursion
t min t max

KD-Trees

  • Traversal
    • top-down recursion
t min t max

KD-Trees

  • Traversal
    • top-down recursion
t max t min t split

KD-Trees

  • Traversal
    • top-down recursion
t min t max

KD-Trees

  • Traversal
    • top-down recursion
t min t max t

KD-Trees

KD-Trees

images/kd_tree_3D_dragon_even.jpg
kd-tree with even splitting

Source

KD-Trees

images/kd_tree_3D_dragon_area.jpg
kd-tree with surface area heuristic splitting

Source

Bounding Volume Hierarchies

  • So far: divide space and assign objects to cells
  • Now: group objects and bound by simple volumes for fast ray-intersection rejection
  • Alternative divide-and-conquer method

Bounding Volume Hierarchies

  • Bounding Volumes
    • Spheres

Bounding Volume Hierarchies

  • Bounding Volumes
    • Spheres
    • Axis-aligned bounding box (AABB)

Bounding Volume Hierarchies

  • Bounding Volumes
    • Spheres
    • Axis-aligned bounding box (AABB)
    • Oriented bounding box (OBB)

Bounding Volume Hierarchies

  • Bounding Volumes
    • Spheres
    • Axis-aligned bounding box (AABB)
    • Oriented bounding box (OBB)
    • \(k\)-discrete orientation polytopes (\(k\)-DOPs)
    • convex hulls, etc.
  • Tradeoff
    • complex shape → tight fit → fewer intersections
    • simple shape → fast intersection

Bounding Volume Hierarchies

  • Construction: bottom-up

Bounding Volume Hierarchies

  • Traversal: recursive top-down

each geometric primitive intersected only once (no mailboxing required)

Comparison

  • Spatial subdivision
    • selects sets of objects based on given volumes
    • top-down construction
  • Bounding volume hierarchies
    • selects volume based on given sets of objects
    • bottom-up construction

Exploiting Hardware

  • Caching
  • Parallelism
  • SIMD extensions
  • Programmable GPUs
  • Dedicated ray-tracing hardware

Summary

  • Brute-Force
    • Intersect ray with all \(n\) triangles of the mesh
    • Select intersection with smallest positive ray parameter \(t\)
    • Computational cost: \(\mathcal{O}(n)\)
  • Bounding Volumes
    • Bound mesh by simple-to-interesect objects (sphere, box, etc.)
    • Only if ray intersects bounding volume, then test individual triangles
    • Bounding volume hierarchy leads to \(\mathcal{O}(\log n)\)
  • Spatial Hierarchy
    • Partition scene into a spatial hierarchy
    • Grid, Octree, kD-tree, BSP-tree
    • Spatial hierarchy leads to \(\mathcal{O}(\log n)\)

Axis-Aligned Bounding Boxes

  • AABBs are simple to code, but quite effective (see exercises)
images/ray-tracer.png
Performance increase from 335s to 11s

Dynamic Scenes?

Photorealistic Rendering

The Quest for Realism

images/cbox-0.pngstandard ray tracing images/cbox-1.png+soft shadows
images/cbox-2.png+caustics images/cbox-3.png+indirect lighting

© Henrik Wann Jensen

Light Paths

image/svg+xml E LE LDE LSE LDSE LSDE LDDE L S D D

  • E = eye point
  • L = light source
  • D = diffuse reflection
  • S = specular reflection

Types of Reflections

images/reflections.png

H. Lensch, “Efficient Image-Based Appearance Acquisition of Real-World Objects”, PhD thesis, 2004

Quiz: Light Paths

Which light paths can a standard recursive ray-tracer handle?

  • \(ED^*L\)
    • Nope, this is what a very different algorithm called Radiosity can handle. Wikipedia
  • \(E[(D|G|S)^+(D|G)]L\)
    • No, this is Kajiya’s path-tracing algorithm. Wikipedia
  • \(E(D|G)[S^*]L\)
    • No, after a diffuse bounce, we cannot trace further specular bounces!
  • \(E[S^*](D|G)L\)
    • Yes, we can handle light rays from the eye that first go through an arbitrary number of mirror reflections, then one diffuse/glossy bounce where the intersection point is connected to the light source using shadow rays (Phong lighting model). Note that multiple paths of different length can be combined in a single pixel.

  • Notation:
    • \(+\) = one or more occurrences
    • \(*\) = zero or more occurrences
    • \(()\) = grouping
    • \(|\) = or

Recursive Ray Tracing

Which light paths can a standard recursive ray-tracer handle?

  • Only \(E[S^*](D|G)L\)
images/cbox-0.png
  • No multiple diffuse inter-reflections
    • E.g. \(EDDL\)
images/cornell.png
  • No caustics
    • E.g. \(EDSL\)
images/caustic.png

Literature

  • Botsch, Kobbelt, Pauly, Alliez, Levy: Polygon Mesh Processing, AK Peteres, 2010.
    • Chapters 1.3 and 2
images/pmp.png
  • Pharr, Humphreys: Physically Based Rendering, Morgan Kaufmann, 2004.
    • Chapter 3
images/pharr.png
  • Hughes et al.: Computer Graphics: Principles and Practice, 3rd Edition, Addison-Wesley, 2014.
    • Chapters 25, 37
images/cgpp.png