TerrainQuad terrain = new TerrainQuad("asdf", 256, 513, heightmap.getHeightMap());
Material mat = new Material(assetManager, "Materials/newMat.j3md");
terrain.setMaterial(mat);
mat.setFloat("Height", height);
From what you have posted, i guess that you are trying to pass a mat param? If that is the case, you need to add it to the j3md in the MaterialParameters block
MaterialParameters {
....
Float Height
....
}
Then you need to retrieve it in the shader like this
uniform float m_Height;
void main(){
...
}
Note the use of the uniform keyword.
TransformWorldViewProjection transforms from the model space to the clip space.
Thx for your advice.
But i dont know what to do with the TransformWorldViewProjection/TransformWorld. Do i need to define them the j3md and in the shader?
They are functions from the Instancing.glsllib file.
Take a look at the shaders provided with the engine (eg Unshaded), you will see that there is an import for Instancing.glsllib.
He’s trying to set a color based on the vertex height, so there’s not need to pass any data to the shader because it already knows the position of the vertex. The inPosition variable contains this data. So you just need to set a color based on the height of the vertex.
also you always say “doesnt work” without any explaination.
We cant really read in mind, you need provide more information what you have done and what you exactly need… and what exactly dont work.
btw. also its not like i provide code and you expect it to just work when you dont even copy it fully. I help you with already done code that need to be put to default shaders to make it work. Its just an example of code ofc and can be modified to be even better. Anyway what i provided there is fully working if all is copy pasted in proper places in default shaders in JME 3.3 (3.2 should be fine too)
My mountains arent getting their color changed its all 1 color.
Could be something wrong with my Heightmap tho
AbstractHeightMap heightmap = new AbstractHeightMap() {
@Override
public boolean load() {
int terrainSize = 256;
size = terrainSize;
// clean up data if needed.
if (null != heightData) {
unloadHeightMap();
}
heightData = new float[size * size];
// transfer temporary buffer to final heightmap
for (int i = 0; i < cords.size(); i++) {
setHeightAtPoint(cords.get(i).getY(), cords.get(i).getX(), cords.get(i).getZ());
}
normalizeTerrain(1);
return false;
}
};
heightmap.load();
if this is all green, i suspect your terrain is placed in world space much below (0,0,0) or heights are too low to make shader even see difference.
what you should check:
highest point of terrain in WorldSpace - its global rootNode space, not local
lowest point of terrain in WorldSpace
try make a very high mountain
simple test would be also placing a Box in rootNode in position (0.0.0) and see if its above terrain or on terrain. (because i suspect it will be much above terrain)
another simple test would be testing values like
height = wPosition.y + 10;
or
height = wPosition.y + 20;
or
height = wPosition.y + 50;
or others to see when it start making red. (because like i said your terrain seems to be not in (0,0,0) in world space.)
also you did not show values you pass as height to heightmap, if this values are like -100, then i belive it will be all green, because its very low height. Like i said in earlier topic, gl_fragColor line need to be “adjusted” to what you need.
the 5.0 value is max height for red color here. you could make some variable you pass that check Maximum height of your terrain and pass as this value, it would be perfect.