240 likes | 262 Views
Explore the intricacies of texture mapping, from creating realistic images to the complexities of texture memory & interpolation. Learn to create texture maps & use noise for creative effects.
E N D
Computer Graphics:Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College PowerPoint Instructor’s Resource
Texture Mapping Creating more realistic and exciting images
Texture Mapping • Adds extra information from an array to graphical objects at the last stage of drawing • Can be viewed as “painting” with 1D, 2D, or 3D values • 1D - painting that depends on one direction • 2D - painting along a surface • 3D - painting throughout a solid • Painting is not literal; the values can be used in many ways
A Texture Map Is… • An array of values stored in a particular memory area in the graphics system • The dimension of the texture map is the dimension of the array • The values in the texture map are used in the final computation of the colors of each pixel
Texture Mapping Needs… • A graphics object that has “texture coordinates” that associate a vertex with texture values • An array of values (usually color, but it can have other meanings) • An association of each vertex with the texture so it can get a value from the array
Texture Mapping is Complex… • … because many things have to go right to make it work, including • Texture memory in the system must be loaded and its format (size and data) known • What is the meaning of the texture (color, …) • How will the texture value will be combined with the object’s pixels • How will the texture value be computed when a pixel does not have an exact texture coordinate or the texture coordinates go out of the unit range
Texture Coordinates • Texture coordinates are 1D, 2D, or 3D vectors with values in [0,1] • Each vertex in you model may have not only geometric coordinates but also texture coordinates • The values in texture coordinates refer proportionately to indices in the texture array
Textures in the Scene Graph • Textures do not affect the geometry of a scene, but only the way that geometry appears in the final image • Textures are thus specified as part of an appearance node in the scene graph: • Color and shading • Lighting and materials • Texture mapping
Creating Texture Maps • From an image: digital photo or scan • Penguins froma trip to SouthAfrica
Creating Texture Maps • Synthetically, from a program that writes values to a file • A brick texture
Format for Texture Files • Any image file could be used to hold a texture map • The only question is reading the file and writing the contents to memory • If you use sophisticated files, you may need to use tools to read the files • Here we choose to use only raw files (the contents are rgbrgbrgb…) to keep things simple
Noise as Texture • Noise is a procedural texture with only one component • Filtered random noise • 1/f noise
Noise is Very Useful • Can be used in any place where you want something random but controlled • Can process the noise to get regions • All regions where the value is greater than a fixed value • Can use noise for varying blending or varying lightness or intensity • …
Texture Interpolation • The texture coordinates of points within a region must be interpolated • This is described in detail in the chapter on rendering • It is important to realize that the way interpolation is done affects the image
Creative Uses of Textures • Texture is often used to “paint realism” onto objects, creating much more interesting images than modeling alone • However, there are many ways to use textures creatively
MIP Mapping • Hold many different resolutions of the same content in one texture map • You can select the version that best fits your geometry, controlling the quality of the image with less computation
Billboards • A billboard is a plane object (usually simple, like a rectangle) on which an image is texture mapped’ • The image often includes zero-alpha areas so they can be “seen through” • The object is rotated to face the viewer so that the viewer sees the image in 3D space, simulating a full 3D object
Creating Complex Textures • You can create textures by reading several different images and combining them as you write the texture array • You can use multitexturing to create texture layers
Chromadepth • Use a 1D texture map that’s red to blue • Color ramp process, but in an array • Apply the texture in eye order on a white object • Resulting image looks 3D through Chromadepth glasses (diffraction grating)
Environment Maps • Environment maps can be made with the sphere map capability • Texture map is made with a spherical filter
Some Details • Texture coordinates that lie outside of [0,1] -- wrapping or clamping
Some Details • Texture coordinates that lie between actual texture map array coordinates -- magnification filters • Nearest (left) and linear (right)
Code For Textures Can Involve Many Stepe • A typical 2D texture setup with the texture already in the array texImage glEnable(GL_TEXTURE_2D); glGenTextures(1, texName); // define texture for sixth face glBindTexture(GL_TEXTURE_2D,texName[0]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,TEX_WIDTH,TEX_HEIGHT, 0,GL_RGB,GL_UNSIGNED_BYTE,texImage);
This Code Does Many Things • Enables textures • Generates a texture with a name • Binds the texture to a texture type • Defines the texture environment • Defines many texture parameters • Links the array texImage with the texture you have defined