Introduction California State University San Marcos

Document Sample
Introduction California State University San Marcos Powered By Docstoc
					   Advanced Computer
Graphics & Visualization
               Introduction & Background

                                Xiaoyu Zhang



Springl 2003            Cal State San Marcos
What is Computer Graphics?
    Imaging = representing 2D images
    Modeling = representing 3D objects
    Rendering = constructing 2D images from 3D
     models
    Animation = simulating changes over time




Springl 2003            Cal State San Marcos
  2D Graphics




                                               Sprites in games: Images are
Compositing in movies: images are              built by overlaying characters
created in layers, and then combined           and objects on a background
  Springl 2003                Cal State San Marcos
Computer Graphics in Movies




                                      • High quality and artistry
                                      • Big budgets
                                      • Complicated models and high
                                        quality rendering




                                        (adapted from MIT CS 6.837)
Springl 2003   Cal State San Marcos
Video Games
  • Focus on interactivity
  • Cost-effective solution
  • High tuned for performance
  • Drive the commodity graphics hardware technology




                                                       (adapted from MIT CS 6.837)
Springl 2003                    Cal State San Marcos
Computer Aided Design




     • Reduces the design cycle
     • Drives the high-end hardware market




                                                         (adapted from MIT CS 6.837)

 Springl 2003                     Cal State San Marcos
  Medical Imaging




• Emphasize precision and correctness
• Focus on presentation and interpretation
 of data
• Construction of models from acquired data



  Springl 2003                      Cal State San Marcos   (adapted from MIT CS 6.837)
Scientific Visualization




  • Handles vast amount of data
  • Requires high-performance computation and graphics


                                                         (adapted from MIT CS 6.837)

Springl 2003                    Cal State San Marcos
Background
    Image Processing
          Basic signal processing
          Filtering, re-sampling, anti-aliasing
    Rendering
          Polygon rendering pipeline
          Ray tracing
    Modeling
          Basic 3D object representations
    Animation
          Basic principles
Springl 2003                      Cal State San Marcos
What to Cover?
    Rendering
          Lighting models
          Global illumination (high quality rendering)
              Ray tracing
              Radiosity
          Visibility
    Modeling
          Polygonal meshes
          Spline and subdivision surfaces
          Volumetric and implicit surfaces
    Animation
          Kinematics
          Procedural and physics based methods
    Visualization
          Introduction to surface and volume visualization techniques


Springl 2003                            Cal State San Marcos
Review
    Display
    Color
    Graphics pipeline and hardware




Springl 2003          Cal State San Marcos
Calligraphic and Raster
Display
    Calligraphic Display Devices draw polygon and
     line segments directly:
          Plotters
    Raster Display Devices represent an image as a
     regular grid of samples.
          Each sample is usually called a pixel, or less commonly, a
           pel.
          Both are short for picture element.
          Rendering requires rasterization algorithms to quickly
           determine a sampled representation of geometric
           primitives.
Springl 2003                     Cal State San Marcos
What is a pixel?
    A pixel is not...
          a box
          a disk
          a teeny tiny little light
    A pixel is a
     point...
          it has no dimension
          it occupies no area
          it can have a coordinate

     A pixel is more than just a
     point, it is a sample

Springl 2003                           Cal State San Marcos
Pixel Grids
    Pixel Centers: Address pixels by integer coordinates (i, j)
    Pixel Center Grid: Set of lines passing through pixel centers
    Pixel Domains: Rectangular Semi-open areas surrounding
     each pixel center

    Pixel Domain Grid: Set of lines formed by domain boundaries




               Pixel center grid                          Pixel domain grid
Springl 2003                       Cal State San Marcos
Picturing an Image as a 2D
Function
    An ideal image can be viewed
     as a function, I(x, y), that gives
     an intensity for any given
     coordinate (x, y). We could plot
     this function as a height field.
     This plot would lowest at dark
     points in the image and
     highest at bright points.




Springl 2003                      Cal State San Marcos
Sampling an Image
    An image is actually a
     sample of the function
     at the pixel locations.
    Pixels are stored in
     memory as arrays of
     numbers representing
     the intensity of the
     underlying function
    Insufficient sampling
     causes aliases
