Search code examples
texturesmeshdirect3d11uv-mappingcinema-4d

Texture coordinates do not map correctly in Direct3D11 game engine


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 sphere, triangulated all polygons, and I UV mapped a texture, as you can see here:enter image description hereand 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 planet is being rendered correctly on all sides, except at the end of the texture, where that strange pattern forms. It appears as if the whole texture was being mapped again on that small patch of triangles.

This is not the first time I get something like this. I also have similar problems with a cube textured cube:
enter image description here
when it should have looked like this: enter image description here

This is the vertex data for the cube:

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.
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_1.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.

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


Solution

  • I finally got it! The Cinema 4D exporter is broken, I don't know why. I switched to .obj and using the parser provided by Microsoft but it was still not working. Then, I switched to Blender, added the texture, triangulated the faces and exported it and it works as supposed.