PDA

View Full Version : cubemapping and texture coordinates

_arts_
03-29-2011, 12:56 AM
Hello,

I have issues for generating texture coordinates for cubemapped objects.

Here's about the story: I load a model which has 3D texture coordinates. This models renders pretty well with cubemapping, the textures do not overlap, are not distorded and so on.

Now I would like to generate textures for it, by program.
For achieving this, I use this tutorial to calculate which cubemap texture to bind for, and the 2D texture coordinates according the 3D textures coordinates:
http://developer.nvidia.com/object/cube_map_ogl_tutorial.html

However, the texture looks very strange (cf image link below).

Basically, choosing the good texture to bind for (GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB...), works very fine, since I tested it for drawing normals with different kind of colors according to the 3D textures coordinates. So I guess, maybe I misunderstood the calculations to transform a (s,t,r) texture coordinates to a (s,t) one.

Here is a piece of code of what I'm doing:

// if s is positive and the major axis direction:
s = (-rz/ax+1)/2;
t = (-ry/ax+1)/2;
// same but s is negative:
s = (rz/ax+1)/2;
t = (-ry/ax+1)/2;
...

where rx,ry,rz are the (s,t,r) texture coordinates, and ax,ay,az, the magnitude (so postive parts) of these texture coordinates.

I stricly followed up what nvidia said about the calculations.

But maybe I misunderstood the sc,tc and ma values ? What do you think about how I calculated s,t here ?

EDIT: I colored every triangle with random color. So, what's messed in the image is not those little colored triangles, but the long rectangles and the big blue triangle.

mobeen
03-29-2011, 04:59 AM
I am not sure whether this helps in solving the issue but just one thing that i note in the tutorial and then skimming through the code snippet u posted. Shouldn't ax in the denominator be abs(ax)?

// if s is positive and the major axis direction:
ax = abs(ax);
s = (-rz/ax+1)/2;
t = (-ry/ax+1)/2;
// same but s is negative:
s = (rz/ax+1)/2;
t = (-ry/ax+1)/2;

_arts_
03-29-2011, 05:07 AM
ax,ay and az are absolute values of rx,ry and rz respectively.

Sorry if it wasn't clear in my explanation. Here is the code I use for them:

GLdouble rx = tx[0];
GLdouble ry = tx[1];
GLdouble rz = tx[2];
GLdouble ax = std::fabs (rx);
GLdouble ay = std::fabs (ry);
GLdouble az = std::fabs (rz);

From what I could deduced, it seems some s,t values are badly calculated. I'm trying to figure it out, but can't for now. What I know is that it has nothing to do with ax,ay,az tending to 0 (checked). It's nothing to do either with the providen 3D texture coordinates since I can render the model with a cubemap very nicely. And I _think_ there is nothing to do with how to choose the correct face of the cubemap: I only use the first texcoord of a face to choose the face of the cubemap. If I use all 3 values, I noticed that sometimes some texcoords of a same face lead to choose different faces of the cubemap... strangely.

_arts_
03-29-2011, 11:17 AM
OK, I found a way. Some triangles share two or more faces of the cubemap, so calculations were wrong for those triangles.

_arts_
03-31-2011, 12:34 AM
Well, my teacher said me it looks very strange for him that I need to manually clip the triangles that lie on several faces of the cubemap, to remove these artifacts. For him, there's not need to "hard-code" this, I can easily do it using OpenGL techniques.

However, I'm playing with OpenGL, since last time, trying to make it clip these triangles without any artifact on the generated texture, but I found nothing convincing at all: I always have such large triangles covering all the texture.