4
\$\begingroup\$

I beg your pardon if this question has been already answered elsewhere or if this is the wrong site, but I have a serious issue with rendering textures with Direct3D 11.

Using Cinema 4D R17, I created a simple cube, triangulated all polygons, and UV mapped a texture, as you can see here:
enter image description here
and it renders correctly.

Next, I exported the file to .x because I created a simpler mesh format and .x is ideal for getting vertices, indices, normals, texture coordinates, etc. This conversion is perfect as all data from the source file is successfully transferred to my file (I checked and double checked it).

However, when I upload the file in my game engine, I get the following result:enter image description here
The cube is being rendered incorrectly where that strange pattern forms.

This is the original .x file (I included only relevant parts):

Mesh CINEMA4D_Mesh {
  8;
  // Cube. These are vertices.
  -0.01;-0.01;-0.01;,
  -0.01;0.01;-0.01;,
  0.01;-0.01;-0.01;,
  0.01;0.01;-0.01;,
  0.01;-0.01;0.01;,
  0.01;0.01;0.01;,
  -0.01;-0.01;0.01;,
  -0.01;0.01;0.01;;

  12;
  // Cube. These are indices.
  3;0,1,3;, // '3;' means that this face contains 3 vertices.
  3;2,3,5;,
  3;4,5,7;,
  3;6,7,1;,
  3;1,7,5;,
  3;6,0,2;,
  3;0,3,2;,
  3;2,5,4;,
  3;4,7,6;,
  3;6,1,0;,
  3;1,5,3;,
  3;6,2,4;;

  MeshNormals {
    8;
    // Cube
    -0.408;-0.408;-0.816;,
    -0.667;0.667;-0.333;,
    0.667;-0.667;-0.333;,
    0.408;0.408;-0.816;,
    0.408;-0.408;0.816;,
    0.667;0.667;0.333;,
    -0.667;-0.667;0.333;,
    -0.408;0.408;0.816;;

    12;
    // Cube
    3;0,1,3;,
    3;2,3,5;,
    3;4,5,7;,
    3;6,7,1;,
    3;1,7,5;,
    3;6,0,2;,
    3;0,3,2;,
    3;2,5,4;,
    3;4,7,6;,
    3;6,1,0;,
    3;1,5,3;,
    3;6,2,4;;

  }
  MeshTextureCoords {
    8;
    // Cube
    1.0;1.0;,
    0.0;1.0;,
    1.0;0.0;,
    1.0;1.0;,
    1.0;1.0;,
    1.0;0.0;,
    0.0;1.0;,
    1.0;0.0;;
  }
  MeshMaterialList {
    2;
    12;
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1;

    Material C4DMAT_NONE {
      1.0;1.0;1.0;1.0;;
      1.0;
      0.0;0.0;0.0;;
      0.0;0.0;0.0;;
    }
    Material C4DMAT_Mat {
      1.0;1.0;1.0;1.0;;
      1.0;
      0.0;0.0;0.0;;
      0.0;0.0;0.0;;
      TextureFilename {
        "tex.bmp";
      }
    }

    {C4DMAT_Mat}
  }
}

I also invert the vtexture coordinate (v = 1 -v). This is the vertex data I extract:

8 // Number of vertices.
-0.01 -0.01 -0.01 -0.01 0.01 -0.01 0.01 -0.01 -0.01 0.01 0.01 -0.01 0.01 -0.01 0.01 0.01 0.01 0.01 -0.01 -0.01 0.01 -0.01 0.01 0.01 // Vertices stored in X, Y, Z.
1 0 0 0 1 1 1 0 1 0 1 1 0 0 1 1  // Texture coordinates stored in U, V.
36 // Indices count.
0 1 3 2 3 5 4 5 7 6 7 1 1 7 5 6 0 2 0 3 2 2 5 4 4 7 6 6 1 0 1 5 3 6 2 4 // Indices. 
tex.bmp // Texture file name.

I read that there might be a conflict between texture coordinates of vertices that are shared among different faces and that resolving this would imply not using index buffers.

EDIT: I did what @wondra said (replaced texture coordinates with 0 0 0 1 1 0 1 1 0 1 0 0 1 1 1 0 and it looks better indeed:
enter image description here

I am not sure what is wrong here. Could anybody help me? Thank you.

UPDATE: The Cinema 4D .obj is broken. Use Blender or anything else.

\$\endgroup\$
  • \$\begingroup\$ I cannot see any [0,1] texture coordinate in your file(unlesss it is not u v u v u v). Are you sure the data are correct? \$\endgroup\$ – wondra Jul 1 '16 at 17:58
  • \$\begingroup\$ Yes they are U, V. \$\endgroup\$ – Victor Gabriel Ungureanu Jul 1 '16 at 18:34
  • \$\begingroup\$ In that case, you need to triple-check your importing/converting code. One of the corners of the texture, upper left, vanquished somewhere in the process(the image even looks like it). The u,v data with just 3 corners cannot be possibly correct. \$\endgroup\$ – wondra Jul 1 '16 at 18:39
  • \$\begingroup\$ I don't know what's wrong, I uploaded more information. @wondra May you check it, please? \$\endgroup\$ – Victor Gabriel Ungureanu Jul 2 '16 at 5:43
  • \$\begingroup\$ What if you try to replace the u,v in the processed file with 0 0 0 1 1 0 1 1 0 1 0 0 1 1 1 0 does it look "better", at least one of the faces? Note: those are probably not entirely correct but should the cube look any better it would prove my theory. Also looking at the original file - there actually are just 3 corners exported - should it be like that? Is it mapped in the editor with just 3 of them(could be)? \$\endgroup\$ – wondra Jul 2 '16 at 9:25
1
\$\begingroup\$

I you look carefully your cube in Cinema4D, the top most corner show different texture coordinate for the side and the top ( probably the same between front and right side, but the texture can't let me state it for sure ).

And in your final cube indices, you only have a range [0..7]. On the GPU, a vertex is a full tuple of values with a single index. It means that your cube is not made of 8 vertex but 24, because each corner has to be split for his own normal and texture coordinate.

Once you split each face properly, you should get the correct visual. A cube is not the best example of index buffer because the vertex reuse rate is quite low, but you still get the idea.

\$\endgroup\$
0
\$\begingroup\$

It turns out that the .obj file exported by Cinema 4D was broken.

Using Blender or anything else to create the .obj file seems to solve the issue.

\$\endgroup\$
  • \$\begingroup\$ I was thinking this as an answer. I will do as you say. \$\endgroup\$ – Victor Gabriel Ungureanu Jul 4 '16 at 17:11
  • 1
    \$\begingroup\$ Oh, hmm. Then make it clear that it's an answer. The term "UPDATE" is generally used to add additional information to the question, not to introduce a solution. \$\endgroup\$ – Alexandre Vaillancourt Jul 4 '16 at 17:14
  • 1
    \$\begingroup\$ You can rephrased if you feel like it, but now it makes it look more like a good answer :) \$\endgroup\$ – Alexandre Vaillancourt Jul 4 '16 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.