Presentation is loading. Please wait.

Presentation is loading. Please wait.

Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.

Similar presentations


Presentation on theme: "Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL."— Presentation transcript:

1 Illumination and Shading

2 Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL computes illumination at vertices illumination

3 Shading Apply the lighting model at a set of points across the entire surface Shading

4 Illumination Model The governing principles for computing the illumination A illumination model usually considers : Light attributes (light intensity, color, position, direction, shape) Object surface attributes (color, reflectivity, transparency, etc) Interaction among lights and objects (object orientation) Interaction between objects and eye (viewing dir.)

5 Illumination Calculation Local illumination: only consider the light, the observer position, and the object material properties Example: OpenGL 

6 Illumination Models Global illumination: take into account the interaction of light from all the surfaces in the scene Example: Ray Tracing (CIS681) object 1 object 2 object 3 object 4

7 Basic Light Sources Point lightDirectional light Spot light Light intensity can be independent or dependent of the distance between object and the light source sun

8 Calculating Reflection Vector The scalar projection of Lon N is a scalar equal to

9 Simple local illumination Consider three types of light contribution to compute the final illumination of an object Ambient Diffuse Specular Final illumination of a point (vertex) = ambient + diffuse + specular

10 Ambient light contribution Ambient light (background light): the light that is scattered by the environment A very simple approximation of global illumination Independent of the light position,object orientation, observer’s position or orientation – ambient light has no direction (Radiosity is the calculation of ambient light) object 1 object 2 object 3 object 4

11 Ambient lighting example

12 Ambient light calculation Each light source has an ambient light contribution (I a ) Different objects can reflect different amounts of ambient (different ambient reflection coefficient Ka, 0 <= K a <= 1 ) So the amount of ambient light that can be seen from an object is: Ambient = I a * K a

13 Diffuse light contribution Diffuse light: The illumination that a surface receives from a light source and reflects equally in all direction It does not matter where the eye is

14 Diffuse lighting example

15 Diffuse light calculation Need to decide how much light the object point receive from the light source – based on Lambert’s Law Receive more light Receive less light

16 Diffuse light calculation (2) Lambert’s law: the radiant energy D that a small surface patch receives from a light source is: D = I * cos (  ) I: light intensity  : angle between the light vector and the surface normal N : surface normal light vector (vector from object to light) 

17 Diffuse light calculation (3) Like the ambient light case, different objects can reflect different amount of diffuse light (different diffuse reflection coefficient K d, 0 <= K d <= 1 )) So, the amount of diffuse light that can be seen is: Diffuse = K d * I * cos (  )   N L cos(  ) = N.L

18 Specular light contribution The bright spot on the object The result of total reflection of the incident light in a concentrate region See nothing!

19 Specular light example

20 Specular light calculation How much reflection you can see depends on where you are The only position the eye can see specular from P if the object has an ideal reflection surface But for a non-perfect surface you will still see specular highlight when you move a little bit away from the idea reflection direction When  is small, you see more specular highlight  ? p 

21 Specular light calculation (2) Phong lighting model specular = K s * I * cos n (  ) K s : specular reflection coefficient N: surface normal at P I: light intensity  : angle between V and R cos(  ): the larger is n, the smaller is the cos value cos(  ) = R.V  p  V R N L n

22 Specular light calculation (3) The effect of ‘n’ in the phong model n = 10 n = 30 n = 90 n = 270

23 Put it all together Illumination from a light: Illum = ambient + diffuse + specular = K a * I + K d * I * (N.L) + K s * I * (R.V) n If there are N lights Total illumination for a point P =  (Illum) Some more terms to be added (in OpenGL): Self emission Global ambient Light distance attenuation and spot light effect (N.H) or

24 Polygon shading model Flat shading – compute lighting once and assign the color to the whole polygon

25 Flat shading Only use one vertex (usually the first one) normal and material property to compute the color for the polygon Benefit: fast to compute It is used when: The polygon is small enough The light source is far away (why?) The eye is very far away (why?) OpenGL command: glShadeModel(GL_FLAT)

26 Mach Band Effect Flat shading suffers from “mach band effect” Mach band effect – human eyes accentuate the discontinuity at the boundary Side view of a polygonal surface perceived intensity

27 Smooth shading Reduce the mach band effect – remove value discontinuity Compute lighting for more points on each face Flat shading smooth shading

28 Gouraud Shading Gouraud shading attempts to smooth out the shading across the polygon facets Begin by calculating the normal at each vertex N

29 Gouraud Shading averaging A feasible way to do this is by averaging the normals from surrounding facets intensities Then apply the reflection model to calculate intensities at each vertex N

30 Gouraud Shading linear interpolation We use linear interpolation to calculate intensity at edge intersection P I P RED = (1-  I P1 RED +  I P2 RED where P divides P1P2 in the ratio  Similarly for Q P4 P2 P1 P3 P Q

31 Gouraud Shading Then we do further linear interpolation to calculate colour of pixels on scanline PQ P2 P1 P3 P Q

32 Gouraud Shading

33 Gouraud Shading Limitations - Specular Highlights Gouraud shading gives intensities within a polygon which are a weighted average of the intensities at vertices a specular highlight at a vertex tends to be smoothed out over a larger area than it should cover a specular highlight in the middle of a polygon will never be shown

34 Gouraud Shading Limitations - Mach Bands The rate of change of pixel intensity is even across any polygon, but changes as boundaries are crossed Mach banding This ‘discontinuity’ is accentuated by the human visual system, so that we see either light or dark lines at the polygon edges - known as Mach banding

35 Phong Shading Phong shading has a similar first step, in that vertex normals are calculated - typically as average of normals of surrounding faces N

36 Phong Shading However rather than calculate intensity at vertices and then interpolate intensities as we do in Gouraud shading... In Phong shading we interpolate normals at each pixel... P4 P2 P1 P3 P Q N2 N1 N

37 Phong Shading... and apply the reflection model at each pixel to calculate the intensity - I RED, I GREEN, I BLUE P4 P2 P1 P3 P Q N2 N1 N

38 Phong Shading

39 Phong versus Gouraud Shading A major advantage of Phong shading over Gouraud is that specular highlights tend to be much more accurate vertex highlight is much sharper a highlight can occur within a polygon Also Mach banding greatly reduced The cost is a substantial increase in processing time because reflection model applied per pixel But there are limitations to both Gouraud and Phong

40 Gouraud versus Phong


Download ppt "Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL."

Similar presentations


Ads by Google