57
Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios [email protected]

Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios [email protected]

Embed Size (px)

Citation preview

Page 1: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Rendering hair with graphics hardware

Tae-Yong Kim

Rhythm & Hues Studios

[email protected]

Page 2: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Overview

State of the Art in Hair Rendering and Modeling

Issues in Hardware Hair Rendering Line drawing with Graphics Hardware Illumination and Hardware Shader Shadows

Page 3: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair representation

Hair is not a single entity – always consider hair volume a a whole

Surface (polygons, nurbs, etc.) Line (guide hair, curve, polyline..) Volumetric representation (implicit

surface, 3D texture, tubes, …)

Page 4: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Representation - Polygons

ATI2004 - Polygonal Model

(from SIGGRAPH Sketch by Thorsten Scheuermann)

Real-time rendering Suited for existing

artists asset

Limited hairstyle Animation difficult

Page 5: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Representation - Lines

nVidia – Line representation

(from Matthias Wloka’s Eurographics 2004 tutorial)

Dynamic hair No restriction in

hairstyle Advanced rendering

possible

No standard modeling technique

Can be time consuming to render

Page 6: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Model Generation

Use control tools to generate bunch of hairs

Control curves (guide hairs) Cylinders – single level/multi level Fluid flow, 3D vector field Automated methods emerging

Page 7: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Guide hair Small number of guide hairs

control hair shape Interpolation generates

whole instances of hairs to render

Properties like density, length can be controlled with maps

Page 8: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Other guide objects (fluid) Create vector fields (e.g.

with fluid dynamics) hairs through 3D vector filed Each hair is instanced

through fluid control

Hadap and Nadia M. Thalmann Eurographics

2001

Page 9: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Other guide objects (cylinders) Cylinders to shape hair Instance hairs inside each

tube

Multi-layered control of cylinders

Kim and Neumann SIGGRAPH 2002

Page 10: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Emerging techniques Hair modeling from

photographs Directly recover hair

geometry from images

S. Paris, H. Briceno, F. Sillion SIGGRAPH 2004

Page 11: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair as line drawing 100-150k hair per human

scalp >100 lines per each hair > millions of lines (micro

polygons) typical in production hair render

Use of graphics hardware

Page 12: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair segment as a GL line

DrawHairLine(ps, pe , cs, ce){

glBegin(GL_LINES)glColor3fv(cs);glVertex3fv(ps);glColor3fv(ce);glVertex3fv(pe);glEnd()

}

Page 13: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair as GL lines

DrawHair(p0,p1,..,pn-1,c0,c1,….cn-1){

glBegin(GL_LINE_STRIP)glColor3fv(c0);glVertex3fv(p0);glColor3fv(c1);glVertex3fv(p1);…

glColor3fv(cn-1);glVertex(pn-1);glEnd()

}

Page 14: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Are we done?DrawHair(p0,p1,..,pn-1,c0,c1,….cn-1)

{glBegin(GL_LINE_STRIP)glColor3fv(c0);glVertex3fv(p0);glColor3fv(c1);glVertex3fv(p1);…

glColor3fv(cn-1);glVertex(pn-1);glEnd()

}

Algorithm1

For each hair, call this function!

Page 15: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Not quite..

Page 16: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Point samples

Computed sample color

True sample

The aliasing problem

Page 17: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Compare this..

Page 18: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Remedies

Increase sampling rate ( large image size, accumulation buffer)

Image quality depends on number of samples at a slow convergence rate

Required sampling rate is above 10,000 x 10,000 pixel resolution

Thinner (smaller) hairs require even higher sampling rate

Page 19: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Remedies

Hardware antialiasing of line drawing

GL_LINE_SMOOTH

Thickness control with alpha blending

Page 20: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

=0.09 0.25 0.60 1.0

Thickness control with alpha blending

Page 21: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Correct

Visibility order is important

correct wrong

Page 22: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair as visibility ordered lines

Algorithm 2

1. Compute color for each end point of the lines (shading, shadowing)

2. Compute the visibility order

3. Draw lines sorted by the visibility order

Page 23: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

ro

k

a

d

bc

e

g

f

v

su

p

t

q

m

hi

j

ln

k,l,m

d,e

c

f,g,h

i,j

n,o,p,q

r,s,t

u,v

b

a

A simple visibility ordering scheme

Drawing order: a, b, c, d, e, f, g, h, I, j, k, l, m, n, o, p, q, r, s, t, u, v

