Download presentation

Presentation is loading. Please wait.

Published byTalia Sharer Modified about 1 year ago

1
Projective Texture

2
Spring Projective Texture Texture projected on a scene as if by a projector Can also be used to generate spot light and shadows

3
Spring Idea Generate texture coordinates based on the projector coordinate system

4
Spring In Projector Space … xpxp ypyp 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

5
Spring Review: Pipeline

6
Fall 2009 revised6 Model Transform Viewing Transform Modelview Matrix world coordinates Pipeline Review

7
Spring 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.

8
Spring 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.

9
Spring Review: Texgen Matrix Concatenate texgen planes into a 4-by-4 matrix Object-linear Eye-linear ToTo

10
Spring 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

11
Spring 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

12
Spring 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!

13
Spring 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

14
Spring 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

15
Spring 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

16
Spring Summary need to generate the texture coordinate according to the projector coordinate system

17
Spring 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)

18
Spring Demo Projective Pass Regular Pass Blended Polygon offset is critical to resolve z-fighting! GL_ONE

19
Spring Implementation Note Border pixels The projected texture needs to be padded with black boundary pixels so that the clamped texture appears Ok

20
Spring 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.

21
Spring Projective Texture Shadow Esp. good for non-planar shadow receivers

22
Spring 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

23
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

24
Frustum Display Shows the location/orientation of the spotlight

25
Spring 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

26
Spring s -f gluLookAt (eye, center, up) LTLT Change of Basis gluLookAt is equivalent to: M T

27
Spring 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]

28
Spring 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)

29
Spring Implementation

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google