Lights, Colour and Materials In OpenGL

Similar documents
Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Why we need shading?

Computer Graphics. Illumination and Shading

Graphics and Visualization

INF3320 Computer Graphics and Discrete Geometry

CEng 477 Introduction to Computer Graphics Fall

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Shading and Illumination

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Lighting. CSC 7443: Scientific Information Visualization

Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

Virtual Reality for Human Computer Interaction

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Illumination and Shading ECE 567

CS Surface Rendering

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

Light Sources. Spotlight model

Comp 410/510 Computer Graphics. Spring Shading

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Illumination & Shading

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Illumination and Shading

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Reflection and Shading

CS Illumination and Shading. Slide 1

Virtual Reality for Human Computer Interaction

Lecture 4 Advanced Computer Graphics (CS & SE )

Shading. Why we need shading. Scattering. Shading. Objectives

Illumination & Shading I

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

CS 4600 Fall Utah School of Computing

CSCI 4620/8626. Computer Graphics Illumination Models and Surface Rendering Methods (Chapter 17)

CPSC 314 LIGHTING AND SHADING

Shading I Computer Graphics I, Fall 2008

Light Transport Baoquan Chen 2017

Introduction to Computer Graphics 7. Shading

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Illumination & Shading: Part 1

LIGHTING AND SHADING

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Shading. Brian Curless CSE 457 Spring 2015

Display Issues Week 5

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Shading. CSE 457 Winter 2015

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Lighting/Shading III. Week 7, Wed Mar 3

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

Today we will start to look at illumination models in computer graphics

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Graphics for VEs. Ruth Aylett

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Graphics for VEs. Ruth Aylett

Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Surface Rendering Methods

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

CS5620 Intro to Computer Graphics

Illumination Models & Shading

Illumination and Shading

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Shading. Brian Curless CSE 557 Autumn 2017

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Illumination in Computer Graphics

Visualisatie BMT. Rendering. Arjan Kok

CS 325 Computer Graphics

w Foley, Section16.1 Reading

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Simple Lighting/Illumination Models

COMP3421. Hidden surface removal Illumination

CS452/552; EE465/505. Lighting & Shading

CS452/552; EE465/505. Intro to Lighting

Illumination Models. To calculate the color of an illuminated position on the

CSE 167: Introduction to Computer Graphics Lecture #6: Colors. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Local Illumination physics. Law of reflection and Snell s law of refraction

Objectives. Shading II. Distance Terms. The Phong Reflection Model

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Lighting. Figure 10.1

Transcription:

Illumination Models Lights, Colour and Materials In OpenGL Illumination models are used to generate the colour of an object s surface at a given point on that surface. The factors that govern the illumination model determine the visual representation of that surface. Due to the relationship defined in the model between the surface of the objects and the lights affecting it, illumination models are also called shading models or lighting models. Light The Simplest Shading Model The physics of light is a complex subject. Shading models are approximations of these laws, in varying levels of realism/complexity. This is based on the fact that surfaces, for the most part, are approximations. Micro facet details defines the lighting characteristics of surface colour. CG Object representation (usually) does not transcend to that level. Radiosity algorithms now mimic photonic reactions with surfaces. The simplest shading model is a simple constant illumination. The model represents an unrealistic assumption in that the surface is self illuminating (the colour of this constant shading is defined by the user).

Illumination Equation We can now introduce the illumination equation, using the notion that Where I represents the illumination colour intensity and value represents the expression resulting in that colour value. Constant shading illumination equation can be defined as: Constant Illumination This simple equation has no reference to light sources, and as such every point on the object has the same intensity. This equation need only be calculated once per object. The process of evaluating the illumination equation at one or more points on an object s surface is referred to as lighting the object. where k represents the basic object intensity. Ambient Light Ambient light is usually a scene-based intensity of non directional light. It affects every object in that scene. We can then incorporate this into our illumination equation Diffuse Reflection Diffuse reflections consider point lights to generate shading properties a change in colour intensity across the surface of an object in relation to light sources. I = I a k a I a is the ambient light intensity the scene-based value that remains the same for all surfaces in the scene. K a is the ambient reflection coefficient a material based property that determines how much ambient light is actually reflected. Material based properties are the properties that characterise one surface from another. This equation allows individual surface properties to reflect a level of ambient light. The simplest of these models is the Lambert Illumination Model.

