Change Color of terrain based on the height of each vertex

I want to be able to represent my height map as a heat map and the hotter it is the higher the height at one point will be. I got a great model going right now and the heat flux is fluxing nicely. But I want to be able to represent the hotter peaks as brighter more yellow and the cooler draws or lower peaks to be more red/ dark red.
How can I do this?
I think Alpha shaders? There is one similar topic to this but the resources there are a 404.

Height based terrain? There is some example code here: https://github.com/jayfella/TerrainWorld/blob/master/src/worldtest/Main.java

And just to give you some keywords, the effect you are describing is called linear interpolation between colours.

Erm actually, why not just use vertex colours for this? If you don’t want to use textures it’s exactly your usecase.

You could just use the distance between the color and those two base colors as a measure.

Awesome, height based terrain is what I needed, thank you! :grinning:

Well, I’m lost now. The first comment you gave me was interesting but as you mentioned I may want to just use vertex coloring. But I can’t find any examples on how to do this.
Also I failed to mention the heights change during run time

https://wiki.jmonkeyengine.org/jme3/advanced/custom_meshes.html#example-vertex-colors

Thank you!
I learned that the TerrainQuad contains TerrainPatches which extend Geometry.

So I would do the following
Create a simple material

Material matVC = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
matVC.setBoolean(“VertexColor”, true);

Next create my color array and set the color based on the height of a vertex (Y). Each patch contains an N number of vertices.

float colorArray = new float[numberOfVertices *4]

Get the mesh from the patch and set the colors

patch.getMesh().setBuffer(Type.Color, 4, colorArray);

You’re on your way. Get a unit-length scale by dividing the height of the vertex by the maximum height. Then interpolate your colours. Something like FastMath.lerp(col1, col2, val).

It’s working great! but I have to why would I want to do what you suggested?

ex1

My heat map looks great! This shows what would happen if you placed a coil under a surface. The surface uses heat conduction and heat radiation. Some parts of the coil are hotter giving a variable heat distribution

2 Likes

Would you mind sharing your sourcecode would need the same for a school project atm. We want to do a heatmap so this would come in handy