Вы находитесь на странице: 1из 11

Visual Realism

http://designer.mech.yzu.edu.tw/ 1
Copyright@2010, YZU Optimal Design Laboratory. All rights reserved.

L La as st t u up pd da at te ed d: : Y Ye eh h- -L Li ia an ng g H Hs su u ( (2 20 01 10 0- -1 12 2- -1 12 2) ). .
N No ot te e: : T Th hi is s i is s t th he e c co ou ur rs se e m ma at te er ri ia al l f fo or r M ME E5 55 50 0 G Ge eo om me et tr ri ic c m mo od de el li in ng g a an nd d c co om mp pu ut te er r
g gr ra ap ph hi ic cs s, , Y Yu ua an n Z Ze e U Un ni iv ve er rs si it ty y. . P Pa ar rt t o of f t th hi is s m ma at te er ri ia al l i is s a ad da ap pt te ed d f fr ro om m C CA AD D/ /C CA AM M T Th he eo or ry y a an nd d
P Pr ra ac ct ti ic ce e, , b by y I Ib br ra ah hi im m Z Ze ei id d, , M Mc cG Gr ra aw w- -H Hi il ll l, , 1 19 99 91 1. . T Th hi is s m ma at te er ri ia al l i is s b be e u us se ed d s st tr ri ic ct tl ly y f fo or r
t te ea ac ch hi in ng g a an nd d l le ea ar rn ni in ng g o of f t th hi is s c co ou ur rs se e. .
Visual Realism
1. Shading models
Line drawings, still the most common means of communicating the geometry of
mechanical parts, are limited in their ability to portray intricate shapes. S Sh ha ad de ed d c co ol lo or r
i im ma ag ge es s c co on nv ve ey y s sh ha ap pe e i in nf fo or rm ma at ti io on n t th ha at t c ca an nn no ot t b be e r re ep pr re es se en nt te ed d i in n l li in ne e d dr ra aw wi in ng gs s. .
S Sh ha ad de ed d i im ma ag ge es s c ca an n a al ls so o c co on nv ve ey y f fe ea at tu ur re es s o ot th he er r t th ha an n s sh ha ap pe e s su uc ch h a as s s su ur rf fa ac ce e f fi in ni is sh h o or r
m ma at te er ri ia al l t ty yp pe e (plastic or metallic look).
Shaded-image-rendering algorithms filter information by displaying only the visible
surface. Many spatial relationships that are unresolved in simple wireframe displays
become clear with shaded displays. Shaded images are easier to interpret because they
resemble the real objects. Shaded images also have viewing problems not present in
wireframe displays. Objects of interest may be hidden or partially obstructed from view, in
which case various shaded images may be obtained from various viewing points. Critical
geometry such as lines, arcs, and vertices are not explicitly shown. Well-known techniques
such as shaded-image/wireframe overlay (Figure 1), transparency, and sectioning can be
used to resolve these problems.
A As ss si ig gn nm me en nt t 1 1
Generate an object with curved surfaces then render it using your CAD software.
Are there any special functions in your CAD software that create
shaded-image/wireframe overlay, transparency, and sectioning images?
Visual Realism
http://designer.mech.yzu.edu.tw/ 2

