Illumination and Surface Rendering

advertisement
Illumination and Surface
Rendering
Shmuel Wimer
Bar Ilan Univ., Eng. Faculty
Technion, EE Faculty
may 2012
1
Why Lighting?
3D without lighting
may 2012
3D with lighting
2
3D without lighting
may 2012
3D with lighting
3
Components of Reflections
Ambient – surface exposed to indirect light reflected from nearby objects.
Diffuse – reflection from incident light with equal intensity in all
directions. Depends on surface properties.
Specular – near total of the incident light around reflection angle.
may 2012
4
may 2012
5
ambient
diffuse
specular
final
may 2012
6
Light Sources
Radial intensity
attenuation is 1 d
2
This is a problem in practice. 1/d2 produces too much
intensity variations for objects very close to source.
Realistic sources are not infinitesimal small. The remedy
is in adding a linear term.
may 2012
7
Another problem occurs when the source is at infinity.
Light rays are nearly parallel but intensity decays
quadratic and we still wish to display the object
source at infinity
 1.0,

f radial
.
1
d   
,
local
source
attenuation
2
a  a d  a d
2
 0 1
may 2012
8
Directional Source (Spotlight)
To object vertex
Light
source


Cone axis vector
Points outside the cone are not illuminated (stay in dark).
Angular attenuation is:

source not a spotlight
 1.0,

f angular     0.0,
Vobj  Vlight  cos   cos 
attenuation

a otherwise
 Vobj  Vlight ,

may 2012

9
Illumination Models
Surface lighting models compute the outcome of the
interactions between incident radiant energy and the
material composition of the object.
When the surface is
smooth reflections are
similar at all point. This
is called total reflection.
may 2012
If the surface is rough.
Reflected light is
scattered in all
directions. This is called
diffuse reflection.
10
A basic illumination is obtained by an ambient light
which determines the brightness of the scene. It is
uniform for all objects, independent of the viewing point
and direction. The amount of the reflected light
(diffuse reflection) depends however on the surface
optical properties.
If the ambient light of the scene is I a and ka is surfce
ambient reflection parameter, the contribution to
surface reflection at any point is I ambient  ka I a .
Ambient light alone is not enough to render a scene
and light sources are added.
may 2012
11
The amount of incident light depends on the orientation
of the surface relative to the light source direction.
N
Il


Incident light
may 2012
12
For a light source Il and surface reflection parameter
kd (independent of ambient relection parameter ka ),
the diffused reflection is I l ,diffuse  kd Il cos  .
The unit direction vector L of a nearly point light
source I l incident with a surface is given by
Psource  Psurface
L
. The difused reflection is
| Psource  Psurface |
I l ,diffuse
may 2012
kd I l  N  L  , N  L  0

.
NL  0
 0.0,
13
Combining ambient and a single point source, the total
diffuse reflection is
more ambient
I diffuse
ka I a  kd I l  N  L  , N  L  0

.
NL  0
 ka I a ,
more diffuse
may 2012
14
Specular Reflection and the Phong Model
N normal
L light


R reflection

V viewing
The bright spot (specular reflection) shown on a
shiny surfaces is the outcome of total reflection of the
incident light in a concentrated region around the
specular-reflection angle.
may 2012
15
Specular Reflection and the Phong Model
N normal
L light


R reflection

V viewing
A shiny surface has a narrow specular reflection range.
A dull (rough) surface has a wide specular reflection
range.
may 2012
16
cosns 
Phong model sets the
intensity of specular
ns  1
ns  5
reflection to cos ns  .
ns  50
 2
 2
Il ,specular  W   Il cosns .
0  W    1 is called specular - reflelection coeficient.
may 2012
17
If light direction L and
viewing direction V are
on the same side of
the normal N, or if L is
behind the surface,
specular effects do not
exist.
For most opaque materials specular-reflection coefficient
is nearly constant ks.
may 2012
18
ns

k I  V  R  , V  R  0 and N  L  0
I l ,specular   s l
.
otherwise

 0.0,
R can be calculated from L and N, R   2N  L  N  L.
The normal N may vary at each point. To avoid N
computations, angle Φ is replaced by an angle α defined
by a halfway vector H between L and V.
Efficient computations
LV
H
|LV|
may 2012
19
If the light source and
the viewer are
relatively far from the
object α is constant.
H is the direction yielding maximum specular reflection
in the viewing direction V if the surface normal N would
coincide with H. If V is coplanar with R and L (and hence
with N too) α= Φ/2.
may 2012
20
Combining Everything Together
For a single point source:
I  I diffuse  I specular  ka I a  kd I l  N  Ll   ks I l  V  R 
ns
For multiple point sources:
I  ka I a  
n
I
l 1 l
k  N  L   k  V  R ns 
l
s
 d

Accounting radial and angular attenuations:
I  ka I a  
may 2012
n
I f
fl ,angular
l 1 l l ,radial
attenuation attenuation
 k  N  L   k  V  R ns 
l
s
 d

