Presentation on theme: "Projective Texture. Spring 20062 Projective Texture Texture projected on a scene as if by a projector Can also be used to generate spot light and shadows."— Presentation transcript:
Fall 2009 revised6 Model Transform Viewing Transform Modelview Matrix world coordinates Pipeline Review
Spring 20067 Review: Texgen (Object_linear) If the texture generation function is GL_OBJECT_LINEAR, the function g = p1 * x o + p2 * y o + p3 * z o + p4 * w o is used, where g is the value computed for the coordinate; p1, p2, p3, and p4 are the four values supplied in params; and x o, y o, z o, and w o are the object coordinates of the vertex.
Spring 20068 Review: Texgen (Eye_linear) If the texture generation function is GL_EYE_LINEAR, the function g =p 1 ' * x e + p 2 ' * y e + p 3 ' * z e + p 4 ' * w e is used, where (p 1 ' p 2 ' p 3 ' p 4 ') = (p 1 p 2 p 3 p 4 ) * M -1 and x e, y e, z e, and w e are the eye coordinates of the vertex, p 1, p 2, p 3, and p 4 are the values supplied in params, and M is the modelview matrix when glTexGen is invoked.
Spring 20069 Review: Texgen Matrix Concatenate texgen planes into a 4-by-4 matrix Object-linear Eye-linear ToTo
Spring 200610 Coordinate Transformation From Object to Projector: From Eye to Projector: Clip coordinate of Projector Space: M: model matrix V p : view matrix to projector space V : view matrix to eye P p : projection matrix to projector space
Spring 200611 Scale to Texture Coordinates Scale-and-bias matrix (S) 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 200612 Use Texgen for Coord. Transform 1 Need to keep track of model matrix M Texgen planes T o should be updated whenever M changes (model moves) Not explicitly available in OpenGL!
Spring 200613 Use Texgen for Coord. Transform 2 The texture coordinate generated is A’x e + B’y e + C’z e + D’ w e 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 200614 Alternatively, For the rest of transformations, set the texture matrix instead We can use OpenGL matrix facility for matrix multiplication Tex coords after texgen Tex coords after texture transformation
Spring 200615 Summary Texgen: eye-linear When texgen is called, set modelview to contain V e only Specify the other transforms (SP p V p ) as texture matrix
Spring 200616 Summary need to generate the texture coordinate according to the projector coordinate system
Spring 200617 Demo (myprojspot - blended) Scene: textured plane and untextured teapot, subject to a textured spotlight Two rendering passes blended together (with polygon offset to resolve z-fighting)
Spring 200618 Demo Projective Pass Regular Pass Blended Polygon offset is critical to resolve z-fighting! GL_ONE
Spring 200619 Implementation Note Border pixels The projected texture needs to be padded with black boundary pixels so that the clamped texture appears Ok
Spring 200620 Multitexture Implementation Rather than using two blended passes, use a single (multitextured) pass Assign 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 200621 Projective Texture Shadow Esp. good for non-planar shadow receivers
Spring 200622 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 occluder Note 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
Frustum Display Shows the location/orientation of the spotlight
Spring 200625 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 200626 s -f gluLookAt (eye, center, up) LTLT Change of Basis gluLookAt is equivalent to: M T
Spring 200627 Model Transform Viewing Transform Modelview Matrix world coordinates [-1,1] 3 MT [clip] = [Proj] [MT] [world] [world] = [MT] -1 [Proj] -1 [clip] = T -1 M -1 P -1 [clip]
Spring 200628 glFrustum (l,r,b,t,n,f) n,f must be positive n cannot be zero n fr rf/n z x y (1,1,1) (-1,-1,-1)