Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lighting Phong's Lighting Model normals

Similar presentations


Presentation on theme: "Lighting Phong's Lighting Model normals"— Presentation transcript:

1 Lighting Phong's Lighting Model normals
OpenGL Light and Material Properties glLightModelfv glMaterialfv glColorMaterial Direction/Position local/infinite viewpoint attenuation spotlights

2 Phong's Lighting Model Ambient light - even light all around. Direction of light and viewer don't matter. Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter. Specular - shininess of surface. Direction of light source and viewer both matter.

3 Run sphereInBox1.cpp Observe box and ball materials and lighting.
Look at code later.

4 Normals To get proper reflection, we need to know "surface direction".

5 angle of incidence and angle of reflection

6 sphereInBox1.cpp notice no ambient, has diffuse and specular

7 SphereInBox1.cpp normals
Experiment: Change the value of ONE_BY_ROOT_THREE to see the effect. Try 0, 1.

8 Phong's Lighting Model Light reflected off of object O due to nature of light and nature of the surface

9 Ambient Ambient light - from light scattered all around. Direction of light and viewer don't matter.

10 Diffuse Diffuse - fine scale graininess of surface. Direction of light source matters, direction of viewer doesn't matter.

11 Specular Specular - shininess of surface. Direction of light source and viewer both matter.

12 For Phong Model Each light source has ambient, diffuse, and specular components for each color. There is global ambient light, with components for each color. Each point on the surface of an object has ambient, diffuse, and specular componets for each color. Specular material also has a shininess factor Some items have "inner glow" - emissive component.

13 Light Source Matrix Liamb,R Liamb,G Liamb,B Lidif,R Lidif,G Lidif,B
For each light source i, 0<=i<N, there is a matrix Liamb,R Liamb,G Liamb,B Lidif,R Lidif,G Lidif,B Lispec,R Lispec,G Lispec,B

14 Material Matrix Vamb,R Vamb,G Vamb,B Vdif,R Vdif,G Vdif,B Vspec,R
For each vertex of an object, there is a material matrix Vamb,R Vamb,G Vamb,B Vdif,R Vdif,G Vdif,B Vspec,R Vspec,G Vspec,B

15 Global Ambient Light Vector
For the global ambient light there is a vector globAmbR globAmbG globAmbB

16 For each vertex there is an
Emissive Light Vector For each vertex there is an emissive light vector Vemit,R Vemit,G Vemit,B

17 Total ambient light of color X at a vertex V (X=R, G, or B)
Sum, for all Light sources i, ∑ (Liamb,X * Vamb,X) for all Light sources i + globAmbX*Vamb,X

18 Total diffuse light of color X at a vertex V (X=R, G, or B)
Sum, for all Light sources i, ∑ (cos(ϴi)*Lidif,X * Vdif,X) for all Light sources i ϴi is the angle between the light and the normal to the surface. If cos(ϴi)<0, then use 0 instead.

19 Total specular light of color X at a vertex V (X=R, G, or B)
Sum, for all Light sources i, ∑ (cos(ϴi)f * Lispec,X * Vspec,X) for all Light sources i ϴi is the angle between the light and the normal to the surface. f is the shininess factor of the material.

20 Shininess factor f cos(ϴ)f

21 Total lighting at vertex, color X
Vemit,X + globAmbX*Vamb,X + ∑ (Liamb,X * Vamb,X + for all Light sources i max{ cos(ϴi), 0}*Lidif,X * Vdif,X + max{cos(ϴi)f,0} * Lispec,X * Vspec,X )

22 For more details of the math, see the book, section 11.2

23 Lots of things to specify for each light and material of objects
Ambient R, G, B Diffuse R, G, B Specular R, G, B For material, also emissive - looks like light coming from object. Material also has a shininess component. Got to here class 12

24 Light in OpenGL setting light properties
glLightfv(light, parameter, value) light: GL_LIGHT0, GL_LIGHT1, ... parameter: GL_AMBIENT,GL_DIFFUSE, GL_SPECULAR, GL_POSITION,... value: an array of values, eg, rgba factors for GL_AMBIENT, position (homogeneous) for GL_POSITION

25 Example from sphereInBox1.cpp
float lightAmb[] = { 0.0, 0.0, 0.0, 1.0 }; float lightDifAndSpec[] = { 1.0, 1.0, 1.0, 1.0 }; float lightPos[] = { 0.0, 1.5, 3.0, 1.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDifAndSpec); glLightfv(GL_LIGHT0, GL_SPECULAR, lightDifAndSpec); glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

26 global ambient light float globAmb[] = { 0.2, 0.2, 0.2, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globAmb); //global ambient light.

