Presentation is loading. Please wait.

Presentation is loading. Please wait.

Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.

Similar presentations


Presentation on theme: "Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission."— Presentation transcript:

1 Steve Sterley

2 Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission (glass)

3 Lighting in OpenGL Simulates absorption and reflection through 3 different types of light: Diffuse Specular Ambient

4 Components of Colour All colours in the spectrum can be represented through the combination of intensities of 3 distinct colours, namely:red, green, blue 1.In coming light carries information about the intensity of each of its 3 components. 2.The reflected intensity of each component is calculated individually. 3.The resulting colour of the reflected light is then the combination of the 3 reflected components. 1. Incoming light 2. Surface colour 3. Reflected light

5 Diffuse Light Does not originate from the source!! Originates from atoms on the surface being excited by incident radiation Therefore Light emitted in all directions (moving the camera relative to the surface and light source will not change how much the face is lit)

6 The amount of diffuse light emitted, does depend on orientation of surface to the light source. A surface  to light source emits the most light I d – Intensity of emitted light I s – Intensity of light source  d – diffuse reflection coefficient (for material) A surface // to light source emits no light Or… A surface at some arbitrary angle to the source emits light whose intensity is dependent on the angle

7 Note: I d – Intensity of emitted light I s – Intensity of light source  d – diffuse reflection coefficient (for material) Or… Its not possible to have a negative intensity!! When  > 90 or  < -90  I d = 0 We could then rewrite the formula above as follows : Note: This is not a physically accurate model: 1.True light is not composed of three components, but an entire spectrum of frequencies. 2.In reality, Light intensity is inversely proportional to the distance from the source squared.

8 Realistically, objects emit diffuse light from all points on their surface, which once again should fall incident on every other object in the room. Practically, OpenGL allows only eight light sources to be used. Why does OpenGL not stick to a physically accurate lighting model?

9 Specular Light Originates from the source, not the material!! Material colour should not influence it Causes highlights to appear on shiny surfaces Light is emitted in specific directions (moving the camera relative to the surface and light source is expected to change which portions of the face are lit)

10 Method used by OpenGL to simulate specular lighting Best for modeling plastic or glassy materials, not very good for metals Phong Model Perfect MirrorPhong Model Light is only reflected in the direction where i = r ir For one particular angle of incidence, light is reflected in a number of directions, but is most intense in the direction where i = r. On either side of this angle, the intensity drops off to 0. i i

11 ir  Phong Model The intensity varies as some complicated function of , but in the Phong Model, it is made to vary according to the following function: cos f (  ), where f should range somewhere in the region between 0 and 200. Or… r v I sp – Intensity of reflected light I s – Intensity of specular light source  d – specular reflection coefficient (for material)  - angle between viewing vector and maximum reflection vector

12 Or… I sp – Intensity of reflected light I s – Intensity of specular light source  d – specular reflection coefficient (for material)  - angle between viewing vector and maximum reflection vector Note: Its not possible to have a negative intensity!! When  > 90 or  < -90  I sp = 0 We could then rewrite the formula above as follows : i This diagram is a polar plot, so the length of the arrows on the right hand side, represent the reflected intensity for different camera angles relative to the normal. Note:

13 f The graph above, shows how the function: cos f (  ) varies with different values of f. When f = 1, the shininess of the material is low, and the specular highlight will be large. When f = 256, the shininess of the material is high (the material is almost mirror like), and the specular highlight will be small.

14 Reasons for Ambient Light In the real world, light reflecting off walls and other objects accounts for a lot of the light in a room. Physically, if an object were placed in a lit room, even the faces not directed towards the light would be visible. If only diffuse and specular light were applied to a scene, large areas of it would be left in darkness. (Areas where the angles between the normal to a face and the light vector were greater than 90, or less than 0 degrees) (Shadows would appear unrealistically dark)

15 Ambient Light Ambient light has a uniform intensity in all directions, and serves to increase the overall brightness of the environment. Too little – Shadows too harsh Too much – picture appears bland

16 The Overall Picture The overall light intensity used to shade each face of an object, is now simply the sum of the three different light intensities incident on that facei.e. Intensity = ++ This calculation must then be performed for each of the three light components (R, G, B) to calculate the overall colour of that face.

17 Application of the Model Intensity = ++ This is the very formula used by OpenGL, and its parameters are set as follows: AmbientSpecularDiffuse I a : Use glLight, set GL_AMBIENT to the desired RGBA value  a : Use glMaterial, set GL_AMBIENT to the desired RGBA value. I s : Use glLight, set GL_SPECULAR to the desired RGBA value  s : Use glMaterial, set GL_SPECULAR to the desired RGBA value. f : Use glMaterial, set GL_SHININESS to the desired floating point value. I d : Use glLight, set GL_DIFFUSE to the desired RGBA value  d : Use glMaterial, set GL_DIFFUSE to the desired RGBA value.

18 Shading Models There are two types of shading available in OpenGL, these are smooth, and flat shading. Flat Shading assigns a single colour to a face Flat shading is best for modeling objects with flat faces e.g. a faceted diamond Smooth shading applies a gradient of colours to a face Smooth shading is best for modeling objects with curved surfaces e.g. sphere, toroid etc.

19 Flat Shading Each vertex for a face has a normal. In flat shading, OpenGL chooses just one of them to calculate the lighting for that face. In order for flat shading to appear correctly, the normals should be set  to each face, and for any particular face, they should all lie // to each other. If the normals are simply estimated e.g. modeling a sphere, through subdividing an icosahedron, the lighting will not appear accurate.

20 Problem with Flat Shading A problem with OpenGL flat shading is that it assumes that all the normals for a surface are the same. (This is sometimes not the case) An incorrect normal could be chosen, resulting in incorrect lighting for a surface. A simple fix (which would be computationally inexpensive) would be to average all the normals for a face, and use this average to calculate the lighting Unfortunately OpenGL does not implement this.

21 Smooth Shading Used for objects that aren’t meant to have flat faces. In OpenGL, smooth surfaces are estimated by a large number of flat faces. Normals should now be different for each vertex of a polygon (perpendicular to the underlying surface)

22 Gourand Shading The type of smooth shading used by OpenGL A unique colour is calculated for each normal to a polygon The face is then coloured in through interpolation Intensity 1Intensity 2 I right Intensity 3Intensity 4 I left 40% 60% Scan Line

23 Phong Shading Not used by OpenGL More computationally expensive Normals are interpolated across the surface of the polygon, then the lighting is recalculated for each pixel. n1n1 n2n2 n4n4 n3n3


Download ppt "Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission."

Similar presentations


Ads by Google