Real World Lighting - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Real World Lighting

Description:

If only green is reflected, red and blue are absorbed, then object ... Interpolate colors at vertices to find color for interior pixels. COMP341 Fall 2002 ... – PowerPoint PPT presentation

Number of Views:10
Avg rating:3.0/5.0
Slides: 25
Provided by: jacky5
Category:
Tags: lighting | pixels | real | world

less

Transcript and Presenter's Notes

Title: Real World Lighting


1
Real World Lighting
Incident Light
Reflected Light
Surface
  • If only green is reflected, red and blue are
    absorbed, then object appears green

2
Lights Reflected Towards Viewer
  • Emissive Light
  • Originate from objects that glow by themselves
  • Reflected Light
  • Reflect part of the incoming light from light
    sources towards the viewer

3
OpenGL Lighting
  • Light source is characterized by the amount of
    RGB emitted
  • Material of surface is characterized by the
    amount of RGB reflected towards the viewer

4
Different Kinds of Light Sources
  • Distant (directional) light source
  • Located infinitely far away
  • Specified as w0
  • Point (positional) light source
  • Specified as w1
  • By default, radiate in all directions
  • Spotlight, radiate within a cone

5
Defining Light in OpenGL
  • glLightifv (Glenum light, Glenum pname, TYPE
    param)
  • light GL_LIGHT0, , GL_LIGHT7
  • pname e.g. GL_AMBIENT, GL_DIFFUSE, GL_POSITION
  • param a pointer to RGBA value, position of
    light, etc

6
Multiple Lights
  • Can support at least 8 lights
  • Each light is identified by constants GL_LIGHTn,
    where n 0, 1, , 7

7
pname in glLight
  • GL_AMBIENT
  • Specifies the ambient RGBA intensities of light
    source
  • GL_DIFFUSE
  • Specifies the diffuse RGBA intensities of light
    source

8
pname in glLight (Cont)
  • GL_SPECULAR
  • Specifies the specular RGBA intensities of a
    light source
  • GL_POSITION
  • Specifies the (x, y, z, w) position of a light
    source

9
Constructing Spotlights
  • glLightif (lightNo, GL_SPOT_CUTOFF, degree)
  • glLightifv (lightNo, GL_SPOT_DIRECTION,
    spot_direction)

10
Switch on the Lights
  • glEnable(GL_LIGHTING)
  • Enable light calculations
  • glEnable(GL_LIGHT0)
  • Turn on a light source
  • glDisable(GL_LIGHT0)
  • Turn off a light source

11
Defining Material in OpenGL
  • glMaterialifv (GLenum face, GLenum pname, TYPE
    param)
  • face GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
  • pname GL_AMBIENT_AND_DIFFUSE, GL_SPECULAR,
    GL_SHININESS
  • param a pointer to the value RGBA value

12
pname in glMaterial
  • GL_AMBIENT
  • Specifies fraction of ambient light reflected
  • GL_DIFFUSE
  • Specifies fraction of diffuse light reflected
  • GL_SPECULAR
  • Specifies fraction of specular light reflected
  • GL_SHININESS
  • Specifies the specular exponent (shininess)

13
Material Properties
  • Ambient light
  • Light being scattered by the environment so much
    that its direction is impossible to determine

14
Material Properties
  • Diffuse
  • Defines the fraction of light scattered into all
    directions
  • Defines the color of the surface

15
Material Properties
  • Specular
  • Defines the fraction of light reflected near the
    mirror reflection direction
  • The shinier the object, the more focused is the
    highlight

16
Rendering Polygonal Mesh
  • Polygonal mesh A collection of
  • Vertices
  • Edges
  • Faces
  • Edge
  • Face

Normal Vector
17
Normal Vector
  • A vector which is perpendicular to a surface at a
    point
  • Determines how the point reflects the incident
    light

18
Normal Vector (Cont)
  • Planar surface (e.g. cube faces)
  • Same normal for entire surface
  • Curved surface
  • Different normals at different points

19
Finding Vertex Normals
  • Compute from analytical representation (e.g.
    Bezier surfaces)
  • Average face normals
  • Special effects, e.g.bump mapping

20
Hints for Building Polygonal Surfaces
  • Consistent polygon orientation
  • Counterclockwise when looking from outside
  • Avoid non-triangular polygons
  • Because they may not be planar
  • Display speed vs quality
  • Small polygons better quality
  • Avoid T-intersections

21
Polygonal mode
  • glPolygonMode(GL_FILL)
  • Shade the interior of polygon
  • glPolygonMode(GL_LINE)
  • Draw the edges of polygon
  • For drawing wireframe model

22
Shading Model
  • Flat shading
  • glShadeModel(GL_FLAT)
  • With a single color for each polygon
  • Smooth shading (Gourand shading)
  • glShadeModel(GL_SMOOTH)
  • Interpolate colors at vertices to find color for
    interior pixels

23
Rendering Polygon
  • glShadeModel(GL_FLAT)
  • glBegin(GL_POLYGON)
  • glNormal3fv(n1)
  • glVertex3fv(v1)
  • glVertex3fv(v2)
  • glVertex3fv(v3)
  • glVertex3fv(v4)
  • glEnd()

v3
v4
n1
v2
v1
24
Rendering Polygon (Cont)
  • glShadeModel(GL_SMOOTH)
  • glBegin(GL_POLYGON)
  • glNormal3fv(n1)
  • glVertex3fv(v1)
  • glNormal3fv(n2)
  • glVertex3fv(v2)
  • glNormal3fv(n3)
  • glVertex3fv(v3)
  • glNormal3fv(n4)
  • glVertex3fv(v4)
  • glEnd()

n3
n2
n4
n1
Write a Comment
User Comments (0)
About PowerShow.com