21
How Colors Get In?
Each light source has red, green and blue (RGB)
components.
I l  I lR , I lG , I lB 
Similarly, the ambient, diffuse and specular coefficients of
each surface has red, green and blue (RGB) components.
ka  kaR , kaG , kaB  kd  kdR , kdG , kdB  ks  ksR , ksG , ksB 
Each components of the color is then calculated
separately. All final components are then combined to
set the final color (RGB) of a point.
may 2012
22
Rendering
Reminder
3D drawing without
rendering results 2D
image.
3D drawing with
rendering obtains
depth and perspective
impression.
may 2012
23
Polygon Rendering Methods
Illumination model can be applied at every projected
pixel. Very expensive.
Intensity can be calculated at few locations of the
surface and then approximated at other locations
Usually only surface approximation by polygons and
scan-line rendering are supported. Color intensities
are calculated at vertices and then interpolated for
the rest points.
may 2012
24
The simplest is to use the color of polygon vertex or
centroid for the rest points. This is called flat surface
rendering.
Flat surface rendering provides accurate display if all
the following assumptions are satisfied:
•
Displayed object is polyhedron.
•
All light sources are sufficiently far from object, so N∙L
attenuation is constant over entire surface.
•
Viewing position is sufficiently far so V∙R is constant over all
surface.
Problem: abrupt color change across edges.
may 2012
25
Gouraud Surface Rendering
Gouraud surface rendering, called also intensityinterpolation surface rendering, provides smooth color
transitions across edges of polygon surfaces. It eliminates
the intensity discontinuities occurring in flat rendering.
• Determine the average unit vector at each polygon
vertex.
• Apply illumination model at each vertex to obtain color
intensities at that position.
• Linearly interpolate intensities over projected areas.
may 2012
26
Flat rendering
may 2012
Gouraud rendering
27
Flat rendering
may 2012
Gouraud rendering
28
Flat rendering
Gouraud rendering
may 2012
29
N2
N1
N4
The normal vector at
the vertex V is the
average of the polygon
normal vectors sharing
that point.
may 2012
N3
V
NV  
n
N
k 1 k
|
n
N
k 1 k
|
30
y
3
1
Scan-line
4
p
5
Ends of a scan-line
are interpolated
from vertices.
y4  y2
y1  y4
I4 
I1 
I2
y1  y2
y1  y2
y5  y2
y3  y5
I5 
I3 
I2
y3  y2
y3  y2
2
x
x5  x p
x p  x4
I4 
I5
Internal point is interpolated from I p 
x5  x4
x5  x4
end points.
Avoid most divisions since progression of y is to y-1 and
progression of x is to x+1. Same methods as used in
basic drawing are applicable.
may 2012
31
Phong Surface Rendering
Gouraud rendering may miss specular reflections and
also create anomalies of bright or dark bands in image.
Gouraud rendering
may 2012
Phong rendering
32
Instead of interpolating intensities, the average normal
vectors at vertices are interpolated. Interpolation is done
similarly as for intensities, taking advantage that y is
progressing to y-1 and x to x+1.
N1
N3
N
y  y2
y1  y
N
N1 
N2
y1  y2
y1  y2
Scan-line y
N2
The computation penalty is that the illumination
model is now computed for every point of surface.
may 2012
33
Fast Phong Surface Rendering
It significantly reduces the amount of computations at
each point by approximating some of the illumination
components (G. Bishop and D.M. Weimer, 1986).
Recall that rendering is done for projected polygons.
Consider an object described by triangles.
We interpolate the normal at  x, y  as
N  x, y   Ax  By  C, where A, B and C are
determined from the equalities
N  xk , yk   Axk  Byk  C, k  1, 2,3.
may 2012
34
Omitting reflectivity and attenuation, light-source
diffuse reflection is
L  A  x   L  B y  L  C

LN
I diffuse  x, y  

.
| L || N |
| L || Ax  By  C |
The following expression is obtained by few
manipulations:
I diffuse  x, y  
may 2012
ax  by  c
12
 dx 2  exy  fy 2  gx  hy  i 
,
35
LA
LB
LC
where a 
, b
, c
, d  AA
|L|
|L|
|L|
e  2A  B, f  B  B, g  2A  C, h  2B  C, i  C  C.
I diffuse  x, y  can be approximated by Taylor expansion
 
 
f  x0   , y0     f  x0 , x0    

f  x0 , y0 

y
 x
n

1 
 
 

f  x0 , y0  

n!   x
y
may 2012
36
Considering the first five terms in taylor expension
of I diffuse  x, y  yields
I diffuse  x, y   T5 x  T4 xy  T3 y  T2 x  T1 y  T0 .
2
2
The various Ti , 1  i  5, are functions of a, b,
,i
calculated before, they are fixed for the entire
triangle and can be stored in registers.
may 2012
37
Since the progression of scan line is x  x  1 and
y  y  1, I diffuse  x, y  is fully calculated for the first
point and then only two additions per pixel suffice.
The method can be extended to account sepecular
reflections terms  N  H  .
ns
may 2012
38
Download