View
252
Download
0
Category
Preview:
Citation preview
Spring 2006 2
Projective Texture
Texture projected on a scene as if by a projectorCan also be used to generate spot light and shadows
Spring 2006 4
In Projector Space …
xp
yp
Whatever is in the projector frustum has clip coord. of [-1,1]x[-1,1]xZ … (Z is irrelevant)
Convert [-1,1] to [0,1] to become the texture coordinates
Fall 2009 revised 6
Model Transform
Viewing Transform
ModelviewMatrix
worldcoordinates
Pipeline Review
Spring 2006 7
Review: Texgen (Object_linear)
If the texture generation function is GL_OBJECT_LINEAR, the function
g = p1 * xo + p2 * yo + p3 * zo + p4 * wo
is used, where g is the value computed for the coordinate; p1, p2, p3, and p4 are the four values supplied in params; and xo, yo, zo, and wo are the object coordinates of the vertex.
Spring 2006 8
Review: Texgen (Eye_linear)
If the texture generation function is GL_EYE_LINEAR, the functiong =p1' * xe + p2' * ye + p3' * ze + p4' * we
is used, where (p1' p2' p3' p4') = (p1 p2 p3 p4) * M -1
and xe, ye, ze, and we are the eye coordinates of the vertex, p1, p2, p3, and p4 are the values supplied in params, and M is the modelview matrix when glTexGen is invoked.
Spring 2006 9
Review: Texgen Matrix
Concatenate texgen planes into a 4-by-4 matrix
Object-linear
Eye-linear
objectw
z
y
x
v
v
v
vpppp
q
r
t
s
4321
To
Spring 2006 10
Coordinate Transformation
opp MvVv From Object to Projector:
epp vVVv 1From Eye to Projector:
ppp vPc Clip coordinate of Projector Space:
M: model matrixVp: view matrix to projector spaceV : view matrix to eye
Pp: projection matrix to projector space
Spring 2006 11
Scale to Texture Coordinates
Scale-and-bias matrix (S)
1000
00
00
00
21
21
21
21
21
21
Clip Coordinate[-1,1]
Texture Coordinate[0,1]
Note: we only care about [s,t] (and then [x,y]). Hence, frustum clipping on z is of no importance
Spring 2006 12
Use Texgen for Coord. Transform1
objectw
z
y
x
T
pp
v
v
v
v
MVSP
q
r
t
s
o
p
T Scqrts ,,,
opp MvVv
ppp vPc
Need to keep track of model matrix MTexgen planes To should be updated whenever M changes (model moves)
Not explicitly available in
OpenGL!
Spring 2006 13
Use Texgen for Coord. Transform2
pT Scqrts ,,,
ppp vPc epp vVVv 1
eyew
z
y
x
T
pp
v
v
v
v
VVSP
q
r
t
s
e
1
The texture coordinate generated is A’xe + B’ye + C’ze + D’we where (A’,B’,C’,D’) is (A,B,C,D)M−1, M is the modelview matrix when glTexGen is invoked. Thus, simply set the modelview matrix to contain only the view matrix
Spring 2006 14
Alternatively,
For the rest of transformations, set the texture matrix instead
q
r
t
s
VP
q
r
t
s
texture
pp
matrix
21
21
21
21
21
21
1000
00
00
00
eyew
z
y
x
e
v
v
v
v
V
q
r
t
s
1
eqns plane eye
1
1
1
1
We can use OpenGL matrix facility for matrix
multiplication
Tex coordsafter texgen
Tex coordsafter texture
transformation
Spring 2006 15
Summary
Texgen: eye-linearWhen texgen is called, set modelview to contain Ve only
Specify the other transforms (SPpVp) as texture matrix
eyew
z
y
x
epp
v
v
v
v
VVP
q
r
t
s
1
matrix texture
21
21
21
21
21
21
1000
00
00
00
Spring 2006 16
Summaryneed to generate the texture coordinate according to the projector coordinate system
Spring 2006 17
Demo (myprojspot - blended)
Scene: textured plane and untextured teapot, subject to a textured spotlightTwo rendering passes blended together (with polygon offset to resolve z-fighting)
Spring 2006 18
Demo
Projective PassRegular Pass
Blended
Polygon offset is critical to resolve z-fighting!
GL_ONE GL_ONE
Spring 2006 19
Implementation Note
Border pixels The projected
texture needs to be padded with black boundary pixels so that the clamped texture appears Ok
Spring 2006 20
Multitexture Implementation
Rather than using two blended passes, use a single (multitextured) passAssign a separate texture unit for spot light texture Projective texture coordinate set by texgen Texture environment set to GL_ADD
Base fragment/texture + spot light RGB: equivalent to one/one blending
The padding is black (0,0,0); GL_ADD plays no role.
Spring 2006 22
Projective Shadow Texture
Generate a shadow texture from light coordinate system Render unlit occluder only
Render the shadow receiver with the projected shadow; then render the occluderNote the shadow texture is padded with white pixels. The texture environment used is GL_MODULATE (white (1,1,1) plays no role)
spot or point light
This is normal! If you see something like this, the artifact comes from projective texture clamping: the shadow touches the texture border (not enough padding). It can be alleviated by increasing the fov or raising the light position
Spring 2006 25
Idea
Projector is set by “gluLookAt” API Eye, center, up
Vertices of the viewing frustum have clip coordinates of [-1,1]3
Need to know their corresponding world coordinates to render
Spring 2006 26
s -f
gluLookAt (eye, center, up)
worldT
worldeye
eyeworld
z
y
x
z
y
x
xLxLx
Lxx
eye
eye
eye
fus
fus
fus
world
world
world
1
]2[]2[]2[
]1[]1[]1[
]0[]0[]0[
LT
Change of Basis
gluLookAt is equivalent to:
s
ss
M T
Spring 2006 27
Model Transform
Viewing Transform
ModelviewMatrix
worldcoordinates
[-1,1]3
MT
[clip] = [Proj] [MT] [world][world] = [MT]-1[Proj]-1[clip] = T-1 M-1 P-1 [clip]
Spring 2006 28
glFrustum (l,r,b,t,n,f)n,f must be positiven cannot be zero
n
f r
rf/n
zx
y
1
11
1
1
1
1
1
11
1
1
1
1
12
22
22
1
12
22
22
1
fR
n
b
l
R
ntfnrf
f
nt
nr
fnnffn
nbt
nbt
nlr
nlr
n
nb
nl
fnnfnf
nbt
nbt
nlr
nlr
(1,1,1)
(-1,-1,-1)
Recommended