Assignments Please fill the dropboxes Volumetric Shaders Still - - PDF document

assignments
SMART_READER_LITE
LIVE PREVIEW

Assignments Please fill the dropboxes Volumetric Shaders Still - - PDF document

Assignments Please fill the dropboxes Volumetric Shaders Still catching up on grading. Questions. Final exam effects Final exam effect Deliverables: Presentation: Research (Grads only) Final exam period Shader


slide-1
SLIDE 1

1

Volumetric Shaders Assignments

 Please fill the dropboxes…  Still catching up on grading.  Questions.

Final exam effects

 Deliverables:

 Research (Grads only)  Shader code  Documentation

 Describe shader params  Explain chosen implementation.  List constraints.  Give results.

Final exam effect

 Presentation:

 Final exam period

 Monday, May 19th  12:30 - 2:30pm  ICL5

 15 minutes per presentation

Ever changing plans for the week

 This week is “wrap it up week”!

 Today: lecture(s)

 Volumetric Rendering  Post-processing

 Thursday: Labs (do one of 2)

 Volumetric Rendering  Postprocessing

 Next week (Week 10)

 Lab catch up / group work time.

Volume Rendering

 From Wikipedia:

 Volume rendering is a technique used to

display a 2D projection of a 3D discretely sampled data set.

slide-2
SLIDE 2

2

Volume Rendering Volume Rendering 3D data

 Data sampled in a 3D space  Voxel -- 3D equivalent of a pixel

 Subdivision of space holding a single data

point

 “density function”

Examples

 Types of data:

 CT / MRI scans  Clouds  Atmospheric effects  Fire, smoke

Rendering Volume Data

 Isosurface Approach

 Convert densities to geometry  Render corresponding geometry  Marching cubes algorithm

 Direct Volume Rendering

 Sample density in a volume along a ray  Splatting (Projection)  Ray marching

Marching Cubes

 Volexize your space  Choose threshold  For each voxel vertex, determine if point

is inside or outside isosurface based on threshold.

 Create polygons for each voxel based

  • n status of voxel vertices.
slide-3
SLIDE 3

3

Marching Cubes Marching cubes

SIGGRAPH - HyperGraph

Direct Volume Rendering

 Splatting SIGGRAPH - HyperGraph

Direct Volume Rendering

 Ray Marching SIGGRAPH - HyperGraph

Ray marching algorithm Ray Marching algorithm

 Psedocode:

Calculate segment of ray on which to march Set starting point while (current point is behind final point) call density function calculate light hitting point update current color total and opacity total Calculate and move to next sample point along ray end Set surface color / opacity.

slide-4
SLIDE 4

4

Ray marching algorithm

 Said another way:

Choose step size len = length (I); Pcur = P - I; while (len > 0) do sample density and light at Pcur Cvol += (1-Ovol) * stepsize*scatteredLight Ovol += (1-Ovol) * stepsize*density Pcur += stepsize * normalize(I) len -= stepsize; end

Volumetric rendering is expensive

 Sampling points in a volume along a ray  Basic trade-off

 Too few samples -- aliasing  Too many samples -- takes too long.

 Choose your step size well

Challenges in procedural volumetric shading

 Determining the “density function”  Determining the “light scattering”  Efficient implementation of ray marching

algorithm

Determining density functions

 Empirical -- data is provided to you

 CR / MRI

 Procedural

 You calculate the density…usually using

some form of noise

 Voxelized

 General 3D data placed in voxel boxes.

Light scattering

 Scattered into the line of sight (in-

scattering)

 Scattered out of the line of sight (out-

scattering)

 Absorbed altogether (absorption)

Determining lighting

 Must consider light illuminating the point  Must determine how much of that light

is scattered toward the viewer

 Uniform scattering  Mie scattering  Raleigh scattering

slide-5
SLIDE 5

5

Light - Scattering

Light is scattered by small particles in its path (e.g. haze, smoke, etc.)

Given by fraction of light with respect to direction from particle light impact.

Size of particles are on the order of wavelengths of light.

  • r

Light -- Scattering

 r << λ total absorption (no scattering)  r < λ Rayleigh Scattering  r ≈ λ Mie scattering  r >> λ Geometric optics

  • r

Light – Raleigh Scattering

 Raleigh scattering (smoke / dust ), the