Lambert s Law Lambertian Reflection light is reflected with equal intensity in all directions (isotropic). The distribution is a basic consideration towards surface detail: Lambert s Law Lambert s law states that the intensity of illumination on a diffuse surface is proportional to the cosine of the angle generated between the surface normal vector and the surface to the light source vector. Light scattering on the surface and in the medium. The only data used in this equation is the surface normal and a light vector that uses the light source position(taken as a point light for simplicity). The intensity is irrespective of the actual viewpoint, hence the illumination is the same when viewed from any direction. Lambert s Model The equation for Lambert s illumination model is: I = I p k d cos(") Directional Light Where: I p is the intensity of the point light source k d is the material diffuse reflection coefficient the amount of diffuse light reflected. By using the dot product between 2 vectors v 1 and v 2 v 1 v 2 = v 1 v 2 cos(") I = I p k d (N L) and if N and L are normalised, we can re-write the illumination equation: So far, we have considered only point lights A light source at a near-infinite distance away from a surface has near-parallel rays. The vector made from the surface to the light source is always the same for every surface. This is known as a directional light light from a known direction- not position. We do not specify a position for directional lights, just a vector to indicate ray direction.

Application of Directional Lights Concatenation of Illuminations To implement a directional light into the illumination equation, Lambert s lighting model can be combined with the previous ambient light equation. we simply use the same light vector in every different surface illumination equation i.e. L does not change, as it is constant for the light source. I = I p k d (N L) Ambient Light I = I a k a Lambert s I = I p k d (N L) I = I a k a + I p k d (N L) Attenuation of Light Application of Attenuation To include attenuation into our illumination equation, we need to insert an attenuation factor into the lighting section in this case labelled f att. I = I a k a + f att I p k d (N L) The above is an example of lighting with no attenuation and below is an example with a more realistic attenuation of light. With this multiplying factor in place, we can control the intensity of light based on distance. An f att of 0 would effectively turn the light off. An f att of 1 would result in a maximum intensity of the light. Light falloff obeys what is commonly known as the inverse square law its intensity decreases exponentially in relation to distance. Real light has an attenuation factor light intensity becomes weaker over distance. In a similar manner, the perception of sound volume decreases the further away you are from its source. If we consider the distance from the surface point to the light L as d L f att = 1 d L 2

Light Colour Specular Reflection So far the notion of using the illumination equation has had no reference to actual colour only monochromatic intensity. What we require to do so, are 3 equations, to represent the Red, Green and Blue data. E.g. Shiny surfaces exhibit specular reflection the reflection of the light source towards the viewer. Specular reflection has 2 main colour biases: 1. The colour of the specular reflection is determined by the light source colour. or I R = I a R k ar + f att I pr k dr (N L) I G = I ag k ag + f att I pg k dg (N L) I B = I ab k ab + f att I pb k db (N L) 2. The colour of the specular reflection is determined by the colour of the surface. Objects that have waxed, or transparent surfaces (apples, plastic, etc.) tend to reflect the colour of the light source. Plastic, for example, is composed of colour pigments suspended in a transparent material. and Gold has a gold coloured highlight. Specular Realism Specular Realism II Most shiny surfaces are not perfect mirrors. Shiny surfaces will reflect the largest intensity where the viewing angle is directly opposite the reflection angle. They usually also reflect a diminishing gradient of highlight as well, enabling light to be seen from angles not directly opposed to the angle of reflection. The above diagram describes a perfectly mirrored surface. The viewer is seen looking at a point on the surface: viewing vector E. The light source L emanates a ray of light that that hits the surface with an angle of i relative to the normal. The angle of reflection of the light ray then leaves with an angle r relative to the normal. The angle of incidence i is the same as angle r. Phong Bui-Tuong developed an illumination model for non-perfect reflectors that has become widely used to portray realistic shiny surfaces. In a perfect mirror (above), the viewer may ONLY see the light ray if the viewing angle E is directly opposite of the reflection vector R. It is commonly known as the Phong illumination model. 20

