fall 2009 revised1 texture mapping (intermediate) jyun-ming chen
TRANSCRIPT
Fall 2009 Revised 1
Texture Mapping (Intermediate)
Jyun-Ming Chen
Fall 2009 Revised 2
Texture Suite
highlightbubble
Fall 2009 Revised 3
Texture Suite
warp
underwater
Fall 2009 Revised 4
Outline
Dynamic sub texture image1D and 3D texturesRender to texture
Environment mapping Cubemap Spheremap
Bump map Light mapProjective textureQ coord
Fall 2009 Revised 5
Dynamic Texture
CopyTexSubImage2DReplace a rectangular portion of 2D texture with pixels from the current READ_BUFFERThis involves a read-back from GPU to CPU.
Can you think of a way to move the dynamic texture
around?!
A better way of doing it: Render-to-texture (RTT) with framebuffer object (FBO)
Fall 2009 Revised 6
glTexSubImage2D
Replace part of the original image as new subimageWidth and size of image need not be 2n
E.g., dynamic texture
glTexSubImage2D (target, level, xoffset, yoffset, width, height, format, type, pixels)
glTexSubImage2D (target, level, xoffset, yoffset, width, height, format, type, pixels)
Fall 2009 Revised 7
Other Related Functions
void glCopyTexImage2D(target, level, internalformat, x, y, width, height, border); defines a two-dimensional texture image with pi
xels from the current GL_READ_BUFFER.void glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); doc replaces a rectangular portion of a two-dimensi
onal texture image with pixels from the current GL_READ_BUFFER (rather than from main memory, as is the case for glTexSubImage2D).
Similar to glCopyPixe
ls
Fall 2009 Revised 8
3D Textures
Fall 2009 Revised 9
Render-to-Texture (RTT)Generate a snapshot every degrees Total 360/ shots
The shots are stored as a single texture Width and height
must be 2n
E.g., 128x128x8, =45
Fall 2009 Revised 10
RTT ImplementationFirst 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 2^n resolution, copy the image to bufferWhen the panorama is done, set all pixels with background color to zero alpha values. Bind it to a texture object.
Fall 2009 Revised 11
RTTThe image version of the model will be set on a (cylindrical) billboardThe texture can be chosen as follows:
360
: take toImage
If you tank is symmetric, you can use even fewer images
Fall 2009 Revised 12
RTT (symmetric tank)
180°8 images: (180/726)° apartport side
starboard side Reverse the port-
side image
0
7
12
3
4
5
6
26
13: take toImage
Fall 2009 Revised 13
Perlin Noise
3D TextureNoise as texture
Fall 2009 Revised 14
Light Map
By Michael Gold (ref)NVIDIA
Fall 2009 Revised 15
Light MapsQuake (雷神之錘 , id software) was the first computer game to use light map
Fall 2009 Revised 16
Fall 2009 Revised 17
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
tessellating
Fall 2009 Revised 18
Lightmaps
Getting the most from the Lightmap Maximize lightmap re-use, minimize light
map size Texture size versus sampling level
Full surface texture with built-in lighting Small surface texture, small low-resolution li
ghtmap Adjust texture matrix to re-use lightmap
Dynamic lighting: track moving lights
Fall 2009 Revised 19
Lightmaps
Segmenting Scene Lighting Static vs. dynamic light fields Global vs. local lighting Similar light shape
Fall 2009 Revised 20
Lightmaps
Segmenting the lightfields
Dominant Lighting Local lighting
Fall 2009 Revised 21
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 intensit
y Projective textures ideal for spotlights
Fall 2009 Revised 22
Lightmaps
Moving Local Lights
TranslateTexture
ScaleTexture
Change BasePolygon Intensity
Fall 2009 Revised 23
Lightmaps
Creating a lightmap Light white, tesselated surface with local
light Render, capture image as texture Texture contains ambient and diffuse lig
hting Texture can also be computed analyticall
y
Fall 2009 Revised 24
Lightmaps
Creating a lightmap
Render surfacelit by local light
Create a TextureMap from Image
Fall 2009 Revised 25
Lightmaps
Lightmap building tips Minimize texture resolution to match required s
ampling Edges of texture should have uniform intensity Light intensity change should be negligible at e
dges Don’t forget borders if you clamp the lightmap
Fill in border to match edge and corner Or use border color
Fall 2009 Revised 26
Lightmaps
Lightmap building tipsBoundary should have
constant value
Intensity changes fromlight should be minimalnear edge of lightmap
Fall 2009 Revised 27
Lightmaps
Lighting with a Lightmap Local light is affected by surface color an
d texture Two step process adds local light contrib
ution: Modulate textured, unlit surfaces with lightm
ap Add locally lit image to scene
Can mix OpenGL, lightmap lighting in same scene
Fall 2009 Revised 28
Lightmaps
Creating local contribution
Unlit Scene Lightmap Intensity Local LightContribution
Lightmap
Fall 2009 Revised 29
Lightmaps
Using Lightmaps Move lightmaps using texture matrix Distance from surface simulated by scali
ng texture and changing intensity Texgen maps lightmap to surfaces, overri
des local texture coordinates Can avoid changing model’s texture coordi
nates
Fall 2009 Revised 30
Projective Texture Mapping
Light source as
slide projector
Also generate shadows
Fall 2009 Revised 31
Projective Texture Mapping
Fall 2009 Revised 32
Implementation Tricks
The projected texture need to be padded with black boundary pixels so that the clamped texture appears OkSome natural faults (more than one layer of surface got textured): no way to resolve this!?
Fall 2009 Revised 33
Q coord
See Sampcode/qcoord
Fall 2009 Revised 34
Code Samples
Cutout textureRender-to-texture (RTT)
Whirlpool
cubemap
lightmap
billboarding