Re: texture matrix

New Message Reply Date view Thread view Subject view Author view

From: Marcin Romaszewicz (marcin++at++asmodean.engr.sgi.com)
Date: 10/01/2001 13:29:34


A texture matrix works just like any other matrix in OpenGL, just on
texture coordinates. Your texture coordinates make a 4 element vector
(s, t, r, q) which is multiplied by the texture matrix. If you want to
"add" perspective to your texture or correct for it, you want to mess with
the q term either directly or by making the texture matrix a perspective
projection.

The OpenGL rasterizer has no notion of 3d, so any projections in the
modelview and projection matrices must be mapped to 2D operations. Here's
how it works:

For any vertex, we have (x, y, z, w) and (s, t, r, q). Assume r=0, q=1 for
a standard 2D matrix and that w=1 for any point.

When you multiply the point (x, y, z, w) by the modelview and projection
matrices, you end up with a point (x', y', z', w') in which the w' term is
no longer 1; it contains intermediate information which we will use to
create the illusion of perspective.

To map this 3d point to a 2d perspective corrected point, we divide x and
y by w, so:

x" = x'/w
y" = y'/w
z" = z'/w (for perspective correct depth interpolation)

We need to apply a similar operation to the texture coordinates. The
trexture coordinates for a 2D texture are computed like this:

s' = s / w
t' = t / w
r' = 0
q' = 1.0 / w

As things get farther from the eye in a perspective projection, the w term
increases. So as you can see, dividing by w will decrease the coordinate
values of x, y, z and make them seem smaller as they recede into the
distance. A similar mapping is applied to texture coordinates. I wrote a
little program to demsonstrate this to someone else earlier, I'm attaching
it to this email. It draws two side by side views which look the same, one
is rendered using 2D operations and one is rendered using 3D
operations. The 2D version performs the texture projection transformation
manually, so you can use it as a starting point to mess around with
projecting your own textures.

-- Marcin

On Mon, 1 Oct 2001, Dirk Scheffter wrote:

> Hi pfFolks,
>
> can anybody tell me anything about texture matrices resp. route me to
> articles, source code about?
>
> I want to map perspective distorted photos onto geometry.
> I know that modelers like MultiGen are able to do this but I want to
> provide this feature in our software.
>
> Any help is appreciated.
>
> Best regards,
> Dirk.
>
> -----------------------------------------------------------
> Dipl.-Inf. Dirk Scheffter scheff++at++iff.fhg.de
> Fraunhofer IFF fon: +49 (0) 391/40 90-854
> Sandtorstr. 22 fax: +49 (0) 391/40 90-870
> D-39106 Magdeburg http://www2.iff.fhg.de/~scheff
> Germany
> -----------------------------------------------------------
>
> -----------------------------------------------------------------------
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Open Development Project: http://oss.sgi.com/projects/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
> -----------------------------------------------------------------------
>




New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Oct 01 2001 - 13:29:37 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.