![Page 1: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/1.jpg)
1GR2-00
GR2Advanced Computer
GraphicsAGR
GR2Advanced Computer
GraphicsAGR
Lecture 5Getting Started with OpenGL
A Simple Reflection Model
![Page 2: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/2.jpg)
2GR2-00
What is OpenGL?What is OpenGL?
OpenGL provides a set of routines for advanced 3D graphics– derived from Silicon Graphics GL– acknowledged industry standard, even on
PCs (OpenGL graphics cards available)– integrates 3D drawing into X (and other
window systems such as Windows NT)– draws simple primitives (points, lines,
polygons) but NOT complex primitives such as spheres
– provides control over transformations, lighting, etc
![Page 3: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/3.jpg)
3GR2-00
Geometric PrimitivesGeometric Primitives
Defined by a group of vertices - for example to draw a triangle:
glBegin (GL_POLYGON);
glVertex3i (0, 0, 0);
glVertex3i (0, 1, 0);
glVertex3i (1, 0, 1);
glEnd(); See Chapter 2 of the OpenGL
Programming Guide
![Page 4: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/4.jpg)
4GR2-00
ViewingViewing
OpenGL maintains two matrix transformation modes– MODELVIEW
to specify modelling transformations, and transformations to align camera
– PROJECTION
to specify the type of projection (parallel or perspective) and clipping planes
See Chapter 3 of OpenGL Programming Guide
![Page 5: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/5.jpg)
5GR2-00
OpenGL Utility Library (GLU)
OpenGL Utility Library (GLU)
Useful set of higher level utility routines to make some tasks easier– written in terms of OpenGL and
provided with the OpenGL implementation
– for example, gluLookAt() is a way of specifying the viewing transformation
See Appendix C of OpenGL Programming Guide
![Page 6: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/6.jpg)
6GR2-00
OpenGL Utility Toolkit (GLUT)
OpenGL Utility Toolkit (GLUT)
Set of routines to provide an interface to the underlying windowing system - plus many useful high-level primitives (even a teapot - glutSolidTeapot()!)
Improved version of the ‘aux’ library described in Appendix E of the Guide
Allows you to write ‘event driven’ applications– you specify call back functions which are
executed when an event (eg window resize) occurs
![Page 7: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/7.jpg)
7GR2-00
How to Get StartedHow to Get Started
Look at the GR2 practicals page:– http://www.scs.leeds.ac.uk/kwb/
GR2/ practicals.html Points you to:
– example programs– information about GLUT– information about OpenGL– a simple exercise
![Page 8: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/8.jpg)
8GR2-00
A Simple Reflection ModelA Simple Reflection Model
![Page 9: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/9.jpg)
9GR2-00
What is a Reflection Model?
What is a Reflection Model?
A reflection modelreflection model (also called lightinglighting or illuminationillumination model) describes the interaction between light and a surface, in terms of:– surface properties– nature of incident light
Computer graphics uses a simplification of accurate physical models– objective is to mimic reality to an
acceptable degree
![Page 10: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/10.jpg)
10GR2-00
Phong Reflection ModelPhong Reflection Model
The most common reflection model in computer graphics is due to Bui-Tuong Phong - in 1975
Has proved an acceptable compromise between simplicity and accuracy
Largely empirical
![Page 11: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/11.jpg)
11GR2-00
Diffuse Reflection and Specular Reflection -
Phong Approach
Diffuse Reflection and Specular Reflection -
Phong Approach
microscopic view
whitelight specular reflection (white)
diffuse reflection(yellow)
yellowpigment particles
Some light reflecteddirectly from surface.
Other light passes intomaterial. Particles ofpigment absorb certainwavelengths fromthe incident light, butalso scatter the lightthrough multiple reflections - somelight emerges backthrough surface as diffuse reflection.
![Page 12: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/12.jpg)
12GR2-00
Ambient ReflectionAmbient Reflection
In addition to diffuse and specular reflection, a scene will also include ambientambient reflection
This is caused by light falling on an object after reflection off other surfaces– eg in a room with a light above a
table, the floor below the table will not be totally black, despite having no direct illumination - this is reflection of ambient light
![Page 13: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/13.jpg)
13GR2-00
Reflection Model - Ambient Light
Reflection Model - Ambient Light
surface
I ( )= Ka ( )Ia()Ia = Intensity of ambient lightKa = Ambient-reflection coefficientI = Reflected intensity= wavelength of light
hemisphereof ambientlight
P
![Page 14: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/14.jpg)
14GR2-00
Reflection Model - Diffuse Reflection
Reflection Model - Diffuse Reflection
Light reflected equally in all directions - intensity dependent on angle between light source and surface normal
Lambert’s cosine law: I = I* cos where I* is intensity of light source
P
lightsource
P
lightsource
lightsourceN
L
surface
![Page 15: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/15.jpg)
15GR2-00
Reflection Model - Diffuse Reflection
Reflection Model - Diffuse Reflection
I = Kd ( cos ) I*
I* = Intensity of light sourceN = Surface normalL = Direction of light sourceKd = Diffuse-reflection
coefficientI = Reflected intensity
lightsourceN
L
surface
Light reflected equallyin all directions, withintensity depending onangle between light andsurface normal:
![Page 16: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/16.jpg)
16GR2-00
Reflection Model - Diffuse Reflection
Reflection Model - Diffuse Reflection
The angle between two vectors is given by their dot product: cos = L . N (assume L, N are unit length)
The coefficient Kd depends on the wavelength of the incoming light
lightsourceN
L
surface
I ( ) = Kd() ( L . N ) I*()
![Page 17: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/17.jpg)
17GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
In perfect specular reflection, light is onlyreflected along the unique direction symmetricto the incoming light
P
lightsource
N
R
![Page 18: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/18.jpg)
18GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
P
lightsource
N
R
In practice, light is reflected within a small angle ofthe perfect reflection direction - the intensity of thereflection tails off at the outside of the cone. Thisgives a narrow highlight for shiny surfaces, and abroad highlight for dull surfaces.
![Page 19: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/19.jpg)
19GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
Thus we want to model intensity, I, as a function of angle between viewer and R, say , like this:
I
with a sharper peak for shinier surfaces, and broader peakfor dull surfaces.
![Page 20: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/20.jpg)
20GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
Phong realised this effect can be modelled by:
(cos )n
with a sharper peak for larger n
I
n=1
n=10
![Page 21: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/21.jpg)
21GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
I = Ks( cos )n I*
I* = Intensity of light sourceV = View directionR = Direction of perfect
reflected lightKs = Specular-reflection
coefficientI = Reflected intensity
n varies with materiallarge n : shinysmall n : dull
Intensity depends onangle between eye andreflected light ray:
V
lightsourceN
LR
eye
surface
![Page 22: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/22.jpg)
22GR2-00
Reflection Model - Specular ReflectionReflection Model -
Specular Reflection
V
lightsourceN
LR
eye
surface
Using cos = R . V (R, V unit vectors), we have:
I () = Ks ( R . V )n I()*
Note: Ks does not depend on the wavelength - hencecolour of highlight is same as source
![Page 23: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/23.jpg)
23GR2-00
Reflection Model -Ambient, Diffuse and
Specular
Reflection Model -Ambient, Diffuse and
Specular
lightsource
I() = Ka()Ia() + ( Kd()( L . N ) + Ks( R . V )n ) I*()
N
LR
Veye
surface
![Page 24: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/24.jpg)
24GR2-00
Reflection Model - Effect of Distance
Reflection Model - Effect of Distance
lightsource
surface
d
The intensity of light reaching a surface decreases with distance - so we use typically:
I*
K1 + K2*d + K3*d2K1, K2, K3 constant- often K2=1, K3=0
![Page 25: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/25.jpg)
25GR2-00
Final Reflection ModelFinal Reflection Model
lightsourceN
LR
Veye
surfaced
I() = Ka()Ia() + ( Kd()( L . N ) + Ks( R . V )n ) I*()
K1 + K2*d + K3*d2
This needs to be applied for every light source in the scene
![Page 26: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/26.jpg)
26GR2-00
Phong Model in PracticePhong Model in Practice
In practice, some simplifications are made to the model for sake of efficiency
For example, ambient light is sometimes assumed to be a constant
Other simplifications are:– lights at infinity– simple colour model
![Page 27: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/27.jpg)
27GR2-00
Practicalities - Effect of Distance
Practicalities - Effect of Distance
There are advantages in assuming light source and viewer are at infinity– L and V are then fixed for whole
scene and calculations become simpler
Lights at infinity are called directionaldirectional lights
Lights at a specified position are called positionalpositional, or point point, lights
![Page 28: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/28.jpg)
28GR2-00
Practicalities - Calculating R
Practicalities - Calculating R
R + L = 2 ( N.L ) NhenceR = 2 ( N.L )N - L In practice,
implementations often compute H = ( L + V ) / 2
and replace (R.V) with (H.N) – these are not the same,
but compensation is made with choice of n (angle between N and H is half angle between R and V)
N
LR
R
L
V
R
H
N
![Page 29: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/29.jpg)
29GR2-00
Practicalities - Calculating R
Practicalities - Calculating R
As noted, if viewer and light source both sufficiently far from surface, then V and L are constant over scene - and also H
Then, for nonplanar surfaces, the calculation:
N . His faster than R . V because R
needs to be evaluated at each point in terms of N.
![Page 30: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/30.jpg)
30GR2-00
Practicalities - Effect of Colour
Practicalities - Effect of Colour
The Phong reflection model gives reflection for each wavelength in visible spectrum
In practice, we assume light to be composed as a mixture of RGB (red, green, blue) components - and reflection model is applied for each component
Coefficients of ambient-reflection (Ka) and diffuse-reflection (Kd) have separate components for RGB
Coefficient of specular-reflection (Ks) is independent of colour
![Page 31: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/31.jpg)
31GR2-00
Example - Ambient Reflection
Example - Ambient Reflection
![Page 32: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/32.jpg)
32GR2-00
Example - Ambient and Diffuse
Example - Ambient and Diffuse
![Page 33: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model](https://reader035.vdocuments.us/reader035/viewer/2022062511/5515f4c4550346d46f8b55a1/html5/thumbnails/33.jpg)
33GR2-00
Ambient, Diffuse and Specular
Ambient, Diffuse and Specular