What I want is, I want to apply colors to the mesh linearly. It could be from Vertex[0] to Vertex[n] or from -Min.x to Max.x. The Min.x should have dark red color then with the increment of vertices position, the red color should transform into green then again increment and end with blue. The second option could be, if I specify any random Vertex[any] and start color mapping from that vertex, then the color map should be transform into RGB with the incremental order. You can call it Color Map from XYZ to RGB. How can I do this ? Any idea ? First how can I transform XYZ into RGB, then how can I make color map or gradient or whatever u can say it.

The attached figure can give you an idea. In this figure, the the normalized vertices X=R, Y=G, Z=B are rendered as colors. Its just a test. Give me an idea how can I make it perfect linear map.

enter image description here

有帮助吗?

解决方案

First off, you must choose a range to map color values from since the RGB components are limited whilst you may have a huge mesh. Consider using the bounding box of your mesh. Given p1 and p2 are the min and max corners of your box, respectively, such mapping could be:

color[i] = 255 * (position[i] - p1) / (p2 - p1);

You can either perform this mapping in your vertex shader or with the CPU to get an array for the color attribute of your vertices, which you may use directly with OpenGL with smooth interpolation. Note that smooth interpolation should be enabled by default. With OpenGL 2.1, use glShadeModel (GL_SMOOTH) to enable it.

If your mesh is UV mapped and you want your color mapping to get onto a texture, render your mesh using texture coordinates as position and then retrieve the rendered image using either glReadPixels() or FBOs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top