Realtime Hair Rendering Erik Sintorn - erik.sintorn@chalmers.se - - PowerPoint PPT Presentation

realtime hair rendering
SMART_READER_LITE
LIVE PREVIEW

Realtime Hair Rendering Erik Sintorn - erik.sintorn@chalmers.se - - PowerPoint PPT Presentation

Realtime Hair Rendering Erik Sintorn - erik.sintorn@chalmers.se State of the art (realtime) In recent games In recent research State of the art (realtime) A few hundred Half a million individual line textured polygons segments What makes


slide-1
SLIDE 1

Realtime Hair Rendering

Erik Sintorn - erik.sintorn@chalmers.se

slide-2
SLIDE 2

State of the art (realtime)

In recent games In recent research

slide-3
SLIDE 3

State of the art (realtime)

A few hundred textured polygons Half a million individual line segments

slide-4
SLIDE 4

What makes hair tricky?

  • Convincing hair requires very many, very thin

primitives (~.5M lines or quads or cylinders):

  • Lots of geometry for GPU to process
  • Very prone to aliasing
  • Hair is semitransparent (refractive):
  • Light is scattered in three strong directions
  • Simple transparency effect can be achieved by

blending, but requires fragments to be sorted

slide-5
SLIDE 5

Aliasing

slide-6
SLIDE 6

The Awful Truth

slide-7
SLIDE 7

Major challenges for realtime

  • Shading
  • Self shadowing
  • Blending for transparency and subsampling
slide-8
SLIDE 8

Hair Shaders

  • Kayija-Kay model

(James T Kajiya and Timothy L Kay, Rendering Fur With Three Dimensional Textures)

  • Pretends hair is infinitesimally

thin specular cylinder

  • Captures the most obvious

specular highlight from hair:

slide-9
SLIDE 9

Hair Shaders

  • Marschner et. al., Light Scattering from Human Hair Fibers
slide-10
SLIDE 10

Hair Shaders

Proper measurements

  • f light scattering

show three distinctive components

slide-11
SLIDE 11

Hair Shaders

  • “Light scattering”
slide-12
SLIDE 12

Self shadowing

slide-13
SLIDE 13

Self Shadowing

traditional techniques

Shadow Mapping

Would require huge shadow maps

Shadow Volumes

  • main problem with

algorithm is overdraw since each sillhouette edge becomes a polygon

  • Hair is ALL sillhouette

edges Neither support semi transparent geometry

slide-14
SLIDE 14

Deep Shadow Maps

  • Introduced in 2000 by Pixar to render

“fuzzy” objects offline

  • Instead of storing the closest fragments

depth in the shadow map, store a function, V(d): The visibility as a function of the depth

  • Requires an A-buffer type renderer
slide-15
SLIDE 15

Deep Shadow Maps

Store depth and opacity for each fragment along the ray (pixel) Compress into piecewise linear function for each pixel

V(d) V(d) d d

slide-16
SLIDE 16

Opacity Maps

Sample opacity at regular intervals

  • Render hair once for

each slice

  • Each time, move far

plane one slice further away

  • Save each slice into a

3d texture

slide-17
SLIDE 17

Opacity Maps

  • Regular sampling

requires very many slices

  • Not feasible to render

hair 256 times

16 slices 256 slices

slide-18
SLIDE 18

Opacity Maps

  • nVidias NALU

demo uses opacity maps with 16 slices, that they can render in a single pass

slide-19
SLIDE 19

Deep Opacity Maps

  • In a first pass, find the closest fragment for each pixel
  • In fragment shader, find the fragments xy-pos in this

map and use fragments depth to find the slice to write to

slide-20
SLIDE 20

Alpha Blending

  • We need to alpha-blend the fragments to

simulate: Antialiasing: Transparency:

slide-21
SLIDE 21

Alpha Blending

slide-22
SLIDE 22

Depth Peeling

  • Only failsafe technique known when no A-

buffer available

  • Sorting the primitives (triangles/lines) is not

necessarily enough

  • Depth peeling will draw the actual

fragments in back to front order

slide-23
SLIDE 23
  • Render the image with z-buffer and draw
  • nly furthest fragments
  • Use z-buffer of previous pass as texture to

discard all fragments with depth >= that texture

  • Continue until an occlusion query reports

no fragments drawn

Depth Peeling (algorithm)

slide-24
SLIDE 24

Depth Peeling (problems)

  • Requires as many passes as is the depth

complexity of the image

  • Images of hair can have depth complexity of

several hundred fragments in one pixel

  • Can use front to back drawing instead and

stop after a certain number of passes, but will still require to many passes to work in realtime

slide-25
SLIDE 25

Real-Time Approximate Sorting for Self Shadowing and Transparency in Hair Rendering

Erik Sintorn and Ulf Assarsson Chalmers University Of Technology

slide-26
SLIDE 26

What we do...

  • Introduces an approximate quicksort

algorithm for lines that runs entirely on the GPU

  • Use this to create high def Opacity Maps in

