Shading

advertisement
Computer Graphics
Page 1
Shading
Shading: determining light reflection from objects at
each pixel.
Basic Reflection Model:
Phong Reflection Model (most commonly used)
ө

I= kaIa + kd Id (l · n) + ksIs(v · r ) α
I : reflected-light intensity
Ambient Reflection: angle independent
ka Ia
Ia : incident ambient-light intensity
ka : object ambient-reflection coefficient
part of the object material properties
Diffusive Reflection: lighting direction dependent
Id kd(ln) = Id kdcos()
02/06/16
Computer Graphics
Page 2
Id : incident difussive-light intensity
kd : object diffusive-reflection coefficient
 : angle between light direction (l) and surface
normal (n). Both l and n are unit vectors.
Specular Reflection: viewing direction dependent
Is ks(vr)α = Is ks cos α (Ф).
Is : incident specular-light intensity
ks : object specular-reflection coefficient
Ф : angle between reflection direction (r) and
viewing direction (v).
 : specular-reflection exponent, shaniness
coefficient.
1/: roughness.
Attenuation: no impact on ambient light
fatt = 1/(a + bd + cd2)
d : distance from the light to the surface point.
a,b,c: constant, linear, quadratic attenuation
coefficients.
I= kaIa + fatt kd Id (l · n) + fatt ksIs(v · r ) α
Colored Lights and Surfaces :
I = (Ir, Ig, Ib) = { I, = r, g, b}
: color channel
Colored lights:
Ia, Id, Is,
Colored objects:
ka, kd, ks,
02/06/16
Computer Graphics
I = Ia ka + fatt Id kd(ln) + fatt Is ks(vr) α
with = r, g, b.
Ir = Iar kar + fatt Idr kdr(ln) + fatt Isr ksr(vr) α
Ig = Iag kag + fatt Idg kdg(ln) + fatt Isg ksg(vr) α
Ib = Iab kab + fatt Idb kdb(ln) + fatt Isb ksb(vr) α
Multiple Lights:
I = Ia ka
+

1 i  m
fatti [Idi kd(l i n) + Isi ks(vr i) α]
with = r, g, b.
(Note: OpenGL support ambient component for
individual light.)
How to get to each pixel?
Two approaches: object order and image order
Object Order Shading (used by OpenGL):
Assuming objects are made of patches (triangles)
Three shading models: Flat, Gouraud, Phong
02/06/16
Page 3
Computer Graphics
Page 4
Flat/Constant Shading:
for (each object)
for(each triangle of the object)
compute the triangle (patch) reflection using
the color and the normal of the triangle
for(each pixel in the triangle)
if(closer to the viewer than the
current z buffer value) {
update z buffer with the new z
update pixel color with the
triangle reflection
Constant/Smooth Shading:
for (each object)
for(each triangle of the object)
for(each vertex in the triangle)
compute the vertex reflection using the color
and the normal of the vertex
for(each pixel in the triangle)
if(closer to the viewer than the
current z buffer value) {
update z buffer with the new z
interpolate the pixel color from
the vertex reflections.
Phong Shading:
for (each object)
for(each triangle of the object)
for(each pixel in the triangle)
02/06/16
Computer Graphics
Page 5
if(closer to the viewer than the
current z buffer value) {
update z buffer with the new z
interpolate the pixel normal
from the vertext normals
compute the pixel
color/relection using Phong
reflection model using pixel
normals and the properties
of the object.
02/06/16
Computer Graphics
Page 6
Image Order Shading:
(Image created by Russell Yuncker)
(Image created by Jian He)
Simple Ray Tracing:
for (each scan line in image ) {
for (each pixel in scan line ) {
determine ray from eye through pixel;
for(each object in scene) {
if(object is intersected and
is closest considered thus far)
record intersection point and object id.
}
set pixel’scolor to that at closest object
intersection point
(Using the I formula given above.)
}
}
02/06/16
Computer Graphics
Page 7
Recursive Ray Tracing:
Set pixel’s color to that at closest object intersection point using the I
formular given below.
I= (1- kr - kt )Iregular+ kr Ir+ kt It
Iregular: regular reflection of lights from light source.
Computed by the formula above.
kr : reflection coefficient.
Ir: illumination from other objects (to be reflected).
kt : transmission coefficient.
It: illumination from other objects (to be transmitted).
Free ray tracing software:
POV-Ray (http://www.povray.org/)
In the lab:
Start->Program Files->Pov Ray for Windows
Run the examples in the “scenes” directory:
C:\Program Files\Pov Ray for Windows\scenes.
The resulting image is stored in the same directory
as the source file.
02/06/16
Computer Graphics
Page 8
// Shading Demonstration
#include "colors.inc"
#include "stdcam.inc"
sphere {
<-1.5, 0.4, -2.5>, 0.4
// center & radius
pigment { rgb <0.0, 0.5, 0.5> } //color
finish {
ambient .2
// ka
diffuse .6
// kd
specular .75
// ks
roughness .01
// 1/n
}
}
text {
ttf "cyrvetic.ttf"
// font type
"Color Sphere", 0.1, 0
// string, thickness, gap
scale <1.25, 1.25, 4>
translate <-3.75, 0, 0>
pigment { rgb <1, 0.5, 0.2> }
}
02/06/16
Download