Jump to content
  • Advertisement
Sign in to follow this  
Hawkblood

texturing an indexed primitive

This topic is 2149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is most likely a noob question, but I haven't figured this out yet and I can't find the answer anywhere in a search (probably because I'm not asking the right question).

 

I am generating a terrain that uses isosurface by Raghvendra Chandrashekara. Once the vertexes are generated, it is converted to an indexed primitive. I want to texture each face separately with its own texture coordinates-- I don't know how to do that.

 

The normal way of texturing has each vertex with a UV coordinate, but I think I need each FACE to have its own set of those coordinates (hope this is making sense). Here is an example texture:

[attachment=18955:ShipIntTex01.png]

 

For instance, I have a flat mesh with 6 vertices and I want the texturing to look like this:

[attachment=18956:Untitled.png]

 

With the conventional way, I would end up with this instead: (similar, but not actual)

[attachment=18957:Untitled2.png]

 

 

How do I achieve this?

Share this post


Link to post
Share on other sites
Advertisement

I assume you mean that the two tiles are two quads (or something equivalent), and you end up with six vertices since the two middle ones are shared between the two adjacent tiles. Long story short, the two vertices in the middle are no the same, and you actually have eight vertices. The four vertices in the middle may have common position attribute values, but since they have different texture coordinate attribute values they are also different vertices.

Share this post


Link to post
Share on other sites

Is that how I have to do it? I was hoping there was a way to have the "common" vertices referenced with different UVs..... If that's the only way, then I already understand how.

Share this post


Link to post
Share on other sites

I was hoping there was a way to have the "common" vertices referenced with different UVs

The vertex is a structure containing a position and texture coordinates here (at least)

So if you have same position but different texture coordinates, you'll have to define different vertices containing the same position but different texture coordinates.

Share this post


Link to post
Share on other sites

sad.png  I was hoping to avoid that.................

Vertex processing works one primitive at a time. When you draw the left square you need vertex records with the left square texture coordinates, when you draw the right square you need vertex records with the right square texture coordinates.

With six plain vertex records containing x,y,z,u and v you only have six places for eight texture coordinate pairs.

Share this post


Link to post
Share on other sites

If your object is described as a grid, you may be able to represent each such square face using integer coordinates.

In 2D, you would have:

int x, y;

Now, you add the texture. This may be a texture ID or the texture coordinates (of which there would be 4 - this is a whole polygon)

int x, y, textureID;

or

int x, y;
float[4][2] texCoords;

Now, what you would do is pass these tiles/faces to the GPU, as well as the offset/scale/orientation of your "grid" from the origin (because the integer x,y coords are relative to the grid origin and dont tell anything about the size of the single grid cell). You can then make the GPU expand these faces into full polygons (or polygon pairs if you use triangles), each vertex having the appropriate position and texture coordinate.

 

 

This however requires the graphics API to support constructing the faces on the GPU, im not sure if DX9 can do that. I feel like it should.

 

 

You are still using individual vertices for each corner of each face, but the size of the data should be significantly lower, especially if you can use a texture ID instead of per-corner coords and if you can use smaller integer types for the position of the face within the grid.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!