Title: Texture Mapping Intermediate
1Texture Mapping (Intermediate)
2Texture Suite
3Texture Suite
4Outline
- Dynamic sub texture image
- 1D and 3D textures
- Render to texture
- Environment mapping
- Cubemap
- Spheremap
- Bump map
- Light map
- Projective texture
- Q coord
5Dynamic Texture
A better way of doing it Render-to-texture (RTT)
with framebuffer object (FBO)
- CopyTexSubImage2D
- Replace a rectangular portion of 2D texture with
pixels from the current READ_BUFFER - This involves a read-back from GPU to CPU.
Can you think of a way to move the dynamic
texture around?!
6glTexSubImage2D
- Replace part of the original image as new
subimage - Width and size of image need not be 2n
- E.g., dynamic texture
glTexSubImage2D (target, level, xoffset,
yoffset, width, height, format, type, pixels)
7Other Related Functions
Similar to glCopyPixels
- void glCopyTexImage2D(target, level,
internalformat, x, y, width, height, border) - defines a two-dimensional texture image with
pixels from the current GL_READ_BUFFER. - void glCopyTexSubImage2D(target, level, xoffset,
yoffset, x, y, width, height) doc - replaces a rectangular portion of a
two-dimensional texture image with pixels from
the current GL_READ_BUFFER (rather than from main
memory, as is the case for glTexSubImage2D).
83D Textures
9Render-to-Texture (RTT)
- Generate a snapshot every q degrees
- Total 360/q shots
- The shots are stored as a single texture
- Width and height must be 2n
- E.g., 128x128x8, q45
10RTT Implementation
- First determine a viewing range such that all
views are rendered well. - The snapshots are taken from slightly elevated
positions. - At each position, pre-render to some 2n
resolution, copy the image to buffer - When the panorama is done, set all pixels with
background color to zero alpha values. Bind it to
a texture object.
11RTT
- The image version of the model will be set on a
(cylindrical) billboard - The texture can be chosen as follows
f
If you tank is symmetric, you can use even fewer
images
12RTT (symmetric tank)
1
2
0
- 180?8 images (180/7?26) apart
- port side
- starboard side
- Reverse the port-side image
3
f
4
f
5
6
7
13Perlin Noise
3D Texture Noise as texture
14Light Map
- By Michael Gold (ref)
- NVIDIA
15Light Maps
Quake (????, id software) was the first computer
game to use light map
16(No Transcript)
17Lightmaps
- Cached Lighting Results
- Reuse lighting calculations
- Multiple local lights (same type)
- Static portion of scenes light field
- Sample region with texture instead of tessellating
18Lightmaps
- Getting the most from the Lightmap
- Maximize lightmap re-use, minimize lightmap size
- Texture size versus sampling level
- Full surface texture with built-in lighting
- Small surface texture, small low-resolution
lightmap - Adjust texture matrix to re-use lightmap
- Dynamic lighting track moving lights
19Lightmaps
- Segmenting Scene Lighting
- Static vs. dynamic light fields
- Global vs. local lighting
- Similar light shape
20Lightmaps
- Segmenting the lightfields
Dominant Lighting
Local lighting
21Lightmaps
- 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
22Lightmaps
Translate Texture
Scale Texture
Change Base Polygon Intensity
23Lightmaps
- Creating a lightmap
- Light white, tesselated surface with local light
- Render, capture image as texture
- Texture contains ambient and diffuse lighting
- Texture can also be computed analytically
24Lightmaps
Render surface lit by local light
Create a Texture Map from Image
25Lightmaps
- Lightmap building tips
- Minimize texture resolution to match required
sampling - Edges of texture should have uniform intensity
- Light intensity change should be negligible at
edges - Dont forget borders if you clamp the lightmap
- Fill in border to match edge and corner
- Or use border color
26Lightmaps
Boundary should have constant value
Intensity changes from light should be
minimal near edge of lightmap
27Lightmaps
- Lighting with a Lightmap
- Local light is affected by surface color and
texture - Two step process adds local light contribution
- Modulate textured, unlit surfaces with lightmap
- Add locally lit image to scene
- Can mix OpenGL, lightmap lighting in same scene
28Lightmaps
Lightmap
- Creating local contribution
Unlit Scene
Local Light Contribution
Lightmap Intensity
29Lightmaps
- Using Lightmaps
- Move lightmaps using texture matrix
- Distance from surface simulated by scaling
texture and changing intensity - Texgen maps lightmap to surfaces, overrides local
texture coordinates - Can avoid changing models texture coordinates
30Projective Texture Mapping
Also generate shadows
Light source as slide projector
31Projective Texture Mapping
32Implementation Tricks
- The projected texture need to be padded with
black boundary pixels so that the clamped texture
appears Ok - Some natural faults (more than one layer of
surface got textured) no way to resolve this!?
33Q coord
34Sphere Map
35Sphere Map (cont)
36Generating Sphere Map (ref)
37Adding Silhouettes with Sphere Map
38Reflection Mapping (wikipedia)
- the most common ones are the Standard Environment
Mapping in which a single texture contains the
image of the surrounding as reflected on a mirror
ball, or the Cubic Environment Mapping in which
the envirornment is unfolded onto the six faces
of a cube and stored therefore as six square
textures. - A typical drawback of this technique is the
absence of self reflections you cannot see any
part of the reflected object inside the
reflection itself.
39Spheremap
- involves the use of a textured sphere infinitely
far away from the object that reflects it. By
creating a spherical texture using a fisheye lens
or via prerendering or with a light probe, this
texture is mapped to a hollow sphere, and the
texel colors are determined by calculating the
light vectors from the points on the object to
the texels in the environment map. This technique
may produce results which are superficially
similar to those produced by raytracing, but
incurs less of a performance hit because all of
the colors of the points to be referenced are
known beforehand, so all it has to do is to
calculate the angles of incidence and reflection. - There are a few glaring limitations to spherical
mapping. For one thing, due to the nature of the
texture used for the map, there is an abrupt
point of singularity on the backside of objects
using spherical mapping. Cube mapping (see below)
was developed to address this issue. Since cube
maps (if made and filtered correctly) have no
visible seams, they are an obvious successor to
the archaic sphere maps, and nowadays spherical
environment maps are almost nonexistent in
certain contemporary graphical applications, such
as video game graphics.
40Cube Mapping
- Cube mapped reflection is a technique that uses
cube mapping to make objects look like they
reflect the environment around them. Generally,
this is done with the same skybox that is used in
outdoor renderings. Though this is not a true
reflection since objects around the reflective
one will not be seen in the reflection, the
desired effect is usually achieved. - Cube mapped reflection is done by determining the
vector that the object is being viewed at. This
camera ray is reflected about the surface normal
of where the camera vector intersects the object.
This results in the reflected ray which is then
passed to the cube map to get the texel which the
camera then sees as if it is on the surface of
the object. This creates the effect that the
object is reflective.
41Dynamic Cube Map
42Reference
43Code Samples
lightmap
- Cutout texture
- Render-to-texture (RTT)
- Whirlpool
billboarding
cubemap