27 enabling lighting // Turn on OpenGL lighting. glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); // Enable particular light source.

28 Material Properties glMaterial*(face, parameter, value)
face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

29 Material Properties glMaterial*(face, parameter, value)
parameter: GL_AMBIENT, GL_DIFFUSE, ... GL_AMBIENT_AND_DIFFUSE,... GL_SHININESS for full list see:

30 Material Properties glMaterial*(face, parameter, value)
value: array with values for that parameter for that face.

31 lightAndMaterial1.cpp Can change material properties.
Discuss all interactions. Quadratic Attenuation. Technique: Disable light to draw text or "colored"objects. Visible lights are fake! got to here

32 lightAndMaterial2.cpp (with my modifications)
Can change light properties. Try all interactions. Infinite vs local viewpoint. Positional vs directional light. Smooth vs Flat shade model.

33 infinite vs local viewpoint
glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, localViewer); 0 infinite 1 at eye

34 Review Idea of Lighting
? ? ? ? ?

35 Which normals to use? shpereInBox2.cpp

36 How to light pixels, flat or smooth?

37 How many triangles are there? myLitRedSquares.cpp

38 spotlight.cpp (modified) check out code, user interaction.
Placement of light subject to transformations. Uses color for material.

39 Watch some shorts Luxo Jr.

40 From Vertices to Faces Think light and color (and more)

41 Triangle with a red, blue, and green corner.

42 Squares with red, green, blue, and yellow corners

43 Understanding the problem and how to get what we want.

44 Compute the indicated point
(7,16) ( ? , ? ) 1/2 (1,4)

45 Weighted average 1/2 * (1,4) + 1/2* (7,16) =
( .5 , 2 ) + ( 3.5 , 8 ) = ( 4 , 10 ) NOT taking the difference... This doesn't generalize.

46 Compute the indicated point
(7,16) ( ? , ? ) ( 4 , 10 ) 3/4 (1,4)

47 Compute the indicated point
(7,16) (7, 16) is pulling harder than (1,4) ( ? , ? ) ( 4 , 10 ) 3/4 3/4 * ( 7 , 16 ) + 1/4 * ( 1 , 4 ) =( 21/4 , 12 ) + (1/4 ,1) = ( 22/4 , 13 ) = ( 5.5 , 13) (1,4)

48 Compute the indicated point
(7,16) c2 c1 + c2 =1 ( 5.5 , 13 ) ( 4 , 10 ) c1 c1* ( 7 , 16 ) + c2* ( 1 , 4 ) (1,4)

49 Compute (INTERPOLATE) the indicated color
(1,4) (7,16) 1/2 ( 4 , 10 ) Blue: ( 0 , 0 , 1 ) Red: ( 1 , 0 , 0 )

50 Compute the indicated color
(7,16) Blue: ( 0 , 0 , 1 ) 1/2*(1,0,0) + 1/2*(0,0,1)= (0.5 , 0, 0) + (0 , 0, 0.5)= (0.5, 0, 0.5) ( 4 , 10 ) 1/2 (1,4) Red: ( 1 , 0 , 0 )

51 V is a convex combination of P and Q
If P and Q are two points in 3-space, then the segment from P to Q is the set of points of the form V = c1 P + c2 Q where ≤c1≤1, 0≤c2≤1 and c1 + c2 = 1 V is a convex combination of P and Q

52 Convex Combinations of three points
c1+c2+c3=1 ci≥0, i=1,2,3 P3 P2

53 Convex Combinations of three points
Find c1,c2,c3 ci≥0, i=1,2,3 that give us P1 P2 P3 W P1 W P3 P2

54 Use Convex Combinations to compute (interpolate) colors in a triangle

55 P1 is 1. (0,0,1)+0. (0,1,0) +0. (1,0,0) P2 is 0. (0,0,1)+1. (0,1,0) +0
P1 is 1*(0,0,1)+0*(0,1,0) +0*(1,0,0) P2 is 0*(0,0,1)+1*(0,1,0) +0*(1,0,0) P3 is 0*(0,0,1)+0*(0,1,0) +1*(1,0,0) W is .5*(0,0,1) +0*(0,1,0)+.5*(1,0,0) V is .1*(0,0,1) + .3*(0,1,0)+.6*(1,0,0) W V V

56 Uniqueness For line segments, c1 and c2 are unique.
For triangles, c1, c2, and c3 are unique. For other shapes, they are NOT unique.

57 Interpolation in a quad is not well defined!

58 How does OpenGL color quads and polygons?
It breaks them into triangles, then colors the triangles.

59 myLitRedSquares more triangles, better lighting.


Download ppt "Lighting Phong's Lighting Model normals"

Similar presentations


Ads by Google