Springl 2003              Cal State San Marcos
How a Monitor Works
    Raster Cathode Ray Tubes (CRTs) are the most common display
     device
          Capable of high resolution.
          Good color fidelity.
          High contrast (100:1).
          High update rates.
    Electron beam scanned in regular pattern of horizontal scan lines.
    Raster images are stored in a frame buffer.
    Frame buffers are composed of VRAM (video RAM).
    VRAM is dual-ported memory capable of
          Random access
          Simultaneous high-speed serial output: built-in serial shift register can
           output entire scan line at high rate synchronized to pixel clock.
    At each pixel in scan line, intensity of electron beam modified by the
     pixel value being shifted synchronously out of VRAM.


Springl 2003                             Cal State San Marcos
Color CRT
    Color CRTs have three different colors of phosphor and three independent
     electron guns.
    Shadow Masks allow each gun to irradiate only one color of phosphor.
    Color is specified either
          Directly, using three independent intensity channels, or
          Indirectly, using a Color Lookup Table (LUT).
    In the latter case, a color index is stored in the frame buffer.




Springl 2003                               Cal State San Marcos
True-Color Frame Buffers




    Each pixel requires at least 3 bytes. One byte for
     each primary color.
    Each pixel can be one of 2^24 colors
Springl 2003              Cal State San Marcos
Indexed Frame buffers




    Each pixel uses one byte
    Each byte is an index into a color map
    Color-map Animations
    Each pixel may be one of 2^24 colors, but only 256 color be
     displayed at a time
Springl 2003                 Cal State San Marcos
Single Buffering Raster Displays




    Display synchronized with CRT sweep
    Special memory for screen update
    Pixels are the discrete elements displayed
    Generally, updates are visible




Springl 2003                     Cal State San Marcos
Double Buffering




    Adds a second frame buffer
    Swaps during vertical blanking
    Updates are invisible


Springl 2003             Cal State San Marcos
Elements of Color




Springl 2003   Cal State San Marcos
Light
    Light is electromagnetic wave in the visible
     spectrum




Springl 2003             Cal State San Marcos
Light intensity and brightness
    Intensity describes the physical amount of
     energy, brightness describes our perception
     of this energy
    Our perception of light is function of our eyes,
     which performs numerous unconscious
     corrections and modifications.
          For example, the equal densities of colored light
           are perceived as being of different brightness
           depending on the color.
Springl 2003                  Cal State San Marcos
Seeing in Color
    The eye contains rods and cones
              Rods work at low light levels and do not see color
                   That is, their response depends only on how many photons, not
                    their wavelength
              Cones come in three types (experimentally and genetically
               proven), each responds in a different way to frequency
               distributions




Springl 2003                            Cal State San Marcos
Color receptors
    There are three types of
     cones, referred to as S, M,
     and L.
    They are roughly equivalent
     to blue, green, and red
     sensors, respectively.
    Their peak sensitivities are
     located at approximately
     430nm, 560nm, and 610nm
     for the "average" observer



Springl 2003                  Cal State San Marcos
Trichromacy
    By experience, it is possible
     to match almost all colors
     using only three primary
     sources - the principle of
     trichromacy
    In practical terms, this
     means that if you show
     someone the right amount
     of each primary, they will
     perceive the right color
    This was how
     experimentalists knew there
     were 3 types of cones
Springl 2003                  Cal State San Marcos
The Math of Trichromacy
    Write primaries as R, G and B
              We won’t precisely define them yet
    Many colors can be represented as a mixture
     of R, G, B: M=rR + gG + bB (Additive
     matching)
    Gives a color description system - two people
     who agree on R, G, B need only supply (r,
     g, b) to describe a color

Springl 2003                    Cal State San Marcos
Color Matching
    Given a spectrum, how do
     we determine how much
     each of R, G and B to use
     to match it?
    First step:
              For a light of unit intensity
               at each wavelength, ask
               people to match it with R,
               G and B primaries
              Result is three functions,
               r(), g() and b(), the RGB
               color matching functions