Colour in OpenGL OpenGL specifies Colour using either a 3 or 4 tuple value. to represent r,g,b or r,g,b,a values or Colour Index mode which uses a user defined palette to set the current colour. As RGBA is the most common this will be discussed in most depth. to set the current colour the command glcolor[3/4] [b,s,i,f,d,ub,us,ui](v) is used Colour in OpenGL 1 // set colour using direct values 2 glcolor3f(1.0f,0.0f,0.0f); 3 4 // or using an array 5 GLfloat col[]={1.0,0.0,0.3,1.0}; 6 glcolor4fv(col); Colour state values The colour acts as a typical OpenGL state variable, so the colour value is retain until another call to glcolor. depending upon the Shade model used the colour for each vertex will be calculated per vertex based on the current colour state. If the GL_FLAT shade model is set each face in a model will have the same colour (i.e. the last colour called using glcolor3f) if GL_SMOOTH is used the colour will be interpolated for each set vertex colour across the face Colour state values The colour acts as a typical OpenGL state variable, so the colour value is retain until another call to glcolor. depending upon the Shade model used the colour for each vertex will be calculated per vertex based on the current colour state. If the GL_FLAT shade model is set each face in a model will have the same colour (i.e. the last colour called using glcolor3f) if GL_SMOOTH is used the colour will be interpolated for each set vertex colour across the face

gllightfv Lighting Parameters 1 void gllightfv( GLenum light, GLenum pname, const GLfloat * params); The light Parameter specifies the light Number GL_LIGHT0 - GL_LIGHT(GL_MAX_LIGHTS-1) (Usually 8 lights) pname specifies the lighting parameter to be changed these parameters are shown on the next slide params Specifies the value that parameter pname of light source light will be set to. Parameter GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_POSITION GL_SPOT_CUTOFF GL_SPOT_DIRECTION GL_SPOT_EXPONENT GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION Usage Sets RGBA Ambient Light Value Sets RGBA Diffuse Light Value Sets RGBA Specular Light Value Sets Light Position (x,y,z,w) Sets cutoff value for Spotlight Sets spotlight direction Sets the intensity distribution of the light Modifies Light Attenuation Modifies Light Attenuation Modifies Light Attenuation Using Light Sources in OpenGL OpenGL provides a number of functions for setting up lighting, and material properties for objects. A default OpenGL configuration allows for 8 light sources to be used in a scene. These are defined as GL_LIGHT0 - GL_LIGHT7. For example to create a light source located at (3,6,5) in world coordinates we use the following code. Light Position The array LighPos[] specifies the location of the light source and is passed to gllightfv() along with the name GL_LIGHT0 to attach is to the particular source. 1 // array for light position 2 GLfloat LightPos[]={3.0,6.0,5.0,1.0}; 3 4 // set the light pos 5 gllightfv(gl_light0,gl_position,lightpos); 6 7 // enable light 8 glenable(gl_lighting); 9 glenable(gl_light0);

