Presentation is loading. Please wait.

Presentation is loading. Please wait.

Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.

Similar presentations


Presentation on theme: "Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use."— Presentation transcript:

1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use geometry, model surface detail with polygons; good for large scale detail, too expensive otherwise. Improvement: map an image of the details onto simple geometry Motivation: -- object/picture often has parts -- model once/instantiate multiple times -- modify only a part 11/21/2018 Hofstra University

2 The wall 11/21/2018 Hofstra University

3 The Wall: Checkers 11/21/2018 Hofstra University

4 Texture Mapping y z x screen geometry t image s Ed Angel 11/21/2018
Textures are images that can be thought of as continuous and be one, two, three, or four dimensional. By convention, the coordinates of the image are s, t, r and q. Thus for the two dimensional image above, a point in the image is given by its (s, t) values with (0, 0) in the lower-left corner and (1, 1) in the top-right corner. A texture map for a two-dimensional geometric object in (x, y, z) world coordinates maps a point in (s, t) space to a corresponding point on the screen. image Ed Angel 11/21/2018 Hofstra University

5 Texture Mapping and the OpenGL Pipeline
Images and geometry flow through separate pipelines that join at the rasterizer “complex” textures do not affect geometric complexity The advantage of texture mapping is that visual detail is in the image, not in the geometry. Thus, the complexity of an image does not affect the geometric pipeline (transformations, clipping) in OpenGL. Texture is added during rasterization where the geometric and pixel pipelines meet. geometry pipeline vertices pixel pipeline image rasterizer Ed Angel 11/21/2018 Hofstra University

6 Texture mapping Texture mapping: adding surface detail by mapping texture patterns to the surface Technique developed by Catmull (1974), Blinn and Newell (1976). 11/21/2018 Hofstra University

7 Texture mapping methods
2D texture mapping: paint 2D pattern onto the surface Environmental (reflection) mapping Bump mapping: perturb surface normals to fool shading algorithms Procedural texture mapping, 3D texture 11/21/2018 Hofstra University

8 More Examples Jim Blinn 11/21/2018 Hofstra University
Contouring: 1D texture Contour curves drawn on an object can provide valuable information about the object's geometry. Such curves may represent height above some plane (as in a topographic map) that is either fixed or moves with the object [Sabella 88]. Alternatively, the curves may indicate intrinsic surface properties, such as geodesics or loci of constant curvature. Contouring is achieved with texture mapping by first defining a one-dimensional texture image that is of constant color except at some spot along its length. Then, texture coordinates are computed for vertices of each polygon in the object to be contoured using a texture coordinate generation function. This function may calculate the distance of the vertex above some plane (Figure 4), or may depend on certain surface properties to produce, for instance, a curvature value. Modular arithmetic is used in texture coordinate interpolation to effectively cause the single linear texture image to repeat over and over. The result is lines across the polygons that comprise an object, leading to contour curves. A two-dimensional (or even three-dimensional) texture image may be used with two (or three) texture coordinate generation functions to produce multiple curves, each representing a different surface characteristic. Environment Mapping Jim Blinn 11/21/2018 Hofstra University

9 More Examples Jim Blinn 11/21/2018 Hofstra University
Contouring: 1D texture Contour curves drawn on an object can provide valuable information about the object's geometry. Such curves may represent height above some plane (as in a topographic map) that is either fixed or moves with the object [Sabella 88]. Alternatively, the curves may indicate intrinsic surface properties, such as geodesics or loci of constant curvature. Contouring is achieved with texture mapping by first defining a one-dimensional texture image that is of constant color except at some spot along its length. Then, texture coordinates are computed for vertices of each polygon in the object to be contoured using a texture coordinate generation function. This function may calculate the distance of the vertex above some plane (Figure 4), or may depend on certain surface properties to produce, for instance, a curvature value. Modular arithmetic is used in texture coordinate interpolation to effectively cause the single linear texture image to repeat over and over. The result is lines across the polygons that comprise an object, leading to contour curves. A two-dimensional (or even three-dimensional) texture image may be used with two (or three) texture coordinate generation functions to produce multiple curves, each representing a different surface characteristic. Environment Mapping Jim Blinn 11/21/2018 Hofstra University

10 Environment Mapping Yoshihiro Mizutani and Kurt Reindel 11/21/2018
Hofstra University

11 2D texture mapping overview
Texture array is a 2D image pattern With elements texels Value at a texel affects surface appearance The “texture map” determines how the pattern lies on the srface 11/21/2018 Hofstra University

12 2D texture mapping overview
Rendering uses the texture mapping Find surface that is front most at current pixel Find the the surface patch corresponding to the pixel Find the part of the texture pattern corresponding to the surface patch Use that part of the texture pattern in setting the pixel color 11/21/2018 Hofstra University

13 11/21/2018 Hofstra University

14 2D texture mapping Source: 2D pattern from drawing, photo, procedure
Destination: any surface, easier if surface given in parametric form The map from 2D texture coord to 3D object Texture mapping transformation: 2D screen coord  3D object coord  2D texture coord and back (see previous slide) 11/21/2018 Hofstra University

15 Mapping the 2D texture to the surface
The map: 2D texture(s,t)  3D object(x,y,z) Mapping onto triangle is not difficult Mapping onto triangular mesh is more difficult (have to handle texture discontinuity) Mapping onto parametric surface is easier Alternative: use an intermediate parametric surface (cylinder, sphere) 11/21/2018 Hofstra University

