CS 352: Computer Graphics - PowerPoint PPT Presentation

1 / 40
About This Presentation
Title:

CS 352: Computer Graphics

Description:

OpenGL supports auto. generation of texture. mapping coordinates ... Texture map with tree image. Use alpha to 'cut away' hollow parts ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 41
Provided by: HarryPl6
Category:

less

Transcript and Presenter's Notes

Title: CS 352: Computer Graphics


1
CS 352 Computer Graphics
Chapter 7 Discrete Techniques
2
(No Transcript)
3
(No Transcript)
4
(No Transcript)
5
Applications
  • How do you do all those nice object textures?
  • Brick pattern on a walkway. How to give it some
    depthmodel the bricks? Model the roughness of
    the brick surface?
  • Pool-like water patterns, caustics
  • Fog. How?
  • 3D scan of artifacts. Digital flattening
  • Data an image and many (x, y, z, u, v) points
  • How to digitally flatten an artifact such as a
    crumpled vellum leaf?
  • How to undo the lighting?

6
Overview
  • Texture mapping
  • Bump mapping
  • Reflection or environment mapping
  • Bit and pixel operations in OpenGL
  • Compositing
  • Blending
  • Antialiasing
  • Depth cueing and fog
  • Using the accumulation buffer

7
The Joy of Frame Buffers
  • For decades, and until recently, shape only no
    access to frame buffer
  • Access to frame buffer and operations on
    fragments have made enormous difference in
    interactive graphics
  • Applications texture mapping, antialiasing,
    compositing, transparency, fog, accumulation
    buffering,
  • Silicon Graphics/GL first real texture-mapping
    systems. Major advance.

8
OpenGL frame buffer
  • The OpenGL frame buffer actually consists of
    many separate buffers

9
Fragment processing
  • These various buffers are accessed during
    fragment processing

10
Reading and writing buffers
  • Typically done in rectangular bit blocks with
    bit-block transfer operations (bitblt), such as
    write_block(source, n, m, x, y, destination, u, v)

11
Setting active buffers
  • OpenGL lets you sent the present drawing buffer
    and present reading buffer
  • glDrawBuffer() // default back color buffer
  • glReadBuffer()
  • Pixels can be read or written
  • glReadPixels(x, y, w, h, format, type, image)
  • glDrawPixels(w, h, format, type, image)
  • glCopyPixels(x, y, w, h, type)

12
Drawing an image
  • Native byte order and padding may not match
    OpenGL
  • may have to pack or unpack
  • or alter OpenGLs format with glPixelStore
  • To draw an image into a buffer
  • QImage gl_buffer convertToGLFormat(buffer)
  • glRasterPos2i(0,0)
  • glDrawPixels(buffer.width(), buffer.height(),
    GL_RGBA, GL_UNSIGNED_BYTE,
    gl_buffer.bits())
  • glFlush()

13
Mapping methods
  • Imagine modeling a piece of carved wood, or a
    golf ball, or a spoon, or a tree
  • Rather than modeling the geometry at a very fine
    level of detail, we may prefer discrete methods
  • texture mapping
  • bump mapping
  • environment mapping

14
Texture mapping
  • Texture mapping applying images to rendered
    polygons.
  • A separate texture buffer on the graphics card
    stores texture images
  • Texture pixels are called texels
  • Textures may be 1-, 2-, or 3- (or 4-!)
    dimensional (mapped onto 1-, 2-, or 3-dimensional
    surfaces)
  • The need for texture images is why you have 256MB
    graphics cards (and repetitive patterns!)

15
Mapping geometry
  • Texture mapping rendering polygons by applying
    images with mapped geometry
  • (s,t) texture coordinates
  • T(s,t) texture
  • x(s,t), y(s,t), z(s,t) texture map (a mapping
    of texture onto world coords)
  • To render, we really want the inverse map
    s(x,y,z) and t(x,y,z)
  • These can be hard to find in practice!

16
Mapping geometry
  • Also have to map screen coordinates (xs,ys) into
    world coordinates before you can map texture
    coordinates onto world coordinates

