Download presentation

Presentation is loading. Please wait.

Published byGavin Brady Modified over 2 years ago

1
1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 5 Getting Started with OpenGL A Simple Reflection Model

2
2GR2-00 What is OpenGL? n 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

3
3GR2-00 Geometric Primitives n 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(); n See Chapter 2 of the OpenGL Programming Guide

4
4GR2-00 Viewing n 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 n See Chapter 3 of OpenGL Programming Guide

5
5GR2-00 OpenGL Utility Library (GLU) n 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 n See Appendix C of OpenGL Programming Guide

6
6GR2-00 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() !) n Improved version of the aux library described in Appendix E of the Guide n Allows you to write event driven applications – you specify call back functions which are executed when an event (eg window resize) occurs

7
7GR2-00 How to Get Started n Look at the GR2 practicals page: – practicals.html n Points you to: – example programs – information about GLUT – information about OpenGL – a simple exercise

8
8GR2-00 A Simple Reflection Model

9
9GR2-00 What is a Reflection Model? reflection modellighting illumination n A reflection model (also called lighting or illumination model) describes the interaction between light and a surface, in terms of: – surface properties – nature of incident light n Computer graphics uses a simplification of accurate physical models – objective is to mimic reality to an acceptable degree

10
10GR2-00 Phong Reflection Model n The most common reflection model in computer graphics is due to Bui-Tuong Phong - in 1975 n Has proved an acceptable compromise between simplicity and accuracy n Largely empirical

11
11GR2-00 Diffuse Reflection and Specular Reflection - Phong Approach microscopic view white light specular reflection (white) diffuse reflection (yellow) yellow pigment particles Some light reflected directly from surface. Other light passes into material. Particles of pigment absorb certain wavelengths from the incident light, but also scatter the light through multiple reflections - some light emerges back through surface as diffuse reflection.

12
12GR2-00 Ambient Reflection ambient n In addition to diffuse and specular reflection, a scene will also include ambient reflection n 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

13
13GR2-00 Reflection Model - Ambient Light surface I ( )= K a ( )I a ( ) I a = Intensity of ambient light K a = Ambient-reflection coefficient I = Reflected intensity = wavelength of light hemisphere of ambient light P

14
14GR2-00 Reflection Model - Diffuse Reflection Light reflected equally in all directions - intensity dependent on angle between light source and surface normal Lamberts cosine law: I = I* cos where I* is intensity of light source P light source P light source light source N L surface

15
15GR2-00 Reflection Model - Diffuse Reflection I = K d ( cos ) I* I* = Intensity of light source N = Surface normal L = Direction of light source K d = Diffuse-reflection coefficient I = Reflected intensity light source N L surface Light reflected equally in all directions, with intensity depending on angle between light and surface normal:

16
16GR2-00 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 K d depends on the wavelength of the incoming light light source N L surface I ( ) = K d ( ) ( L. N ) I*( )

17
17GR2-00 Reflection Model - Specular Reflection In perfect specular reflection, light is only reflected along the unique direction symmetric to the incoming light P light source N R

18
18GR2-00 Reflection Model - Specular Reflection P light source N R In practice, light is reflected within a small angle of the perfect reflection direction - the intensity of the reflection tails off at the outside of the cone. This gives a narrow highlight for shiny surfaces, and a broad highlight for dull surfaces.

19
19GR2-00 Reflection 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 peak for dull surfaces.

20
20GR2-00 Reflection Model - Specular Reflection n Phong realised this effect can be modelled by: (cos ) n with a sharper peak for larger n I n=1 n=10

21
21GR2-00 Reflection Model - Specular Reflection I = K s ( cos ) n I* I* = Intensity of light source V = View direction R = Direction of perfect reflected light K s = Specular-reflection coefficient I = Reflected intensity n varies with material large n : shiny small n : dull Intensity depends on angle between eye and reflected light ray: V light source N L R eye surface

22
22GR2-00 Reflection Model - Specular Reflection V light source N L R eye surface Using cos = R. V (R, V unit vectors), we have: I ( ) = K s ( R. V ) n I( )* Note: K s does not depend on the wavelength - hence colour of highlight is same as source

23
23GR2-00 Reflection Model - Ambient, Diffuse and Specular Reflection Model - Ambient, Diffuse and Specular light source I( ) = K a ( )I a ( ) + ( K d ( )( L. N ) + K s ( R. V ) n ) I*( ) N L R V eye surface

24
24GR2-00 Reflection Model - Effect of Distance light source surface d The intensity of light reaching a surface decreases with distance - so we use typically: I* K 1 + K 2 *d + K 3 *d 2 K 1, K 2, K 3 constant - often K 2 =1, K 3 =0

25
25GR2-00 Final Reflection Model light source N L R V eye surface d I( ) = K a ( )I a ( ) + ( K d ( )( L. N ) + K s ( R. V ) n ) I*( ) K 1 + K 2 *d + K 3 *d 2 This needs to be applied for every light source in the scene

26
26GR2-00 Phong Model in Practice n In practice, some simplifications are made to the model for sake of efficiency n For example, ambient light is sometimes assumed to be a constant n Other simplifications are: – lights at infinity – simple colour model

27
27GR2-00 Practicalities - Effect of Distance n 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 directional n Lights at infinity are called directional lights positional point n Lights at a specified position are called positional, or point, lights

28
28GR2-00 Practicalities - Calculating R n R + L = 2 ( N.L ) N hence R = 2 ( N.L )N - L n 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

29
29GR2-00 Practicalities - Calculating R n As noted, if viewer and light source both sufficiently far from surface, then V and L are constant over scene - and also H n Then, for nonplanar surfaces, the calculation: N. H is faster than R. V because R needs to be evaluated at each point in terms of N.

30
30GR2-00 Practicalities - Effect of Colour The Phong reflection model gives reflection for each wavelength in visible spectrum n 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 n Coefficients of ambient-reflection (K a ) and diffuse-reflection (K d ) have separate components for RGB n Coefficient of specular-reflection (K s ) is independent of colour

31
31GR2-00 Example - Ambient Reflection

32
32GR2-00 Example - Ambient and Diffuse

33
33GR2-00 Ambient, Diffuse and Specular

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google