Local or Remote Light Sources Some sources such as a desk lamp, are in the scene, whereas others, like the sun, are infinitely remote. OpenGL allows you to create both types by using homogeneous coordinates to specify the position of the source, thus we have (x,y,z,1) : a local light source at the position (x,y,z) and (x,y,z,0) : a vector to an infinitely remote light source in the direction (x,y,z) Local or Remote Light Sources Infinitely remote light sources are often called directional There are computational advantages to using directional light sources since the direction S in the calculations of the diffuse and specular reflections is constant for all vertices in the scene. Some times light must be placed local to an object in a scene and thus the directional light is not appropriate. However this will increase the computation time Setting Light Colour values A light is said to emit ambient, diffuse and specular colour. The ambient colour is attached to the light and is still treated as a non-directional light that bathes the entree scene. However this light may be turned on and off with the light in question. OpenGL also has a true ambient light which is associated with the whole scene. 1 // create ambient light values 2 GLfloat amb[]={0.2,0.4,0.6,1.0}; 3 // diffuse 4 GLfloat diff[]={0.8,0.9,0.5,1.0}; 5 // specular 6 GLfloat spec[]={1.0,0.8,1.0,1.0}; 7 // now set the values 8 gllightfv(gl_light0,gl_ambient,amb); 9 gllightfv(gl_light0,gl_diffuse,diff); 10 gllightfv(gl_light0,gl_specular,spec);

Light Colour Colours are specified in RGBA format using Red, Green, Blue and Alpha. The alpha colour is used for blending two colours. The default OpenGL values for a light are as follows and give a good general light for a scene. For all sources :- default ambient =(0,0,0,1); - dimmest possible = black For GL_LIGHT0 default diffuse = (1,1,1,1) - brightest possible = white. default specular = (1,1,1,1) - brightest possible = white. For all other Lights the diffuse and specular default to black Spotlights Light sources are point sources by default; that is they emit light uniformly in all directions. A spotlight is a restricted version of a normal light so that the light travels in only a certain direction. The light in the above figure shows a light aimed in the direction d with a cutoff angle of α No light is seen at points lying outside of the cutoff cone. For vertices such a P which lie inside the cone the amount of light reaching the P is attenuated by the factor cos ε (β) where β is the angle between d ε and a line from the source to P and is an exponent chosen by the user to give the desired fall-off of light with angle Spotlight Code The following code shows how to make a light into a spot light 1 // set the light direction 2 GLfloat dir[]={2.0,1.0,-4.0}; 3 4 5 gllightf(gl_light0,gl_spot_cutoff,45.0); 6 7 gllightf(gl_light0,gl_spot_exponent,4.0); 8 9 gllightfv(gl_light0,gl_spot_direction,dir); The default values for these parameters are d=(0,0,-1), α=180 ε =0 which makes the light an omnidirectional point source. Attenuation of light with distance OpenGL allows the specification of how rapidly light diminishes with distance from a source. Most of the light models seen so far do not rely on this factor however it can add interesting effects to a scene. OpenGL attenuates the strength of a positional light source using the attenuation factor

Attenuation of light with distance atten = 1 k c + k l D + k q D 2 where kc,kl and kq are coefficients and D is the distance between the position of the light and the vertex in question. These can be set by the function call 1 // set Kc 2 gllightf(gl_light0,gl_constant_attenuation,2.0); 3 // set Kl 4 gllightf(gl_light0,gl_linear_attenuation,2.0); 5 // set Kq 6 gllightf(gl_light0,gl_quadratic_attenuation,2.0); Adding Global Ambient Light In any given scene a global ambient light may be added which is independent of any other light source. This is done using the following code 1 GLfloat amb[]={0.2,0.3,0.1,1.0}; 2 3 gllightmodelfv(gl_light_model_ambient,amb); The default value is (0.2,0.2,0.2,1.0) so the ambient light is always present, unless it is purposely altered. Making the ambient light source value non-zero makes any object in a scene visible even if no other lights are turned on. Local or Remote Viewpoint? OpenGL computes specular reflections using the halfway vector h=s+v The true directions s and v are normally different at each vertex in a mesh. If the light source is directional, then s is constant, but v still varies from vertex to vertex. The rendering speed is increased if v is kept constant from all vertices. As a default OpenGL uses v=(0,0,1) which points down the positive z axis. You can force OpenGL to compute v for each vertex by using the following gllightmodeli(gl_light_model_local_viewer,gl_true); By default this is set to GL_FALSE Front and Back Faces Each polygonal face in a model had two sides. When modelling we tend to think of these sides as inside and outside surfaces. The convention is to list the vertices of a face in counterclockwise (CCW) order as seen from the outside of the object OpenGL has no notion of inside or outside; it can only distinguish between front faces and back faces A face is a front face is its vertices are listed in CCW order as seen by the eye.

