* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Illumination Models
Gravitational lens wikipedia , lookup
Light pollution wikipedia , lookup
Bicycle lighting wikipedia , lookup
Photopolymer wikipedia , lookup
Doctor Light (Kimiyo Hoshi) wikipedia , lookup
Bioluminescence wikipedia , lookup
Daylighting wikipedia , lookup
Architectural lighting design wikipedia , lookup
Steve Sterley Real World Lighting Physical objects tend to interact with light in three ways: • Absorption (black body) • Reflection (mirror) • Transmission (glass) Lighting in OpenGL Simulates absorption and reflection through 3 different types of light: • Diffuse • Specular • Ambient 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 3. Reflected light 2. Surface colour 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) 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 Intensity n r Or… Intensity cos Intensity n r A surface // to light source emits no light r nˆ I d I s d r I d I s d cos A surface at some arbitrary angle to the source emits light whose intensity is dependent on the angle Id – Intensity of emitted light Is – Intensity of light source d – diffuse reflection coefficient (for material) Intensity n r Or… Intensity cos r nˆ I d I s d r I d I s d cos Id – Intensity of emitted light Is – Intensity of light source d – diffuse reflection coefficient (for material) Note: Its not possible to have a negative intensity!! When > 90 or < -90 Id = 0 We could then rewrite the formula above as follows : r nˆ I d I s d max ,0 r Note: This is not a physically accurate model: 1. 2. True light is not composed of three components, but an entire spectrum of frequencies. In reality, Light intensity is inversely proportional to the distance from the source squared. Why does OpenGL not stick to a physically accurate lighting model? 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. 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) Phong Model • Method used by OpenGL to simulate specular lighting • Best for modeling plastic or glassy materials, not very good for metals Perfect Mirror i r Light is only reflected in the direction where i = r Phong Model i i 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. 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: cosf(), where f should range somewhere in the region between 0 and 200. Intensity r v f Or… Intensity cos f I sp r v I s s rv r i r f I sp I s s cos f v Isp – Intensity of reflected light Is – Intensity of specular light source d – specular reflection coefficient (for material) - angle between viewing vector and maximum reflection vector Intensity r v f Or… Intensity cos f I sp r v I s s rv f I sp I s s cos f Isp – Intensity of reflected light Is – 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 Isp = 0 We could then rewrite the formula above as follows : I sp r v f ,0 I s s max r v Note: 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. i f The graph above, shows how the function: cosf() 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. 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) Ambient Light Ambient light has a uniform intensity in all directions, and serves to increase the overall brightness of the environment. I I a a • Too little – Shadows too harsh • Too much – picture appears bland 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 face i.e. Intensity = I a a r v f r nˆ ,0 ,0 + I d d max + I s s max r r v This calculation must then be performed for each of the three light components (R, G, B) to calculate the overall colour of that face. Application of the Model Intensity = I a a r v f r nˆ ,0 ,0 + I d d max + I s s max r r v This is the very formula used by OpenGL, and its parameters are set as follows: Ambient • Ia : Use glLight, set GL_AMBIENT to the desired RGBA value • a : Use glMaterial, set GL_AMBIENT to the desired RGBA value. Specular • Is : 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. Diffuse • Id : Use glLight, set GL_DIFFUSE to the desired RGBA value • d : Use glMaterial, set GL_DIFFUSE to the desired RGBA value. 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 • Smooth shading applies a gradient of colours to a face • Flat shading is best for modeling objects with flat faces e.g. a faceted diamond • Smooth shading is best for modeling objects with curved surfaces e.g. sphere, toroid etc. 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. <digression> 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. 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) 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 4 Intensity 3 I left ( I 4 I1 ) f I1 I right ( I 3 I 2 ) f I 2 60% I left 40% Intensity 1 I right Scan Line Intensity 2 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. n3 n4 n right (n 3 n 2 ) f n 2 n2 n1 n left (n 4 n1 ) f n1