Download Texture Mapping and Generation: Understanding Texture Coordinates and Mapping Techniques and more Papers Computer Science in PDF only on Docsity!
Texture Coord Generation
Texture Mapping
Map a 2D Texture onto an Object
– How?
Consider a Cylinder
What if we don’t have a cylinder or sphere?
glTexGen
• Powerful, flexible, underutilized
– Contour mapping
– Reflection mapping
– Lighting effects
– Atmospheric effects
glTexGen (cont’d)
• Generate texture coordinates from
geometry
– Object space
- texture is “attached” to object
– Eye space
- object moves within texture “field”
– Sphere map
- based on reflection vector
Reference Plane
• Uses plane equation
– Ax + By +Cz = D
• Computes dot product
– coord = Ax + By + Cz + Dw
– coord is distance from plane
• Computation is “separable”
Object Linear Mapping
• Texture is “attached” to object
GLfloat params = {A,B,C,D};
glTexGenfv(GL_S, GL_OBJECT_PLANE,
params);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,
GL_OBJECT_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
• Default mapping is identity
(s,t,r,q) = (Xo, Yo, Zo, Wo);
Object Linear Sample
• Texture is “attached” to object
Object Linear Mapping
• Demo
Eye Linear Mapping
• Texture is “fixed” in eye space
GLfloat params = {A,B,C,D};
glTexGenfv(GL_S, GL_EYE_PLANE, params);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,
GL_EYE_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
• Default mapping is identity
(s,t,r,q) = (Xe, Ye, Ze, We);
Eye Linear Sample
• Texture is “fixed” in eye space
Eye Linear Mapping
• Demo
Textures and Specular
• Getting Highlights Right
With texture GL_SEPARATE_ SPECULAR_COLOR
Filtering
“Optimal” case
Minification Magnification
Pixel Footprint Pyramid Textures (Mipmapping)
Linear vs. Nearest
Trilinear Anisotropic
Phong Shading
• Spheremap Details
Eye (^) Texture Map
Specular Map Texture looks like a highlight on a sphere projected to a plane
90 degree Reflection
Unused
Center
Phong Shading
• Phong Shading with Texture
– Multipass technique:
- Render object without specular light
- Redraw object: no lighting, color, surface texture
- Modulate intensity with highlight texture
- Combine images with additive blend
– Can be done in single pass using fragment
prog
Phong Shading
• Steps to adding texture highlights
Diffuse Lit, Textured
White, Modulated by Specular Texture
Combined Image (additive blending)
Phong Shading
• Creating Highlight Textures
– Build an environment map
- Sphere lit by object’s light
- Relative light position same as object
- Copy image into highlight texture
– New texture when light moves relative to viewer
– Object movement doesn’t require changing
texture
Phong Shading
• Compare the Results
Single pass Phong Lighting Gouraud Shading
Phong Lighting, Gouraud Shading Separate specular
Two pass Phong Lighting, Phong Shading
End of Phong Shading Lightmaps
• Cached Lighting Results
– Reuse lighting calculations
- Multiple local lights (same type)
- Static portion of scene’s light field
- Sample region with texture instead of tesselating
– Low resolution sampling
- Local lighting; rapid change over small area
- Global lighting; slow change over large area
Lightmaps
• Segmenting Scene Lighting
– Static vs. dynamic light fields
– Global vs. local lighting
– Similar light shape
Lightmaps
• Segmenting the lighting
Dominant Lighting (^) Local lighting
Lightmaps
• Moving Local Lights
– Recreate the texture; simple but slow
– Manipulate the lightmap
- Translate to move relative to the surface
- Scale to change spot size
- Change base polygon color to adjust intensity
– Projective textures ideal for spotlights
– 3D textures easy to use (if available)
Texture Tricks
vs.
Precompute lighting, Fold into texture
Surface Texture plus Lightmap
Lightmaps
• Adding local light to scene
OpenGL Lighting Combined Image
Lightmaps in Quake
×
(modulate)
lightmaps onlylightmaps only^ decal onlydecal only
combined scenecombined scene
Packing Many Lightmaps
into a Single Texture
• Quake 2 light map texture image example • Quake 2 light map texture image example
– Lightmaps typically
heavily magnified.
– Permits multiple
lightmaps packed into a
single texture.
– Quake 2 computes
lightmaps via off-line
radiosity solver.
– Lightmaps typically
heavily magnified.
– Permits multiple
lightmaps packed into a
single texture.
– Quake 2 computes
lightmaps via off-line
radiosity solver.
Lightmaps
• Lightmap considerations
– Lightmaps are good:
- Under-tesselated surfaces
- Custom lighting
- Multiple identical lights
- Static scene lighting
Lightmaps
• Lightmap considerations
– Lightmaps less helpful:
- Highly tesselated surfaces
- Directional lights
- Combine with other surface effects (e.g. bump-
mapping)
- eats a texture access in fragment programs
- may need to go to multi-pass rendering (fill-bound app)
Multitexturing
- Multitexturing allows the use of multiple textures at one time.
- It is a standard feature of OpenGL 1.3 and later.
- An ordinary texture combines the base color of a polygon with color from the texture image. In multitexturing, this result of the first texturing can be combined with color from another texture.
- Each texture can be applied with different texture coordinates.
Texture Units
- Multitexturing uses multiple texture units.
- A texture unit is a part of the rendering pipeline that applies one texture to whatever is being drawn.
- Each unit has a texture, a texture environment, and optional texgen mode.
- Most current hardware has from 2 to 8 texture units.
- To get the number of units available: glGetIntegerv(GL_MAX_TEXTURE_UNITS)
Texture Units
- Texture units are named GL_TEXTURE0, GL_TEXTURE1, etc.
- The unit names are used with two new functions.
- glActiveTexture(texture_unit)
- selects the current unit to be affected by texture calls (such as glBindTexture, glTexEnv, glTexGen).
- glMultiTexCoord2f(texture_unit, s, t)
- Sets texture coordinates for one unit
Detail Texture
Multitexture Lightmapping
Billboards
look = camera_pos - point_pos; right = up x look; up = look x right;