page 1
play

Page 1 1 Texture Pipeline Texture Pipeline Compute Use projector - PDF document

University of British Columbia Correction & Review: Surface Texture CPSC 314 Computer Graphics define texture pattern over (s,t) domain Jan-Apr 2005 image 2D array of texels Tamara Munzner assign (s,t) coordinates to


  1. University of British Columbia Correction & Review: Surface Texture CPSC 314 Computer Graphics � define texture pattern over (s,t) domain Jan-Apr 2005 � image – 2D array of “texels” Tamara Munzner � assign (s,t) coordinates to each point on object surface Textures II t Week 8, Wed Mar 2 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2005 � s Correction & Review: Example Texture Map Correction & Review: Example Texture Map (4,0) (4,4) glTexCoord2d(4, 4); glVertex3d (x, y, z); glTexCoord2d(1,1); (0,0) (0,4) glVertex3d (-x, y, z); (1,0) (1,1) glTexCoord2d(1, 1); glTexCoord2d(0,0); glVertex3d (x, y, z); glVertex3d (-x, -y, -z); (0,0) (0,1) � � Review: Texture Texture Functions � once have value from the texture map, can: � action when s or t is outside [0…1] interval � directly use as surface color: GL_REPLACE � tiling � throw away old color, lose lighting effects � clamping � modulate surface color: GL_MODULATE � multiply old color by new value, keep lighting info � texturing happens after lighting, not relit � texture matrix stack � use as surface color, modulate alpha: GL_DECAL glMatrixMode( GL_TEXTURE ); � like replace, but supports texture transparency � blend surface color with another: GL_BLEND � new value controls which of 2 colors to use � indirection, new value not used directly for coloring � � Page 1 1

  2. Texture Pipeline Texture Pipeline Compute Use projector Use corresponder t eye object space function to find function to find Texel color location (s, t) texels (0.9,0.8,0.7) s Apply value Modify value transform function (color, normal,...) (scale, trans, rot) (x, y, z) (s, t) Texture Object position Parameter space Image space (-2.3, 7.1, 17.7) (0.32, 0.29) (81, 74) � � Texture Mapping Texture Objects and Binding � texture object � an OpenGL data type that keeps textures resident in t t (s 2 ,t ,t 2 ) ) (s 1 1 memory and provides identifiers to easily access them � provides efficiency gains over having to repeatedly load and reload a texture (s 0 ,t ,t 0 ) ) (s (s 1 ,t ,t 1 ) ) � you can prioritize textures to keep in memory (s � OpenGL uses least recently used (LRU) if no priority is assigned 0 0 s s � texture binding 0 0 1 1 � which texture to use right now � switch between preloaded textures � �� Basic OpenGL Texturing Low-Level Details � create a texture object and fill it with texture data: � there are a large range of functions for controlling the layout glGenTextures(num, &indices) to get identifiers for the of texture data: � objects � state how the data in your image is arranged glBindTexture(GL_TEXTURE_2D, identifier) to bind � � e.g.: glPixelStorei(GL_UNPACK_ALIGNMENT, 1) tells � following texture commands refer to the bound texture OpenGL not to skip bytes at the end of a row � glTexParameteri(GL_TEXTURE_2D, …, …) to specify � you must state how you want the texture to be put in memory: parameters for use when applying the texture how many bits per “pixel”, which channels,… � glTexImage2D(GL_TEXTURE_2D, ….) to specify the � you will be given texture template sample code for project 3 texture data (the image itself) � enable texturing: glEnable(GL_TEXTURE_2D) � textures must be square and size a power of 2 � state how the texture will be used: � common sizes are 32x32, 64x64, 256x256 � glTexEnvf(…) � smaller uses less memory, and there is a finite amount of texture memory on graphics cards � specify texture coordinates for the polygon: � use glTexCoord2f(s,t) before each vertex: � glTexCoord2f(0,0); glVertex3f(x,y,z); �� �� Page 2 2

  3. Texture Mapping Texture Mapping � texture coordinates � texture coordinate interpolation � specified at vertices � perspective foreshortening problem glTexCoord2f(s,t); � also problematic for color interpolation, etc. glVertexf(x,y,z); � interpolated across triangle (like R,G,B,Z) � …well not quite! �� �� Interpolation: Screen vs. World Space Texture Coordinate Interpolation � perspective correct interpolation � screen space interpolation incorrect � α , β , γ : � problem ignored with shading, but artifacts � barycentric coordinates of a point P in a more visible with texturing P 0 (x,y,z) triangle � s0 , s1 , s2 : V 0 (x’,y’) � texture coordinates of vertices � w0 , w1 , w2 : � homogeneous coordinates of vertices α α ⋅ ⋅ / + + β β ⋅ ⋅ / + + γ γ ⋅ ⋅ / / / / s w s w s w s w s w s w 0 0 1 1 2 2 V 1 (x’,y’) = = 0 0 1 1 2 2 s s α α / + + β β / + + γ γ / / / / w w w w w w 0 0 1 1 2 2 P 1 (x,y,z) �� �� Reconstruction Reconstruction � how to deal with: � pixels that are much larger than texels? � apply filtering, “averaging” � pixels that are much smaller than texels ? � interpolate (image courtesy of Kiriakos (image courtesy of Kiriakos Kutulakos Kutulakos, U Rochester) , U Rochester) �� �� Page 3 3

  4. MIPmapping MIPmaps � multum in parvo -- many things in a small place � prespecify a series of prefiltered texture maps of use use “ “image pyramid image pyramid” ” to to precompute precompute averaged versions of the texture averaged versions of the texture decreasing resolutions � requires more texture storage � avoid shimmering and flashing as objects move � gluBuild2DMipmaps � automatically constructs a family of textures from Without MIP- Without MIP -mapping mapping original texture size down to 1x1 without with store whole pyramid in store whole pyramid in single block of memory single block of memory �� �� With MIP- With MIP -mapping mapping Texture Parameters Bump Mapping: Normals As Texture � in addition to color can control other � object surface often not smooth – to recreate correctly need complex geometry model material/object properties � can control shape “effect” by locally perturbing surface � surface normal (bump mapping) normal � reflected color (environment mapping) � random perturbation � directional change over region �� �� Bump Mapping Bump Mapping �� �� Page 4 4

  5. Embossing Displacement Mapping � at transitions � bump mapped normals are � rotate point’s surface normal by � or - � inconsistent with actual geometry � silhouettes wrong � shadows wrong � displacement mapping actually affects the surface geometry �� �� Environment Mapping Environment Mapping � cheap way to achieve reflective effect � used to model object that reflects � generate image of surrounding surrounding textures to the eye � map to object as texture � movie example: cyborg in Terminator 2 � different approaches � sphere, cube most popular � OpenGL support � GL_SPHERE_MAP, GL_CUBE_MAP � others possible too �� �� Sphere Mapping Cube Mapping � texture is distorted fish-eye view � 6 planar textures, sides of cube � point camera at mirrored sphere � point camera in 6 different directions, facing � spherical texture mapping creates texture out from origin coordinates that correctly index into this texture map �� �� Page 5 5

  6. Cube Mapping Cube Mapping F � direction of reflection vector r selects the face of the cube to be indexed � co-ordinate with largest magnitude � e.g., the vector (-0.2, 0.5, -0.84) selects the –Z face A � remaining two coordinates (normalized by the 3 rd coordinate) selects the pixel from the face. C B � e.g., (-0.2, 0.5) gets mapped to (0.38, 0.80). E D � difficulty in interpolating across faces �� �� Blinn/Newell Latitude Mapping �� Page 6 6

Recommend


More recommend