title: OpenGL, applying texture from image to isosurface
body: <p>I have a program in which I need to apply a 2-dimensional texture (simple image) to a surface generated using the marching-cubes algorithm. I have access to the geometry and can add texture coordinates with relative ease, but the best way to generate the coordinates is eluding me. </p>
  
  <p>Each point in the volume represents a single unit of data, and each unit of data may have different properties. To simplify things, I'm looking at sorting them into "types" and assigning each type a texture (or portion of a single large texture atlas).</p>
  
  <p>My problem is I have no idea how to generate the appropriate coordinates. I can store the location of the type's texture in the type class and use that, but then seams will be horribly stretched (if two neighboring points use different parts of the atlas). If possible, I'd like to blend the textures on seams, but I'm not sure the best manner to do that. Blending is optional, but I need to texture the vertices in some fashion. It's possible, but undesirable, to split the geometry into parts for each type, or to duplicate vertices for texturing purposes.</p>
  
  <p>I'd like to avoid using shaders if possible, but if necessary I can use a vertex and/or fragment shader to do the texture blending. If I do use shaders, what would be the most efficient way of telling it was texture or portion to sample? It seems like passing the type through a parameter would be the simplest way, but possible slow.</p>
  
  <p>My volumes are relatively small, 8-16 points in each dimension (I'm keeping them smaller to speed up generation, but there are many on-screen at a given time). I briefly considered making the isosurface twice the resolution of the volume, so each point has more vertices (8, in theory), which may simplify texturing. It doesn't seem like that would make blending any easier, though.</p>
  
  <p>To build the surfaces, I'm using the <a href="http://www.visualizationlibrary.com/jetcms/" rel="nofollow">Visualization Library</a> for OpenGL and its marching cubes and volume system. I have the geometry generated fine, just need to figure out how to texture it.</p>
  
  <p>Is there a way to do this efficiently, and if so what? If not, does anyone have an idea of a better way to handle texturing a volume?</p>
  
  <p><em>Edit</em>: Just to note, the texture isn't simply a gradient of colors. It's actually a texture, usually with patterns. Hence the difficulty in mapping it, a gradient would've been trivial.</p>
  
  <p><em>Edit 2:</em> To help clarify the problem, I'm going to add some examples. They may just confuse things, so consider everything above definite fact and these just as help if they can.</p>
  
  <p>My geometry is in cubes, always (loaded, generated and saved in cubes). If shape influences possible solutions, that's it. </p>
  
  <p>I need to apply textures, consisting of patterns and/or colors (unique ones depending on the point's "type") to the geometry, in a technique similar to the splatting done for terrain (this isn't terrain, however, so I don't know if the same techniques could be used). </p>
  
  <p>Shaders are a quick and easy solution, although I'd like to avoid them if possible, as I mentioned before. Something usable in a fixed-function pipeline is preferable, mostly for the minor increase in compatibility and development time. Since it's only a minor increase, I will go with shaders and multipass rendering if necessary.</p>
  
  <p>Not sure if any other clarification is necessary, but I'll update the question as needed.</p>