Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (604) Games in Android Showcase (171) games submitted by our members Games in WIP (652) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 3D perspective correct texture mapping  (Read 3571 times) 0 Members and 1 Guest are viewing this topic.
lcass
 « Posted 2013-11-20 21:59:19 »

Hello. Im looking for help with an algorithm on 3D Affine perspective correct texture mapping. This is basically rasterizing a 2d image in 3d space orthagonally.
EgonOlsen
 « Reply #1 - Posted 2013-11-20 22:32:19 »

You have either affine or perspective correct texture mapping. What is "affine perspective correct" supposed to be?

lcass
 « Reply #2 - Posted 2013-11-21 07:51:49 »

Ooop sorry I meant perspective correct
Roquen
 « Reply #3 - Posted 2013-11-21 07:54:02 »

Use hardware.
EgonOlsen
 « Reply #4 - Posted 2013-11-21 09:07:35 »

Ooop sorry I meant perspective correct
It's not much different from affine texture mapping, where you interpolate u/v linear along the edges and for each scan line. The problem here is that u and v are linear in 3d, but not in screen space. By doing it that way, you'll get this Playstation 1-wobble-effect in the textures.
However, what is linear in screen space is "anything" divided by z. So instead of interpolating u and v, you interpolate u/z and v/z. To get the proper texture coordinates from this, you have to know the current z. z itself is again not linear in screen space. But 1/z is, so you interpolate three values: u/z, v/z and 1/z. To get u and v for each pixel, you simply divide u/z and v/z by 1/z...which is rather costly to be done per pixel. You can do a little optimzation here by doing this all 8/16/32/whatever... pixels only and do a linear interpolation between these correct values.

If done well, it's pretty fast: http://www.jpct.net/quapplet/

Roquen
 « Reply #5 - Posted 2013-11-21 10:40:26 »

There's always the quadratic approximation which works in a fair number of situations and the error is easy to calculate so you can decide to sub-divide or use a different routine.  But I wouldn't bother, CPUs are much faster then when software rendering was required and the latency (in cycles) has also decreased.  But then again I wouldn't write a software renderer today either.
Roquen
 « Reply #6 - Posted 2013-11-21 11:22:24 »

Oh and an easy and reasonable thing to do is be correct every Nth pixel (do the divide) and lerp the coordinates for the pixels between.  Quake did this at every 4th pixel if memory serves.
EgonOlsen
 « Reply #7 - Posted 2013-11-21 11:26:19 »

Oh and an easy and reasonable thing to do is be correct every Nth pixel (do the divide) and lerp the coordinates for the pixels between.  Quake did this at every 4th pixel if memory serves.
That's what i wrote. Quake did it every 16 pixels btw.

Roquen
 « Reply #8 - Posted 2013-11-21 13:25:09 »

You did indeed.
lcass
 « Reply #9 - Posted 2013-11-21 15:37:34 »

Ooop sorry I meant perspective correct
It's not much different from affine texture mapping, where you interpolate u/v linear along the edges and for each scan line. The problem here is that u and v are linear in 3d, but not in screen space. By doing it that way, you'll get this Playstation 1-wobble-effect in the textures.
However, what is linear in screen space is "anything" divided by z. So instead of interpolating u and v, you interpolate u/z and v/z. To get the proper texture coordinates from this, you have to know the current z. z itself is again not linear in screen space. But 1/z is, so you interpolate three values: u/z, v/z and 1/z. To get u and v for each pixel, you simply divide u/z and v/z by 1/z...which is rather costly to be done per pixel. You can do a little optimzation here by doing this all 8/16/32/whatever... pixels only and do a linear interpolation between these correct values.

If done well, it's pretty fast: http://www.jpct.net/quapplet/
Are the U and V the coordinates of the pixel on the screen or are they the vector coordinates? . An example would really help .
EgonOlsen
 « Reply #10 - Posted 2013-11-21 17:54:44 »

Neither. u and v are the texture coordinates. Each vertex has x,y,z to define the point in space and u,v to define the texture coordinates.

lcass
 « Reply #11 - Posted 2013-11-21 18:10:32 »

sorry I dont quite understand what u and v are then. Are they just temporary coordinates?
cylab

JGO Wizard

Medals: 89

 « Reply #12 - Posted 2013-11-21 18:51:37 »

The letters "U" and "V" denote the axes of the 2D texture[note 1] because "X", "Y" and "Z" are already used to denote the axes of the 3D object in model space.

Source: Texture Mapping Mania

Mathias - I Know What [you] Did Last Summer!
lcass
 « Reply #13 - Posted 2013-11-22 08:19:29 »

Ahh I understand U and v now.
Roquen
 « Reply #14 - Posted 2013-11-22 08:39:05 »

As an aside I'd suggest not wasting your time writing a software rasterizer.  It's too big a time commitment vs. the useful learning (approaching none) you'll get from it.  Do something else.
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (24 views) 2015-08-01 03:58:20 Jesse (19 views) 2015-07-29 04:35:27 Riven (39 views) 2015-07-27 16:38:00 Riven (21 views) 2015-07-27 15:35:20 Riven (24 views) 2015-07-27 12:26:13 Riven (14 views) 2015-07-27 12:23:39 BurntPizza (35 views) 2015-07-25 00:14:37 BurntPizza (46 views) 2015-07-24 22:06:39 BurntPizza (28 views) 2015-07-24 06:06:53 NoxInc (36 views) 2015-07-22 22:16:53
 theagentd 51x wessles 46x basil_ 35x KaiHH 26x orangepascal 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x CelestialCreator 11x princec 11x klaus 11x Jesse 11x pquiring 9x chrislo27 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org