High Performance Visualization I Week 4 - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

High Performance Visualization I Week 4

Description:

It uses many variables to determine color, one of them lighting ... This means you can't have a red box that reflects only blue light, that's just weird ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 35
Provided by: cs196
Category:

less

Transcript and Presenter's Notes

Title: High Performance Visualization I Week 4


1
High Performance Visualization I Week 4
  • Instructors
  • Dr. James Sochacki
  • Dr. Ramon Mata-Toledo
  • Lab Instructors
  • Joshua Blake
  • Justin Creasy

2
Review
  • 3D Basics
  • Processing input from keyboard and mouse
  • Homework Terrain with Textures
  • Share? Problems?

3
Today
  • Lighting!
  • Ambient
  • Diffuse
  • Specular
  • Collision Detection
  • Bounding Boxes
  • Advanced
  • Read Data from file
  • Lighting program

4
Lighting
  • Recall that OpenGL determines the color of an
    object not just by its color specification. It
    uses many variables to determine color, one of
    them lighting
  • OpenGL approximates light by assuming it can be
    broken into red, green, and blue components.
  • So color of light sources is determined by amount
    of red, green, and blue in the light.

5
Lighting Cont.
  • An objects color is determined by the amount of
    each color that if reflects
  • A blue box would reflect 100 of blue light
    shined on it, and 0 of red and green light
    shined on it.
  • Under white light or all blue light, this box
    would appear blue, but under all green or all red
    light this box would appear black.

6
Types of lighting
  • Ambient
  • Diffuse
  • Specular
  • Emissive
  • All these are computed separately, and then added
    together.

7
Ambient Light
  • Light that has been scattered so many times by
    the environment that its direction is impossible
    to determine
  • Scatters equally in all directions when it hits a
    surface.
  • GL_AMBIENT (default values differ for light
    sources and materials)

8
Diffuse Light
  • Light that comes from one direction
  • Once it hits a surface it is scattered in all
    directions
  • Any light coming from a specified direction has
    some amount of diffuse light in it.
  • GL_DIFFUSE (default values differ for light
    sources and materials)

9
Specular Light
  • Light that comes from a particular direction and
    bounces off a surface in a particular direction
  • A perfect laser would be 100 specular
  • GL_SPECULAR (default values differ for light
    sources and materials)

10
Examples of specular light
  • Metal or other shiny objects reflect light in a
    very directional manner, and so use lots of
    specular light.
  • Carpet does not reflect light in any direct
    manner, and so has almost no specular light.

11
Emissive Light
  • Like light sources, objects have ambient,
    diffuse, and specular properties.
  • The objects light properties are then combined
    with the light sources properties to produce the
    desired effect.
  • Emissive light is light that is generated solely
    from the object and is unaffected by other light
    sources
  • It also adds no additional light to the scene

12
Specifying your light source
  • Just like specifying color of a object, light
    sources have RGB values.
  • The values range between 0 and 1 and specify the
    intensity of the color
  • So R1, G1, and B1 creates white light
  • R.5, G.5, and B.5 also creates white light,
    but with less intensity.

13
Object light properties
  • An objects specified colors correspond to its
    reflection properties.
  • This means you cant have a red box that reflects
    only blue light, thats just weird

14
Normals
  • A vector that is perpendicular to the surface of
    the polygon
  • Helps determine an objects orientation relative
    to the light source
  • This is sometimes automatic, and sometimes must
    be specified

15
Considerations
  • The default for OpenGL is that only 8 light
    sources can be defined, some versions may allow
    more
  • Lights have many attributes, such as distance
    (lights can be infinitely far away)
  • All of these add considerable calculations to
    your environment and may affect performance
  • One option is to use emissive light because it
    requires very little calculation (desk lamp)

16
Directional Light
  • As mentioned before, light sources can be defined
    to be infinitely far away
  • These are considered directional lights sources
  • A directional light source has parallel rays of
    light

17
Positional Light
  • Positional light sources exist within the scene
  • Their exact position in the scene determine how
    they affect the scene
  • Attenuation can also be a factor
  • Positional lighting is much more complicated,
    both conceptually and computationally

