1 l
play

1 L Feb-18-04 SMD159, Buffers and Texture Mapping Overview - PDF document

INSTITUTIONEN FR SYSTEMTEKNIK LULE TEKNISKA UNIVERSITET Buffers and Texture Mapping David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E. Angel 1 L Feb-18-04 SMD159, Buffers and Texture Mapping Overview


  1. INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Buffers and Texture Mapping David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E. Angel 1 L Feb-18-04 SMD159, Buffers and Texture Mapping Overview • Buffers - Additional OpenGL buffers - Reading and writing buffers - Blending • Texture mapping - Mapping Methods + Texture mapping + Environmental Mapping + Bump Mapping - Basic strategies + Forward versus backward mapping + Point sampling versus area averaging 2 L Feb-18-04 SMD159, Buffers and Texture Mapping INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Buffers 3 L Feb-18-04 SMD159, Buffers and Texture Mapping 1

  2. Buffer Define a buffer by its spatial resolution ( n x m ) and its depth k , the number of bits/pixel pixel 4 L Feb-18-04 SMD159, Buffers and Texture Mapping OpenGL Buffers • Color buffers - Front - Back - Auxiliary + Undisplayed + System dependent - Overlay + Chroma key animation • Depth • Accumulation - High resolution buffer • Stencil - Holds masks 5 L Feb-18-04 SMD159, Buffers and Texture Mapping Writing in Buffers • Conceptually, we can consider all of memory as a large two- dimensional array of pixels • We read and write rectangular block of pixels - Bit block transfer ( bitblt ) operations • The frame buffer is part of this memory memory source frame buffer (destination) writing into frame buffer 6 L Feb-18-04 SMD159, Buffers and Texture Mapping 2

  3. Writing Model • Read destination pixel before writing source 7 L Feb-18-04 SMD159, Buffers and Texture Mapping Writing Modes • Source and destination bits are combined bitwise • 16 possible functions (one per column in table) XOR replace OR 8 L Feb-18-04 SMD159, Buffers and Texture Mapping XOR mode • Recall from Chapter 3 that we can use XOR by enabling logic operations and selecting the XOR write mode • XOR is especially useful for swapping blocks of memory such as menus that are stored off screen If S represents screen and M represents a menu the sequence S ¨ S ⊕ M M ¨ S ⊕ M ([S ⊕ M] ⊕ M) S ¨ S ⊕ M ([S ⊕ M] ⊕ S) swaps the S and M 9 L Feb-18-04 SMD159, Buffers and Texture Mapping 3

  4. The Pixel Pipeline • OpenGL has a separate pipeline for pixels - Writing pixels involves + Moving pixels from processor memory to the frame buffer + Format conversions + Mapping, Lookups, Tests - Reading pixels + Format conversion 10 L Feb-18-04 SMD159, Buffers and Texture Mapping Raster Position • OpenGL maintains a raster position as part of the state • Set by gl.glRasterPos*() - 2D or 3D position in various forms • The raster position is a geometric entity - Passes through geometric pipeline - Eventually yields a 2D position in screen coordinates - This position in the frame buffer is where the next raster primitive is drawn 11 L Feb-18-04 SMD159, Buffers and Texture Mapping Buffer Selection • OpenGL can draw into or read from any of the color buffers (front, back, auxiliary) • Default to the back buffer Change with gl.glDrawBuffer and gl.glReadBuffer • • Note that format of the pixels in the frame buffer is different from that of processor memory and these two types of memory reside in different places - Need packing and unpacking - Drawing and reading can be slow 12 L Feb-18-04 SMD159, Buffers and Texture Mapping 4

  5. Bitmaps • OpenGL treats 1-bit pixels ( bitmaps ) differently than multi-bit pixels ( pixelmaps ) • Bitmaps are masks which determine if the corresponding pixel in the frame buffer is drawn with the present raster color - 0 fi color unchanged - 1 fi color changed based on writing mode • Bitmaps are useful for raster text fonts 13 L Feb-18-04 SMD159, Buffers and Texture Mapping Raster Color • Same as drawing color set by gl.glColor*() • Fixed by last call to gl.glRasterPos*() gl.glColor3f(1.0, 0.0, 0.0); gl.glRasterPos3f(x, y, z); gl.glColor3f(0.0, 0.0, 1.0); gl.glBitmap(……. gl.glBegin(GL_LINES); gl.glVertex3f(…..) • Geometry drawn in blue • Ones in bitmap use a drawing color of red 14 L Feb-18-04 SMD159, Buffers and Texture Mapping Drawing Bitmaps gl.glBitmap(width, height, x0, y0, xi, yi, bitmap) offset from raster position increments in raster position after bitmap drawn first raster position second raster position 15 L Feb-18-04 SMD159, Buffers and Texture Mapping 5

  6. Pixel Maps • OpenGL works with rectangular arrays of pixels called pixel maps or images • Pixels are in one byte (8 bit) chunks - Luminance (gray scale) images 1 byte/pixel - RGB 3 bytes/pixel • Three functions - Draw pixels: processor memory to frame buffer - Read pixels: frame buffer to processor memory - Copy pixels: frame buffer to frame buffer 16 L Feb-18-04 SMD159, Buffers and Texture Mapping OpenGL Pixel Functions gl.glReadPixels(x,y,width,height,format,type,myimage) type of pixels start pixel in frame buffer size type of image pointer to processor memory byte myimage[512][512][3]; gl.glReadPixels(0,0, 512, 512, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, myimage); gl.glDrawPixels(width,height,format,type,myimage) starts at raster position 17 L Feb-18-04 SMD159, Buffers and Texture Mapping Image Formats • We often work with images in a standard format (JPEG, TIFF, GIF) • How do we read/write such images with OpenGL? • No support in OpenGL - OpenGL knows nothing of image formats - Some code available on Web • Basic plan of attack - Find (write) a class that reads/writes into a standard data structure - Write a translation to a pixel map - Transfer pixel map to OpenGL 18 L Feb-18-04 SMD159, Buffers and Texture Mapping 6

  7. INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Texture Mapping 19 L Feb-18-04 SMD159, Buffers and Texture Mapping Application • Want to: - Map realistic variation onto an object - Limit model complexity • Solution directly map a digital pattern to an object • Example, mapping reflections to Geri’s glasses Image Box texture map Centered on the lens 20 L Feb-18-04 SMD159, Buffers and Texture Mapping The Limits of Geometric Modeling • Graphics cards can render over 10 million polygons per second • But, that is insufficient for many phenomena - Clouds - Grass - Terrain - Skin 21 L Feb-18-04 SMD159, Buffers and Texture Mapping 7

  8. Modeling an Orange • Consider the problem of modeling an orange (the fruit) • Start with an orange-colored sphere - Too simple • Replace sphere with a more complex shape - Does not capture surface characteristics (small dimples) - Takes too many polygons to model all the dimples 22 L Feb-18-04 SMD159, Buffers and Texture Mapping Modeling an Orange (Alternate) • Take a picture of a real orange, scan it, and “paste” onto simple geometric model - This process is texture mapping • Still might not be sufficient because resulting surface will be smooth - Need to change local shape - Bump mapping 23 L Feb-18-04 SMD159, Buffers and Texture Mapping Three Types of Mapping • Texture Mapping - Uses images to fill inside of polygons • Environmental (reflection mapping) - Uses a picture of the environment for texture maps - Allows simulation of highly specular surfaces • Bump mapping - Emulates altering normal vectors during the rendering process 24 L Feb-18-04 SMD159, Buffers and Texture Mapping 8

  9. Texture Mapping Geometric Model Texture Mapped 25 L Feb-18-04 SMD159, Buffers and Texture Mapping Environment Mapping 26 L Feb-18-04 SMD159, Buffers and Texture Mapping Bump Mapping 27 L Feb-18-04 SMD159, Buffers and Texture Mapping 9

  10. Where Does Mapping Take Place? • Mapping techniques are implemented at the end of the rendering pipeline - Very efficient because few polygons pass down the geometric pipeline 28 L Feb-18-04 SMD159, Buffers and Texture Mapping Is It Simple? • Although the idea is simple - Map an image to a surface - There are 3 or 4 coordinate systems involved 2D image 3D surface 29 L Feb-18-04 SMD159, Buffers and Texture Mapping Coordinate Systems • Parametric coordinates - May be used to model curved surfaces • Texture coordinates - Used to identify points in the image to be mapped • World Coordinates - Conceptually, where the mapping takes place • Screen Coordinates - Where the final image is really produced 30 L Feb-18-04 SMD159, Buffers and Texture Mapping 10

  11. Texture Mapping parametric coordinates texture coordinates screen coordinates world coordinates 31 L Feb-18-04 SMD159, Buffers and Texture Mapping Mapping Functions • Basic problem is how to find the maps • Consider mapping from texture coordinates to a point a surface • Appear to need three functions (x,y,z) x = x(s,t) y = y(s,t) t z = z(s,t) • But we really want to go s the other way 32 L Feb-18-04 SMD159, Buffers and Texture Mapping Backward Mapping • We really want to go backwards - Given a pixel, we want to know to which point on an object it corresponds - Given a point on an object, we want to know to which point in the texture it corresponds + Need a map of the form s = s(x,y,z) t = t(x,y,z) • Such functions are difficult to find in general 33 L Feb-18-04 SMD159, Buffers and Texture Mapping 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend