Just add Water

Download Report

Transcript Just add Water

Just add
Water
Early Attempt
•
•
•
•
Per-Vertex sinusoidal warping of position
Per-Vertex sinusoidal warping of normal
All Lighting Per-Vertex
VS/PS 1
Next Attempt
•
•
•
•
Still VS/PS1
Per-Vertex creation of “Tangent-Space” Basis
Scrolling Normal-Map coordinates (scrolled in VS)
Normal-Map sampled in PS, then put in world-space and
reflected to sample Environment Map
– This is possible with the magic PS instructions
texm3x3pad
t1, t0_bx2
texm3x3pad
t2, t0_bx2
texm3x3vspec
t3, t0_bx2
– This performs a 3x3 matrix multiply, reflection, and cube-map
lookup; AMAZING!
– This is impossible to do without dropping into the assembly-style
shader programming
Next Attempt (cont.)
• Additionally, some per-vertex light color
computation (Gouraud-style)
• Also added “reflection-map”, perturbed in VS and
sampled in PS using a second pass
– This required rendering the reflected scene to a
dynamic texture, and implementing per-pixel clipping
using the instruction “tex-kill” (simulated user-clip
planes)
– This texture is the “reflection-map”, which is then
projectively-textured onto the water geometry
rd
3
Time’s the Charm
• VS/PS 2 (ahh… more than 8 instructions in the pixel
shader! Yay!)
• No more sin/cos stuff
• 4 scrolling bump maps, scrolled in different directions and
speeds
• Reflection Map (render to texture, 1st pass)
• Refraction Map (render to texture, 2nd pass)
• “Real” User Clip Planes
– When using Fixed-Function Pipeline, user clip planes are expected
to be in World Space
– When using Programmable Pipeline, user clip planes are expected
to be in Clip Space… go figure! Good ol’ DirectX
rd
3
Time’s the Charm (cont.)
• Render everything for real, and then draw water
using reflection and refraction maps (3rd pass)
• All perturbation occurs in pixel-shader
– All 4 scrolling normal maps are sampled, the normals
summed and normalized into single normal
– Projective reflection and refraction map coordinates are
perturbed by this normal
• each is perturbed with a different scaling factor
• Reflection and refraction maps are sampled and combined with
their respective “water color”
rd
3
Time’s the Charm (cont.)
• Fresnel term is calculated using the angle between
the normal and the view vector
– Creates for much more realistic “transparency” and
lighting effects
– Fresnel term defines the blending factor between
reflection and refraction map
• Looking straight down at water, water should look clear
• Looking across/from the side, water should be highly reflective
Where the Water Meets the Sky
• Sky Dome
– Needs sphere geometry
– Possible with VS/PS1 in a single pass for sky color, sun, and moon
– Uses projective texturing for sun and moon
• Additional Normal mapping for moon
• ADDSMOOTH color blending for sun
– Prevents overflow for highly saturated colors when using additive
blending
– Instead of usual blending of ONE*SRC + ONE*DEST
» Uses ONE*SRC + DEST*INVSRC
– Base sky color uses simple 1D gradient function
• Atmospheric color scattering performed in Vertex Shader