Jorge125


Hello,

I'm writing my own content importer for my maps.
At the moment, I'm able to load all triangles and draw the map but i have a problem with textures.

In my importer i load texture like this (it's just a test) :

BasicMaterialContent material = new BasicMaterialContent();

String texturePath = Path.GetDirectoryName(filename) + "\\Textures\\wall.jpg";

if (!System.IO.File.Exists(texturePath))
throw new Exception("Texture not found !");

material.Texture = new ExternalReference<TextureContent>(texturePath);

Then I apply my texture to a mesh :

builder.SetMaterial(material);

When I deploy it on xbox360 or run it on my pc, my mesh have a color similar to my texture but it's just a color! I can't see real texture.

Before that, for each vertices of my map I have U and V coordinates. I init vertices and UV coordinates at the same time like this :

builder.CreatePosition(
curVertex.Coord.X,
curVertex.Coord.Y,
curVertex.Coord.Z
);

Vector2 uv = new Vector2((float)curVertex.U, (float)curVertex.V);

builder.SetVertexChannelData(
texCoordChannel,
uv
);

And finally I set indices.

Thanks to help me


Re: Texturing problem

Leaf.


Seeing meshes with a solid colour similar to the texture is almost always a problem with your UV coordinates. Where that problem is I can't tell you. You could try using Pix in the DirectX SDK to investigate. Using Pix you can see exactly what the content of the vertices when they are submitted to the card.

Cheers,
Leaf.





Re: Texturing problem

Jorge125

thanks for your answer.

That's what i was thinking it's a problem with my UV coordinates.

But I have UV coordinates for each vertex of my map, what's the right way to initialize my texture coordinates channel

As you can see, I've tried the solution above but nothing.

 

Thanks






Re: Texturing problem

Shawn Hargreaves - MSFT

Have you checked the values of your texture coordinates Is it possible these are all zero, or perhaps too large (anything much greater than 1.0 is probably an error).





Re: Texturing problem

Jorge125

yes i make a logFile to check that, here for example a little simple map :

Polygon 0
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
Polygon 1
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
Polygon 2
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
Polygon 3
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0
Polygon 4
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
Polygon 5
U : 1 V : 1
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
Polygon 6
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0
Polygon 7
U : 1 V : 1
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
Polygon 8
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
U : 1 V : 0
Polygon 9
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0
U : 0 V : 0
Polygon 10
U : 0 V : 1
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
Polygon 11
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
Polygon 12
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
Polygon 13
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0
Polygon 14
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
Polygon 15
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
U : 1 V : 0
Polygon 16
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
Polygon 17
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
Polygon 18
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
U : 0 V : 0
Polygon 19
U : 1 V : 0
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
Polygon 20
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0
Polygon 21
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
Polygon 22
U : 0 V : 0
U : 1 V : 0
U : 1 V : 1
U : 0 V : 1
Polygon 23
U : 0 V : 0
U : 0 V : 1
U : 1 V : 1
U : 1 V : 0

Coordinates seems to be good.

I've see some examples where UV are initialize at the same time of adding index, is it the right way





Re: Texturing problem

Shawn Hargreaves - MSFT

Your builder code looks ok to me.

I think this would be a good time to bring out PIX for Windows. Get a capture of one frame of your game, and debug inside the rendering of your mesh. This will let you examine exactly what was in the texture while rendering, what values were read into the vertex shader, and what the vertex shader outputs were: that should make it easy to see where along the line the data is going wrong.





Re: Texturing problem

Jorge125

I've just tried PIX for windows, it's look to be a nice tool!

I've ran my test app and when i capture frame I have following results (screen shot) : http://img410.imageshack.us/img410/903/testsq6.jpg

I directly see the problem is my textures coordinates. All values are 0 and 1 for each vertex, I'm always looking for why.

If someone can help me it could be very useful :)

Thanks a lot





Re: Texturing problem

Jorge125

To render my model I use :

foreach (ModelMesh mesh in map.Meshes)

{

foreach (BasicEffect effect in mesh.Effects)

{

effect.EnableDefaultLighting();

effect.World = sceneWorldTransformation;

effect.View = view;

effect.Projection = proj;

}

mesh.Draw();

}

In my draw() function, Do I need a special effect file to render textures correctly

Thanks





Re: Texturing problem

Shawn Hargreaves - MSFT

BasicEffect can handle texturing just fine, as long as it has good UV coordinates in the input mesh.





Re: Texturing problem

The ZMan

Its sometimes useful to assing your u,v to the color of the vertex. put u in the R channel and v in the B channel. This will give you a way to visualize the u,v coordinates and see if they look 'right' on the screen and the triangles.