Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

Shading

Part 1:
What is Light?

Lig
h t t
g h
Li Part II:
Part IV:

Light
Lighting The Eye
No
Lig
Part III: ht
Part V:
Reflectance Shadows
!"#$%&'()*++,-%&#.%/&
0%'".)!/,1234)3-%.)+%'".
56)4732.1,-
8/4%.%/&)#&$)$%132.%/&

!,19#234)139+32.)+%'".
:39+32.#&23
;3/-3.1<)=7/4%.%/&>)/1%3&.#.%/&>)-%21/?4.1,2.,13@
AB4/17.%/&
C1#&4-%44%/&

*++,-%&#.%/&)$3.31-%&3$)B<)."3)%&.31#2.%/&4)B3.D33&)+%'".)4/,1234)#&$)
4,19#234

Computer Graphics 15-462 19


!"#$%&'()'$*'&+,-.
/ 01'.(*,21+(1,+3(%.(-4%5"'(3"#$%&'(3-6'(,3(%73-#7'89(
+1'(#'3+(,3(#'$*'&+'8(:3-6'(&%.(7'(+#%.36,++'8(+--;;7"+(,2.-#'(+1%+($-#(.-<=
/ >1'(#'$*'&+'8(*,21+(,3(<1%+(<'(3''
/ )'$*'&+,-.(,3(.-+(3,64*'(%.8(?%#,'3(<,+1(6%+'#,%*
@ +1'(3"#$%&'A3(6,&#-(3+#"&+"#'(8'$,.'(+1'(8'+%,*3(-$(#'$*'&+,-.
@ ?%#,%+,-.3(4#-8"&'(%.B+1,.2($#-6(7#,21+(34'&"*%# #'$*'&+,-.(
:6,##-#3=(+-(8"**(6%++'($,.,31(:&1%*C=

Incident Light Camera


Reflected Light

Surface
Computer Graphics 15-462 20
BRDF

Surface scattering can be modeled as a function that maps light from incoming (light)
directions ωin to outgoing (viewing) directions ωout:

This function is called the Bi-directional Reflectance Distribution Function (BRDF).

Here’s a plot with ωin held constant:

BRDF’s can be quite sophisticated…

4
BRDFs (Continued)

BRDF Model:

Lo (ωo ) = Li (ωi )f (ωi , ωo )dω

Constraint:

f (ωi , ωo )dω ≤ 1

5
!"#$%&'%&())%)'#*+%#,-.$%$-/#0
1(2"$%3&($"%4-)-*5
67'4.)#* "(2")(2"$8
6"#/-&8
9-%$*#+8:(88(-+%-;%)(2"$%$"*-.2"%8.*;#4'8
9-%*';)'4$(-+8%;*-:%-$"'*%8.*;#4'8

Computer Graphics 15-462 21


Diffuse reflectors

Diffuse reflection occurs from dull, matte surfaces, like latex paint, or chalk.
These diffuse or Lambertian reflectors reradiate light equally in all directions.
Picture a rough surface with lots of tiny microfacets.

7
Diffuse reflectors

…or picture a surface with little pigment particles embedded beneath the surface
(neglect reflection at the surface for the moment):

The microfacets and pigments distribute light rays in all directions.


Embedded pigments are responsible for the coloration of diffusely reflected light in
plastics and paints.
Note: the figures above are intuitive, but not strictly (physically) correct.

8
Diffuse reflectors, cont.

The reflected intensity from a diffuse surface does not depend on the direction of the
viewer. The incoming light, though, does depend on the direction of the light source:

9
!"##$%&'(&#)&*+",-
. /"01)&%+'2"-3',#'4&#)&*+,4'56)%,'2-,7-'6%'Lambertian
Reflection8
. 9,3&)%'6'06++&'%$4#6*&':: 4,$;<'6+'+<&'0"*4,%*,1"*')&=&)
. >3&6)'3"##$%&'4&#)&*+,4
? "-*,0"-;')";<+'"%'%*6++&4&3'&@$6))A'"-'6))'3"4&*+",-%
? ="&7&3'B4";<+-&%%'3,&%'-,+'3&1&-3',-'="&7"-;'3"4&*+",-
? B4";<+-&%% does 3&1&-3',-'3"4&*+",-',#'"))$0"-6+",-

Illumination direction

Computer Graphics 15-462 22


!"#$%&'(") *+",()-./0,%1

c # cos !
c # n"l
n 2..34&5"6%.)0&#"1

l 2.,(&%6'(0).'0.1(-+'

! 2..!(-+'780&#"1.")-1%

n"l
cos ! $
nl

Computer Graphics 15-462 23


!"#$%&'()*!"+

I diffuse # k d I light cos !


# k d I light (n " l )
I light ,**!-./'*012&3%*45'%5)-'6

kd ,**02&7"3%*&%78%3'"53%*31%77-3-%5'*-5*9:;<=

! ,**!-./'>?1&#"8*"5.8%

Computer Graphics 15-462 24


!"#$%"#&&'()%*+,%)-,*#.')%*#./(0%#1#2%*,+3%$"'%4/0"$5

c " cr cl max(0, n ! l )
c " cr cl n ! l 61+7)/8'8%4/0"$

Computer Graphics 15-462 25


Wavelength dependence

Really, ke, ka, and La are functions over all wavelengths λ.

Ideally, we would do the calculation on these functions. For the ambient shading
equation, we would start with:

then we would find good RGB values to represent the spectrum I(λ).
Traditionally, though, ka and Ia are represented as RGB triples, and the computation is
performed on each color channel separately:

14
!"#$%&'()*+),-++.(')/&&.$-0#1-*0

2#$')(%3'4')&-1)5-++.('&6)+4*$)5-++'4'01)&-731-07)#07&'(

83#1)3#%%'0()9-13)(.4+#:'()+#:-07)#9#6)+4*$)13')&-731;
<-1:3)=&#:>?0*1)'"#:1&6)4'#&-(1-:
@*9)1*)(*&A';
2'A'4#&)&-731)(*.4:'(?5-$)&-731)(*.4:')#1)'6'B)+*4)
'"#$%&'
C$=-'01)&-731
Computer Graphics 15-462 26
!"#$%&'()(*$++,-%(.%+/%0'$1&

I d " a # k a I a " k d I light ( n ! l )


c # cr (ca " cl max(0, n ! l )

Ia B((!"#$%&'(/$45'($&'%&-$'>(@4/1#2/A

ka B((!"#$%&'(6%+/%0'2&0%(@/102/A

*$++,-%($//,"$&2'$1&(3/,-(2(-$"3/%(2"#$%&'(/$45'('%6"
2(7.89:('1(2001,&'(+16(2(#20;461,&<(/$45'(/%=%/(02,-%<(#>(
",/'$3/%(6%+/%0'$1&-(+61"(2//(1#?%0'-($&('5%(-0%&%(@/%--(526-5(
233%262&0%A

Computer Graphics 15-462 27


!"#$%&#'()*+,&'-,,"*)./$)0.'122&3$4
56)7%$'/$$&."/$)0.8
9 ,)7%$').$&.4)$:'2/,,4'022';)$%'$%&'4<"/#&'02'$%&'=)4$/.3&'2#0*'$%&'
40"#3&'> 40';&'/=='/.'&?$#/'$&#*'20#'$%)4

I d " a # k a I a " f att k d I light (n ! l ) ;%&#& 2/$$'Q' RS


=
;)$%'='$%&',)7%$'40"#3&'$0'4"#2/3&'=)4$/.3&@*0#&'30*+,)3/$&='
20#*",/&'/#&'+044)A,&
5B0,0#&=',)7%$4'/.='4"#2/3&48
9 C"4$'%/D&'$%#&&'4&+/#/$&'&<"/$)0.4'20#'EFG'
5H$*04+%&#)3'/$$&."/$)0.8
9 "4&'D)&;&#>$0>4"#2/3&'=)4$/.3&'$0'7)D&'&?$#/'&22&3$4
9 $%&'=)4$/.3&')4'"4&='$0'A,&.='$%&'0AC&3$I4'#/=)/.$'30,0#';)$%'/'
J2/#K 30,0#'L&M7MN'/'.)3&'%/O:'7#/:P

Computer Graphics 15-462 28


Specular reflection

Specular reflection accounts for the highlight that you see on some objects.
It is particularly important for smooth, shiny surfaces, such as:
 metal
 polished stone
 plastics
 apples
 skin

Properties:
 Specular reflection depends on the viewing direction V.
 For non-metals, the color is determined solely by the color of the light.
 For metals, the color may be altered (e.g., brass)

18
!"#$%&'( )#*&#$+,-./012-.3 !2'4,.35
6 !2,.7/8%(*'$#8/$2'.3#/'""#'('.$#/92#./:,#9"-,.+/,8/:'(,#4
; 8"#$%&'(,+,#8 02,32&,32+85/'(#/:,#9<4#"#.4#.+
; $'%8#4/=7/8%(*'$#8/+2'+/'(#/>,$(-8$-",$'&&7/8>--+2/0+,&#/*&--(8? 3&-88/
"',.+?/92,+#=-'(485
6 @-(/82,.7/8%(*'$#8/"'(+/-*/+2#/,.$,4#.+/&,32+/(#*&#$+8/
$-2#(#.+&7
; './,.$->,.3/('7/,8/(#*&#$+#4/,./'/8,.3&#/4,(#$+,-./0-(/.'((-9/=#'>5
; 4,(#$+,-./,8/4#*,.#4/=7/+2#/,.$->,.3/4,(#$+,-./'.4/+2#/8%(*'$#/.-(>'&
; 92#./! ,8/.#'(/A#(-?/:,#9#(/8##8/(#*&#$+,-.

Computer Graphics 15-462 29


5,+#6 733'1*#-)*+#
! "#$%&'#()*+#%),-)%-../+0*1-)$2%2.$('3-/ &-33+&&%*2%(-33$4%
),$%Phong Illumination 1+4$3
c " cl (e ! r )
c " cl max(0, e ! r ) p

p
I specular " k s I light (e ! r )

ks 8%%9.$('3-/ /$&3$()-#($
p 8%%:-)$%+&%2.$('3-/ &-33+&&%;.,+#6 $0.+#$#)<

Computer Graphics 15-462 30 p


=/$-)$/%%%%%%>%1+/$%&+('2$4%?$-1
!"#$% &''()*$+,*#$

! -../$%'0.10,200$.304'05,06.'*%",.3+7.R +$6.8*0203.V
ks -..9:05('+3 304'05,+$50
p -..;+,0.#4.<:05('+3 4+''#44.=:"#$% 0>:#$0$,?

@#.30+'.:"7<*5+'.1+<*<.1(,.:3#8*60<.+::3#>*)+,0'7.,"0.3*%",.+$<203
Computer Graphics 15-462 33
!"#$%&'()*&+,*-,./,0&,1*-23

blackboard

Computer Graphics 15-462 31


!"#$% &''()*$+,*#$

-#.*$%/,"0/'*%",/1#(230

4"+$%*$%/5

Computer Graphics 15-462 34


24
Choosing the parameters

Experiment with different parameter settings. To get you started, here are a few
suggestions:

 Try ns in the range [0,100]


 Try ka + kd + ks < 1
 Use a small ka (~0.1)

ns kd ks

Metal large Small, color of metal Large, color of metal

Medium, color of
Plastic medium Medium, white
plastic

Planet 0 varying 0

25
More sophisticated BRDF’s

Cook and
Torrance, 1982

Westin, Arvo, Torrance 1992

26
BRDF

What assumptions does the BRDF model make?

27
ating the sample material. By fitting an expression derived f
BSSRDF
usion theory it is possible to estimate the absorption and sca
properties of the material.
source: http://graphics.stanford.edu/papers/bssrdf/

Theory
BSSRDF, S, relates the outgoing radiance, Lo (xo , ω � o ) at
t xo in direction ω� o , to the incident flux, Φi (xi , ω
� i ) at the p
rom direction ω � i [14]:

dLo (xo , ω
� o ) = S(xi , ω
� i ; xo , ω
� o ) dΦi (xi , ω
� i ).

he BRDFBRDF is an
is an approximation of
approximation thatthe
assumes xi = xofor
BSSRDF . whic
ssumed that light enters and leaves at the same point (
= x ). Given a BSSRDF, the outgoing radiance is compu 28
Snow
Shading

Part 1:
What is Light?

Lig
h t t
g h
Li Part II:
Part IV:

Light
Lighting The Eye
No
Lig
Part III: ht
Part V:
Reflectance Shadows
Shading

Part 1:
What is Light?

Lig
h t t
g h
Li Part II:
Part IV:

Light
Lighting The Eye
No
Lig
Part III: ht
Part V:
Reflectance Shadows
Types of Light Sources

! "#$%&'()**&+,-.*.%/0(*%'*-..*1%2&3(%4'5
6 -*0-37*(4*#41&.*%'(&282&9.&3(%4'5

! :%2&3(%4'-.)**.%/0(*2-;5*42%&'(&1*%'*5-#&*1%2&3(%4'
6 /441*942*1%5(-'3&*.%/0(*54,23&5*<5,'.%/0(=

! >4%'()**.%/0(*2-;5*1%?&2/&*924#*-*5%'/.&*@4%'(
6 -@@24A%#-(%4'*(4*-*.%/0(*$,.$*<$,(*0-250&2=

Computer Graphics 15-462 35


Lights

OpenGL supports three different kinds of lights: ambient, directional, and point. Spot
lights are also supported as a special form of point light.
We’ve seen ambient light sources, which are not really geometric.
Directional light sources have a single direction and intensity associated with them.

[Note: Lights not discussed in Shirley.]

33
Point lights

The direction of a point light sources is determined by the vector from the light
position to the surface point.

Physics tells us the intensity must drop off inversely with the square of the distance:

Sometimes, this distance-squared dropoff is considered too “harsh.” A common


alternative is:

with user-supplied constants for a, b, and c.

34
Spotlights

OpenGL also allows one to apply a directional attenuation of a point light source, giving a
spotlight effect.

The spotlight intensity factor is computed in OpenGL as:

where
 L is the direction to the point light.
 S is the center direction of the spotlight.
 β is the cutoff angle for the spotlight
 e is the angular falloff coefficient

35
“Iteration four”

Since light is additive, we can handle multiple lights by taking the sum over every light.
Our equation is now:

This is the Phong illumination model.


Which quantities are spatial vectors?

Which are RGB triples?

Which are scalars?

36
More Light Sources

! "#$%&'()%*++#$',%+-$./01+2'%)+3'/10%'$,4&+54&&6$55
7 ',%1,-'%8+'-+94:'94&+4&$,(+-$91+3'/10%'$,+;<+54&&-+$55+4248+5/$9 ;
7 -#10'5'13+=8+0$&$/<+#$',%<+3'/10%'$,<+54&&6$55+#4/491%1/-

! >/14+"$./01*++?.9',$.-+@;+-./5401+
7 /43'4%1-+&'()%+5/$9+4&&+#$',%-+$,+'%-+-./5401
7 (1,1/4%1-+-$5%+-)43$2-

Computer Graphics 15-462 36


!"##$%&'(#')**'+,&-#.-/
0 1,23$%$%&'423$-%#5'6$77"8-5'4%6'89-:"*4/ $**"2$%4#$,%

!
I & ka I a % fatt Ilight kd cos$ % ks (cos#) p
"
0 ;,/'2"*#$9*-'*$&.#'8,"/:-8
< =-9-4#'#.-'6$77"8-'4%6'89-:"*4/ :4*:"*4#$,%8'7,/'-4:.'*$&.#'8,"/:-
< )66'#.-':,29,%-%#8'7/,2'4**'*$&.#'8,"/:-8
< +.-'423$-%#'#-/2':,%#/$3"#-8',%*>',%:-
0 +.-'6$77-/-%#'/-7*-:#4%:-':,-77$:$-%#8':4%'6$77-/?'
< @$29*-'A2-#4*BC'ka 4%6'kd 8.4/-'24#-/$4*':,*,/5'ks $8'D.$#-'
< @$29*-'9*48#$:C'ks 4*8,'$%:*"6-8'24#-/$4*':,*,/
< E,/-',%'#.-8-'F$%68',7'94/42-#-/8'D.-%'D-'#4*F'43,"#'
/-7*-:#4%:-'2,6-*8'$%'4'7-D'D--F8

Computer Graphics 15-462 37


!"#$%&'(#)*$+

Computer Graphics 15-462 38


Shading

Part 1:
What is Light?

Lig
h t t
g h
Li Part II:
Part IV:

Light
Lighting The Eye
No
Lig
Part III: ht
Part V:
Reflectance Shadows
Shading

Part 1:
What is Light?

Lig
h t t
g h
Li Part II:
Part IV:

Light
Lighting The Eye
No
Lig
Part III: ht
Part V:
Reflectance Shadows
!"#$%&'
!"#$%&'(%))*+(&",+,(%-.,)/'(#+,("0$$,1(2+%3(#(405"/('%*+),
%30/(#16(01/,1'0/6()%1/+0-*/0%1(2+%3("0$$,1(405"/('%*+),'
7%+8015(%*/(&"#/(0/("0$$,1(0'('03946(#(:0'0-040/6(9+%-4,3
)#1(/",(405"/('%*+),(',,(/",(%-.,)/;
*',(/",(<=-*22,+('"#$%&(#45%+0/"3>
+*1(/",(#45%+0/"3(2+%3(/",(405"/('%*+),?'(:0,&9%01/
'#:,(/",(<=-*22,+(#'(/",('"#$%&(-*22,+
+*1(/",(+,#4(<=-*22,+(#45%+0/"3@(/+#1'2%+3015(,#)"(9%01/(01/%(/",(405"/(
How does the z-buffer work?
'%*+),?'()%%+$01#/,'(#1$()%39#+015(/",(<(:#4*,(#5#01'/(/",('"#$%&(
How can we use the z-buffer to compute shadows?
-*22,+

Computer Graphics 15-462 43


Light Sources

• What is a good model for the sun?


• What is a good model for the lights in this
room?
Hard Shadows
Soft Shadows

• Why? How?
!"#$%&'%%'($)*'+,)-./"#0+'($
1 -./"#0+'($2
3 +,.)4.$5'$6)(/)7'6,+)58.)+()'+%)5'//.".$+)9.7(0'+'.%)+,"(86,)5'//.".$+)
&#+."'#7%
1 -./"#0+'9.)'$5.:2
3 7'6,+)+"#9.7%)#+)%;..5)c/n '$)#)&#+."'#7)(/)"./"#0+'9.)'$5.:)n
3 c '%)+,.)%;..5)(/)7'6,+)'$)#)9#088&
3 9#"'.%)*'+,)*#9.7.$6+,),.$0.)"#'$4(*%)#$5);"'%&%

<=!>-?=@ ?AB>C)DE)->E-=F!?DA
='"GH#088& I
J#+." IKLL
M7#%% #4(8+)IKN
B'#&($5 OKP

Computer Graphics 15-462 41


!"#$$%&'()*
(+,-.'/#"0&'/1'.-#'2-1&+3&'principle of least time
$+,-.'.4)5#$&'6478'27+".'9'.7'27+".':'/1'.-#'6)&.#&.'2).-
*-#"'2)&&+",'6478')'8).#4+)$'76'+"0#;'n< .7'7"#'76'+"0#;'n= Snell’s
law ,+5#&'.-#')",$#'76'4#64)3.+7">
n< &+"'!< ?'n= &+"'!=
*-#4#'!< )"0'!= )4#'.-#')",$#&'6478'2#42#"0+3@$)4
A-#"'.4)5#$+",'+".7')'0#"&#4'8).#4+)$'B$)4,#4'nCD'$+,-.'
/#"0&'.7'/#'874#'2#42#"0+3@$)4'B#, )+4'.7'*).#4C')"0'
5+3#'5#4&)
$+,-.'.4)5#$&'6@4.-#4'+"'.-#'6)&.#4'8).#4+)$
+6'.-#'+"0+3#&')4#'.-#'&)8#'.-#'$+,-.'07#&"%.'/#"0
A-#"'.4)5#$+",'+".7')'$#&&'0#"&#'8).#4+)$'.7.)$'
+".#4")$'4#6$#3.+7"'733@4&'+6 !<E&+"F<Bn=Gn<C

Computer Graphics 15-462 42


!"#$%&'
(%)*&+#&+*,-#.%/&+./+0#10-1#.*+2-34#0*+3#$%#&0*5+6*+2.%11+
7-2.+#8819+%.+./+."*+3*#1+7/$*1
: ;2-#119+8*34/37*$+$-3%&'+20#&+0/&)*32%/&
: <"*3*+#3*+*44%0%*&.+7*."/$2+4/3+$/%&'+."%2+,-%0=19+>6"%0"+6*+6%11+
$%20-22+%&+7/3*+$*.#%1+1#.*3+%&+."*+2*7*2.*3

?1#.+2"#$*$

(/-3#-$@+A/37#1+#.+)*3.*B+%2+#)*3#'*+
/4+&/37#12 4/3+#$C#0*&.+4#0*2+

D"/&'@+%&.*38/1#.*+&/37#12 %&2.*#$+/4+
blackboard %&.*&2%.%*2

Computer Graphics 15-462 44


A460&/9$:%+,#<"<%+./0#)"+%#/"%+*6$$%.4/"#$6+*6)

!"#$%&'(")*+%,#-"%+./0#)"%0"#*./"+1%&/%*"2*./"
34"%&5*6&47%.+"%#%,.8"%4.9'"/%&0%5&$:8&4+%;6*,%
#55/&5/6#*"%+./0#)"%)&$&/648%#4<%/"0$")*#4)"%
),#/#)*"/6+*6)+
="2*./"%9#55648%8"*+%:&.%9&/"%<"*#6$%#*%$"++%)&+*
> ?++684%/#<6#4)"%'#+"<%&4%#4%69#8"
3/%.+" Procedural shaders *&%+5")60:%#4:%0.4)*6&4%:&.%
;#4*%*&%<"064"%/#<6#4)"
> @"4"/#*"%/#<6#4)"%&4%*,"%0$:1%<./648%+,#<648

Computer Graphics 15-462 45


!"#$%&'()*#+,)-.

GLfloat white8[] = {.8, .8, .8, 1.}, white2 = {.2,.2,.2,1.},black={0.,0.,0.};


GLfloat mat_shininess[] = {50.}; /* Phong exponent */

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);


glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white8);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white2);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

Computer Graphics 15-462 39


!"#$%&'&()*+($)

GLfloat white[] = {1., 1., 1., 1.};


GLfloat light0_position[] = {1., 1., 5., 0.}; /* directional light (w=0) */

glLightfv(GL_LIGHT0, GL_POSITION, light0_position);


glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0, GL_SPECULAR, white);
glEnable(GL_LIGHT0);

glEnable(GL_NORMALIZE); /* normalize normal vectors */


glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); /* two-sided lighting*/

glEnable(GL_LIGHTING);

Computer Graphics 15-462 40

You might also like