Springl 2003                           Cal State San Marcos
Computing the Matching
    The spectrum function that we are trying to match,
     E(), gives the amount of energy at each wavelength
    The RGB matching functions describe how much of
     each primary is needed to match one unit of energy
     at each wavelength
    Hence, if the “color” due to E() is E, then the match
     is:




Springl 2003              Cal State San Marcos
Alpha
    Basic idea: Encode opacity information in the
     image
    Add an extra channel, the alpha channel, to
     each image
              For each pixel, store R, G, B and Alpha
              alpha = 1 implies full opacity at a pixel
              alpha = 0 implies completely clear pixels
    Images are now in RGBA format, and
     typically 32 bits per pixel (8 bits for alpha)

Springl 2003                     Cal State San Marcos
 Compositing
    Interpret  to represent the fraction of the pixel area
     covered by an object
          We’ll see ways of deciding how much background shows
           through when images are combined
    If the foreground pixel has  = 1 (non-transparent),
     the final pixel is taken from the foreground image.
     Otherwise we need to blend the foreground and
     background images.
    A blending of two images, the resulted pixel value is
     a linear combination of the two component pixels


Springl 2003                   Cal State San Marcos
Alpha Blending
    Alpha blending simulates
     the effect of transparency
    Adds one channel to each
     pixel [r, g, b, α]
    Usually process layers
     back-to-front (using the over
     operator)
    255 or 1.0 indicates an
     opaque pixel
    0 indicates a transparent
     pixel
    Result is a function of
     foreground and background
     pixel colors

Springl 2003                  Cal State San Marcos
Alpha Compositing Details
    Definition of the Over compositing operation:
    αresultcresult = αfg cfg + (1 - αfg) αbgcbg
    αresult = αfg + (1 - αfg) αbg
 Associative but not Commutative




Springl 2003                   Cal State San Marcos
 Rendering
• Rendering is the conversion of a 3D scene into a 2D image:




• The scene composed of models in three space.
  Models are composed of primitives, supported by the rendering system.
• Models entered by hand or created by a program.
• The image drawn on monitor, printed on laser printer, or written to a raster in
  memory or a file.
  require us to consider device independence


 Springl 2003                       Cal State San Marcos
Rendering
    Rendering can be done both in hardware or
     software
    Hardware
          Fast
          Interactive
          Lower in realism
    Software
          Slow
          Flexible
          High quality

Springl 2003                  Cal State San Marcos
Rendering Primitives
    Models composed of, or converted to a large number of geometric
     primitives.
    The only rendering primitives typically supported in hardware are
          Points (single pixels)
          Line Segments
          Polygons (often restricted to convex polygons).

    Modeling primitives include these, but also
          Piecewise polynomial (spline) curves
          Piecewise polynomial (spline) surfaces
          Implicit surfaces (quadrics …)
          Other...

    A software renderer may support modeling primitives directly, or may
     convert into polygonal or linear approximations for hardware rendering.


Springl 2003                          Cal State San Marcos
GPU – Programmable
Graphics Card
    Classically, ``model'' to ``scene'' to ``image'' conversion broken into
     finer steps, called the graphics pipeline.
    Part of the pipeline often implemented in graphics hardware to get
     interactive speeds.
    Hardware accelerators begin to support programmable pipelines.
     (NVidia Geforce 3, Geforce 4, ATI Radeon 9700)
          Allow more flexibility in the rendering process
          You can implement your own lightening model or geometric
           transformations to achieve high-quality rendering
          Has more transistors and higher processing power than CPU
          GPU does computations in parallel and can be thought of as a
           programmable single-chip parallel computer
          How to make full use of GPU is a hot research topic.


Springl 2003                        Cal State San Marcos
Graphics Rendering Pipeline




Springl 2003   Cal State San Marcos
Rendering Pipeline Algorithms
    Modeling Transformation
          Convert representations of primitives from local modeling coordinates to the
           world coordinates.
    Lighting
          Calculate the color and shading of a scene by simulating the interaction of
           light with a scene.
    Viewing Transformation
          Convert representations of primitives from the world coordinates to the
           viewing coordinates (eye coordinates).
    Projection Transformation
          Project the 3D scene onto the 2D/3D screen space
    Clipping
          Remove primitives and parts of primitives that are not visible on the display.
    Scan Conversion (Rasterization)
          Convert a projected screen-space primitive to a set of pixels.