17
Other difficulties
  • Consider examples
  • Rendering a face on a sphere how to map?
  • Leaf picture water droplets rubber deformations
  • Zooming way in or way out on a texture-mapped
    object
  • Have to handle
  • Geometry mapping
  • Modifying the geometry map (rubber example)
  • Extreme magnification or minification
  • Antialiasing
  • Render modes decal, replace, modulate (), blend

18
(No Transcript)
19
Texture mapping examples
  • hplantin/public/352/OpenGL/Examples
  • Redbook
  • Check
  • Wrap
  • Mipmap
  • Texbind
  • Texturesurf
  • Examples
  • Mjkwarp
  • Mjkshift
  • Dinoshade
  • Advanced
  • Projtex
  • Textile
  • Texwinalign
  • Texext

20
Texture mapping overview
  • Assume texture image has coordinates (s,t) from
    (0,0) to (1,1)
  • Specify texture coordinates for each vertex
  • To render polygon, find texture colors by
    interpolation over the texture image region
  • Mix texture color with object color
  • Replace just use the texture map color
  • Decal apply lighting to texture mapped point
  • Modulate multiply object color by texture map
  • Blend alpha-blend colors

21
Pixel color from texture map?
  • How do we get the pixels color from the texture
    map?
  • We could map the center of the pixel to the
    texture map and use the color we find
  • But this can result in severe aliasing and
    flickering
  • Better to map the whole pixel and average. But
    wont that be slow?

22
Mipmaps
  • Make pre-filteredimages of size1x1, 2x2, 4x4,
    , nxn
  • Choose the best

23
Texture mapping in OpenGL
  • Steps
  • Create texture object and specify texture image
    for the object
  • Indicate how the texture is to be applied to each
    pixel (set texture mapping parameters)
  • Enable texture mapping
  • Draw the scene, supplying both texture and
    geometric coordinates for each vertex
  • Works only in RGBA mode
  • Example checker.c

24
Creating a texture
  • Synthesize
  • Glubyte checkImagewidthheight3
  • glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
  • set values
  • or read
  • Use QTs load image and convert-to-gl-format
    functions
  • Define as OpenGL texture
  • glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height,
    0, GL_RGB, GL_UNSIGNED_BYTE, checkImage000)

25
glTexImage2D parameters
  • glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height,
    0, GL_RGB, GL_UNSIGNED_BYTE, checkImage000)
  • glTexImage2D(target, level, internalFormat,
    width, height, border, format, type, texels)
  • Target texture or texture proxy for size
    testing
  • Level 0, unless you are mipmapping
  • internalFormat 0..3 or one of 38 formats, e.g.
    GL_LUMINANCE6_ALPHA2, GL_RGB (3)
  • Border 0 (no border) or 1 (border)
  • Width, height must be 2m 2b
  • Format, type of texture image

