Deadlock in Texture Coords for Cube Rendering

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
nighthawk
Posts: 16
Joined: Tue May 30, 2006 5:43 am

Deadlock in Texture Coords for Cube Rendering

Post by nighthawk »

Hi all,

I was trying to render a cube with a distinct texture for each surface. I found there is a dead lock in texture coords that prevents rendering all six surfaces correctly. In other words, only four surfaces can show texture correctly. It is inevitable that textures in the other two surfaces are distorted.

Please refer to the following illustration and please be noted that in symbol Axy, A is the name of the vertex while xy is the texture coords of the vertex.

Image

With texture coords shown above, the texture for ABHE is distorted because both E and B are with the texture coords of (1, 1). It's the same for surface CDGF except that C and G are both with the texture coords of (0, 0).

Is this a problem intrinsic to Irrlicht? Is there any way that this problem can be solved with the current code base? Any input will be appreciated.

Thanks,
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

You'd have to have 3*6 verticles to solve this, where each corner has 3 verticles each, since they 'touch' 3 (poossibly) individual surfaces.
Last edited by Luben on Tue May 15, 2007 5:57 pm, edited 1 time in total.
If you don't have anything nice to say, don't say anything at all.
nighthawk
Posts: 16
Joined: Tue May 30, 2006 5:43 am

Post by nighthawk »

Hi Luben, thank you for the reply. But can you elaborate a little bit more. I'm new to Irrlicht. I did not get the whole picture of what you've said.
nighthawk
Posts: 16
Joined: Tue May 30, 2006 5:43 am

(Solved) Deadlock in Texture Coords for Cube Rendering

Post by nighthawk »

Never mind, I figured it out. Actually to render the cube, 12 vertices are enough. For example, given the vertices are like the following:

vertices[0] = S3DVertex(-1,-1,-1, -1,-1,-1, SColor(255,255,255,255), 0, 1);
vertices[1] = S3DVertex( 1,-1,-1, 1,-1,-1, SColor(255,255,255,255), 1, 1);
vertices[2] = S3DVertex( 1, 1,-1, 1, 1,-1, SColor(255,255,255,255), 1, 0);
vertices[3] = S3DVertex(-1, 1,-1, -1, 1,-1, SColor(255,255,255,255), 0, 0);
vertices[4] = S3DVertex( 1,-1, 1, 1,-1, 1, SColor(255,255,255,255), 0, 1);
vertices[5] = S3DVertex( 1, 1, 1, 1, 1, 1, SColor(255,255,255,255), 0, 0);
vertices[6] = S3DVertex(-1, 1, 1, -1, 1, 1, SColor(255,255,255,255), 1, 0);
vertices[7] = S3DVertex(-1,-1, 1, -1,-1, 1, SColor(255,255,255,255), 1, 1);
vertices[8] = S3DVertex(-1, 1, 1, -1, 1, 1, SColor(255,255,255,255), 0, 1);
vertices[9] = S3DVertex(-1, 1,-1, -1, 1,-1, SColor(255,255,255,255), 1, 1);
vertices[10] = S3DVertex( 1,-1, 1, 1,-1, 1, SColor(255,255,255,255), 1, 0);
vertices[11] = S3DVertex( 1,-1,-1, 1,-1,-1, SColor(255,255,255,255), 0, 0);

For surface ABHE, vertices 0, 11, 4 and 7 should be used instead of 0, 1, 4 and 7. And for surface CDGF, vertices 2, 9, 6 and 5 should be used instead of 2, 3, 6 and 5.

With these changes, the cube is rendered as designed.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Yah it can but you'll lose the individuality of the triangle edges, since some verticles are shared between faces. Consider this pictures that show some possible combinations, where 2 triangles use the same vert(and not)

Image

It works fine for the vertical side, but the horizontal side now have a wierd normal. The solution is either to make the normal a mix of the both wanted normals, but that creates a 'round'-like effect, since the normal is interpolated around the corner then.
Or, you could make 2 verticles with individual normals, and you'll have a 'sharp edge' again.

The same applies for tex coords, they'll share the coord unless you make multiple verticles at the same point with individual tex coords.
I failed to count the corners of a box before, it should be 3*8 verticles :P
If you don't have anything nice to say, don't say anything at all.
Post Reply