Figure 1. Shaded-image/wireframe overlay
1.1 The pinhole camera model
One of the most challenging problems in computer graphics is to generate images that
appear realistic. The demand for shaded images began in the early 1970s when memory
prices dropped enough to make the cost of raster technology attractive compared to the
then-prevailing calligraphic displays. A three-dimensional model can be displayed by
assigning different degrees of shading to the surfaces, knows as s sh ha ad di in ng g o or r r re en nd de er ri in ng g. A
virtual light source is assumed, and various shading techniques are available to determine
strikes on each portion of the surfaces to provide a realistic image of the object.
Rendering begins by solving the hidden surface removal problem to determine which
objects and/or portions of objects are visible in the scene. As the visible surfaces are found,
they must be broken down into pixels and shaded correctly. T Th hi is s p pr ro oc ce es ss s m mu us st t t ta ak ke e i in nt to o
a ac cc co ou un nt t t th he e p po os si it ti io on n a an nd d c co ol lo or r o of f t th he e l li ig gh ht t s so ou ur rc ce es s a an nd d t th he e p po os si it ti io on n, , o or ri ie en nt ta at ti io on n, , a an nd d
s su ur rf fa ac ce e p pr ro op pe er rt ti ie es s o of f t th he e v vi is si ib bl le e o ob bj je ec ct ts s. .
S Sh ha ad di in ng g m mo od de el ls s simulate the way visible surfaces of objects reflect light. They
d de et te er rm mi in ne e t th he e s sh ha ad de e o of f a a p po oi in nt t o of f a an n o ob bj je ec ct t i in n t te er rm ms s o of f l li ig gh ht t s so ou ur rc ce es s, , s su ur rf fa ac ce e
c ch ha ar ra ac ct te er ri is st ti ic cs s, , a an nd d t th he e p po os si it ti io on ns s a an nd d o or ri ie en nt ta at ti io on ns s o of f t th he e s su ur rf fa ac ce es s a an nd d s so ou ur rc ce es s. T Tw wo o
t ty yp pe es s o of f l li ig gh ht t s so ou ur rc ce es s c ca an n b be e i id de en nt ti if fi ie ed d: : p po oi in nt t l li ig gh ht t s so ou ur rc ce e a an nd d a am mb bi ie en nt t l li ig gh ht t. . Objects
illuminated with only point light source look harsh because objects are illuminated from
one direction only. This produces a flashlight-like effect in a black room. A Am mb bi ie en nt t l li ig gh ht t i is s
a a l li ig gh ht t o of f u un ni if fo or rm m b br ri ig gh ht tn ne es ss s a an nd d i is s c ca au us se ed d b by y t th he e m mu ul lt ti ip pl le e r re ef fl le ec ct ti io on ns s o of f l li ig gh ht t f fr ro om m
t th he e m ma an ny y s su ur rf fa ac ce es s p pr re es se en nt t i in n r re ea al l e en nv vi ir ro on nm me en nt ts s. .
Visual Realism
http://designer.mech.yzu.edu.tw/ 3
Let us examine the interaction of light with matter to gain an insight into how to
develop shading models. Particularly, we consider point light sources shining on surfaces
of objects. A Am mb bi ie en nt t l li ig gh ht t a ad dd ds s a a c co on ns st ta an nt t i in nt te en ns si it ty y v va al lu ue e t to o t th he e s sh ha ad de e a at t e ev ve er ry y p po oi in nt t. .
T Th he e l li ig gh ht t r re ef fl le ec ct te ed d o of ff f a a s su ur rf fa ac ce e c ca an n b be e d di iv vi id de ed d i in nt to o t tw wo o c co om mp po on ne en nt ts s: : d di if ff fu us se e a an nd d
s sp pe ec cu ul la ar r. . W Wh he en n l li ig gh ht t h hi it ts s a an n i id de ea al l d di if ff fu us se e s su ur rf fa ac ce e, , i it t i is s r re er ra ad di ia at te ed d e eq qu ua al ll ly y i in n a al ll l
d di ir re ec ct ti io on ns s, so that the surface appears to have the same brightness from all viewing angles.
D Du ul ll l s su ur rf fa ac ce es s e ex xh hi ib bi it t d di if ff fu us se e r re ef fl le ec ct ti io on n. . Examples of real surfaces that radiate mostly
diffuse light are chalk, paper, and flat paints. I Id de ea al l s sp pe ec cu ul la ar r s su ur rf fa ac ce es s r re er ra ad di ia at te e l li ig gh ht t i in n
o on nl ly y o on ne e d di ir re ec ct ti io on n, , t th he e r re ef fl le ec ct te ed d l li ig gh ht t d di ir re ec ct ti io on n. . E Ex xa am mp pl le es s o of f s sp pe ec cu ul la ar r s su ur rf fa ac ce es s a ar re e
m mi ir rr ro or rs s a an nd d s sh hi in ny y s su ur rf fa ac ce es s. . Physically, the difference between these two components is
that diffuse light penetrates the surface of an object and is scattered internally before
emerging again while specular light bounces off the surface.
The light reflected from real objects contains both diffuse and specular components,
and both must be modeled to create realistic images. A A b ba as si ic c s sh ha ad di in ng g m mo od de el l t th ha at t
i in nc co or rp po or ra at te es s b bo ot th h a a p po oi in nt t l li ig gh ht t s so ou ur rc ce e a an nd d a am mb bi ie en nt t l li ig gh ht t c ca an n b be e d de es sc cr ri ib be ed d a as s f fo ol ll lo ow ws s: :

