0% found this document useful (0 votes)
41 views4 pages

TUTO3

The document outlines the revised coordinate system and discusses the importance of lighting in 3D graphics, specifically in OpenGL. It explains various lighting components such as ambient, diffuse, and specular light, as well as how to define material properties and create light sources. Additionally, it covers animation techniques and buffer swapping for rendering frames in computer graphics.

Uploaded by

simon wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

TUTO3

The document outlines the revised coordinate system and discusses the importance of lighting in 3D graphics, specifically in OpenGL. It explains various lighting components such as ambient, diffuse, and specular light, as well as how to define material properties and create light sources. Additionally, it covers animation techniques and buffer swapping for rendering frames in computer graphics.

Uploaded by

simon wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Revised Coordinate System

in Ass 1 Specification

 Old
Tutorial 3
coordinate
system

 Revised
Yang Rong coordinate
system
2003/01/27

1 2

lighting OpenGL Lighting

 Most objects don’t look 3D until they are lit !  The color of light sources is characterized by amount of
Red, Green, and Blue light they emit
 The material of surfaces is characterized by the
percentage of the incoming R, G, B components that is
reflected in various direction
 The light in the scene comes from several light sources
which can be individually turned on and off
 In OpenGL lighting model, the lighting is divided into four
independent components:
emissive, ambient, diffuse, and specular,
 All four components are computed independently and then
added together
Lit sphere Unlit sphere

3 4
Ambient Light Diffuse Component
 The light that’s been scattered so much by the environment  Come from ne direction
that its direction is impossible to determine
 It seems to come from all directions  Once it hits a surface, it’s scatter equally in all directions
 The object appears equally bright, no matter where the eye is
Backlighting in a room Spotlight outdoors located

 Tiny ambient component


 Large ambient component  Most of the light travels in the same direction
 Light reaches you after bouncing off many surfaces  Very little of the light reaches your eyes after
bouncing off other objects

5 6

Specular light Material Color


 A material’s color depends on the percentages of the incoming R, G,
 Comes from a particular direction B light it reflects
 Tends to bounce off the surface in a preferred direction  Materials also have different ambient, diffuse, and specular colors
 Think of specularity as shininess  Determine the ambient, diffuse, and specular reflectance (values
betwwen 0 and 1) of the material
E.g. A laser beam bouncing
off a mirror produces
almost 100 percent Define color of ambient ambient
combine
specular reflection the material reflectance component

diffuse combine diffuse


reflectance component
Usually white or gray,
simulate white
shining on object specular combine
specular
reflectance component
material lighting

7 8
RGB Values
Creating Light Sources
for Lights and Materials
 For light, RGB numbers correspond to a percentage of glLight{if}(Glenum light, Glenum pname, TYPE param )
full intensity for each color glLight{if}v(Glenum light, Glenum pname, TYPE *param )
R=1, G=1, B=1 R=0.5, G=0.5, B=0.5 light 0, light 1,…, light 7
White Still white, half intensity, so appear gray Parameter name Indicate parameter values
 For material, RGB numbers correspond to the reflected RGBA intensity of the ambient light RGBA color of the diffuse light that
proportions of RGB component from incoming light that a light source adds to the scene a light source adds to the scene
“the color of a light”
All the incoming red light
R=1, G=0.5, B=0 Half the incoming green light GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0}; Affects the color of the
Material reflects None of the incoming blue light GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; specular highlight on an object
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; Position the light
Light Component
(LR, LG, LB) glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); Determine the light type
Light arrive at eyes glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
(LR*MR, LG*MG, LB*MB) glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
material Component glLightfv(GL_LIGHT0, GL_POSITION, light_position);
(MR, MG, MB)

9 10

Directional and Positional Lights Defining Material Properties


 Directional light: rays are parallel glMaterial{if}(Glenum face , Glenum pname , TYPE param )
glMaterial{if}v(Glenum face , Glenum pname , TYPE *param )
GLfloat light_position[] ={x, y, z, 0.0);
Which face the material
applies to, GL_FRONT, Property name Desired values of property
GL_BACK,
GL_FRONT_AND_BACK
 Positional light: spotlights
w not equal 0 Parameter Name Meaning
GL_POSITION
GLfloat spot_position[] ={x, y, z, w);
GL_AMBIENT Ambient color of material
GLfloat spot_direction[] ={x’, y’, z’);
GL_DIFFUSE Diffuse color of material
GL_SPOT_CUTOFF glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); GL_AMBIENT_AND _DIFFUSE Ambient and diffuse color of material, have same RGBA values
glLightfv(GL_LIGHT0, GL_POSITION, GL_SPECULAR Specular color of material, highlight produced by reflection
spot_position);
GL_SHININESS Specular exponent,control the size and brightness of the
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, highlight
GL_SPOT_DIRECTION spot_direction);
Emission color of material, make an object appear to be giving
GL_EMISSION off light of that color

11 12
Example Animation
 Computer graphics screen typically refresh 60 to 70 t/s
No ambient reflection  Each frame is complete when it is displayed
 Double-buffering – two complete color buffers
 One is displayed while the other is calculating next scene to be
drawn
gray ambient reflection
 When the drawing of the next frame is completed, the two
buffers are swapped

blue ambient reflection Computing


Frame 2 Motion =
Swap Frame 1
buffer Redraw + Swap

Blue diffuse Blue diffuse Blue diffuse Blue diffuse


Computing Computing
No specular white specular white specular No specular Frame 3 ……
Low shininess high shininess Emission Frame 2
Buffer 1 Buffer 2

13 14

Swap_the_buffer() Example
glutSwapBuffers(void) glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE|
Idle time after the Swapping GLUT_DEPTH);
buffers is used to do Double buffer display mode,
calculations set in main routine

glutIdleFunc(function name) void display(void)


{
Define which function will be glClear(GL_DEPTH_BUFFER_BIT
called at idle time |GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(0.0f, 0.0f, 1.0f);
void spinDisplay(void) glTranslatef(0.0f, 0.0f, -5.0f);
{ glutIdleFunc(spinDisplay) glTranslatef(0.0f, 1.0f, 0.0f);
angle+=1; glRotatef(45.0f, 1.0f, 1.0f, 0.0f);
if(angle>360) angle-=360; update glRotatef(angle, 0.0f, 1.0f, 0.0f );
glutPostRedisplay(); glutSolidCube(1.0);
}
Idle function called at idle glutSwapBuffers();
time }

15 16

You might also like