SEM023CD3018 Advanced Computer Graphics - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

SEM023CD3018 Advanced Computer Graphics

Description:

Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors) Smooth surfaces show specular highlights due to incoming light being reflected ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 29
Provided by: Abir
Category:

less

Transcript and Presenter's Notes

Title: SEM023CD3018 Advanced Computer Graphics


1
SEM023/CD3018 Advanced Computer Graphics
  • Lecture 7- Lighting and shading
  • Friday
  • Lecture 1200 1300, Room 3.08
  • Lab/Tutorials 1300 1500, Lab 6.16/6.20
  • Lecturer Dr Abir Hussain
  • Room 633, a.hussain_at_ljmu.ac.uk

2
Todays lecture
  • The basics of lighting and shading
  • Normal calculations
  • Shading models
  • (some of the materials are taken from Angels
    book)

3
Why we need shading
  • Suppose we build a model of a sphere using many
    polygons and colour it with glColor. We get
    something like
  • But we want

4
Shading
  • Why does the image of a real sphere look like
  • Light-material interactions cause each point to
    have a different color or shade
  • Need to consider
  • Light sources
  • Material properties
  • Location of viewer
  • Surface orientation

5
Scattering
  • Light strikes A
  • Some scattered
  • Some absorbed
  • Some of scattered light strikes B
  • Some scattered
  • Some absorbed
  • Some of this scattered
  • light strikes A
  • and so on

6
Simple Light Sources
  • Spotlight
  • Restrict light from ideal point source
  • Ambient light
  • Same amount of light everywhere in scene
  • Can model contribution of many sources and
    reflecting surfaces

7
Surface Types
  • The smoother a surface, the more reflected light
    is concentrated in the direction a perfect mirror
    would reflected the light
  • A very rough surface scatters light in all
    directions

rough surface
smooth surface
8
Phong Model
  • A simple model that can be computed rapidly
  • Has three components
  • Diffuse
  • Specular
  • Ambient
  • Uses four vectors
  • To source
  • To viewer
  • Normal
  • Perfect reflector

9
Normal vector
  • REMINDER
  • The first important data value in any lighting
    and shading algorithm is the Normal Vector
  • This is a line in 3D space that runs at right
    angles ( is orthogonal ) to a point P on the
    polygon to be illuminated
  • For convenience it has length 1

10
Normal vector
  • The different shading models use different points
    on the surface of a polygon to determine how it
    should be lit.
  • We can calculate the Normal Vector and either
  • give it to the glNormal3fv(N) function, or
  • use it in our own calculations to affect the
    shading

11
Plane Normal
  • Equation of plane axbyczd 0
  • The plane is determined by three points p0, p1,
    p2 or normal n and p0
  • Normal can be obtained by

n (p2-p0) (p1-p0)
12
Flat shading
  • For flat shading, as used by setting
    glShadeModel(GL_FLAT), we assume that the polygon
    is equally lit across its surface at all pixels.
    So we just take one vertex of the polygon to
    calculate the normal and thus set the shading for
    that whole polygon
  • The Vertex OpenGL uses depends on the type of
    polygon, e.g.
  • Triangles, Triangle strips, Quads, Quad strips
    and so on

13
Flat shading
All the pixels in the same quad, triangle
or polygon have the same colour value
14
Smooth shading
  • For Smooth Shading, as used by glShadeModel(GL_SMO
    OTH) we interpolate the colour changes in pixels
    across adjoining polygons to make sure that the
    transitions in shading appear more natural
  • However, simple interpolation can have unnatural
    effects as one polygon meets another at a sharp
    boundary
  • This is also known as Gouraud Shading

15
Smooth Shading
  • Phong shading the interpolating by calculating
    the normals for adjoining polygons.
  • It then calculates the average normal vector for
    the point at which the polygons meet.
  • This produces a more accurate transition in
    shading between the adjoining polygons

16
Smooth shading
pixel colour values are re-calculated across a
polygon according to how the light is reflected
from a light source towards the viewer
17
Specular Surfaces
  • Most surfaces are neither ideal diffusers nor
    perfectly specular (ideal reflectors)
  • Smooth surfaces show specular highlights due to
    incoming light being reflected in directions
    concentrated close to the direction of a perfect
    reflection

specular highlight
18
Specular reflection
  • This shading technique uses only ambient and
    diffuse reflections
  • This approach to smooth shading works well for
    objects with a diffuse or matt surface
  • For shiny, metallic objects we need to show the
    highlights
  • These occur when the angle of reflection back to
    the viewer is the same or very near to the angle
    of the light hitting the object

19
Phong Specular Shading
  • The attached code fragment gives a set of
    functions for the Phong shading model to provide
    specular reflection or shininess
  • It takes values for the Eye vector, Light Vector
    and Normal vector and a shininess value and
    calculates the new light intensity at the point
    for the normal vector

20
Uses of shading
  • We can of course use shading directly to
    approximate shading in the real world.
  • However, we can manipulate the normals on a
    surface to give the appearance of surface
    roughness
  • If we displace the normal slightly we can create
    the illusion that the polygons at that point are
    tilted towards or away from the light source

21
Other approaches
  • The shading models we have considered so far are
    local models
  • They only consider the light coming from one or
    more sources, reflecting off one object and
    travelling to the viewpoint
  • They do not consider light bouncing off or
    refracting through other objects

22
Global Effects
shadow
multiple reflection
translucent surface
23
Local vs Global Rendering
  • Correct shading requires a global calculation
    involving all objects and light sources
  • Incompatible with pipeline model which shades
    each polygon independently (local rendering)
  • However, in computer graphics, especially real
    time graphics, we are happy if things look
    right
  • Exist many techniques for approximating global
    effects

24
Global Lighting Models
  • Raytracing traces the light ray as it bounces
    around the scene and adds that information to the
    final pixel value
  • This approach works well for scenes with
    reflective and refractive surfaces

25
Ray tracing
  • Ray tracing traces a ray back from a pixel and
    produces a node in a tree each time a ray
    reflects off or refracts through an object
  • If the ray reflects, its path is followed until
    it hits another object
  • If the ray refracts, a secondary ray is produced
    going through the object
  • This is repeated for a maximum depth of the tree
  • The tree is then traversed and optical laws
    applied to calculate how qualities of the light
    falling on the pixel

26
(No Transcript)
27
Other approaches
  • Radiosity is another approach. This method uses
    the physical laws governing the radiant energy
    transfers within an illuminated scene.
  • However neither Ray tracing nor radiosity are
    currently real-time methods
  • Thus they are reserved for
  • high-quality image rendering or
  • producing high quality series of images for
    animated 3D movies

28
Summary
  • We have looked at the basics of lighting and
    shading and the role that the normal vector plays
    in their calculation
  • Flat, Phong and Gouraud shading remain the most
    used real-time shading methods
Write a Comment
User Comments (0)
About PowerShow.com