b s d p
I I I I + + = (1)
where
p
I ,
d
I ,
s
I , and
b
I are respectively the resulting intensity at point P the
intensity due to the diffuse reflection component of the point light source, the intensity due
to the specular reflection component, and the intensity due to ambient light.
A As ss si ig gn nm me en nt t 2 2
Put shading on the object you created in Assignment 1. Can you adjust the light
source to adjust the intensities of defuse light, specular light, and ambient light in your
CAD software? Draw several pictures to show the effect of the adjustments.
1.2 Diffuse reflection
Lambert's cosine law governs the diffuse reflection. It relates the amount of reflected
light to the cosine of the angle u between I

and n . Lambert's law implies that the


amount of reflected light seen by the viewer is independent of the viewers position. As
shown in Figure 2, the diffuse illumination is given by
u cos
d L d
K I I = (2)
Visual Realism
http://designer.mech.yzu.edu.tw/ 4
where
L
I and
d
K are the intensity of the point light source and the diffuse-reflection
coefficient respectively.
d
K is a constant between 0 and 1 and varies from one material to
another. Replacing u cos by the dot product of I

and n , we can rewrite Equation (2) as


( ) I n

=
d L d
K I I (3)

Figure 2. The geometry of shading a point.
Note that since diffuse light is radiated equally in all directions, the position of the
viewing eye is not required by the computations, and t th he e m ma ax xi im mu um m i in nt te en ns si it ty y o oc cc cu ur rs s
w wh he en n t th he e s su ur rf fa ac ce e i is s p pe er rp pe en nd di ic cu ul la ar r t to o t th he e l li ig gh ht t s so ou ur rc ce e. On the other hand, i if f t th he e a an ng gl le e
o of f i in nc ci id de en nc ce e u u e ex xc ce ee ed ds s 9 90 0, , t th he e s su ur rf fa ac ce e i is s h hi id dd de en n f fr ro om m t th he e l li ig gh ht t s so ou ur rc ce e a an nd d
d
I m mu us st t
b be e s se et t t to o z ze er ro o. .
1.3 Specular reflection
Specular reflection is a characteristic of shiny surfaces. H Hi ig gh hl li ig gh ht ts s v vi is si ib bl le e o on n s sh hi in ny y
s su ur rf fa ac ce es s a ar re e d du ue e t to o s sp pe ec cu ul la ar r r re ef fl le ec ct ti io on n while other light reflected from these surfaces is
caused by diffuse reflection. If you illuminate an apple with a bright light, you can observe
the effects of specular reflection. Note that at the highlight the apple appears to be white
(not red), which is the color of the incident light.
One of the reasonable approximations to the specular component is an empirical
approximation and takes the form
( ) o u
n
L s
W I I cos (4)
Visual Realism
http://designer.mech.yzu.edu.tw/ 5
For real objects, as the angle of incidence ( ) u changes, the ratio of incident light to
reflected light also changes, and ( ) u W is intended to model the change. In practice,
however, ( ) u W has been ignored by most implementors or very often is set to a constant
s
K , which is selected experimentally to produce aesthetically pleasing results.
The value of n is the shininess factor and typically varies from 1 to 200, depending on
the surface. As shown in Figure 3, for a perfect reflector, n would be infinite. o
n
Cos
reaches a maximum when the viewing eye is in the direction of ( ) 0 = o r .
Is
-
t
/2
t
/2
0
o
Perfect mirror
Is
-
t
/2
t
/2
0
o
Shiny Surface
-
t
/2
t
/2
0
O
Dull surface
Is

