Game Development Community

(psuedo-) 3D (gl) question.

by Sebastiaan Keek · in Torque Game Engine · 05/02/2003 (2:29 am) · 10 replies

Assuming we've got a nice square texture.
And we put it into the game world using GL_QUADS.
It's possible to create a rail-road effect.
If two points of the square are close by, and 2 are really far away, you can see an semi-triangle in wich the texture is really nicely fitted.

Now it's possible to create the same thing (visually) by keeping the closest points where they where and pulling the furthest points close to each other and upwards.
While if you move the difference becomes apparant, this configuration really recreates the same visual apearance of our real 3d configuration and becomming some sort of psuedo 3d.

However, the texture wrapping inside this semi-triangle is off as one of the faces of the square is differently mapped compared to the other.

Now my question, Is there some trick,gl-routine or methode to make the second configuration have the same mapping as the real 3d one?

I'm not really concerned about it looking 3d or whatnot.. however the current mapping is just not right.


Any help will be greatly apriciated. :D

#1
05/02/2003 (4:34 am)
Not sure what you're trying to do but it sounds like you are referring to perspective texture correction.

You'll find plenty of references to this about.

- Melv.
#2
05/02/2003 (5:25 am)
Maybe I could put that in a more techinal description.

Assuming we've got an square texture. "0 0" "1 0" "1 1" "0 1"
If I try to fit on to the following surface.
"-5 -1 0" "5 -1 0" "1 1 0" "-1 1 0".
The surface now is split up into two vertices.
However vertice "-5 -1 0" "5 -1 0" "1 1 0" takes up allot more area than vertice "5 -1 0" "1 1 0" "-1 1 0" while still having only half of the texture.

Therefore 50% of the texture goes into a large area streching it out like crazy, while the other 50% of the texture goes into the remaining small area compressing it.

So, is there a way to make up for this "area" difference without making changes to the texture externally?

And if not, how does the effect of perspective manage to do this?
#3
05/02/2003 (5:58 am)
I think I can visualise what you're doing here although I don't know why and I'm not sure what you mean by "make up for it".

Is it the stretching that bothers you? If so, then simply use a higher resolution texture so the interpolation is not so evident.

If it's the texture distortion from the top/bottom of your QUAD you don't like then you can always manipulate the texture coordinates so that the largest edge textures the whole width of the texture and the smallest edge textures a relatively smaller width. If you adjust the bottom-edge texture coords inwards by (Smallest-Edge / Largest-Edge)/2 then this would work, e.g.

Width vertices...
[-10,-1]
[-5,+1]
[+5,+1]
[+10,-1]

Therefore Offset = (Smallest-Edge / Largest-Edge)/2 = ( 10 / 20 ) / 2 = 0.25

Texture Coords become...
[0,0]
[Offset,1]
[-1-Offset,1]
[1,0]

This equates to screen-space texturing.

There are also things you can play with using glTexCoord3f/4f!

If I've understood your problem, I hope this helps!

- Melv.
#4
05/02/2003 (7:03 am)
Your second solution would be sufficient, where it not that I would like to use the whole texture.

The problem really is that the shape is torn into half (the two vertices) and it's visually apparent since one has half the texture, but takes up for 75% of the object.

Like I tried to mention earlier, if the same shape would be infact an correct square, but only seen in perspective, the shape would be the same, but the mapping would be correct.


I'm bassically working on an ring shaped object.
Imagine two circles, one with radius 10 and one with radius 5.
The smaller one inside the larger one. This makes a band.
Now I would like to put a texture in it, wich isn't really hard.
The ring is constructed out of shapes like I mentioned bassically squares, only the top is smaller than the bottom.

The problem is, as the smaller circle gets smaller and smaller.. the shapes become triangles, where two points of the triangle ly on the edge of the outer circle.. and one points is located at the center of the cirlce (or the inner circle wich has become a dot).
However that point at the center of the circle represents two points on the texture.

Confused?.. I know I am. Just forget you just read that. ;)

Eitherway,

When in perspective two points of an texture square get close to each other, the texture mapping is correct.
When however the shape of the object is such that two points are close to each other the vertices that make up the square become unequal size while remaining equal part of the texture.

...
oh well.. maybe I'm asking too much of the poor ol' graphic engine, thought I still find it curious.
#5
05/03/2003 (3:06 am)
I think this is one of those things where you'd have to post an image so show the effect your describing!

- Melv.
#6
05/03/2003 (3:31 am)
Your very right... so here we go.
www.tribes3.org/forums/attachment.php?s=&postid=31326
The object on the right is an correctly mapped square object.
The object in the center is the same shape as on the right.. only titled so it takes apearance of the shape I want because of perspective.

Now.. the shape on the left is what I've been talking about... you can clearly see an defect in the mapping and see that it's build out of two vertices.

Now how would I get the mapping(texture scaling) of the center object onto the left object?
#7
05/03/2003 (4:01 am)
And here is why I'd rather not use your second methode melv...
even thought your correct when you say it'l keep the textures from dissorting this way.

www.tribes3.org/forums/attachment.php?s=&postid=31328
Here you see two disks using the texture displayed on the bottom.

The right disk has correct mapping... but only because it's not really a disk.. but an cylinder. in perspective.

The left one is flat.. only because of the mapping problem looks oddly mapped.

The reason I'd rather not cut edges out of the texture to amount for the dissortion is because it'l keep the ring segments from matching their textures like they should.
#8
05/03/2003 (4:22 am)
The issue here is the use of homogenous texture co-ordinates and perspective texture mapping.

There are lots of references to this on the net.

Here's one but there are plenty of others to explain it with images better than I could here.

- Melv.
#9
05/03/2003 (4:34 am)
That link makes sense... maybe there's a hacky way to implement that by rearanging the vertice locations.
I'l go try.

You where kinda right from the start... tho this isn't perspective (perspective is only a good exapmle how it should be).
But messing with the 'gl' powers that be is a bit out of my league..


Anyways.. thank for your help..
#10
05/03/2003 (5:33 am)
After checking.. the only easy solution would be to divide one plane into a large amount of vertices.

Either that, or dig through the gl code and implement a new perspective correction interpolation feature for all textures.