probability that the light will scatter in direction α.

) cos 1 ( 4 3 ) (

2

  • +

= P

Light – Mie Scattering

 Mie Scattering (haze / fog)

8

2 cos 1 9 1 ) (

  • +

+ =

  • P

Sparse / hazy

32

2 cos 1 50 1 ) (

  • +

+ =

  • P

Dense / murky Questions so far?

Uniform fog Uniform fog

 Ray marching with assumptions:

 Density is uniform and constant.  Light scattering is uniform and constant.

 Can solve analytically

slide-6
SLIDE 6

6

Uniform fog

Cleave= Center - Creduce + Cincrease

Where

Cleave = light leaving along a ray Center = light entering along a ray Creduce = light absorbed due to density

Cincrease = light scattered

Uniform fog

 Other assumptions:

 0 ≤ Creduce ≤ Center

 Can’t reduce more light than comes in

 Creduce = h Center

 h is uniform density.

 Cincrese = h Cfog

 Cfog is the constant color of light scattered

toward eye due to fog.

Uniform fog

 So…

 Cleave = (1-h)Center + hCfog

 Rearranging things

 g = 1-h  Cleave = gCenter + (1-g)Cfog

 Light exiting fog is a fraction of the light

entering the fog plus 1 minus that fraction times the fog color

Uniform fog

 Apply ray marching algorithm…Let’s

assume 3 steps:

 More generally for z steps:

Cleave = g3Center + (1 g3)C fog Cleave = gzCenter + (1 gz)C fog Ceye = gzCobject + (1 gz)C fog

Uniform fog

 Recall exponentials:

 Exp and log base 2 are quick

 Final equation

 Where:

 z is fog distance  h is fog density

gz = exp2(log2(g)z)

Ceye = fCobject + (1 f )C fog f = exp2(dz) d = log2(1 h)

Hypertexture [Perlin89]

 Extension of procedural textures  Between surface + texture, i.e., spatial

filling/volumetric

 Objects modeled as distribution of density

 hard region - objects completely solid  soft region - object shape is malleable using a toolkit of

shaping functions and CSG style operators to combine shapes

slide-7
SLIDE 7

7

Hypertexture

 D(x) - Object Density Function over R3

 D (x) for all points x in 3D space [0,1]  Density of 3D shape  D (x) = 0 for all points outside the surface  D (x) = 1 for hard region of the object  0 < D (x) < 1 for soft region of the object

(fuzzy region)

Hypertexture

 Toolbox of base DMFs

 Bias – up / down control  Gain – controls gradiant  Noise (controlled randomness)

 Won Ken an Academy Award!

 Turbulence

 Sum of noise at variety of frequencies

 Mathematical functions

Bias

 Used to bend the density upwards or

downwards over [0,1]

 Properties:

 biasb (0.00) = 0  biasb (0.5) = b  biasb (1.00) = 1

 Definition:

biasb(t) = t

ln(b) ln(0.5)

Bias

Bias0.25 Bias0.5 Bias0.75

Gain

 used to help shape how fast the

midrange of an objects soft region goes from 0 to 1.

 Properties:

 gaing (0.0) = 0.0;  gaing (0.25) = 0.5 - g/2;  gaing (0.5) = 0.5;  gaing (0.75) = 0.5 + g/2;  gaing (1.0) = 1.0;

Gain

 Definition

gaing(t) = if (t > 0.5) then bias

1g(2t)

2 else 2 bias

1g(2 2t)

2

slide-8
SLIDE 8

8

Gain

gain0.25 gain0.5 gain0.75

Noise

 Noise resembles a sin wave but with

“random” bumps:

 For hypertexture we use 3D noise

fBm / Turbulence

 fBm -- fractional Brownian motion.  1/f noise

 Sum of noise functions  Contribution of each is proportional to the

inverse of the frequency

float value = 0; for (f = MINFREQ; f < MAXFREQ; f *=2) value += snoise (P * f) / f; return value;.

fBm / Turbulence

 Turbulence

 Like fBm but absolute value of noise is

summed

 Both are useful for “natural” effects float value = 0; for (f = MINFREQ; f < MAXFREQ; f *=2) value += abs (snoise (P * f)) / f; return value;.

fBm / Turbulence

fBm turbulence

Hypertexture Noise Examples

2* frequency, 1/2 amplitude

[Perlin89]

High Amplitude, Noisy Sphere Noisy Fractal, noise - Σ many f’s

slide-9
SLIDE 9

9

Hypertexture Example - Fire

))) ( 1 ( ) ( x turbulence sphere(x x D + =

[Perlin89] Red = low density Yellow = high

Hypertexture Example - Fur/Hair

[Perlin89]

Tribble

Here noise displaces x before projecting; uses variable to control curliness

Rendering hypertextures

 Use a basic ray marching algorithm  A priori knowlegde of shape being

shaded

 E.g. for sphere

 Define inner_raidus (where D = 1)  Define outer_radius (outside of which D = 0)  Ray march from inner to outer.

Hypertexture clouds

 Set inner radius = 0.0

 Entire interior region is “fuzzy”

 See Perlin paper for more details/uses

  • f hypertextures.

 Questions?

Volume Rendering in RenderMan

 volume shader

 Defines how light, passing through a volume is

affected.

 Global variables:

 P - origin of ray  I - incident vector (direction of ray)  E - eye point  Ci / Oi -- surface color / opacity (output variables)

Volume Rendering in RenderMan

 From the spec:

 A volume shader is not associated with a surface,

but rather attenuates a ray color as it travels through space. As such, it does not have access to any geometric surface parameters, but only to the light ray I and its associated values. The shader computes the new ray color at the ray

  • rigin P-I. The length of I is the distance traveled

through the volume from the origin of the ray to the point P.

slide-10
SLIDE 10

10

Volume Rendering in RenderMan

 Three places where volume shaders can be

bound:

 Interior -- for volume within a primitive

 Interior shaders are often implemented as surface

shaders.

 Exterior -- for volume between light and primitive

(can sample lights using illuminance)

 Atmospheric -- for volume between primitive and

camera.

Implementation in GLSL

 Once again…

 In GLSL, there are only vertices and

fragments.

 Volume effects are achieved by explicit

modification of lighting paths in either fragment or vertex program.

 Real time ray marching is a very recent

advancement.

Volumetric Effects as surface shaders Questions?

 In the lab…

 Basic fog  Ray marching  Hypertextures or Mie Scattering

break