Jump to content
  • Advertisement
Sign in to follow this  
Dominick Holman

Build a texture out of vertecies

This topic is 700 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 have a set of Triangles with color for each vertecie. My question is, is there an easy way to implement an algorithm, where I can put these triangles as input and get, triangles, with vertecies and texture coords and a texture with the color informations. It is important for future works to have such kind of a texture.

 

Or maybe there is a library I could use that does such stuff for me.

 

I am working on XCode with OpenGL and C++

Share this post


Link to post
Share on other sites
Advertisement

Sounds like you want to automatically lay out / pack  arbitrary triangles on some rectangular area, which will be used later as a texture for those triangles. So you need texture coords generated for vertices, after triangle was laid out. And you want initial colors pre-baked into that texture you get after packing triangles.

Is that what you're asking?

Share this post


Link to post
Share on other sites

This entails two stages:

  1. UV unwrapping. There are smart unwrapping algorithms but the results tend to be better with manual placement of seams, depending on the mesh.
  2. Interpolating the colours of the triangle texels from the corners, in UV space. You can do this using barycentric coordinates.

Although interpolating the colours is pretty easy, the method of unwrapping can be difficult to get right because you can get 'bleedover' of colours on the UV map because of texture filtering and mipmapping. There may well be libraries to do UV unwrapping for you, if you don't want to write it yourself. Blender for instance does it, and is open source.

Share this post


Link to post
Share on other sites

If I understand correctly, I'd tackle this in 2 parts:

1) Store colours into a set so that each colour is stored only once. Each vertex gets an index into the set for its colour.
2) Add the set of colours to a texture, converting the vertex's colour index into a texture coordinate.

For (1) I'd create a simple hash function that allows you to bin the colours together to reduce compares, or use some other mechanism to create the set. For (2), that's a case of writing the colours as pixels to a texture of a given dimension, and then storing the resulting location as a UV.

 

Sorry my answer is brief, my lunch break just run out!

 

T

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!