Figure 3. The reflectance of various surfaces as a function of o .
1.4 Ambient light
Ambient light is a light with uniform brightness. It therefore has a uniform or constant
intensity
a
I . The intensity at point P due to ambient light can be written as:

a a b
K I I = (5)
where
a
K is a constant which ranges form 0 to 1. It indicates how much of the ambient
light is reflected from the surface to which point P belongs. Finally, considering both
specular reflection and ambient light, the intensity at point P.
( ) ( )( ) | |
n
d L a a P
W K I K I I v r I n

+ + = u (6)
If ( ) u W is set to the constant
s
K , this equation becomes
( ) ( ) | |
n
s d L a a P
K K I K I I v r I n

+ + = (7)
Visual Realism
http://designer.mech.yzu.edu.tw/ 6
A As ss si ig gn nm me en nt t 3 3
Put shading on the object you created in Assignment 1. Can you adjust the
material property to adjust the intensities of defuse light, specular light, and ambient
light in your CAD software? Draw several pictures to show the effect of the
adjustments.
2. Shading Algorithms
Shading models are simple. T Th he e i in np pu ut t t to o a a s sh ha ad di in ng g m mo od de el l i is s i in nt te en ns si it ty y a an nd d c co ol lo or r o of f
l li ig gh ht t s so ou ur rc ce e( (s s) ), , s su ur rf fa ac ce e c ch ha ar ra ac ct te er ri is st ti ic cs s a at t t th he e p po oi in nt t t to o b be e s sh ha ad de ed d, , a an nd d t th he e p po os si it ti io on ns s
a an nd d o or ri ie en nt ta at ti io on ns s o of f s su ur rf fa ac ce es s a an nd d s so ou ur rc ce es s. . T Th he e o ou ut tp pu ut t f fr ro om m a a s sh ha ad di in ng g m mo od de el l i is s a an n
i in nt te en ns si it ty y v va al lu ue e a at t t th he e p po oi in nt t. . Shading models are applicable to points only. To shade an
object, a shading model is applied many times to many points on the object. These points
are the pixels for a raster display. To compute a shade for each point on a 10241024 raster
display, the shading model must be calculated over one million times. T Th he es se e c ca al lc cu ul la at ti io on ns s
c ca an n b be e r re ed du uc ce ed d b by y t ta ak ki in ng g a ad dv va an nt ta ag ge e o of f s sh ha ad di in ng g c co oh he er re en nc ce e; that is, t th he e i in nt te en ns si it ty y o of f
a ad dj ja ac ce en nt t p pi ix xe el ls s i is s e ei it th he er r i id de en nt ti ic ca al l o or r v ve er ry y c cl lo os se e. There are several different shading
algorithms.
2.1 Constant shading
This is the simplest and less realistic shading algorithm. S Si in nc ce e t th he e u un ni it t n no or rm ma al l
v ve ec ct to or r o of f a a p po ol ly yg go on n n ne ev ve er r c ch ha an ng ge es s, , p po ol ly yg go on ns s w wi il ll l h ha av ve e j ju us st t o on ne e s sh ha ad de e. . An entire
polygon has a single intensity value. C Co on ns st ta an nt t s sh ha ad di in ng g m ma ak ke es s t th he e p po ol ly yg go on na al l
r re ep pr re es se en nt ta at ti io on n o ob bv vi io ou us s a an nd d p pr ro od du uc ce es s u un ns sm mo oo ot th h s sh ha ad de ed d i im ma ag ge es s ( (i in nt te en ns si it ty y
d di is sc co on nt ti in nu ui it ti ie es s) ).
2.2 Gourand shading
G Go ou ur ra an nd d s sh ha ad di in ng g i is s a a p po op pu ul la ar r f fo or rm m o of f i in nt te en ns si it ty y i in nt te er rp po ol la at ti io on n o or r f fi ir rs st t- -d de er ri iv va at ti iv ve e
s sh ha ad di in ng g. . Gourand proposed a technique to eliminate (not completely) intensity
discontinuities caused by constant shading. The first step in the Gourand algorithm is to
calculate surface normals. If more than one polygon shares the same vertex as shown in
Figure 4, the surface normals are averaged to give the vertex normal. If smooth shading
between the four polygons shown is required, then
Visual Realism
http://designer.mech.yzu.edu.tw/ 7
( )
D C B A v
N N N N N + + + =
4
1
(8)
A
D
C
B
N
A
N
B
N
C
N
D
N
v
v
(a) Surface normals
(b) Intensity interpolation along polygon edges
I
2
I
3
I
4
I
1
I
P
P
I
s2 I
s1
Scan line
X
Y
y
s

