Sign in to follow this  
AntiGuy

Texture Coordinate Storage within Model

Recommended Posts

AntiGuy    267
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
karwosts    840
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
AntiGuy    267
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
Geometrian    1810
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
AntiGuy    267
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
karwosts    840
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this