real time

  • And to solve the alpha blending problem
slide-27
SLIDE 27

Transform Feedback

  • Allows us to save the data
  • utput from the Geometry

Shader (without rendering to screen)

  • Introduced to simplify for

example displacement mapping and cube map

  • Called “Stream Out” in

DirectX 10

slide-28
SLIDE 28

Quicksorting points on GPU

  • Submit all points twice.
  • First time we discard all points on one side
  • f a split plane, second time we discard the
  • thers
slide-29
SLIDE 29

Quicksorting points on GPU

  • Results are stored in two buffers using

stream out

  • Recursively repeat until we have N buffers

where all elements in a buffer lie within one

  • f N slices
slide-30
SLIDE 30

Quicksorting lines on GPU

  • A line can lie on both sides of the plane
  • Just clip the line in the Geometry Shader
slide-31
SLIDE 31

Building Opacity Map

  • Use planes parallel with the light-plane to divide

geometry

  • Now, it is easy to build the opacity map texture by:
  • Enabling additive blending
  • Set up camera from lights viewpoint
  • For each slice s
  • Render sublist s into the final texture-slice
  • Copy the final texture-slice to texture-slice s
slide-32
SLIDE 32

Alpha Sorting

  • With GPU based Partial Quicksort, alpha blending is

easy

  • Simply sort geometry into sublists for each slice of the

viewing frustrum from the cameras viewpoint

  • This time, sort back to front
  • Render the generated VBO (as one large batch) with alpha

blending enabled

slide-33
SLIDE 33
slide-34
SLIDE 34

Hair Self Shadowing and Transparency Depth Ordering Using Occupancy maps

Erik Sintorn and Ulf Assarsson Chalmers University Of Technology

slide-35
SLIDE 35

Occupancy Maps

  • One big problem with Opacity Maps is that they

take up very much space

  • 256 slices of 512x512 maps take ~256MB if we

use float opacity values

  • That’s half the available memory on many cards
  • In this paper we suggest a more compact

representation, with similar quality that is also faster to generate

slide-36
SLIDE 36

Occupancy Maps

  • The Occupancy Map is like an opacity map, but we

store, for each texel and slice, only a bit that says if the voxel is occupied or not.

  • In this way, we can keep information about 128

slices in 4 32-bit words (one texture-map with unsigned ints representing RGBA)

  • We also use the technique suggested in Deep

Opacity Maps to optimize the available precision in this map

slide-37
SLIDE 37

Occupancy Maps

slide-38
SLIDE 38

Occupancy Maps

  • Generating the occupancy map
  • In a first pass, render the geometry from the light to find

the minimum and maximum depth of each texel

  • Render the geometry again, to a UINT32 framebuffer.

Using an OR logical operation for blending

  • For each generated fragment, figure out what slice it

belongs to and set the corresponding bit in the output

slide-39
SLIDE 39

Occupancy Maps

  • When we shade the hair from the cameras view, for

each fragment we find the projected light-space coordinates (x,y) and the slice s and fetch the

  • ccupancy words with a texture lookup.
  • We then count the number of set bits corresponding

to slices < s and set the opacity to this number multiplied by some constant

  • Since several fragments may have recorded

themselves in the same slice (the same bit) they may

  • nly be counted once... bad.
slide-40
SLIDE 40

The Slab Map

  • Enter the slab-map
  • The slab map is a simple rgba texture map
  • f the same size as the occupancy map
  • Each color

channel holds the number of fragments recorded into that slab

slide-41
SLIDE 41

Putting it together

  • The slab map and occupancy map together provide a

very good estimate of the visibility. So, given the light MVP coords (x,y), the slice s and the slab m:

  • Find out how many fragments are in slabs preceeding

m, call this a

  • Find the average number of fragments per bit in slab

m: avg = (number of fragments in slab / total number

  • f set bits in slab)
  • Find approximate number of fragments occluding this

as: a + avg * (number of bits set in slabs < s)

slide-42
SLIDE 42

Putting it together

slide-43
SLIDE 43

Resulting visibility function

slide-44
SLIDE 44

Alpha “sorting”

  • The blending function typically used for

rendering transparent objects is:

slide-45
SLIDE 45

Alpha “sorting”

  • For three fragments blended in back to front
  • rder, this would expand to:
slide-46
SLIDE 46

Alpha “sorting”

  • Which can be rewritten as:

=>

slide-47
SLIDE 47

Alpha “sorting”

All alphas are approximately the same =>

slide-48
SLIDE 48

Alpha “sorting”

All alphas are approximately the same => =>

slide-49
SLIDE 49

Alpha “sorting”

  • We donʼt know the depth order of the

fragment...

  • But we can approximate how many fragments

precede it! Which is really the same thing. So:

  • Calculate the shaded and shadowed color c
  • f the fragment.
  • Approximate the depth order i using
  • ccupancy and slab maps
  • Write to the framebuffer:
slide-50
SLIDE 50

Results

slide-51
SLIDE 51

Video