Front and Back Faces For an object that encloses some space, all faces that are visible to the eye are front faces. If one face is removed so we can see inside the object the inside faces are deemed to be back faces and are thus not shaded but left dark. If we wish for these to be shaded properly we need to reverse the normals for each of the faces inside. To do this we use the following code gllightmodeli(gl_light_model_two_side,gl_true) By default this value is set to GL_FALSE Note that faces drawn by OpenGL do not cast shadows, so all of the back faces receive the same light from the source, even thought there may be some other face between them and the light source. Moving a Light Source. Light sources pass through the model view matrix just as vertices do. Therefore light sources can be re-positioned by suitable uses of glrotated and gltranslated. The array pos[] specified by using gllightfv(gl_light0,gl_position,pos); is modified by the model view matrix that is in effect at the time gllightfv is called So to modify the position of the light with transformations and independently move the camera we embed the light positioning command in a push-pop pair as in the following code Moving a Light Source. 1 void Display() 2 { 3 GLfloat pos[]={2,1,3,1}; 4 5 glmatrixmode(gl_modelview); 6 glloadidentity(); 7 glpushmatrix(); 8 glrotated(...); //move light 9 gltranslated(...); // 10 gllightfv(gl_ligt0,gl_position,pos); 11 glpopmatrix(); 12 13 14 glulookat(..); //set the camera 15 16 // draw obj 17 18 glutswapbuffers(); 19 } Moving a light To have a light move with a camera we use the following code. 1 GLfloat pos[]={0,0,0,1}; 2 3 glmatrixmode(gl_modelview); 4 5 glloadidentity(); 6 7 gllightfv(gl_light0,gl_position,pos); 8 9 glulookat(...); //move the light and the camera

Material Properties and OpenGL You can only see the effect of a light source when light reflects off an object's surface. OpenGL allows the programmer to set the reflection coefficients that appear in the lighting equations (effectively the material properties) These coefficients are set with variations of the function glmaterial, and they can be specified individually for front and back faces. face glmaterialfv 1 void glmaterialfv( GLenum face, GLenum pname, GLfloat param ); glmaterialfv allows us to set the material parameters The first parameter of glmaterialfv() can take the following values GL_FRONT GL_BACK GL_FRONT_AND_BACK Usage Set the reflection coefficient for the front faces Set the reflection coefficient for the back faces Set the reflection coefficient for both the front and back faces Param GL_AMBIENT GL_DIFFUSE GL_SPECULAR GL_AMBIENT_AND_DIFFUSE GL_EMISSIVE glmaterialfv Usage Set the ambient reflection coefficients Set the diffuse reflection coefficients Set the specular reflection coefficients Set the ambient and diffuse reflection coefficients Set the emissive reflection coefficients, this causes the face to have a glow in a particular colour without a light being turned on. OpenGL Lighting Model Equation I r = e r + I mr ρ ar + i atten i spot i (I i arρ ar + I i drρ dr lambert i + I i sprρ sr phong f i ) Expressions for the Green and blue are similar. The emissive light is er and Imr is the global ambient light. The summation indicates that the contribution of all the sources (i indicating the index) is added to the final value.

Flat and Smooth Shading In the modelling process, we attach a normal vector to each vertex of each face. If a certain face is to appear as a distinct polygon we attach the same normal vector to all of its vertices; The normal vector chosen is that indicating the direction normal to the plane of the face If the face is supposed to approximate an underlying surface, we attach to each vertex the normal to the underlying surface at that point. The main distinction between shading models is how they paint the individual polygons. Flat shading gives all polygons the same colour, where as smooth shading tries to de-emphasize the edges between the polygons Flat Shading When a face is flat and the light sources are quite distant, the diffuse light component varies little over different points on the roof. In such cases, it is reasonable to use the same colour for every pixel covered by the face. OpenGL provides a rendering mode that does this with the following command glshademodel(gl_flat); Smooth Shading Smooth shading attempts to de-emphasize edges between faces by computing colours at more points on each face OpenGL only does Gouraud shading as part of the fixed functionality pipeline. OpenGL >2.0 supports Vertex/Fragment Shaders which will be able to apply user defined shading to each vertex Gouraud Shading Computationally Gouraud shading is slightly more expensive than than flat shading. To enable Gouraud shading in OpenGL we use glshademodel(gl_smooth); The above figure shows that the buckyball remains the same as in flat shading mode, however the sphere now looks smooth. There are no abrupt jumps in colour between neighboring faces, and the edges of the faces (and the Mach bands) are gone. However along the silhouette, we can still see the bounding edges of the individual faces.

Transparency OpenGL uses blending to create the effect of transparency. With blending enabled the alpha value is used to combine the colour value of the current fragment being processed with the pixel value stored in the framebuffer. During blending the colour values of the incoming fragment (source) are combined with the values of the corresponding currently stored pixels (destination) The way the blending occurs is based on the glbendfunc set by the programmer. it must be enabled using glenable(gl_blend); glblendfunc( GLenum sfactor, GLenum dfactor); the sfactor and dfactor specifies how the blending functions are calculated as shown in the following table Constant factor Computed blend Factor GL ZERO src / dest (0,0,0,0) GL ONE src / dest (1,1,1,1) GL DST COLOR src (R d,g d,b d,a d ) GL SRC COLOR dest (Rs,Gs,Bs,As) GL ONE MINUS DST COLOR src (1, 1, 1, 1) (R d,g d,b d,a d ) GL ONE MINUS SRC COLOR dest (1, 1, 1, 1) (Rs,Gs,Bs,As) GL SRC ALPHA src / dest (As,As,As,As) GL ONE MINUS SRC ALPHA src / dest (1, 1, 1, 1) (As,As,As,As) GL DST ALPHA src / dest (A d,a d,a d,a d ) GL ONE MINUS DEST ALPHA src / dest (1, 1, 1, 1) (A d,a d,a d,a d ) GL SRC ALPHA SATURATE src (f,f,f,f); f=min(as, 1 A d ) GL CONSTANT COLOR src / dest (Rc,Gc,Bc,Ac) GL ONE MINUS CONSTANT COLOR src / dest (1,1,1,1)-(Rc,Gc,Bc,Ac) GL CONSTANT ALPHA src / dest (Ac,Ac,Ac,Ac) GL ONE MINUS CONSTANT ALPHA src / dest (1,1,1,1)-(Ac,Ac,Ac,Ac) Fog As images can seem too sharp and well defined especially with distant object OpenGL allows the user to make distant images fade into a background colour by using fog. To enable Fog glenable(gl_fog); is used Fog then blends a fog colour with an incoming fragment's colour by using one of three equations f = e (density z) (GL EXP) f = e (density z)2 (GL EXP2) Fog 2 1 GLfloat fogcolour[4]={0.5,0.5,0.5,1.0}; 2 3 glfogi(gl_fog_mode,gl_exp); 4 5 glfogfv(gl_fog_color,fogcolour); 6 7 glfogf(gl_fog_density,0.35); 8 9 glhint(gl_fog_hint,gl_dont_care); 10 11 glfogf(gl_fog_start,1.0); 12 13 glfogf(gl_fog_end,5.0); f = end z end start (GL LINEAR)

References Computer Graphics With OpenGL, F.S. Hill jr, Prentice Hall Shreiner Et Al OpenGL Programming Guide: The Official Guide to Learning OpenGL Foley & van Dam Computer Graphics: Principles and Practice in C (2nd Edition) (Redbook online) http://fly.cc.fer.hr/~unreal/ theredbook/