Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


computer Graphics (open GL)

No description

Maaz Irfan

on 19 January 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of computer Graphics (open GL)

OpenGL functions used for lighting and shading
• In OpenGL the normal vector is part of the state
• Set by
-glNormal3f(x, y, z);
• Usually we want to set the normal to have unit
length so cosine calculations are correct
- Length can be affected by transformations
- Note that scaling does not preserved length
allows for
autonormalization at a performance penalty
• Shading calculations are enabled by
- Once lighting is enabled, glColor() ignored
• Must enable each light source individually
• Can choose light model parameters
-glLightModeli(parameter, GL_TRUE)
computer Graphics (open GL)
BY Maaz 'Gl'

Discuss the creation of light source in OpenGL.
Discuss the types of light sources that can be created in OpenGL.
In OpenGL Shading language you can access built in OpenGL lighting states. Implementing an advanced lightning model would be compatible with standard OpenGL statements.•
For each light source, set
•RGBA for diffuse, specular, ambient
•positionGL float diffuse0[]={1.0, 0.0, 0.0, 1.0};
GL float ambient0[]={1.0, 0.0, 0.0, 1.0};
GL float specular0[]={1.0, 0.0, 0.0, 1.0};
Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0};
glLightv(GL_LIGHT0, GL_POSITION, light0_pos);
glLightv(GL_LIGHT0, GL_AMBIENT, ambient0);
glLightv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
glLightv(GL_LIGHT0, GL_SPECULAR, specular0);
What is meant by material properties of an object? Discuss its effect with light.
this defines the reaction of an object when its surface is hit with the light . for example some objects absorbs a particular colours or reflection light. usually when the lighting is enable it is equally likely to assign material properties with it
the material properties of an object (defines RGB) color format is usually the colors reflected by that object , the first parameters of the glMaterial fb command indicates which face of the polygon should reflect the light specified by mcolor apparently there are two sides to a polygon front and back open gl provides two way to specify a polygon in 3d space in order to decide the front face
open gl lets you specyfy these rules with the glfront face command the following code denote that counter clockwise direction of the polygon is considerd to be front face
gkFront face (GL.CCW);

Discuss the OpenGL functions used for lighting and shading
Steps in OpenGL shading
1. Enable shading and select model
2. Specify normals
3. Specify material properties
4. Specify lights
Briefly introduce the shading models. Also discuss the flat shading and smooth shading.
In computer graphics, shading refers to the process of altering the color of an object/surface/polygon in the 3D scene, based on its angle to lights and its distance from lights to create a photo realistic effect. Shading is performed during the rendering process by a program called a shader.
Flat shading gives you an edgy and geometric look and keeps the faces of your meshes sharp and clean. Sometimes that’s desirable. The tricky thing with a commonly used mesh is that the normals are usually interpolated between vertices, and in order to render faces with the correct flat normals, you’d have to push the geometry for every face to the mesh individually.
Shading calculations enabled by
­ Once lighting enabled, glColor() ignored
•Must enable each light source individually
-glEnable(GL_LIGHTi) i = 0, 1…..
•Can choose light model parameters
-glLightModeli(parameter, GL_TRUE)
simplifying distant viewer assumption in calculation
•GL_LIGHT_MODEL_TWO_SIDED shades both sides of
polygons independently

In the OpenGL lighting model, the light in a scene comes from several light sources that can be individually turned on and off. Some light comes from a particular direction or position, and some light is generally scattered about the scene. For example, when you turn on a light bulb in a room, most of the light comes from the bulb, but some light comes after bouncing off one, two, three, or more walls. This bounced light (called ambient) is assumed to be so scattered that there is no way to tell its original direction, but it disappears if a particular light source is turned off.

Defining Colors and Position for a Light Source

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
As you can see, arrays are defined for the parameter values, and glLightfv() is called repeatedly to set the various parameters. In this example, the first three calls to glLightfv() are superfluous, since they're being used to specify the default values for the GL_AMBIENT, GL_DIFFUSE, and GL_SPECULAR parameters.

Note: Remember to turn on each light with glEnable().
Light Source Parameters
gl_LightSource[] is a built-in array you can access for all lights. gl_LightSource is defined this way:
struct gl_LightSourceParameters
vec4 ambient; // Aclarri
vec4 diffuse; // Dcli
vec4 specular; // Scli
vec4 position; // Ppli
vec4 halfVector; // Derived: Hi
vec3 spotDirection; // Sdli
float spotExponent; // Srli
float spotCutoff; // Crli
// (range: [0.0,90.0], 180.0)
float spotCosCutoff; // Derived: cos(Crli)
// (range: [1.0,0.0],-1.0)
float constantAttenuation; // K0
float linearAttenuation; // K1
float quadraticAttenuation;// K2

uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
You should put:

As the first thing in your render function, then set the light parameters:

Then set the properties of the material and call the object. All the objects from now on will have this property, if you want to use another material on another object just type:

again, before modeling the second object and so on
Defining a Point Light Source
• For each light source, we can set an RGB for the
diffuse, specular, and ambient parts, and the
GL float diffuse0[]={1.0, 0.0, 0.0, 1.0};
glLightv(GL_LIGHT0, GL_AMBIENT, ambient0);
•Ambient light depends on color of light
to set
- Direction
- Cutoff
- Attenuation
• Proportional to cosαφ
- A red light in a white room will cause a red
ambient term that disappears when the light is
turned off
•OpenGL allows a global ambient term that
is often helpful

Shading calculations are done for each
- Vertex colors become vertex shades
•By default, vertex colors are interpolated
across the polygon
•If we use
color at the first vertex will determine the
color of the whole polygon
Full transcript