16 Mapping a Texture Based on parametric texture coordinates
glTexCoord*() specified at each vertex Texture Space Object Space t 1, 1 (s, t) = (0.2, 0.8) 0, 1 A a When you want to map a texture onto a geometric primitive, you need to provide texture coordinates. The glTexCoord*() call sets the current texture coordinates. Valid texture coordinates are between 0 and 1, for each texture dimension, and the default texture coordinate is ( 0, 0, 0, 1 ). If you pass fewer texture coordinates than the currently active texture mode ( for example, using glTexCoord1d() while GL_TEXTURE_2D is enabled ), the additionally required texture coordinates take on default values. c (0.4, 0.2) b B C 0, 0 1, 0 s (0.8, 0.4) 11/21/2018 Hofstra University

17 Mapping texture onto parametric surface
Point on the parametric surface The map from texture to the parametric coord, invertible 11/21/2018 Hofstra University

18 Mapping texture onto parametric surface
Example of a linear mapping Does not take into account curvature of surface Equal size texture patches are stretched to fit various areas 11/21/2018 Hofstra University

19 Mapping texture to a surface using an intermediate surface
Two-step mapping Map the texture to a simple intermediate surface (sphere, cylinder, cube) Map the intermediate surface (with the texture) onto the surface being rendered 11/21/2018 Hofstra University

20 Two-step mapping example
cylinder: x = r cos(2 PI u) y = r sin(2 PI u) z = v h first step: u = s, v = t sphere cube 11/21/2018 Hofstra University

21 Two-step mapping example
Second-step: map intermediate surface to the surface being rendered Various strategies: a, b, c 11/21/2018 Hofstra University

22 The texture mapping transformation
11/21/2018 Hofstra University

23 Texture mapping transformation
Consider surface visible at current pixel. Find the patch on the surface that corresponds to it. Map screen coord of pixel corners back to object Find texels that map to the surface patch If multiple texels lie on patch combine them: weighted avg; supersampling with postfiltering 11/21/2018 Hofstra University

24 Environmental Mapping
Put texture on a highly reflective object by picking up texture from the environment in which the object is immersed. Realized as two-step process Project the environment (excluding the object) onto an intermediate surface. Place object back, and map texture from intermediate surface to object 11/21/2018 Hofstra University

25 Bump mapping 2D Texture map creates odd looking rough surfaces
Bump mapping: texture map that alters surface normals. Use texture array to set a function which perturbs surface normals Altered normals match a bumpy surface Applying illumination model to the new normals shades the bumps correctly 11/21/2018 Hofstra University

26 Bump mapping Bump map is in texture array: d(s,t) << 1
p point on the surface corresponding to texture coordinates s,t. N the normal at p p’ the bump point for p p’ = p + d(s,t)N We actually do not “bump” the surface, just the normal at p. N’ the normal at p’ . This normal used by the illumination model at p. 11/21/2018 Hofstra University

27 Bump mapping How to get N’ : given two vectors tangent to the bumpy
surface, N’ is their cross product The two vectors follow from the partial derivatives of the p’ equation wrt u,v p’ = p + d(s,t)N These partial derivatives expressed in terms of the derivatives of d(s,t) as s,t change 11/21/2018 Hofstra University

28 2DTexture mapping in OpenGL
Pixel pipeline Texture map done at rasterization stage 11/21/2018 Hofstra University

29 Texture Mapping in OpenGL
Get hold of texture array Create texture object and specify texture for it Specify mode for applying texture to pixels Enable texture mapping Draw the scene providing both texture and geometric coordinates 11/21/2018 Hofstra University

30 Create texture object and texture for it
Texel values could be up to 4D (R,G,B,A) Texturing is expensive. Texture objects similar to display lists: faster to bind(reuse) stored texture than load with glTexImage*D() 11/21/2018 Hofstra University

31 Using texture objects Create texture names, glGenTextures() ,
Returns available id’s in second parameter which is passed by reference static Gluint texName; glGenTextures(1, &texName); Create and use texture objects: glBindTexture(GL_TEXTURE_2D, texName); In first use: new texture object is created and assigned the name; subsequent uses: activate the texture object 11/21/2018 Hofstra University

32 Using texture objects glBindTexture(), “sets” texture state, subsequent calls to glTexImage, glTexParameters,etc., store data in the active texture object The data may include: texture image (mipmaps), width, height,border, internal format, texture properties (minmag filters, wrapping modes,…) 11/21/2018 Hofstra University

33 2D texture mapping in OpenGL
Provide texture array Glubyte my_texels[512][512][3]; Specify which texture array to use glTexImage2D( GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); Enable texture mapping glEnable(GL_TEXTURE_2D); Specify map from texture array to object. 0 <= s, t <= 1 Assign texture coordinates to vertices glTexCoord2f(s, t); 11/21/2018 Hofstra University

34 Mapping texture coordinates to object
Example: map the array to quadrilateral glBegin(GL_QUAD); glTexCoord2f(0.0,0.0); glVertex3f(x1,y1,z1); glTexCoord2f(1.0,0.0); glVertex3f(x2,y2,z2); glTexCoord2f(1.0,1.0); glVertex3f(x3,y3,z3); glTexCoord2f(0.0,1.0); glVertex3f(x4,y4,z4); glEnd(); 11/21/2018 Hofstra University

35 OpenGL texture parameters
glTexParameterf(GL_TEXTURE_WRAP_S,GL_REPEAT); GL_CLAMP glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL_LINEAR Mipmapping: create sequence of texture arrays at different sizes, it will use the appropriate size glBuild2DMipmaps(GL_TEXTURE_2D,…, my_texels); Interaction between texturing and shading glTexEnvi(GL_TEX_ENV_MODE, GL_MODULATE); GL_DECAL glHINT(GL_PERSPECTIVE_CORRECTION, GL_NICEST); 11/21/2018 Hofstra University


Download ppt "Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use."

Similar presentations


Ads by Google