assignments volumetric shaders
TRANSCRIPT
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 Thursday, May 24th 12:30 - 2:30pm ICL6
15 minutes per presentation
Announcement As promised:
THE ILLUSION OF LIFE, REVISITED Or
Dancing with the Network Sheep Ken Perlin
Thursday, May 10th @ 12 noon Golisano Building Auditorium
Plan for today This week is Volume Week!
Today: lecture Thursday: volumetric rendering lab.
2
Volume Rendering From Wikipedia:
Volume rendering is a technique used todisplay a 2D projection of a 3D discretelysampled data set.
Volume Rendering
3D data Data sampled in a 3D space Voxel -- 3D equivalent of a pixel
Subdivision of space holding a single datapoint
“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 onthreshold.
Create polygons for each voxel basedon status of voxel vertices.
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 marchSet starting pointwhile (current point is behind final point)
call density functioncalculate light hitting pointupdate current color total and opacity totalCalculate and move to next sample point along
rayendSet surface color / opacity.
4
Ray marching algorithm Said another way:
Choose step sizelen = length (I);Pcur = P - I;while (len > 0) do
sample density and light at PcurCvol += (1-Ovol) * stepsize*scatteredLightOvol += (1-Ovol) * stepsize*densityPcur += stepsize * normalize(I)len -= stepsize;
end
NOTE THERE IS AN ERROR IN THE TEXT…the above iscorrect.
Volumetric rendering isexpensive 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 usingsome 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
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 particlelight 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 indirection α.
)cos1(4
3)( 2!! +=P
Light – Mie Scattering Mie Scattering (haze / fog)
8
2
cos191)( !
"
#$%
& ++=
''P Sparse / hazy
32
2
cos1501)( !
"
#$%
& ++=
''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
6
Uniform fogCleave= Center - Creduce + Cincrease
WhereCleave = light leaving along a rayCenter = 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 lightentering the fog plus 1 minus that fraction timesthe fog color
Uniform fog Apply ray marching algorithm…Let’s
assume 3 steps:
More generally for z steps:
!
Cleave = g3Center + (1" g
3)Cfog
!
Cleave = gzCenter + (1" g
z)Cfog
!
Ceye = gzCobject + (1" g
z)Cfog
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 )Cfog
f = exp2("dz)
d = "log2(1" h)
break
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 combineshapes
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 themidrange of an objects soft region goesfrom 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 bias1"g (2t)
2 else
2 " bias1"g (2 " 2t)
2
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 frequencyfloat 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 issummed
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
9
Hypertexture Example - Fire
)))(1()( xturbulencesphere(xxD +=[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/usesof hypertextures.
Questions?
Volume Rendering inRenderMan volume shader
Defines how light, passing through a volume isaffected.
Global variables: P - origin of ray I - incident vector (direction of ray) E - eye point Ci / Oi -- surface color / opacity (output variables)
Volume Rendering inRenderMan From the spec:
A volume shader is not associated with a surface,but rather attenuates a ray color as it travelsthrough space. As such, it does not have accessto any geometric surface parameters, but only tothe light ray I and its associated values. Theshader computes the new ray color at the rayorigin P-I. The length of I is the distance traveledthrough the volume from the origin of the ray to thepoint P.
10
Volume Rendering inRenderMan Three places where volume shaders can be
bound: Interior -- for volume within a primitive
Interior shaders are often implemented as surfaceshaders.
Exterior -- for volume between light and primitive(can sample lights using illuminance)
Atmospheric -- for volume between primitive andcamera.
Implementation in Cg Once again…
In Cg, there are only vertices andfragments.
Volume effects are achieved by explicitmodification of lighting paths in eitherfragment or vertex program.
Real time ray marching is a very recentadvancement.
Questions? In the lab…
Basic fog Ray marching Hypertextures or Mie Scattering