D3DTutorial Crytek
D3DTutorial Crytek
Carsten Wenzel
The deal
v v v
v (t ) = o + t d
∫ f ((o ) v
+ td x , o y + td y , o z + td z )
1
v
∫ f (v (t ))dt =
T
x d dt
0
− co z ⎡ 1 − e − cd z ⎤
= be dx + dy + dz
2 2 2
⎢ ⎥
⎣ cd z ⎦
v
F (v (t )) = e
v
− ∫ f (v (t ))dt (2)
! Fog color
! Average in-scattering samples along the
horizon while building texture
! Combine with per-pixel result of phase
function to yield approximate fog color
! Use fog color and density to blend
against back buffer
Combining Sky Light and Fog:
Results
*
Fog Volumes
! Fog volumes via ray-tracing in the shader
! Currently two primitives supported: Box,
Ellipsoid
! Generalized form of Global Volumetric Fog
! Exhibits same properties (additionally, direction of
height no longer restricted to world space up vector,
gradient can be shifted along height dir)
! Ray-trace in object space: Unit box, unit sphere
! Transform results back to solve fog integral
! Render bounding hull geometry
! Front faces if outside, otherwise back faces
! For each pixel…
! Determine start and end point of view ray to plug into
Eq.2
Fog Volumes
! Start point
! Either camera pos (if viewer is inside) or ray’s
entry point into fog volume (if viewer is outside)
! End point
! Either ray’s exit point out of the fog volume or
world space position of pixel depending which
one of the two is closer to the camera
! Render fog volumes back to front
! Solve fog integral and blend with back
buffer
Fog Volumes
! Simple idea
! Instead of rendering a particle as a regular billboard,
treat it as a camera aligned volume
! Use per-pixel depth to compute view ray’s travel
distance through volume and use the result to fade out
the particle
! Hides jaggies at intersections with other geometry
! Some recent publications use a similar idea and treat
particles as spherical volumes
! We found a volume box to be sufficient (saves shader
instructions; important as particles are fill-rate hungry)
! GS can setup interpolators so point sprites are finally
feasible
Soft Particles: Results
v v v
v (t ) = o + td
( ) v
f (v (t ))dt = ∫ f (ox + td x , o y + td y , oz + td z ) d dt
1
v
∫
T
⎡ ⎛ v + 2w ⎞ ⎛ v ⎞⎤
⎢ arctan⎜⎜ ⎟ − arctan ⎜ ⎟⎥
⎟ ⎜ ⎟
2⎢ ⎝ 4uw − v 2 ⎠ ⎝ 4uw − v 2 ⎠⎥
= 2i d x + d y + d z
2 2
⎢ 4uw − v 2 ⎥
⎢ ⎥
⎢⎣ ⎥⎦
v (3)
= F (v (t ))
*
River shading
River shading –
Screens taken from a hidden section of the E3 2006 demo *
Ocean shading
v v v
v (t ) = o + td
v v v
p−o
d= v v
p−o
v v
l = p−o
v
attenuation = f ( p, l ) = e − c ( s − p z +l )
v
l
v
inscatter = ∫ f (v (t ), t )dt = ∫ e − c ( s − (o z + td z )+ t )
d dt
0
l
−c ( s −oz ) − ct (1− d z )
=e ∫e
0
dt
⎡ e (d z −1)ct ⎤
l
−c ( s −oz )
=e ⎢ ⎥
⎣ (d z − 1 ) c ⎦0
−c ( s −oz ) ⎡ e (d z −1)cl − 1⎤
=e ⎢ ⎥
⎣ (d z − 1)c ⎦
finalCol = attenuation ⋅ sceneCol + inscatter ⋅ envlightCol (4)
Ocean shading: Results
Fog full screen pass with MSAA disabled (left) / enabled (right)
???