18
Attenuation
  • The amount of decrease in intensity of light over
    a distance
  • Not a factor for directional light
  • Optional for positional light
  • Formula is complicated, so not included in the
    slides
  • Know that ambient, diffuse, and specular light
    are affected equally and that attenuation adds
    greatly to computation

19
Collision Detection
  • Used when creating a physical model in your
    program (when objects shouldnt pass through each
    other)
  • Also useful for making sure the camera doesnt
    pass through an object

20
Methods
  • There is a lot of research on this subject
  • Easy methods
  • Bounding Spheres
  • Bounding Boxes
  • Harder Methods (MATH!)
  • Bounding Volume Trees
  • Proximity queues
  • http//www.cs.unc.edu/dm/collision.html
  • http//www.cosy.sbg.ac.at/held/projects/collision
    /collision.html

21
Bounding Spheres
  • Algorithm
  • Approximate any object as a sphere (point
    radius)
  • Select a pair of objects (point1, radius1,
    point2, radius2)
  • Calculate the distance between the centers
  • Distance SQRT( (point1.x point2.x)2
    (point1.y point2.y)2
    (point1.z
    point2.z)2 )
  • IF distance
  • Collision!
  • Repeat for all other possible object pairs

22
No Collision.
Collision!
23
Bounding Boxes
  • Same concept as bounding spheres
  • IF
  • A.x.max B.x.min A.x.min
  • A.y.max B.y.min A.y.min
  • A.z.max B.z.min A.z.min
  • Collision!

1
3
Object A
4
Object B
2
24
Collision!
No collision.
25
Collide a box and a plane
  • Same as two boxes, except treat the plane as an
    extremely thin box.

26
Implementation
  • Must have logical representation of all objects
    you want to collision detect (including camera!)
  • Must process collision detection algorithm each
    world update
  • Must do something (or not do something) when a
    collision is detected

27
Representation of Objects
  • We already have a simple one
  • Array of height points
  • We know how to convert pointsij into (x,y,z)
    world coordinates.
  • The object on the terrain is a form of
    collision detection.
  • When moving around, it is simple to do bounding
    spheres or boxes to keep the camera from going
    through your object

28
Representation of Objects
  • With more complicated worlds, a more robust
    object management system is needed
  • Arrays or lists of objects
  • Each object can draw itself, and create/compute
    bounding box
  • Simple functions can compare bounding boxes
  • Iterate over your list of objects, get bounds,
    compare, change data as needed
  • Nullify velocity?
  • Reverse velocity?
  • Do physics calculations?
  • Can read/write this world data, save the state of
    the world

29
Reading Data
  • Depending upon the format of your object and data
    needed, you can create a simple table that
    describes the world

30
Reading Data
  • After figuring out what data you need to save,
    write functions to read and write the file
  • ReadConfig(char filename)
  • WriteConfig(char filename)
  • These should save the entire state of the program
  • The state of the program should be contained
    within a data structure (struct or class)

31
Reference
  • Collision detection tutorial
  • http//nehe.gamedev.net/data/lessons/lesson.asp?le
    sson30
  • Lighting tutorial
  • http//www.gamedev.net/reference/articles/article1
    682.asp
  • www.gamedev.net (The Redbook)
  • Chapter 5 for lighting

32
Homework
  • Add Lighting to the Terrain
  • Add at least two lights, one of which should be a
    positional light and move around the environment
    in some way
  • Be able to switch each light on or off separately
    using a toggle key.
  • Makes sure all of your polygons and textures have
    material properties defined
  • Add appropriate collision detection between
    objects
  • Create a data structure to hold the state of the
    program
  • Write functions to save the state of the program
    and read it back in from a config file

33
Homework
  • This is the final week on the terrain program, so
    turn it into a complete product (think of it as
    an independent demo)
  • Should be FULLY COMMENTED

34
Projects
  • Every program will have an introduction paragraph
  • Your Name
  • Course Name
  • Date
  • Project number
  • 1-2 Sentences describing the project
  • Instructions for operating the program (including
    all of the keys and mouse functions) should be in
    the header of the program as well as be printed
    out if the user presses h (for help)
Write a Comment
User Comments (0)
About PowerShow.com