Page 24: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

A simple visibility ordering scheme

Efficient (700K lines per second on 700Mhz CPU)

Approximate, but works well for small line fragments

dcpD )(

NiDD

DDNi

0,

minmax

min

Page 25: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Correct Cached

Coherence of visibility ordering

Visibility ordering can be cached and reused (useful for interactive application)

Page 26: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair shading model

Describes the amount of reflected/scattered light toward the viewing direction

Kajiya-Kay (1989)

Marschner et al. (2003)

Page 27: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

L

V

T

Kajiya-Kay model

),sin( LTKdDiffuse

Page 28: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

L

V

T

H

Kajiya-Kay model

psSpecular VTLTVTLTK )],sin(),sin())([(

Page 29: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Example cg program

Page 30: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

),sin( LTKdDiffuse 2)(1 LTKdDiffuse

Page 31: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

psSpecular VTLTVTLTK )],sin(),sin())([(

Page 32: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Real-time hair shading

Hair as set of unstructured lines

Sort visibility of hair lines

line render with vertex shader

Page 33: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Shadow2Color2Tangent2Pos2

Shadow1Color1Tangent1Pos1

Data structure

Position: comes from modeling, animation Tangent : computed from position (Unshadowed) Color: shaded with either CPU/

or Vertex Shader Shadow: computed with opacity shadow

maps Sort each line with visibility order

Page 34: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

..........

..........

..........

ShadowNColorNTangentNPosNN

..........

Shadow4Color4Tangent4Pos44

Shadow3Color3Tangent3Pos33

Shadow2Color2Tangent2Pos22

1

Index

Shadow1Color1Tangent1Pos1

ShadowColorTangentPos

Vertex table

N-1

..

..

4

3

2

1

V1

NM

....

....

54

43

32

21

V2Index

Line table

Data structure

Page 35: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

A shading model describes the amount of reflected light when hair is fully lit

Most hair receives attenuated light due to self-shadowing

Crucial for depicting volumetric structure for hair

Self-shadows

Page 36: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

No shadows With shadows

Self-shadows

Page 37: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Front lighting Back lighting

Self-shadows

Page 38: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Shadow is a fractional visibility functionHow many hairs between me and the light?What percentage of light is blocked?

Self-shadows

Page 39: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Shadow is a fractional visibility function

Self-shadows

Page 40: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Self-shadows

Opacity shadow maps

[Kim and Neumann EGRW 2001]

Fast approximation of the deep shadowing functionIdea: use graphics hardware as much as possible

Page 41: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

)exp()( p l dll0 ')'(

Ω(l)

l

Transmittance Opacity

Monotonically increasing

Self-shadows

Page 42: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps

Page 43: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps - Algorithmfor (1 i N) Determine the opacity map’s depth Di from the light

for each shadow sample point pj in P (1 j M)

Find i such that Di-1 Depth(pj) < Di

Add the point pj to Pi.

Clear the alpha buffer and the opacity maps Bprev, Bcurrent.

for (1 i N) Swap Bprev and Bcurrent.

Render the scene clipping it with Di-1 and Di.

Read back the alpha buffer to Bcurrent.

for each shadow sample point pk in Pi

Ω prev = sample(Bprev , pk)

Ω current = sample(Bcurrent , pk)

Ω = interpolate (Depth(pk), Di-1, Di, Ω prev, Ω current)

τ(pk) = e-κΩ

Φ(pk) = 1.0 - τ(pk)

Page 44: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Uniform slicing 1D BSP Nonlinear spacing

How many opacity maps?

Page 45: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps - Algorithmfor (1 i N) Determine the opacity map’s depth Di from the light

for each shadow sample point pj in P (1 j M)

Find i such that Di-1 Depth(pj) < Di

Add the point pj to Pi.

Clear the alpha buffer and the opacity maps Bprev, Bcurrent.

for (1 i N) Swap Bprev and Bcurrent.

Render the scene clipping it with Di-1 and Di.

Read back the alpha buffer to Bcurrent.

for each shadow sample point pk in Pi

Ω prev = sample(Bprev , pk)

Ω current = sample(Bcurrent , pk)

Ω = interpolate (Depth(pk), Di-1, Di, Ω prev, Ω current)

τ(pk) = e-κΩ

Φ(pk) = 1.0 - τ(pk)

Page 46: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Storing all the opacity maps incur high memory usage

Sort shadow computation points based on the map’s depth

P0

Pi

PN-1

As soon as the current map is rendered, compute shadows for corresponding sample points.

Preparing Shadow Samples

Page 47: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps - Algorithmfor (1 i N) Determine the opacity map’s depth Di from the light

for each shadow sample point pj in P (1 j M)

Find i such that Di-1 Depth(pj) < Di

Add the point pj to Pi.

Clear the alpha buffer and the opacity maps Bprev, Bcurrent.

for (1 i N) Swap Bprev and Bcurrent.

Render the scene clipping it with Di-1 and Di.

Read back the alpha buffer to Bcurrent.

for each shadow sample point pk in Pi

Ω prev = sample(Bprev , pk)

Ω current = sample(Bcurrent , pk)

Ω = interpolate (Depth(pk), Di-1, Di, Ω prev, Ω current)

τ(pk) = e-κΩ

Φ(pk) = 1.0 - τ(pk)

Page 48: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

The alpha buffer is accumulated each time the scene is drawn.

The scene is clipped with Di and Di-1

Speedup factor of 1.5 to 2.0

In very complex scenes, preorder the scene geometry so that the scene object is rendered only for a small number of maps.

More speedup and reduce memory requirement for scene graph

Clipping and Culling

Page 49: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps - Algorithmfor (1 i N) Determine the opacity map’s depth Di from the light

for each shadow sample point pj in P (1 j M)

Find i such that Di-1 Depth(pj) < Di

Add the point pj to Pi.

Clear the alpha buffer and the opacity maps Bprev, Bcurrent.

for (1 i N) Swap Bprev and Bcurrent.

Render the scene clipping it with Di-1 and Di.

Read back the alpha buffer to Bcurrent.

for each shadow sample point pk in Pi

Ω prev = sample(Bprev , pk)

Ω current = sample(Bcurrent , pk)

Ω = interpolate (Depth(pk), Di-1, Di, Ω prev, Ω current)

τ(pk) = e-κΩ

Φ(pk) = 1.0 - τ(pk)

Page 50: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

)-/())((,)0.1()(p 1-ii1currentprevk DDDpDepthttt ik

Opacity Shadow Maps

Page 51: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps - Algorithmfor (1 i N) Determine the opacity map’s depth Di from the light

for each shadow sample point pj in P (1 j M)

Find i such that Di-1 Depth(pj) < Di

Add the point pj to Pi.

Clear the alpha buffer and the opacity maps Bprev, Bcurrent.

for (1 i N) Swap Bprev and Bcurrent.

Render the scene clipping it with Di-1 and Di.

Read back the alpha buffer to Bcurrent.

for each shadow sample point pk in Pi

Ω prev = sample(Bprev , pk)

Ω current = sample(Bcurrent , pk)

Ω = interpolate (Depth(pk), Di-1, Di, Ω prev, Ω current)

τ(pk) = e-κΩ

Φ(pk) = 1.0 - τ(pk)

Page 52: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

)exp()( p

)exp()( p1.0

1.0

1.0•Quantization in alpha buffer limits Ω to be 1.0 at maximum

•κ scales the exponential function s. t. Ω value of 1.0 represents a complete opaqueness (τ = 0)

•κ = 5.56 for 8 bit alpha buffer

(e-κ = 2-8)

Exponential Attenuation

Page 53: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

N = 7(5secs) N = 15(7secs) N = 30(10secs)

N = 60(16secs) N = 100(25secs) N = 200(46secs) N = 500(109secs)

No shadow

Opacity Shadow Maps

Page 54: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair rendering with lines in graphics hardwareSetup pass:

Compute the visibility order Compute shadow values

Drawing pass: For each line segment Li ordered due to the

visibility order Set thickness (alpha value) Draw Li with programmable shader

Page 55: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Opacity Shadow Maps – Recent Extensions Whole opacity maps stored in 3D texture

nVidia’s demo Koster et al., Real-Time Rendering of Human Hair using Programmable Graphics Hardware, CGI 2004

Mertens et al, A Self-Shadow Algorithm for Dynamic Hair using Density Clustering, EGSR 2004

Page 56: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Hair rendering with lines in graphics hardware Antialiasing Shading through vertex/fragment shader Shadows with opacity maps

Page 57: Rendering hair with graphics hardware Tae-Yong Kim Rhythm & Hues Studios tae@rhythm.com

Questions