Title: http:www.ugrad.cs.ubc.cacs314Vjan2005
1Textures IWeek 8, Mon Feb 28
- http//www.ugrad.cs.ubc.ca/cs314/Vjan2005
2News
- face to face p2 grading this week
- you can check your time slot from scans posted to
course page - (student numbers blocked out)
- Mon 1-5, Tue 10-1, 3-5, Wed 1-5
- midterm scaling announced
3Midterm 1 Raw Scores
4Midterm 1 Scaled Scores
5News
- Homework 2 Q1-3 correction
- point A is (2,0,0)
- point B is (3,0,0)
- point C is (4,0,0)
6Review Warnocks Algorithm
- start with root viewport and list of all objects
- recursion
- clip objects to viewport
- if only 0 or 1 objects
- done
- else
- subdivide to new smaller viewports
- distribute objects to new viewpoints
- recurse
7Review Warnocks Algorithm
- termination
- viewport is single pixel
- explicitly check for object occlusion
- single-pixel case common in high depth complexity
scenes
8Review Z-Buffer Algorithm
- augment color framebuffer with Z-buffer or depth
buffer which stores Z value at each pixel - at frame beginning, initialize all pixel depths
to ? - when rasterizing, interpolate depth (Z) across
polygon - check Z-buffer before storing pixel color in
framebuffer and storing depth in Z-buffer - dont write pixel if its Z value is more distant
than the Z value already stored there
9Z-Buffer Demo
10Review Object vs. Image Space
- object space
- determine visibility on object or polygon level
- resolution independent, VCS / NDC coords
- early in pipeline
- requires depth sorting objects/polygons
- image space
- determine visibility at viewport or pixel level
- resolution dependent, screen coords
- late in pipeline
11Texturing
12Reading (whole week)
- FCG Chapter 10
- Red Book Chapter Texture Mapping
13Rendering Pipeline
Geometry Processing
Rasterization
Fragment Processing
14Texture Mapping
- real life objects nonuniform in terms of color
normal - to generate realistic objects - reproduce
coloring normal variations Texture - can often replace complex geometric details
15Texture Mapping
- introduced to increase realism
- lighting/shading models not enough
- hide geometric simplicity
- images convey illusion of geometry
- map a brick wall texture on a flat polygon
- create bumpy effect on surface
- associate 2D information with 3D surface
- point on surface corresponds to a point in
texture - paint image onto polygon
16Color Texture Mapping
- define color (RGB) for each point on object
surface - two approaches
- surface texture map
- volumetric texture
17Surface Texture
- define texture pattern over (u,v) domain (Image)
- image 2D array of texels
- assign (u,v) coordinates to each point on object
surface - for free-form use inverse of surface function
- for polygons (triangle)
- inside use barycentric coordinates
- for vertices need mapping function
v
u
18Texture Mapping
19Mapping for Triangular Meshes
- mapping defined by
- vertices (3D) mapped to specified (u,v) locations
in 2D - each interior point mapped to 2D using
barycentric coordinates
20Texture Mapping
- texture map is an image, two-dimensional array of
color values (texels) - texels are specified by textures (u,v) space
- at each screen pixel, texel can be used to
substitute a polygons surface property (color) - we must map (u,v) space to polygons (s, t) space
21Example Texture Map
Applied to tilted polygon
22Texture Mapping
- (u,v) to (s,t) mapping can be explicitly set at
vertices by storing texture coordinates with each
vertex - OpenGL
- generation at vertices
- specified by programmer or artist
- glTexCoord2f(s,t)
- glVertexf(x,y,z)
- ...
23Texture Coordinates
- every polygon has object coordinates and texture
coordinates - object coordinates describe where polygon
vertices are on the screen - texture coordinates describe texel coordinates of
each vertex - texture coordinates are interpolated along
vertex-vertex edges - glTexCoord1234sifd(TYPE coords)
24Example Texture Map
glVertex3d (s, s, s) glTexCoord2d(1,1)
glVertex3d (-s, -s, -s) glTexCoord2d(0,0)
25Example Texture Map
glVertex3d (s, s, s) glTexCoord2d(5, 5)
glVertex3d (s, s, s) glTexCoord2d(1, 1)
26Texture Lookup
- issue
- what happens to fragments with s or t outside the
interval 01? - multiple choices
- take only fractional part of texture coordinates
- cyclic repetition of texture to tile whole
surfaceglTexParameteri( , GL_TEXTURE_WRAP_S,
GL_REPEAT ) - clamp every component to range 01
- re-use color values from border of texture image
glTexParameteri( , GL_TEXTURE_WRAP_S,
GL_CLAMP )
27Texture Coordinate Transformation
- Motivation
- Change scale, orientation of texture on an object
- Approach
- texture matrix stack
- 4x4 matrix stack
- transforms specified (or generated) tex coords
- glMatrixMode( GL_TEXTURE )
- glLoadIdentity()
-
28Texture Coordinate Transformation
(0,1)
(1,1)
(0,0)
(1,0)
glScalef(4.0,4.0,?)
29Texture Functions
- once have value from the texture map, can
- directly use as surface color GL_REPLACE
- modulate surface color GL_MODULATE
- blend surface and texture colors GL_DECAL
- blend surface color with another GL_BLEND
- specific action depends on internal texture
format - only existing channels used
- specify with glTexEnvi(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, mode)
30Demo Robbins Tutor
31Texture Pipeline
Compute object space location
Use projector function to find (u, v)
Use corresponder function to find texels
Apply value transform function (e.g., scale, bias)
Modify illumination equation value
32Texture Pipeline
v
eye
Texel color (0.9,0.8,0.7)
u
(x, y, z) Object position (-2.3, 7.1, 17.7)
(u, v) Parameter space (0.32, 0.29)
Texture Image space (81, 74)
33Texture Mapping
t
(s2,t2)
1
(s0,t0)
(s1,t1)
0
s
0
1
(s, t) parameterization in OpenGL
34Texture Mapping
- texture coordinates
- generation at vertices
- specified by programmer or artist
- glTexCoord2f(s,t)
- glVertexf(x,y,z)
- generate as a function of vertex coords
- glTexGeni(), glTexGenfv()
- s ax by cz dh
- interpolated across triangle (like R,G,B,Z)
- well not quite!
-
35Texture Mapping
- texture coordinate interpolation
- perspective foreshortening problem
- also problematic for color interpolation, etc.
36Attribute Interpolation
Bilinear Interpolation Incorrect
Perspective correct Correct
37Texture Coordinate Interpolation
- perspective correct interpolation
- ?, ?, ?
- barycentric coordinates of a point P in a
triangle - s0, s1, s2
- texture coordinates of vertices
- w0, w1,w2
- homogeneous coordinates of vertices
38Volumetric Texture
- define texture pattern over 3D domain - 3D space
containing the object - texture function can be digitized or procedural
- for each point on object compute texture from
point location in space - common for natural material/irregular textures
(stone, wood,etc)
39Volumetric Texture Principles
- 3D function r
- r r(x,y,z)
- texture space 3D space that holds the texture
(discrete or continuous) - rendering for each rendered point P(x,y,z)
compute r(x,y,z) - volumetric texture mapping function/space
transformed with objects
40Texture Effects Simple Marble
- boring marble
- function boring_marble(point)
- x point.x
- return marble_color(sin(x))
- // marble_color maps scalars to colors
41Texture Effects Bombing
- bombing
- randomly drop bombs of various shapes, sizes and
orientation into texture space (store data in
table) - for point P search table and determine if inside
shape - if so, color by shape
- otherwise, color by objects color