Springl 2003                            Cal State San Marcos
Graphics Pipeline
    A number of coordinate systems are used:
      MCS: Modeling Coordinate System.
      WCS: World Coordinate System.
      VCS: Viewer Coordinate System.
      NDCS: Normalized Device Coordinate System.
      DCS or SCS: Device Coordinate System or equivalently
       the Screen Coordinate System.
     Keeping these straight is the key to understanding a rendering
       system.
    Transformation between two coordinate systems
     represented with matrix multiplications.

Springl 2003                 Cal State San Marcos
Local Coordinate Space
    It is easiest to define individual objects in a
     local coordinate system
              For instance, a cube is easiest to define with
               faces parallel to the coordinate axis
    Key idea: Object instantiation
              Define an object in a local coordinate system
              Use it multiple times by copying it and
               transforming it into the global system
              This is the only effective way to have libraries of
               3D objects, and such libraries do exist
Springl 2003                      Cal State San Marcos
Global Coordinate System
    Everything in the world is transformed into one
     coordinate system - the global coordinate system
    Lighting is defined in this space
              The locations, brightness’ and types of lights
    The camera is defined with respect to this space
    Some higher level operations, such as advanced
     visibility computations, can be done here




Springl 2003                         Cal State San Marcos
View Space
    Associate a set of axes with the image plane
       The image plane is the plane in space on which the image
        should “appear,” like the film plane of a camera
       One normal to the image plane
       One up in the image plane
       One right in the image plane
       These three axes define a coordinate system (a rigid body
        transform of the world system)
    Some camera parameters are easiest to define in this space
       Focal length, image size
    Depth is represented by a single number in this space
       The “normal to image plane” coordinate



Springl 2003                  Cal State San Marcos
3D Screen Space
    Transform view space into a cube: [-1,1]×[-
     1,1]×[-1,1]
              The cube is the canonical view volume
              Parallel sides make many operations easier
    Tasks to do:
              Clipping – decide what you can see
              Rasterization - decide which pixels are covered
              Hidden surface removal - decide what is in front
              Shading - decide what color things are
Springl 2003                     Cal State San Marcos
Screen Space
    Also called window space
    Convert the virtual screen into real screen
     coordinates
              Drop the depth coordinates and translate
    The windowing system takes care of this




Springl 2003                    Cal State San Marcos
3D Screen to Window
Transform
    Typically, windows are specified by an origin, width
     and height
              Origin is either bottom left or top left corner, expressed as
               (x,y) on the total visible screen on the monitor or in the
               framebuffer
    This representation can be converted to (xmin,ymin)
     and (xmax,ymax)
    3D Screen Space goes from (-1,-1,-1) to (1,1,1)
              Lets say we want to leave z unchanged
    What basic transformations will be involved in the
     total transformation from 3D screen to window
     coordinates?

Springl 2003                         Cal State San Marcos
3D Screen to Window
Transform

               (1,1)                                         (xmax,ymax)



                                              (xmin ,ymin)

  (-1,-1)

    How much do we translate?
    How much do we scale?

Springl 2003           Cal State San Marcos
3D Screen to Window
Transform

               (1,1)                                         (xmax,ymax)



                                              (xmin ,ymin)

  (-1,-1)




Springl 2003           Cal State San Marcos
Rasterization
    Rasterization is the process of deciding which pixels
     to fill
              Term comes form the regular raster grid pattern for pixels
    Example: line drawing
              Task: Decide which pixels to fill (samples to use) to
               represent a line
              We know that all of the line lies inside the visible region
               (clipping gave us this!)
              Assume slope between 0 and 1, symmetry gives us the
               rest


Springl 2003                          Cal State San Marcos
Line Rasterization
    Line equation y = mx + b
    At each x coordinate i, the y coordinate of the pixel is
     determined as
    Pick pixels closest to the line




