1 / 45

The Limits of Geometric Modeling

The Limits of Geometric Modeling. Modeling surfaces with complex surface finishes is too complex if we simply try to do it with uniform colored polygons! For example: a book’s cover painting of Mona Lisa. Textured Map Scene. Modeling an Orange. Start with an orange-colored sphere

Télécharger la présentation

The Limits of Geometric Modeling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Limits of Geometric Modeling • Modeling surfaces with complex surface finishes is too complex if we simply try to do it with uniform colored polygons! • For example: • a book’s cover • painting of Mona Lisa

  2. Textured Map Scene

  3. Modeling an Orange • 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

  4. Modeling an Orange • 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

  5. Three Types of Mapping • Texture Mapping • Uses images to fill 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

  6. Texture Mapping geometric model texture mapped

  7. Environment Mapping

  8. Bump Mapping

  9. Texture Mapping • Map 2D texture (any digitized image) onto clipped, visible parts of a surface.

  10. Texture Mapping Examples All based on same 2D checkerboard texture

  11. Texture attached to Geometry

  12. Texture Mapping Image may come in different formats • But can be read and stored as a 2D array of RGB values

  13. Texture Image Assume we have an NxN image • OpenGL requires N to be a power of 2 • Typically, images are indexed using upper left is the origin N Individual RGB pixel values of the texture image are called texels N

  14. Texture Space • Rather than thinking of the image as an array, we will think of it as a function T that maps a point (s,t) to an RGB value 0 <= s, t <= 1 • s,t : texture coordinates • Given any (s,t) in [0,1], the texture image defines the value of T(s,t)

  15. Texture Space T(s,t)=Im[round((1-t)(N-1))][round(s(N-1))] Texel (0,0) (1,1) t (0,0) s NxN Image Im Texture space: (s,t) coordinates

  16. Wrapping • We wish to wrap this 2D texture image on to a 2D surface • But, the surface resides in 3D

  17. Is it Simple? • Although the idea is simple – map an image to a surface – there are 3 or 4 coordinate systems involved 2D image 2D surface residing in 3D

  18. Texture Mapping parametriccoordinates texture coordinates screen coordinates world coordinates

  19. 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 = Fx(s,t) • y = Fy(s,t) • z = Fz(s,t) • But we really want to go the other way (x,y,z) t s

  20. Inverse Mapping • We really want to go from model to texture • Given a point on an model, we want to know to which point in the texture it corresponds • Need a map of the form s = Fs(x,y,z) t = Ft(x,y,z) • Although these functions exist conceptually, finding them might not be easy (or even possible) in practice

  21. Parameterized Surfaces • We first compute a 2D parameterization of the surface. • Associate each point (x, y, z) in world coordinates with a (u,v) in parameter coordinates • Recall the sphere parameterization we saw earlier • Then, we will have functions • fx(u,v) = x, • fy(u,v) = y, • fz(u,v) = z, and their inverses as well. • Mapping (u,v) -> (s,t) is easier!

  22. Cylindrical Mapping parametric cylinder maps rectangle in (u,v) parameter space to cylinder of radius r and height h in world coordinates (x, y, z) s = u t = v maps from texture space to parameter space

  23. OpenGL Texture Mapping • At this point texture mapping is rather abstract and we will see how OpenGL does it.

  24. Where Does Mapping Take Place? • At the end of the rendering pipeline • At rasterization stage we need the texture value • How do we match points on a surface with texels?

  25. OpenGL Texture Mapping • OpenGL handles this by: • Forcing programmer to define “texture coordinates” for each vertex! • Texture coordinates are “part of state” • Thus, we never define the inverse mapping functions explicitly!

  26. OpenGL Texture Mapping • We define texture coordinates (s,t) for vertices • OpenGL interpolates texture coordinates for intermediate points during rasterization! • We will see more details about this part.

  27. OpenGL Texture Mapping • The process involves a large variety of options! • We will concentrate on 2D texture mapping (3D is also available)

  28. Wood Grain

  29. Wood with Cut-Outs

  30. 3D Solid Texture – Allows Complex Geometries to be Textured

  31. OpenGL Texture Mapping • First thing to do: enable texturing • glEnable(GL_TEXTURE_2D) • Input texture into an array of RGB (or RGBA) values • 3 bytes per pixel • Stored row by row from upperleft to lowerright • Image dimensions should be powers of 2 • See example code for reading a PPM file into an array.

  32. glTexImage2D • Process image into OpenGL internal texture format glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, image); Image dimensions Texels are in RGB Pointer to image data (name of image array) Internally use RGB Use highest level resolution Type of R, G and B No border

  33. glTexCoord2f • Assign texture coordinates to each vertex • glTexCoord2f(s, t) • Part of state • Texture coordinates for interior points of a polygon is found by interpolation

  34. Example glBegin(GL_POLYGON); glNormal3f(0.0,0.0,1.0); glColor3fv(ground_color); glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0); glTexCoord2f(0.0,1.0); glVertex3f(0.0,200.0,0.0); glTexCoord2f(1.0,1.0); glVertex3f(200.0,200.0,0.0); glTexCoord2f(1.0,0.0); glVertex3f(200.0,0.0,0.0); glEnd(); (200,200) (1,1) (0,0) (0,0) polygon Texture space (s,t)

  35. Example (200,400) glBegin(GL_POLYGON); glNormal3f(0.0,0.0,1.0); glColor3fv(ground_color); glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0); glTexCoord2f(0.0,1.0); glVertex3f(0.0,400.0,0.0); glTexCoord2f(1.0,1.0); glVertex3f(200.0,400.0,0.0); glTexCoord2f(1.0,0.0); glVertex3f(200.0,0.0,0.0); glEnd(); (1,1) (0,0) Texture space (s,t) (0,0) polygon

  36. GL_REPEAT, GL_CLAMP • How to interpret (s,t) outside of [0,1]? • Repeat texture (GL_REPEAT) Or • Clamp values less than 0 to 0, clamp values greater than 1 to 1 (GL_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

  37. GL_REPEAT glBegin(GL_POLYGON); glNormal3f(0.0,0.0,1.0); glColor3fv(ground_color); glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0); glTexCoord2f(0.0,2.0); glVertex3f(0.0,200.0,0.0); glTexCoord2f(2.0,2.0); glVertex3f(200.0,200.0,0.0); glTexCoord2f(2.0,0.0); glVertex3f(200.0,0.0,0.0); glEnd(); (200,200) (1,1) (0,0) (0,0) polygon Texture space (s,t)

  38. Some more detail… • Mapping of a texture to a surface takes place during rasterization • Hence, it is not really applied to the surface but to a pixel, that is the projection of a small region of the surface

  39. Each pixel corresponds to a small region on a surface and a small region of texture space. Texture map t Surface of object s Pixel on projection plane

  40. Depending on the surface, viewer, texture coordinates • Each texel may cover multiple pixels (MAGNIFICATION) • Or, each pixel may cover multiple texels • (MINIFICATION)

  41. GL_NEAREST or GL_LINEAR What does OpenGL do? • Simplest/Fastest: Point sampling Pick center of each pixel (maps to a single point on surface, and in texture space) and use the texture value at that point. Visible aliasing errors: center point does not give information on the rest of the pixel glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

  42. GL_NEAREST or GL_LINEAR (2) Smoother results: Average texels Use average of a group of texels around the point sample to obtain the value of the texture OpenGL uses 2x2 array of neighboring texels glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

  43. GL_MODULATE or GL_DECAL How does texture interact with shading? GL_DECAL: color of pixel=color of texture GL_MODULATE: color of pixel= product of the color of pixel (without the texture) and the color of texture glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

  44. Perspective Correction Perspective projection does not preserve affine combinations, that is Projection followed by wrapping (using affine combination in 2D) IS NOT EQUAL TO wrapping (using affine combination in 3D)followed by projection You can ask OpenGL to employ a better interpolation scheme by: glHint(GL_PERSPECTIVE_CORRECTION, GL_NICEST);

More Related