Figure 4. Gourand shading.
The third step in the Gourand algorithm (after calculating surface and vertex normals)
is to compute vertex intensities using the vertex normals and the desired shading model
[Equation (7)]. The fourth and the last step is to compute the shade of each polygon by
linear interpolation of vertex intensities.

2
1 2
1
1
1 2
2
s
s s
s p
s
s s
p s
P
I
x x
x x
I
x x
x x
I

= (9)

2
2 1
1
1
2 1
2
1
I
y y
y y
I
y y
y y
I
s s
s

= (10)

4
3 4
3
3
3 . 4
4
2
I
y y
y y
I
y y
y y
I
s s
s

= (11)
Gourand shading takes longer than constant shading and requires more planes of
memory to get the smooth shading for each color. Figure 5 shows the Gourand shading of a
cone.
Visual Realism
http://designer.mech.yzu.edu.tw/ 8

Figure 5. Gourand shading of a cone
While Gourand shading produces smooth shades, it has some disadvantages. If it is
used to produce shaded animation (motion sequence), shading changes in a strange way
because i in nt te er rp po ol la at ti io on n i is s b ba as se ed d o on n i in nt te en ns si it ti ie es s a an nd d n no ot t s su ur rf fa ac ce e n no or rm ma al ls s that actually
change with motion. H Hi ig gh hl li ig gh ht ts s a ar re e d di is st to or rt te ed d d du ue e t to o t th he e l li in ne ea ar r i in nt te er rp po ol la at ti io on n o of f v ve er rt te ex x
i in nt te en ns si it ti ie es s. .
2.3 Phong shading
T Th he e b ba as si ic c i id de ea a b be eh hi in nd d P Ph ho on ng g s sh ha ad di in ng g i is s t to o i in nt te er rp po ol la at te e n no or rm ma al l v ve ec ct to or rs s a at t t th he e
v ve er rt ti ic ce es s i in ns st te ea ad d o of f t th he e s sh ha ad de e i in nt te en ns si it ti ie es s and to apply the shading model [Equation (7)] at
each point (pixel). To perform the interpolation, Equation (8) can be used to obtain an
average normal vector at each vertex. Figure 6 shows phong shading of a cone.

Figure 6. Phong shading of a cone
A As ss si ig gn nm me en nt t 4 4
What are the shading algorithms provided in your CAD software? Use the object
generated in Assignment 1 to illustrate different shading algorithms and discuss their
differences.
Visual Realism
http://designer.mech.yzu.edu.tw/ 9
3. Shading Enhancements
The basic shading model is usually enhanced to produce special effects for both
artistic value and realism purposes. These effects include t tr ra an ns sp pa ar re en nc cy y, , s sh ha ad do ow ws s, , s su ur rf fa ac ce e
d de et ta ai il ls s, , a an nd d t te ex xt tu ur re e. .
Two shading techniques can be identified: o op pa aq qu ue e a an nd d t tr ra an ns sl lu uc ce en nt t. In the opaque
technique, hidden surfaces in every pixel are completely removed. In the translucent
method, hidden surfaces are not completely removed. This allows some of the back pixels
to show through, producing a screen-door effect.
Consider the box shown in Figure 7. If the front face
1
F is made translucent, the
back face
2
F can be seen through
1
F . The intensity at a pixel coincident with the
locations of points
1
P and
2
P can be calculated as a weighted sum of the intensities at
these two points, that is,
( )
2 1
1 I K KI I + = (12)
where
1
I and
2
I are the intensities of the front and back faces respectively, calculated
using, say, Equation (12). K is a constant that measures the transparency of the front face:
when K=0, the face is perfectly transparent and does not change the intensity of the pixel;
when K=1, the front face is opaque and transmits no light. Sometimes transparency is
referred to as x-ray due to the similarity in effect.
Viewing direction
Front face F
1
Back face F
2
X
v
Y
v
Z
v
P
1
P
2