Springl 2003                   Cal State San Marcos
Bresenham’s Algorithm
Overview
    Aim: For each x, plot the pixel whose y-value is
     closest to the line
    Given (xi,yi), must choose from either (xi+1,yi+1) or
     (xi+1,yi)
    Idea: compute a decision variable
              Value that will determine which pixel to draw
              Easy to update from one pixel to the next
    Bresenham’s algorithm is the midpoint algorithm for
     lines
              Other midpoint algorithms for conic sections (circles,
               ellipses)

Springl 2003                         Cal State San Marcos
Midpoint Methods
        Consider the midpoint between (xi+1,yi+1) and (xi+1,yi)
        If it’s above the line, we choose (xi+1,yi), otherwise we
         choose (xi+1,yi+1)

       yi+1                                         yi+1

           yi                                             yi

                     xi   xi+1                                      xi   xi+1
                Choose (xi+1,yi)                               Choose (xi+1,yi+1)
Springl 2003                       Cal State San Marcos
Midpoint Decision Variable
    Write the line in implicit form:

    The value of F(x,y) tells us where points are with
     respect to the line
              F(x,y)=0: the point is on the line
              F(x,y)<0: The point is above the line
              F(x,y)>0: The point is below the line
    The decision variable is the value of di =
     2F(xi+1,yi+0.5)
              The factor of two makes the math easier
Springl 2003                         Cal State San Marcos
What Can We Decide?


    di negative => next point at (xi+1,yi)
    di positive => next point at (xi+1,yi+1)
    At each point, we compute di and decide
     which pixel to draw
    How do we update it? What is di+1?


Springl 2003           Cal State San Marcos
Updating The Decision
Variable
    dk+1 is the old value, dk, plus an increment:

    If we chose yi+1=yi+1:

    If we chose yi+1=yi:

    What is d1 (assuming integer endpoints)?

    Notice that we don’t need c any more
Springl 2003                Cal State San Marcos
Bresenham’s Algorithm

    For integers, slope between 0 and 1:
       x=x1, y=y1, d=2dy - dx, draw (x, y)

       until x=x2
                x=x+1
                If d>0 then { y=y+1, draw (x, y), d=d+2y - 2x }

                If d<0 then { y=y, draw (x, y), d=d+2y }

    Compute the constants (2y-2x and 2y ) once at
     the start
       Inner loop does only adds and comparisons

    Only integer arithmetic -> very efficient
Springl 2003                       Cal State San Marcos
Example: (2,2) to (7,6)
                                                 x=5, y=4
7                                                x      y     d
6
5
4
3
2
1
      1        2 3 4   5 6   7 8

Springl 2003                  Cal State San Marcos
Example: (2,2) to (7,6)
                                                 x=5, y=4
7
                                                 x      y     d
6                                                2      2     3
5                                                3      3     1
4                                                4      4     -1
                                                 5      4     7
3
                                                 6      5     5
2                                                7      6     3
1
      1        2 3 4   5 6   7 8

Springl 2003                  Cal State San Marcos
Application Programming
Interfaces
    Application programming interfaces (API) provide access to
     rendering hardware:
      Xlib: 2D rasterization.
      PostScript, PDF: 2D transformations, 2D rasterization
      Phigs+, GL, OpenGL, Direct3D: 3D pipeline
    APIs hide which parts are implemented in hardware by
     simulating missing pieces in software.
    For 3D interactive applications, we might modify the scene or a
     model directly or just the viewing information.
    After each modification, usually the image needs to be
     regenerated.
    We need to consider how to interface to window system in an
     asynchronous and device independent fashion. APIs also
     defined for this task; e.g. GLUT, GLUI, fltk, QT …

Springl 2003                   Cal State San Marcos
Graphics Pipeline Summary
    Properties of the Graphics Pipeline
          Processing is forward-mapping
          Primitives are processed one at a time
          All analytic processing early on




Springl 2003                         Cal State San Marcos
  Ray Tracing
Ray-casting searches along lines of sight, or rays, to determine the
primitive that is visible along it.




  Properties of ray-casting:
     Go through all primitives at each pixel
     Image space sample first
     Analytic processing afterwards
  Springl 2003                     Cal State San Marcos
Readings
    Chap 3, 4, 13




Springl 2003         Cal State San Marcos