Volume and Participating Media
Digital Image Synthesis g g y Yung-Yu Chuang
with slides by Pat Hanrahan and Torsten Moller
Participating media
• We have by far assumed that the scene is in a vacuum Hence radiance is constant along the vacuum. Hence, radiance is constant along the ray. However, some real-world situations such as fog and smoke attenuate and scatter light as fog and smoke attenuate and scatter light.
They participate in rendering.
N t l h
• Natural phenomena
– Fog, smoke, fire – Atmosphere haze
– Beam of light through clouds
– Subsurface scattering
Volume scattering processes
• Absorption (conversion from light to other forms)
E i i
• Emission (contribution from luminous particles)
• Scattering (direction change of particles) – Out-scattering
– In-scattering
– Single scattering v.s. multiple scattering
• Homogeneous v.s. inhomogeneous(heterogeneous) Homogeneous v.s. inhomogeneous(heterogeneous)
emission in-scattering out-scattering absorption
Single scattering and multiple scattering
attenuation attenuation
single scattering multiple scattering
Absorption
The reduction of energy due to conversion of light to another form of energy (e g heat)
to another form of energy (e.g. heat)
L dL ( )
L x ( , ) L dL
L x
ds
) , (
ax
ds
ds x
L x
x
dL ( x ) ( x ) L ( x ) ds dL ( , )
a( , ) ( , )
Absorption cross-section:
a( x , )
Probability of being absorbed per unit length
Transmittance
ds x
L x
x
dL ( , )
a( , ) ( , )
dL ( )
xsdL ( ' )
s
sds x x
L x dL
a
( , ) )
, (
) ,
(
s
a s
x
x
ds s
x x L
x dL
0
' ) , ' ) (
, ' (
) , '
(
s L x
ax s ds s
x L
0
) ( '
) , ' (
) , ( ln )
, (
ln
x Optical distance or depth
x
p p 0
' s
x s '
s
a
x s ds
s
0
' ) , ' (
)
(
Homogenous media: constant ( ) s s
a
s
0
a
( ) s
as
Transmittance and opacity
ds x
L x
x
dL ( , )
a( , ) ( , )
dL ( )
xsdL ( ' )
s
sds x x
L x dL
a
( , ) )
, (
) ,
(
s
a s
x
x
ds s
x x L
x dL
0
' ) , ' ) (
, ' (
) , '
(
) (
L
s L x
ax s ds s
x L
0
) ( '
) , ' (
) , ( ln )
, (
ln
) (
) ( )
( )
(
( )L T L
L ( x s , ) e
(s)L ( x , ) T
( s ) L ( x , ) L ( x , )
L
s
Transmittance T (s )
)
)
(( s e
sT
Opacity
) , ( x s L
)
( s e T
) ( 1
)
( T L ( x s , )
) ( 1
)
( s T
s
Absorption
Emission
• Energy that is added to the environment from luminous particles due to chemical thermal or luminous particles due to chemical, thermal, or nuclear processes that convert energy to visible light
light.
• : emitted radiance added to a ray per it di t t i t i di ti
) , ( x L
veunit distance at a point x in direction
ds x
L x
dL ( x ) L ( x ) ds dL ( , )
ve( , )
L dL ( , )
L x ( , ) L dL
L x
ds
) , ( x L
ve
ds
Emission
Out-scattering
Light heading in one direction is scattered to other directions due to collisions with particles
directions due to collisions with particles
L dL ( , )
L x
) , (
sx ds
d L
dL ( ) ( ) ( ) Scattering cross-section:
ds x
L x
x
dL ( , )
s( , ) ( , ) Scattering cross-section:
Probability of being scattered per unit length
sy g p g
Extinction
L dL ( , )
L x ( , ) x L dL ds
) , (
tx ds
ds x
L x
x
dL ( , )
t( , ) ( , )
t a s
Total cross-section
Alb d
s st a s
W
Albedo
Attenuation due to both absorption and scattering
s
t
x s ds
s ) ( ' , ) '
(
s
tx s ds
0
) , (
)
(
Extinction
• Beam transmittance x '
s
x ) , ( x
L
s
t x s ds
e x
x
Tr
0' ) , ' (
) ' (
s: distance between x and x’ x
• Properties of Tr:
• In vaccum Tr ( x x ' ) 1
• In vaccum
• Multiplicative
B ’ l (i h di )
1 )
( x x Tr
) '' '
( )
' (
) ''
( x x Tr x x Tr x x
Tr
• Beer’s law (in homogeneous medium)
ts
e x
x
Tr ( x )' x e
Tr ( )
In-scattering
Increased radiance due to scattering from other directions
directions
L dL ( )
L x
'
L dL ( , )
L x
ds ) , (
sx
ds
ds d
x L x
p x
x
dL
s
( , ) ( , ' ) ( , ' ) '
) ,
(
Phase function p ( )
s
p
) ,
( ) ,
( )
, ( )
, (
( ) ( )
p p Reciprocity
( ) 1
p d
Energy conserving Phase function p ( )
( ) ( )
p p
2
( ) 1
S
p d
Source term
' )
' , ( ) '
, ( )
, ( )
, ( )
,
( x L x x p x L x d
S
ve s
ds x
S x
dL ( , ) ( , )
• S is determined by
Volume emission – Volume emission
– Phase function which describes the angular
distribution of scattered radiation (volume analog of
distribution of scattered radiation (volume analog of
BSDF for surfaces)
Phase functions
Phase angle cos Phase functions
(from the phase of the moon)
( p )
1. Isotropic (cos ) 1 p 4
- simple
2. Rayleigh
2 43 1 cos (cos )
p 4
- Molecules (useful for very small particles whose radii smaller than wavelength of light)
3 Mi tt i 3. Mie scattering
- small spheres (based on Maxwell’s equations; good
model for scattering in the atmosphere due to water
model for scattering in the atmosphere due to water
droplets and fog)
Henyey-Greenstein phase function
Empirical phase function
1 1
2p p
g = -0.3
2
2 32
1 1
(cos )
4 1 2 cos
p g
g g
g = 0.6
0
2 p (cos ) cos d g
0
g : average phase angle
Henyey-Greenstein approximation
• Any phase function can be written in terms of a series of Legendre polynomials (typically n<4) series of Legendre polynomials (typically, n<4)
1 ( 2 1 ) (cos ) )
(cos n b P
p
0
) (cos )
1 2
4 ( )
(cos
n
n n
P b n
p
1 )
(
P
) ( )
( P
b
) (
1 )
(
1 0
x x
P x P
cos )
(cos )
(cos
) (cos ),
(cos
1
d P
p
P p
b
n n
) 1 3
2 ( ) 1
(
22
x x
P
) (cos ) cos (cos
1
d P
p
n
) 3 5
2 ( ) 1
(
33
x x x
P
...
Schlick approximation
• Approximation to Henyey-Greenstein
2 2
) cos 1
(
1 4
) 1
(cos
k
p
Schlick k
• K plays a similar role like g
) cos 1
(
4 k
• K plays a similar role like g
– 0: isotropic
-1: back scattering – -1: back scattering
– Could use k 1 . 55 g 0 . 55 g
2Importance sampling for HG
1 1
2(cos ) g
p
2
32(cos )
4 1 2 cos
p
g g
2
2 if 0
1
2
g
otherwise 2
1 1 1
| 2
|
cos 1
2 2 2
g g
g g
g
1 2
| 2
| g g g
Pbrt implementation
• core/volume.* volume/*
class VolumeRegion { t0 t1
public:
bool IntersectP(Ray &ray, float *t0, float *t1);
Spectrum sigma a(Point &, Vector &);p g _ ( , ) Spectrum sigma_s(Point &, Vector &);
Spectrum Lve(Point &, Vector &);
// phase functions: pbrt has isotropic, Rayleigh, // phase functions: pbrt has isotropic, Rayleigh, // Mie, HG, Schlick
virtual float p(Point &, Vector &, Vector &);
// attenuation coefficient; s a+s s // attenuation coefficient; s_a+s_s
Spectrum sigma_t(Point &, Vector &);
// calculate optical thickness by Monte Carlo or
// l d f l ti
// closed-form solution
Spectrum Tau(Ray &ray, float step=1., float offset=0.5);
t0 step t1
}; t0 step t1
offset
Homogenous volume
• Determined by (constant)
d
– and
– g in phase function
E i i L
s
a– Emission
– Spatial extent L
veSpectrum Tau(Ray &ray, float, float){
float t0 t1;
float t0, t1;
if (!IntersectP(ray,&t0,&t1)) return 0.;
return Distance(ray(t0),ray(t1)) * (sig_a + sig_s);
}
Homogenous volume
Varying-density volumes
• Density is varying in the medium and the volume scattering properties at a point is the product of scattering properties at a point is the product of the density at that point and some baseline
value value.
• DensityRegion
– 3D grid, VolumeGrid
– Exponential density, ExponentialDensity
DensityRegion
class DensityRegion : public VolumeRegion { public:
DensityRegion(Spectrum &sig_a, Spectrum &sig_s,
float g, Spectrum &Le, Transform &VolumeToWorld);
float Density(Point &Pobj) const = 0;
sigma_a(Point &p, Vector &) {
return Density(WorldToVolume(p)) * sig_a; } Spectrum sigma s(Point &p, Vector &) {p g _ ( p, ) {
return Density(WorldToVolume(p)) * sig_s; } Spectrum sigma_t(Point &p, Vector &) {
return Density(WorldToVolume(p))*(sig a+sig s);}
return Density(WorldToVolume(p)) (sig_a+sig_s);}
Spectrum Lve(Point &p, Vector &) {
return Density(WorldToVolume(p)) * le; } ...
protected:
Transform WorldToVolume;
S i i l
Spectrum sig_a, sig_s, le;
float g;
};
VolumeGrid
• Standard form of given data
T i li i l i f d i
• Tri-linear interpolation of data to give continuous volume
• Often used in volume rendering
VolumeGrid
VolumeGrid(Spectrum &sa, Spectrum &ss, float gg,
Spectrum &emit, BBox &e, Transform &v2w,p , , , int nx, int ny, int nz, const float *d);
float VolumeGrid::Density(const Point &Pobj) const { if (!extent.Inside(Pobj)) return 0;
// Compute voxel coordinates and offsets // Compute voxel coordinates and offsets float voxx = (Pobj.x - extent.pMin.x) /
(extent.pMax.x - extent.pMin.x) * nx - .5f;
( p p )
float voxy = (Pobj.y - extent.pMin.y) /
(extent.pMax.y - extent.pMin.y) * ny - .5f;
float voxz = (Pobj.z - extent.pMin.z) /
(extent.pMax.z - extent.pMin.z) * nz - .5f;
VolumeGrid
int vx = Floor2Int(voxx);
int vy = Floor2Int(voxy);
int vz = Floor2Int(voxz);
float dx = voxx - vx, dy = voxy - vy, dz = voxz - vz;
// Trilinearly interpolate density values // Trilinearly interpolate density values
float d00 = Lerp(dx, D(vx, vy, vz), D(vx+1, vy, vz));
float d10 = Lerp(dx, D(vx, vy+1, vz), D(vx+1, vy+1, vz));
float d01 = Lerp(dx, D(vx, vy, vz+1), D(vx+1, vy, vz+1));
float d11 = Lerp(dx, D(vx, vy+1,vz+1),D(vx+1,vy+1,vz+1));
float d0 = Lerp(dy, d00, d10);p( y, , );
float d1 = Lerp(dy, d01, d11);
return Lerp(dz, d0, d1);
}
float D(int x, int y, int z) {
} x = Clamp(x, 0, nx-1);
y = Clamp(y, 0, ny-1);
z = Clamp(z, 0, nz-1);
d i [ * * * ]
return density[z*nx*ny+y*nx+x];
}
Exponential density
• Given by
h
bhd ( )
• Where h is the height
ae
bhh
d ( )
ExponentialDensity in the direction of
the up-vector
ExponentialDensity
class ExponentialDensity : public DensityRegion { public:
ExponentialDensity(Spectrum &sa, Spectrum &ss,
float g, Spectrum &emit, BBox &e, Transform &v2w, float aa, float bb, Vector &up)
...
float Density(const Point &Pobj) const {y( j) { if (!extent.Inside(Pobj)) return 0;
float height = Dot(Pobj - extent.pMin, upDir);
return a * expf(-b * height);
return a expf( b height);
}
private:
BBox extent; P bj
h BBox extent;
float a, b;
Vector upDir;
}
upDir Pobj
};
extent.pMin
Light transport
• Emission + in-scattering (source term)
' )
' , ( ) '
, ( )
, ( )
, ( )
,
( x L x x p x L x d
S
ve s
• Absorption + out-scattering (extinction)
ds x
S x
dL ( , ) ( , )
• Absorption + out scattering (extinction)
ds x
L x
x
dL ( , )
t( , ) ( , )
• Combined
) , ( )
, ( ) , ) (
,
(
x S x
L ds x
x dL
t
Infinite length, no surface
• Assume that there is no surface and we have an infinite length we have the solution
infinite length, we have the solution
ds x
S x x
Tr x
L ( ( , , ) )
( ( ' ) ) ( ( ' , , ) )
0
s t x s ds
T
0' ) , ' (
) '
(
) '
( S
x e
x
Tr ( ' )
0x '
x L ( x , )
) ,
' ( x S
) '
( x x
Tr L ( x , )
' x s
x '
With surface
• The solution
ds x
S x x
Tr x
L x x
Tr x
L
d
) ,
' ( ) '
( )
, ( ) (
) , (
0 0
0
from the surface point x
0) , ( x
0 L
x
) , ( x L
0
x
d
) ( x
0x
Tr
)
,
( x
L
With surface
• The solution
ds x
S x x
Tr x
L x x
Tr x
L
d
) ,
' ( ) '
( )
, ( ) (
) , (
0 0
0
from the surface point x
0from the participating media
) , ( x
0 L
x
) , ( x L
0
x
d
) ( x
0x
Tr
'
x L ( x , )
' x s
x '
Simple atmosphere model
Assumptions
H di
• Homogenous media
• Constant source term (airlight)
( ) ( )
L s L S
( )
t
( )
s L s S
s
( ) 1
s sL ( ) 1
ts S
tsC S C
L s e
S e
C S C
• Fog
• Haze
• Haze
OpenGL fog model
fog
in
f C
fC
C ( 1 )
) (d
GL_EXP
)
)
(( z e
density zf
GL EXP2
)2
)
(( z e
density zf
_
z
f end
) (
GL_LINEAR
start z end
f ( )
From http://wiki.delphigl.com/index.php/glFog
VolumeIntegrator
class VolumeIntegrator : public Integrator { public: Beam transmittance for a given public:
virtual Spectrum Transmittance(
const Scene *scene
g ray from mint to maxt
const Scene *scene, const Ray &ray,
const Sample *sample const Sample *sample,
float *alpha) const = 0;
} };
Pick up functions Preprocess(), RequestSamples()
d f
and Li() from Integrator.
Emission only
• Solution for the emission-only simplification
) ,
' ( )
, '
( x L x
S
evd
ds x
L x x
Tr x
L x x
Tr x
L
evd
) ,
' ( )
' ( )
, ( ) (
) , (
0 0
0
• Monte Carlo estimator
N
i
i ev i
N
i
i ev
i
Tr x x L x
N t t
x p
x L
x x
Tr
N
10 1
1
) , ( )
) ( (
) , ( )
(
1
i
i
p x
iN
N
1( )
1Emission only
• Use multiplicativity of Tr
) (
) (
)
( x x Tr x x
1Tr x
1x Tr
i
i
i
i
• Break up integral and compute it incrementally by ray marching y y g
• Tr can get small in a long ray
– Early ray termination – Early ray termination
– Either use Russian Roulette or deterministically
EmissionIntegrator
class EmissionIntegrator : public VolumeIntegrator { public:
EmissionIntegrator(float ss) { stepSize = ss; } void RequestSamples(Sample *sample, const Scene
*scene);scene);
Spectrum Transmittance(const Scene *, const Ray
&ray, const Sample *sample, float *alpha) const;
Spectrum Li(const Scene * const RayDifferential Spectrum Li(const Scene *, const RayDifferential
&ray, const Sample *sample, float *alpha) const;
private:
float stepSize;
int tauSampleOffset, scatterSampleOffset;
};
single 1D sample for each
};
g p
EmissionIntegrator::Transmittance
if (!scene->volumeRegion) return Spectrum(1);
float step = float step
sample ? stepSize : 4.f * stepSize;
float offset =
use larger steps for shadow and indirect rays for efficiencysample ? sample->oneD[tauSampleOffset][0] : RandomFloat();
indirect rays for efficiency
Spectrum tau =
scene->volumeRegion->Tau(ray,step,offset);
return Exp(-tau);
)
)
(( s e
sT
s
a
x s ds
s
0
' ) , ' (
)
(
EmissionIntegrator::Li
VolumeRegion *vr = scene->volumeRegion;
float t0, t1;
if (!vr || !vr->IntersectP(ray, &t0, &t1)) return 0;
// Do emission-only volume integration in vr Spectrum Lv(0 );
Spectrum Lv(0.);
// Prepare for volume integration stepping int N = Ceil2Int((t1-t0) / stepSize);
float step = (t1 - t0) / N;
Spectrum Tr(1.f);
Point p = ray(t0), pPrev;
Point p ray(t0), pPrev;
Vector w = -ray.d;
if (sample)
t0 += sample->oneD[scatterSampleOffset][0]*step;
else
t0 += RandomFloat() * step;() p;
EmissionIntegrator::Li
for (int i = 0; i < N; ++i, t0 += step) { // Advance to sample at t0 and update T pPrev = p;
p = ray(t0);
Spectrum stepTau = vr->Tau(Ray(pPrev,p-pPrev,0,1),
) (
) (
)
( x x Tr x x
1Tr x
1x Tr
i
i
i
i
.5f * stepSize, RandomFloat());
Tr *= Exp(-stepTau);
// Possibly terminate if transmittance is small
// y
if (Tr.y() < 1e-3) {
const float continueProb = .5f;
if (RandomFloat() > continueProb) break;
if (RandomFloat() > continueProb) break;
Tr /= continueProb;
}
// Compute emission only source term at p // Compute emission-only source term at _p_
Lv += Tr * vr->Lve(p, w);
}
*
t
1 t
0
NT ( ) L ( )
return Lv * step;
i
i ev
i
x L x
x N
1Tr
0
1
( ) ( , )
Emission only
exponential density
Single scattering
• Consider incidence radiance due to direct illumination
illumination
ds x
S x x
Tr x
L x x
Tr x
L
d
) , ' ( ) '
( )
, ( ) (
) ,
(
0
0
0
' )
' , ( ) '
, ( )
, ( )
, ( )
,
( x L x x p x L x d
S
ve s
d
) (
L
x )
, ( x
0 L
' x
x
Single scattering
• Consider incidence radiance due to direct illumination
illumination
ds x
S x x
Tr x
L x x
Tr x
L
d
) , ' ( ) '
( )
, ( ) (
) ,
(
0
0
' )
' , ( ) '
, ( )
, ( )
, ( )
,
( x L x x p x L x d
S
ve s
d
0
) (
L
x )
, ( x
0 L
x
Single scattering
• L
dmay be attenuated by participating media A h i f h i l ld
• At each point of the integral, we could use multiple importance sampling to get
' )
' , ( ) '
, ( )
,
(
sx p x L
dx d