26
Texture mapping parameters
  • Wrapping glTexParameterf
  • (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
    // or GL_REPEAT
  • Filtering
  • glTexParameterf(GL_TEXTURE_2D, GL_MAG_FILTER,
    GL_LINEAR) // or GL_NEAREST (severe artifacts)
  • Perspective correction glHint(GL_PERSPECTIVE_CORR
    ECTION_HINT, GL_NICEST) // or GL_FASTEST
  • Texture mode
  • glTexEnvi(GL_TEX_ENV, GL_TEX_ENV_MODE,
    GL_DECAL)// or GL_REPLACE, GL_MODULATE,
    GL_BLEND
  • glEnable(GL_TEXTURE_2D)

27
Draw the scene
  • glBegin(GL_QUADS)
  • glTexCoord2f(0.0, 0.0) glVertex3f(-2.0, -1.0,
    0.0)
  • glTexCoord2f(0.0, 1.0) glVertex3f(-2.0, 1.0,
    0.0)
  • glTexCoord2f(1.0, 1.0) glVertex3f(0.0, 1.0,
    0.0)
  • glTexCoord2f(1.0, -1.0) glVertex3f(0.0, -1.0,
    0.0)
  • glEnd()

28
Mipmaps
  • You can create mipmap levels individually if you
    really want to (see mipmap.c)
  • Or, create them automatically using
  • gluBuild2DMipmaps(target, iformat, width, height,
    format, type, texels)
  • // parameters same as glTexImage2d()
  • Additional glTexParameter types
  • GL_NEAREST_MIPMAP_NEAREST
  • GL_LINEAR_MIPMAP_NEAREST
  • GL_NEAREST_MIPMAP_LINEAR
  • GL_LINEAR_MIPMAP_LINEAR

29
Handling multiple textures
  • Using multiple texture objects
  • Generate texture names
  • Bind texture objects to texture data (including
    wrap mode and filtering parameters)
  • See if you have enough high performance texture
    space (or establish texture priorities)
  • Bind the texture you want to use, then draw
  • Example texbind.c

30
Texture map fonts
  • If you have many shapes to draw, such as a font
    face, you can store as texture maps

31
Environment Maps
  • A form of texture mapping
  • Compute image of environment
  • Map to surface of object
  • OpenGL supports autogeneration of
    texturemapping coordinates
  • glTexGenfv(GL_S, GL_SPHERE_MAP, 0)
  • glTexGenfv(GL_T, GL_SPHERE_MAP, 0)
  • glEnable(GL_TEXTURE_GEN_S)
  • glEnable(GL_TEXTURE_GEN_T)

32
Bump Maps
  • Simulate localvariations in shape
  • Vary lighting byperturbing the surface normals
  • Lighting does the rest
  • Bump map an image or array of normal
    variations (in two directions)

33
Buffer reads and writes
  • You can read and write buffers
  • Color (normal drawing buffers)
  • Depth (for hidden surface removal)
  • Stencil (masking e.g. screendoor transparency)
  • Accumulation (antialiasing, image processing)
  • 16 buffer write modes set, clear, copy, or, and,
    xor, nand, invert, copy_inverted, etc.
  • Can magnify, reduce, flip, fog, blend, gamma
    correct, modify colors, dither, histogram, add,
    multiply, do screendoor transparency

34
Anti-Aliasing
  • Render an image multiple times with a jittered
    viewpoint
  • Average them in the accumulation buffer

35
Screen-door transparency
  • Alpha-blending and z-buffering dont work
    together
  • blending depends on order of polygons rendering
  • Z-buffering allows arbitrary polygon order
  • How to get quick transparency effects?
  • Screen door approach put a pattern with a
    set percent coverage into the stencil buffer
    and render.
  • Even works with many layers (but use different
    patterns)

36
Colors for Picking
  • How can you determine from a click on an image
    which object was selected?
  • One method pseudo-colored image
  • Render image of scene in off-screen bitmap
  • Use false colors unique solid color for each
    object
  • Determine color of point clicked this gives
    object

37
Compositing
  • Forest Gump how?
  • Motion capture actors for crowd scenes
  • Actors are worried about losing work
  • Compositing the general term for combining
    different images or video sequences using alpha
    blending, mattes, etc.

38
Blending in OpenGL
  • Steps
  • Use colors with alpha values
  • Enable blending
  • Set a blending function
  • glEnable(GL_BLEND)
  • glBlendFunc(source_factor, dest_factor)
  • Possible values for source or destination factor
    GL_ONE, GL_ZERO, GL_DST_COLOR, GL_SRC_ALPHA,
    GL_DST_ALPHA, GL_ONE_MINUS_DEST_ALPHA,
    GL_CONSTANT_ALPHA, etc.

39
Blending example
  • To get blend based on alpha of second picture
  • Set source to GL_ONE and dest to GL_ZERO draw
    first picture
  • Set source to GL_SRC_ALPHA and dest to
    GL_ONE_MINUS_SRC_ALPHA draw second picture

40
More uses of blending
  • Paint program airbrush tool
  • Simulate colored filter set R, G, and B alpha
    components separately
  • Billboarding
  • Draw two intersecting rectangles at right angles
  • Texture map with tree image
  • Use alpha to cut away hollow parts
Write a Comment
User Comments (0)
About PowerShow.com