Computer Graphcs Jeng-Sheng Yeh 葉正聖 Mng Chuan Unversty (modfed from Bng-Yu Chen s sldes)
llumnaton and Shadng llumnaton Models Shadng Models for Polygons Surface Detal Shadows Transparency Global llumnaton Recursve Ray Tracng Radosty The Renderng Ppelne
Why We Need Shadng? Suppose we buld a model of a sphere usng many polygons and color t wth only one color. We get somethng lke But we want
Shadng Why does the mage of a real sphere look lke Lght-materal nteractons cause each pont to have a dfferent color or shade Need to consder Lght sources Materal propertes Locaton of vewer Surface orentaton
Lght Sources General lght sources are dffcult to work wth because we must ntegrate lght comng from all ponts on the source
Smple Lght Sources Pont source Model wth poston and color Dstant source = nfnte dstance away (parallel) Spotlght Restrct lght from deal pont source Ambent lght Same amount of lght everywhere n scene Can model contrbuton of many sources and reflectng surfaces
Surface Types The smoother a surface, the more reflected lght s concentrated n the drecton a perfect mrror would reflected the lght A very rough surface scatters lght n all drectons smooth surface rough surface
llumnaton Models Ambent Lght: a : ntensty of the ambent lght k a = a k a : ambent-reflecton coeffcent: 0 ~ Dffuse Reflecton: p : pont lght source s ntensty k d : dffuse-reflecton coeffcent: 0 ~ θ : angle: 0 ~ 90 = p k d cosθ
Dffuse Reflecton drecton to the lght source L N surface normal θ = p k d ( N L)
Examples 0.4 0.55 0.7 0.85.0 dffuse-reflecton model wth dfferent k d 0.0 0.5 0.3 0.45 0.6 ambent and dffuse-reflecton model wth dfferent ka and = =.0, k 0. 4 a p d =
Lght-Source Attenuaton = att a k a + f att p d ( N L) f : lght-source attenuaton factor f the lght s a pont source fatt = 2 d d L L k where s the dstance the lght travels from the pont source to the surface fatt = mn(,) 2 c + c d + c d 2 L 3 L
Examples d 2 L d L
Colored Lghts and Surfaces f an object s dffuse color s O = d ( OdR, OdG, OdB) then where for the red component R ar a dr pr however, t should be λ = k = aλka λ O O dλ + + dr ( = where s the wavelength f f att att pλ k k d d O O dλ ( N N ( R, G, B) L) L)
Specular Reflecton L N R V θ θ α drecton of reflecton drecton to the vewpont
Specular Surfaces Most surfaces are nether deal dffusers nor perfectly specular (deal refectors) Smooth surfaces show specular hghlghts due to ncomng lght beng reflected n drectons concentrated close to the drecton of a perfect reflecton specular hghlght
The Phong llumnaton Model A smple model that can be computed rapdly Has three components Dffuse Specular Ambent Uses four vectors To source To vewer Normal Perfect reflector
The Phong llumnaton Model = k O + f k O cosθ + W W ( θ ) = k: specular-reflecton coeffcent:0~ so, the Eq. can be rewrtten as λ λ = aλ aλ k a a s O dλ dλ + att pλ consder the object s specular color λ = aλ O sλ k a O dλ + att : specular color f f att pλ pλ[ d dλ [ kdodλ ( N L) + ks [ kdodλ ( N L) + ksosλ ( θ )cos ( R ( R n α] V ) n V ) n ] ]
The Phong llumnaton Model 0 0 cosα 90 0 0 cos 2 α 90 0 0 cos 8 64 α 90 0 0 cos α 90
k s Examples 0..25 0.5 n = 3.0 n = 5. 0 n =0. 0 n = 27. 0 n = 200. 0
Calculatng the Reflecton Vector L S N S N cosθ θ θ R R = = = = N cosθ + S N cosθ + N cosθ 2N cosθ L 2N( N L) L L
The Halfway Vector L N H R β θ θ α V L + V H = L + V cosα N H
Multple Lght Sources f there are lght sources, then + + = m n V R O k L N O k f O k sλ s dλ d pλ att dλ a aλ λ ] ) ( ) ( [ m
Shadng Models for Polygons Constant Shadng Faceted Shadng Flat Shadng Gouraud Shadng ntensty nterpolaton Shadng Color nterpolaton Shadng Phong Shadng Normal-Vector nterpolaton Shadng
Constant Shadng Assumptons The lght source s at nfnty The vewer s at nfnty The polygon represents the actual surface beng modeled and s not an approxmaton to a curved surface
Gouraud Shadng y y y 2 y 3 y s 2 3 a p b Scan lne a b p b a b b p s b s a x x x x y y y y y y y y = = = ) ( ) ( ) ( 3 3 2 2
Gouraud v.s. Phong Shadng Gouraud Phong Gouraud Phong
Phong Shadng N 0 N a N b c N N P0 Pa Pb Pc P
Texture Mappng = Pattern Mappng v y texture map u surface of object x four corners of pxel on screen
Bump Mappng & Dsplacement Mappng Copyrght 2003, Mcrosoft
Shadows + + = m n V R O k L N O k f S O k sλ s dλ d pλ att dλ a aλ λ ] ) ( ) ( [ = pont not blocked at ths s lght f, pont blocked at ths s lght f 0, S
Scan-Lne Generaton of Shadows Lght A Current scan lne a b c d A B Vewer
Shadow Volumes Lght Object C B A shadow polygons
Shadow Volumes x x A A B C B C z V z V
Transparency 2 x nterpolated transparency λ = ( kt) λ + kt λ2 k t : transparency: 0 ~ fltered transparency = + k O λ O tλ λ t λ2 : transparency color tλ z Lne of sght
Scatterng Lght strkes A Some scattered Some absorbed Some of scattered lght strkes B Some scattered Some absorbed Some of ths scattered lght strkes A and so on
Global Effects shadow translucent surface multple reflecton
Global llumnaton ε ( x, x ) x ( x, x ) ρ( x, x, x ) x ( x, x ) x
The Renderng Equaton ( x, x ) = g( x, x ) ε ( x, x ) + ρ( x, x, x ) ( x, x ) dx S ( x, x ) : ntensty passng from x to x ε ( x, x ) : emtted lght ntensty from x to x ρ( x, x, x ) : ntensty of lght reflected from x to x from the surface at x g x, x ) 0, = / r ( 2 r : the dstance between x and x S : all surfaces [ ], f x s nvsble from x f x s vsble from x
Recursve Ray Tracng T 2 R 2 N 2 R T N 3 R 3 N R L T surface normal reflected ray shadow ray transmtted ray L 2 L L 3 N Vewpont Pont lght source
The Ray Tree Vewpont L R T L 2 rλ : ntensty of reflected ray k t : transmsson coeffcent : 0 ~ tλ : ntensty of transmtted ray L 3 λ R 2 = aλkaodλ + m S f R 3 T 2 [ k n att pλ kdodλ ( N L ) + ks( N H ) ] + ks rλ + t tλ
The Radosty Equaton : radosty of patch : rate at whch lght s emtted from patch : reflectvty of patch : form factor (confguraton factor) : area of patch snce thus + = n j j j j A A F B E B ρ B E ρ j F A + = n j j j F B E B ρ j j j F A F A =
The Radosty Equaton rearrangng terms therefore progressve refnement n j j j E F B B = ρ = n n n n n n n n n n n E E E B B B F F F F F F F F F 2 2 2 2 2 2 2 2 2 2 2 ρ ρ ρ ρ ρ ρ ρ ρ ρ
Computng Form Factors da j vsble or nvsble 0 N θ da A r θ j N j df A j ddj F d j j F = = = cosθ cosθ j HjdA 2 j πr cosθ cosθ j HjdAj A 2 j πr cosθ cosθ j H A A A 2 j πr j da da j
Hemsphere A j N N j θ j r θ da
Hemcube A j N da
The Renderng Ppelne Local llumnaton Ppelnes z-buffer and Gouraud shadng z-buffer and Phong shadng lst-prorty algorthm and Phong shadng Global llumnaton Ppelnes radosty ray tracng
Renderng Ppelne for z-buffer & Gouraud shadng db traversal Modelng transformaton Trval accept / reject Lghtng Vewng transformaton Clppng Dvde by W, map to 3D vewport Rasterzaton Dsplay
Renderng Ppelne for z-buffer & Phong shadng db traversal Modelng transformaton Trval accept / reject Vewng transformaton Clppng Dvde by W, map to 3D vewport Rasterzaton (wth lghtng) Dsplay
Renderng Ppelne for lst-prorty algorthm & Phong shadng db traversal Prelmnary vsble-surface determnaton Modelng transformaton New db New db traversal Trval accept / reject Vewng transformaton Clppng Dvde by W, map to 3D vewport Rasterzaton (wth lghtng) Dsplay
Renderng Ppelne for radosty & Gouraud shadng db traversal Vertex ntensty calculaton usng radosty method Modelng transformaton New db New db traversal Trval accept / reject Vewng transformaton Clppng Dvde by W, map to 3D vewport Rasterzaton Dsplay
Renderng Ppelne for ray tracng db traversal Modelng transformaton Ray tracng Dsplay