Terrain and NPR Rendering on the GPU

Download Report

Transcript Terrain and NPR Rendering on the GPU

Hardware
Feature
Edges
June 7, 2004
Morgan McGuire and John F. Hughes
Brown University
NPAR 2004
1
Goal
Find and stroke feature edges on the GPU
2
Feature Edges
Contour
Front-face meets back-face
Boundary
Ridge
Valley
Silhouette
Subset of contour
All defined by derivatives of normals…
i.e. for nice polyhedra, adjacent face normals
3
Feature Tests
Contour: sgn(n A  eye)  sgn(nB  eye)

Valley : v  v   n  0  n
Ridge: v3  v2   n A  0  n A  nB   cos ridge
3
2
A
A


 nB   cos valley
Boundary| Artist :~ nB
Silhouette: Contour depthcom plexity 1
n1
eye = center of projection – v0
eye nA
v1
nB
n0
 = depth complexity
A
v2
v0
B
v3
4
Challenge
GPU limitations:
No “Edge Processor”
No access to adjacency
No previous state for coherence
Cannot create or destroy edge geometry
x
Adjacency
Vertices
Edges
x
Vertex
Processor
Rasterizer
Pixel
Processor
Triangles
5
Related Work
CPU Silhouettes
Exhaustive: Sutherland (circa ’77)
Randomized: Markosian et al. ’97
Cutting sphere: Gooch ’99
Dual space: Zorin and Hertzmann ’00
GPU Silhouettes
G-Buffer: Saito and Takahashi ’90; McCool ’03
Environment maps: Gooch ’99, Deitrich ’99
Halo: Raskar ’01, ’02
Pixel Processor + Readback: Brabec and Seidel ’03
Edge vertices: Card & Mitchell ’02, Brennan ’03, Gooch ’03
(None allow thick lines or brush strokes)
6
Vertex Attributes
GPUs allow 16 vertex “attributes”
<position, normal, color, tex coords>
Can store other information…
<position, face-normal A, face-normal B>
i.e. adjacent face normals
nA
v1
A
B
nB
The edge from v0 to v1 with
adjacent faces A and B.
v0
7
Agnosticism
The GPU doesn’t care
Attributes don’t have to be texture coords, colors
Face list doesn’t have to describe faces
Just has to have the right form
Face list: set of indices into vertex table
Vertex attributes: set of 4-vectors
e.g. store information about an EDGE of the
model mesh:
In each VERTEX structure we send to the GPU
Call these “edge vertices”
8
Edge Vertices
Make a new mesh
Every edge becomes two vertices
<v0,
nA, nB>, <v1, nA, nB>
Connected by a line
Use vertex processor to find vertices on contours
Hide non-contours when rendering
Degenerate polygons, a = 0, etc.
nA
v1
A
B
nB
(nA  eye > 0) xor (nB  eye > 0)
v0
9
Our Contribution
Extend Edge Vertices with
More edge types
Ridge, Valley, Silhouette
Smooth Silhouette
Suggestive Contour
Brush strokes
Animation
Plan for Future Hardware
10
The Edge-Mesh
Every edge becomes four identical* vertices
Connected into a quadrilateral
Store adjacent vertices, not face normals
Scalar texture parameter
(i) = < v0, v1, v2, v3, n0, n1, r, i >
n1
nA
n0
v2
v1
A
v0
3D Vectors
nB
* Differentiated
by i = {0, 1, 2, 3}
B
v3
11
Rendering
Test edges on the vertex processor
i=0
v0
Feature Edge:
i=3
Extrude into a screen-space rectangle
Choose vertex position from i
i=1
i=2
v1
Non-Feature Edge:
Hide beyond clipping plane
Early-out avoids rasterization overhead
Animation:
Animate v and n as a regular vertex and vertex-normal
12
Result
13
Building a Style
14
15
Performance
16
Thick Lines
Thick quads leave visible gaps at joints
Common problem (e.g. Raskar ’02)
17
Solution: End Caps
m0
start cap
p
“outside”
finish cap
m1
s0
quad
s1
“inside”
Computed in screen space
Follow projected normals m0, m1
The only mutual information between
adjacent edges!
18
Result
No Caps
Caps
Works well for smooth objects…
19
Heuristic can Fail
Vertex normals
poorly reflect
curvature for this
object and our
heuristic fails.
20
Heuristic can Fail
Hidden
Failures:
Cap is on the
wrong side, but
the gap is inside
the object.
21
Heuristic can Fail
Visible
Failure:
Cap is on the
wrong side and
the gap is outside
the object.
22
Analysis of Failure
Failure occurs when s is on the “concave” side of joint:
i.e. 2D curvature is negative
s  d  e  0 or s  d  f   0
Probability of failure increases when:
Curvature is high and tessellation is low
Vertex normal represents curvature poorly
e
f
23
Brush Textures
24
Screen vs. Object Space
s0 = r
s1 = r + L
s = vx | vy
Attached to vertices
during animation
Good for still and
high-poly models
Good for animated
low-poly models
25
Applications
“Zero CPU cycles were harmed in the
rendering of the following images.”
26
Different Strokes
Crayon-Bot
Pen-Bot
Bunny-Bot
Blue Print-Bot
27
Wispy-Bot
Ink & Wash
28
Hidden Line
29
Toon Fur
30
J. Lengyel’s Realistic Fur Algorithm
Shells
Stack 16 sparse textures
Perform extrusion in vertex
shader
Looks like fur when viewed
“head on”
Looks like 16 dots when viewed
“side on”
Fins
Striped texture near
CONTOURS
Looks like fur when viewed
“side on”
We move this onto GPU
Images from Lengyel et. al, Real-Time Fur over Arbitrary Surfaces
Anisotropic shading
31
Realistic Fur
32
Shadow Volumes

