Revision date: 08/12/07.
GP4 is now fully in 3D and thus editing GP4 graphics needs from modders to know some 3D basic knowledge.
This quick guide is here as a reference material about texture mapping questions and especially when applied to GP4 in general and GP4Builder in particular.
Generaly speaking, 3D Objects do not need textures to exist.
You can quickly experiment in GP4, if a texture is missing in a .wad, object won't disappear but it will be white.
So if we decide to apply a texture to an object, we will have to make a link between the object and the texture.
This link is made of 2 parts : the name of the texture the object will use and the way texture will be applied on the object.
For this second part, 3D art needs to set what we call texture coordinates for each vertex of the object we want to map the texture onto.
Basically, these are 2 coordinates applied to each point and which are coming along the 3 vertex coordinates and the 3 normals coordinates that usualy defines a 3D face vertex.
If three dimensional coordinates like vertex and normal ones are often named as x, y and z, texture coordinates have been named differently to differentiate them from standard vector coordinates. So they are named u and v (in 3D, everything can have 3 dimensions and there's also a third texture component that is named w but it will never be used with GP4 so we will forget about it in this guide).
u coordinate tells what point on the width of the texture will be pined at the vertex location.
v coordinate tells what point on the height of the texture will be pined at the vertex location .
So using both u and v coordinates for a vertex will tell the 3D engine witch point of the texture will be pined on the object at each vertex location.
Note that in GP4, u positive direction goes from left to right and v positive one goes from top to bottom.
So a 0,0 texture coordinates will point to the top-left texture point when a 1,1 will point to the most bottom-right one.
In practice, you can use texture coordinates for any object and even the smallest one which is ... a triangular face.
But triangular faces are barely used alone and our textures are rectangular, so applying a rectangular texture on a triangle is something quite hmm...weird.
So let's talk about the common case, the quad.
A quad is simply a rectangular 3D shape made of 2 triangular faces sharing 2 vertices.
So here is our quad model :
This quad has already received some default mapping coordinates.
In every example of this guide, texture coordinates will be written as on the quad model above using the following notation : (u,v).
We also need a texture to map so here is the one I chose :
The last thing to do is to apply the texture onto the quad. If you apply it right now, here is the result you will get :
You can check that texture point are pined to the four vertices as decribed by the coordinates.
The most top-left point of the texture is pined on vertice having (0,0) coordinates for example.
Using (1,0) coordinates, we call for the top-right texture point for the top right vertice.
The texture is then stretched between the vertices to pin every texture points to every vertice.
Nature hates vacuum, as does 3D engines, so if any coordinate is above 1 (or below 0), texture will be repeated.
For example, if we want to repeat the texture twice over the quad on the horizontal direction, we can easily change u values to rightmost vertices to 2.
As we do not change the v values, texture is always stretched normally in height, but it has been squeezed by 2 on its width.
let's change v now :
The ratio came back to normal but as u and v coordinates are between 0 and 2, texture is repeated twice vertically and horizontally : we get four textures.
Let's come back to our original mapping.
Note that u and v values are not integer but floating point values, so using decimals is very possible like in :
Here I changed u values to 0.5 and thus only the left half of the texture appears on the quad.
Using both u and v values between 0 and 0,5, we then only see 1/4 of the texture.
To end this part, I want to also tell you that u and v values can also be negative.
This can be pretty usefull to mirror a texture :
Here I invert the horizontal direction of the texture using u=0 for left vertices and u= -1 for right ones.
Texture is then stretched reversed.
As a last note, result would have been the same if I would have used positive but reversed values, like u=1 for left vertices and u=0 for right one.
Of course, because we would have pined the left texture points (u=0) to right vertices and the right texture points (u=1) to left ones !
I hope you're not lost yet. If so, calm down and re-read slowly the section above to better get what you missed so far.
When you will be confident, keep on the 2 quads case...
Most of the time, quads won't be alone but rather linked in a more or less long ribbon, each quad sharing two vertices with each of its neighbours.
To keep simplicity, we will only use 2 quads in the following examples as below :
With this default texture coordinates, we will get :
You can note that texture is perfectly stretched over the 2 quads as texture points are pined to vertices as they should.
If we prefer to have 1 texture per quad as before, we can do it by simply doing :
As with the example for a single quad, using values above 1 repeats the texture to fill the "gap".
As vertices are equally distant in this example and that coordinates are integer values equally distant of 1, each texture cover one quad.
But with non-integer values ?
As you can see below, you can easily set the texture to repeat 3 times over the 2 quads by setting u values to 0, 1.5 and 3.
0 is for the top left texture point, 3 is for the top right texture position of the third tile (texture repetition) and in the middle, to keep harmony we set 1.5, the average of 0 and 3.
To end this part, here is a last example to show that we can still reverse reverse textures with negatives values :
As we saw for the single quad example, using u between 0 and -1 reverse the texture, and so it is for the first quad here. The second quad is mapped as usual. Don't get fooled by the fact we used negative values for the middle vertices, result is the same as if we have used u between 0 and 1, texture is simply repeated here in the usual direction.
So here is the end of this little guide.
I hope it helped you to see clearer on what's texture mapping and how texture coordinates are pinning a texture on 3D object vertice.
Examples above are simple (yes, they are :)), I avoid to tell you about the single face case or about the sphere case or the case where each vertices are absolutely not drawing a rectangle but a deformed quadrilatere, or...well, I think you get the idea :)
So let's start with these cases and they should just cover most of what you will encounter when you will start to map textures onto game objects.
So I hope you had a good read and I wish you the best your your next 3D projects.
(Creator of TeamEditor and GP4Builder amongst many other GP4 tools)
Revision History
v1.02 : fixed several missing words and typing errors
v1.01 : fixed a mistake in very last example with 2 quads and negative values
v1.00 : Initial release