Figure 7. Transparency and visibility of back faces.
Visual Realism
http://designer.mech.yzu.edu.tw/ 10
S Sh ha ad do ow ws s are important in conveying realism to computer images. More importantly,
t th he ey y f fa ac ci il li it ta at te e t th he e c co om mp pr re eh he en ns si io on n o of f s sp pa at ti ia al l r re el la at ti io on ns sh hi ip ps s b be et tw we ee en n o ob bj je ec ct ts s o of f o on ne e
i im ma ag ge e. The complexity of a shadow algorithm is related to the model of the light source. If
it is a point source outside the field of view at infinity, the problem is simplified. F Fi in nd di in ng g
w wh hi ic ch h o ob bj je ec ct ts s a ar re e i in n s sh ha ad do ow w i is s e eq qu ui iv va al le en nt t t to o s so ol lv vi in ng g t th he e h hi id dd de en n s su ur rf fa ac ce e p pr ro ob bl le em m a as s
v vi ie ew we ed d f fr ro om m t th he e l li ig gh ht t s so ou ur rc ce e. . I If f s se ev ve er ra al l l li ig gh ht t s so ou ur rc ce es s e ex xi is st t i in n t th he e s sc ce en ne e, , t th he e h hi id dd de en n
s su ur rf fa ac ce e p pr ro ob bl le em m i is s s so ol lv ve ed d s se ev ve er ra al l t ti im me es severy time one of the light sources is
considered as the viewing point. The surfaces that are visible to both the viewer and the
light source are not shaded. T Th ho os se e s su ur rf fa ac ce es s t th ha at t a ar re e v vi is si ib bl le e t to o t th he e v vi ie ew we er r b bu ut t n no ot t t to o t th he e
l li ig gh ht t s so ou ur rc ce e a ar re e s sh ha ad de ed d. .
A As ss si ig gn nm me en nt t 5 5
Can you generate shadow with your CAD software? Can you generate shadows
from multiple light sources? Use the object generated in Assignment 1 to demonstrate
the functions in your CAD software.
Texture is important to provide the illusion of reality. For example, modeling of a
rough casting should include the rough texture nature of its surfaces. These objects, rich in
high frequencies, could be modeled by many individual polygons, but as the number of
polygons increases, they can easily overflow the modeling and display programs. T Te ex xt tu ur re e
m ma ap pp pi in ng g (Figure 8) is introduced to solve this problem and provide the illusion of
complexity at a reasonable cost. It is a method of w wa al ll lp pa ap pe er ri in ng g the existing polygons.
As each pixel is shaded, its corresponding texture coordinates are obtained from the texture
map, and a lookup is performed in a two-dimensional array of colors containing the texture.
The value in this array is used as the color of the polygon at this pixel, thus providing the
wallpaper.
Visual Realism
http://designer.mech.yzu.edu.tw/ 11

Polygon to be shaded
Pixel
Screen Texture map

Figure 8. Texture mapping.
A As ss si ig gn nm me en nt t 6 6
Use the object generated in Assignment 1 to demonstrate the texture mapping
capability of your CAD software. Play around with the light sources and view points.
Is there anything unnatural?

Вам также может понравиться