Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!apple!turk From: turk@Apple.COM (Ken "Turk" Turkowski) Newsgroups: comp.graphics Subject: Re: Texture mapping Keywords: Texture mapping, convex quadrilaterals, triangles Message-ID: <4330@internal.Apple.COM> Date: 25 Sep 89 04:30:16 GMT References: <9119@pyr.gatech.EDU> Organization: Advanced Technology Graphics, Apple Computer, Cupertino, CA, USA Lines: 99 In article <9119@pyr.gatech.EDU> ccoprrm@pyr.gatech.edu (ROBERT E. MINSK) writes: > I am currently trying to add texture mapping to my ray tracer. The problem >I am having is texture mapping and normal interpolation to convex >quadrilaterals and triangles. The situation is as follows: > Given 4 points forming a convex planer quadrilateral,the texture verticies >associated with each point, and the intersection point on the quadrilateral, >find the associated (u,v) mapping coordinates for the intersection point. >For example: > 4 points the associated texture vertices > p1=(-5, 1, 2) t1=(.2,.4) > p2=(-2,-3, 6) t2=(.4,.2) > p3=( 2,-1, 4) t3=(.8,.3) > p4=( 1, 4,-1) t4=(.7,.5) >intersection point = (-2,-1, 4) >find the (u,v) mapping coordinates > >I assume a triangle will be the same mapping with two vertices sharing the >same points and mapping coordinates. For suitably well-behaved texture mappings (i.e. no bowtie quadrilaterals), there is a projective mapping, that maps quadrilaterals to quadrilaterals. This is represented by a 3x3 matrix, unique up to a scale factor. [x y z] = [uw vw w] [M] (1) where w is a homogeneous coordinate, and [M] is the 3x3 matrix. Since the 4 points must obey (1), we have the nonlinear system of equations: |x0 y0 z0| |u0*w0 v0*w0 w0| |x1 y1 z1| |u1*w1 v1*w1 w1| |x2 y2 z2| = |u2*w2 v2*w2 w2| [M] (2) |x3 y3 z3| |u3*w3 v3*w3 w3| This represents 12 equations in 13 unknowns, but one of the w's may be arbitrarily chosen as 1. System (2) can be solved for the matrix [M] by any nonlinear system equation solver, such as those available in the Collected Algorithms of the ACM. When this matrix is inverted, it gives the mapping you desire: -1 [uw vw w] = [x y z] [M] (3) You just plug the desired [x y z] into (3), and divide by w. For triangles, the mapping (1) is affine: [x y z] = [u v 1] [M] (4) and the resulting system is linear: |x0 y0 z0| |u0 v0 1| |x1 y1 z1| = |u1 v1 1| [M] (5) |x2 y2 z2| |u2 v2 1| This linear equation (9 equations in 9 unknowns) can easily be solved by LU decomposition. Note that this matrix computed in (2) and (5) depends only on the parametrization, so its only needs to be computed once, offline, at the time the texture is assigned. Take note that the texture parameters are not interpolated linearly (or bilinearly), but projectively. Also note that, unlike standard bilinear interpolation (such as that used for Gouraud interpolation) this method of interpolation is rotation invariant. For more information on projective mappings, see the the book "Projective Geometry and Applications to Computer Graphics" by Penna and Patterson. (I hope this reference is correct -- I'm doing it from memory). For more detail on this approach to texture-mapping, including texture-mapping by scan-conversion, request a copy of the following paper: Turkowski, Ken The Differential geometry of Texture Mapping Apple Technical Report No. 10 May 10, 1988 from Apple Corporate Library Apple Computer, Inc. 20525 Mariani Avenue Mailstop 8-C Cupertino, CA 95014 The e-mail address for the library is: corp.lib1@applelink.apple.com, but the gateway is one-way, so don't expect an electronic reply. -- Ken Turkowski @ Apple Computer, Inc., Cupertino, CA Internet: turk@apple.com Applelink: TURKOWSKI1 UUCP: sun!apple!turk