Modelowanie i wizualizowanie 3W-grafiki
O ´swietlenie i cieniowanie
Aleksander Denisiuk
denisjuk@matman.uwm.edu.pl
Uniwersytet Warmi ´nsko-Mazurski w Olsztynie Wydział Matematyki i Informatyki
ul. Słoneczna 54
O ´swietlenie i cieniowanie
Najnowsza wersja tego dokumentu dost ˛epna jest pod
adresem http://wmii.uwm.edu.pl/~denisjuk/uwm
Opcje o ´swietlenia i cienia
(a) (b)
( ) (d)
(e) (f)
O ´swietlenie Phonga
Model odbicia ´swiatła
´Zródło ´swiatła — punkt
Swiatło ma trzy składowe, RGB ´
Odbicie rozproszone
zabarwia ´swiatło na kolor przypisany do obiektu.
Light sour e
FigureIII.2: Diuselyre e tedlightisre e tedequallybrightlyinalldire tions.
Thedoublelineisabeamofin ominglight. Thedottedarrowsindi ateoutgoing
light.
Odbicie zwierciadlane
Swiatło nie zmienia swojej barwy. ´
Light sour e
Figure III.3: Spe ularly re e ted light is re e ted primarily in the dire tion
with the angle of in iden e equal to the angle of re e tion. The double line is a
beam of in oming light. The dotted arrows indi ate outgoing light; the longer
Swiatło docieraj ˛ ´ ace do obserwatora
Swiatło odbijane zwierciadlane: I ´ s . Swiatło rozproszone: I ´ d .
Swiatło otoczenia: I ´ a .
Swiatło emitowane powierzchni ˛ ´ a: I e .
I = I s + I d + I a + I e
Swiatło rozproszone ´
`
n
v
I
in
d
I
d
Figure III.5: The setup for diuse re e tion in the Phong model. The angle of
in iden e is . I in
d
and I
d
are the in oming and outgoing light intensities in
the indi ated dire tions.
Model Lamberta:
I d = ρ d I d In cos θ
Swiatło odbijane zwierciadlanie ´
`
r n
v
' I
in
s
I
s
Figure III.7: The setup for spe ular re e tion in the Phong model. The angle
of in iden e is . The ve tor r points in the dire tion of perfe t mirror-like
re e tion. I in
s
and I
s
are the in oming and outgoing spe ular light intensities
in the indi ated dire tions.
I s = ρ s I s In (cos ϕ) f
Swiatła otoczenia i emitowane ´
I a = ρ a I a In
I e = Const
Obliczanie wektora normalgego
trójk ˛ at
powierzchnia parametryzowana
powierzchnia okre´slona równaniem
Cieniowanie płaskie (flat)
Ka˙zdy bok ma swój kolor.
Cieniowanie Gourauda
Oblicza si ˛e o´swietlenie w wierzchołkach.
Wektor normalny w wierzchołku jest ´sredni ˛ a
arytmetyczn ˛ a wektorów normalnych wszystkich ´scian, do których ten wierzchołek nale˙zy.
Interpoluje si ˛e na cał ˛ a powierzchni ˛e wieloboku.
v
1
v
2
hi;ji
hi4;ji hi5;ji
Cieniowanie Gourauda
Mo˙zna straci´c ´swiatło odbijane zwierciadlane na du˙zych wielobokach. (Stosuje si ˛e podział na
mniejsze wieloboki.)
Mo˙ze w ogóle nie zauwa˙zy´c ´swiatła na szerokiej
´scianie.
Wynik zale˙zy od orientacji prostopadłych w
wierzchołkach, od blisko´sci ´swiatła wierzchołkowi.
Cieniowanie Gourauda
Dobrze działa w wielu przypadkach.
Łatwo do implementacji zarówno programowej jak i sprz˛etowej.
Jest rozpowszechnione.
Cieniowanie Phonga
Oblicza si ˛e wektor normalny w wierzchołkach.
Wektor normalny interpoluje si ˛e na cał ˛ a powierzchni ˛e wieloboku.
Na tej podstawie oblicza si ˛e kolor w ka˙zdym pikselu
v1
v2
v hi;ji
hi4;ji hi5;ji
Cieniowanie Phonga
Kosztowne obliczenia: n α = kαn αn 1 1 +(1−α)n +(1−α)n 0 0 k .
Cała informacja o kolorach i kierunkach ´swiatła
powinna przechowywa´c si ˛e do ostatniej stadji oblicze ´n.
Interpolacja we współrz˛ednych ekranowych: mog ˛ a wyst ˛ api´c nieporz ˛ adane efekty przy projekcji
perspektywicznej.
Cieniowanie Phonga
Małe odbicia zwierciadlane si ˛e nie gubi ˛ a na du˙zych
wielobokach.
Obserwator lokany i nielokalny
` r
h n
v
' I
in
s
I
s
FigureIII.8: Thesetupfor al ulatingthespe ularre e tionusingthehalfway
ve torh,the unitve torhalfwaybetween ` and v.
h = kℓ+vk ℓ+v ,
I s = ρ s I s in cos ψ f
.
Normalizacja wektorów
Domy´slnie ka˙zdy wektor jednostkowy powinien by´c normalizowany.
Je˙zeli macierz przekształcenia zawiera skalowanie,
wektory nale˙zy normalizowa´c.
BRIDF
`
n
v I
;in
I
;out
Figure III.13: The BRIDF fun tion relates the outgoing light intensity and the
in oming light intensity a ording to BRIDF(`;v ;) = I
;out
=I
;in
:
Funkcja rozkładu współczynnika odbicia dwukierunkowego
(Bidirectional Reflected Intesity Distridution Function)
Powierzchnia mikroluster
I
1
I
2
Figure III.14: A mi rofa et surfa e onsists of small at pie es. The horizontal
line shows the average level of a at surfa e, and the mi rofa ets show the
mi ros opi shape of the surfa e. Dotted lines show the dire tion of light rays.
The in oming light an either be re e ted in the dire tion of perfe t mirror-like
re e tion (I
1
), or an enter the surfa e (I
2
). In the se ond ase, the light is
modeled as eventually exiting the material as diusely re e ted light.
Model Cooka-Torrance’a (1982)
I = I a + I d + I s = ρ a I a in + ρ d I d in (ℓ · n) + I s , I s = (n · ℓ)
(n · v) s · F · G · D · I s in s — stała,
F (ℓ, v, λ) — współczynnik Fresnela,
G (ℓ, v) — współczynnik tłumienia geometrycznego,
D(ℓ, v) — funkcja rozkładu mikroluster.
Funkcja Rozkładu Mikroluster
` r
h n
v
' I
in
s
I
s
Figure III.8: The setup for al ulating the spe ular re e tion using the halfway
ve tor h, the unit ve tor halfway between ` and v.
D(ψ) = ce −ψ 2 /m 2 — rozkład Gaussa
Tłumienie Geometryczne
FigureIII.15: Forthederivationofthegeometri term, G,themi rofa etsare
modeledassymmetri , \V"-shapedgrooveswiththetopsofthe groovesallat
thesameheight. Thehorizontallineshowstheoverallplaneofthe surfa e.
h
0 h
`
v
h
h 0
`
v
(a)Noshadowingormasking. (b)Onlymasking.
v
`
v