[SOLVED] Custom color gradient in VertexColor mode

I want to use Vertex coloring as described in the link below in the Vertex coloring example, but I want to use a custom gradient. http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:custom_meshes

Specifically, say I have three vertices of my mesh with different temperatures of 500K 800K and 1300K, and and array of colors indexed by temperature (ar[temp]=Color) I want the color at any point in each triangle of the mesh to be the color of the linearly interpolated temperature from the vertices, instead of interpolating the color.

another solution would be to cut triangles with vertices out of a texture atlas and stretch them to fit the mesh, but I am not sure how to use the texture atlas like that.

Since temperature is effectively a single value per vertex then you might be better off using a one dimensional texture and just set the texture coordinates to (0, t/tMax) (presuming the 1D texture is vertical).

Then you will have extremely fine control over the color of every temperature in the range.

Edit: also presumes you don’t also want a regular diffuse texture.

So the cutting and stretching “triangles” (in quotes since, as you point out, they are 1 dimensional) out of texture atlases is something I can do? I always have a hell of a time understanding Java apis.

No cutting necessary. Make a big one pixel wide texture where every ‘y’ value is a color for your temperatures from lowest to highest.

Then set texture coordinates for each vertex to (temperature, 0) where temperature is a value adjust to 0…1 for minTemperature and maxTemperature.

Nothing else needs to be done as the texture coordinates are already interpolated between vertexes… that’s how texture mapping works. At each point on the triangle there will be a texture coordinate interpolated to some (temperature, 0) value… that will relate directly to your 1 dimensional texture.

Oh, sweet. Thank you very much. I will get right on this.

Now I’m curious, how hard would it be to extend JME to support higher (than 2) dimensional textures?

It already supports it as I understand… though it might be limited to certain platforms and might not necessarily be what you are looking for since it doesn’t really have anything at all to do with the conversation so far.