Jump to content
  • Advertisement
Sign in to follow this  
Kitasia

Texture Coordinate Storage within Model

This topic is 2835 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

I've read that texture coordinates are applied on a triangle/face basis. I've been storing them on a polygon mesh basis and referencing them from face indices.

Wouldn't applying texture coordinates per face, create a lot of vertex duplicates? Not only does that increase the size of the file but I would think it decreases rendering effecientcy by supplying vertex duplicates.

The problem with my current setup is, when I actually need seperate uvs or normals, I have to use the polygonmesh itself as a face.

Any advice? I'm hoping the vertex duplicates aren't as bad as they sound.

Share this post


Link to post
Share on other sites
Advertisement
Can you try to explain this more?

Quote:

I've been storing them on a polygon mesh basis and referencing them from face indices.


I'm not familiar with your terminology, or what you mean to use a 'polygonmesh itself as a face'

Typically you store UV coordinates per vertex, and face indices point to unified vertices (position,normal,texcoord). Data duplication is required anytime any part of the unified vertex varies to use hardware buffers on GPU.

Share this post


Link to post
Share on other sites
This is pretty much a simplified version of what I'm doing

+ PolygonMesh/ Triangle Mesh
--Vertices
--Material Data etc..
-+Faces
---Indices

Here's a version of what I think is more common

+Mesh
--Material Data etc...
-+Faces
---Vertices
---Indices (if faces are not triangle only)

I would need duplicate data whever parts of the vertices change but with the second setup I'm guaranteed duplicate data. But of course if that isn't a big deal I don't really mind.

Lots of things seldom need seperate uvs and normals, like character models.

Share this post


Link to post
Share on other sites
Hi,

In OpenGL, normals, texture coordinates, color, etc. are all specified per-vertex--the intermediate calls simply change OpenGL's state. If you want to specify per-face texture coordinates, OpenGL will simply specify the same texture coordinate at all three vertices.

In code:
glTexCoord2d(1.0,0.0); glVertex3d(0.0,0.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)
glTexCoord2d(1.0,0.0); glVertex3d(1.0,0.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)
glTexCoord2d(1.0,0.0); glVertex3d(1.0,1.0,0.0); //Sets the texcoords to (1,0), then issues vertex with the current texture coordinate (1,0)
Is exactly the same as:
glTexCoord2d(1.0,0.0); //Sets texcoords to (1,0)
glVertex3d(0.0,0.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))
glVertex3d(1.0,0.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))
glVertex3d(1.0,1.0,0.0); //Issues vertex with the current texture coordinate (which is (1,0))
In both cases, the texture coordinate (1,0) will be applied for each vertex--each vertex storing its own copy of (1,0), which was the current state of OpenGL at the time.

You can make your own optimized model loader that only changes the OpenGL state when necessary (i.e., the second block of code), but generally, each of the parameters you're using are specified per-vertex.

Ian

Share this post


Link to post
Share on other sites
There seems to be a consensus that uvs are stored per vertex. My source is actually wikipedia so it's definitely possible the article could be wrong in a general sense.
Quote:

UV coordinates are applied per face[2], not per vertex.



Quote:

In OpenGL, normals, texture coordinates, color, etc. are all specified per-vertex--the intermediate calls simply change OpenGL's state. If you want to specify per-face texture coordinates, OpenGL will simply specify the same texture coordinate at all three vertices.


Do all graphics APIs internally do that? I'm using XNA which is probably the same for DirectX. If that's the case, my point would be more or less moot.

Share this post


Link to post
Share on other sites
The texture coordinates should be per vertex. However if you want two faces that share vertices to use different texcoords, than just duplicate the vertices to achieve the same thing.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!