Find polyhedron bounding shadowed points
Any intersected surface is shadowed
Compute intersection via stencil operations

Caps


– At the object and infinity
– E. Lengyel implemented with GPU

Side
Light Cap
Side
Sides
– Find CONTOUR edges
– Extrude each one into a quad
Dark Cap (at infinity)
33
Shadows
34
Zorin-Hertzmann Smooth Silhouettes
fA  0
n0
v0
f0= 0.8
n2
f2= -0.1
v2
n1
A
B
v1
fB  0
f1= -0.2
Extend edge vertex to <v0, v1, v2, v3, n0, n1, n2, n3, r, i>
Define an “above-water” function f = eye • n
Either 0 or 2 edges have zero-crossings in f
Estimate zero-crossing points A, B and connect them
35
Animation
36
DeCarlo et. al’s Suggestive Contours*




Smooth silhouettes with new above-water function
f  k1 w  T1   k 2 w  T2 
Only stroke when “ wk r  0 ”
– i.e.  f ( A)  f ( B)  A  B   w  t d
2
2
A
A B
2
B
Pack k1, k2, t1, t2, n, v (x4, for a quad) into edge vertex
37
* Don’t try our S.C. method at home on GeForceFX…
it is too hard to squeeze the curvature data into only 16
attributes!
Just use DeCarlo’s image space algorithm, or…
38
GeForce 6800
GeForce 6800 and Radeon X800 support texture
reads in the vertex processor. Commercially available
by August.
Pointers (stored in textures) cut redundant data.
Using 16-bit pointers:
Current:
E = <v,v,v,v,n,n,r,i> x 4
= 304 bytes
New:
E = <ptr, i> x 4 + <#,#,#,#,r> = 14 bytes
20x improvement!
(# is a pointer to a regular mesh vertex)
39
GeForce 7800?
DirectX Next specification allows geometry
to be created and destroyed– this eliminates
the need for degenerate quads…
40
Follow-Up
Jorn Loviscach extended our method to halos with MAX alpha
blending and suggests a new curved silhouette algorithm.
41
Acknowledgements
Evasion Group, INRIA Rhone-Alpes
NVIDIA
Tomer Moscovich
42
43
Feature Expressions
<v0, v1, v2, v3, n0, n1, r, i>
nA = (v1 – v0)  (v2 – v0)
nB = (v3 – v0)  (v1 – v0)
Contour: sgn(n A  eye)  sgn(nB  eye)

Valley : v  v   n  0  n
Ridge: v3  v2   n A  0  n A  nB   cos ridge
3
2
A
A


 nB   cos valley
Boundary| Artist :~ nB
Silhouette: Contour depthcom plexity 1
n1
eye nA
eye = center of projection – v0
 = depth complexity
v1
nB
n0
A
v2
v0
B
v3
44
Silhouettes
1. Set S := (S + 1) mod 255
2. If S == 0 then clear stencil buffer to 255
3. Render the model, setting stencil to S
wherever the depth test passes
4. Set the stencil test to pass where stencil == S
5. Render contour edges
45