Height based terrain with shading

Hi. What I’m asking is a terrain height based shader with support of shading. Currently the height based terrain material looks very not promising. One can’t guess whatever terrain is falling or rising when using this material.
If anybody has an idea how to implement such a shader or have it done and is willing to share - I would be thankfull.


have u tried Common/MatDefs/Terrain/TerrainLighting.j3md??

The TerrainLighting doesn’t support height based texturing. In my case it is needed that the terrain texture is related to its height at given point.
It would be good if the terrain in the game was premade, but in project I’m currently developing - player can terraform terrain.

Take the height code from the height based shader and combine it with the TerrainLighting shader.
The current heightBased shader is not really a full implementation, the author hasn’t finished it and probably won’t. It also needs some improvements with slopes and edges.

Here is a solution I came to. There are three files:
The material definition file:

The vertex shader:

The fragment shader:

IMPORTANT: Only one light in scene may be present for this material to work, and it must be a directional light.

It supports additional parameters: that is a minimum slope at which the slope texture will be visible and a maximum. These are angles which should be between 0 and 90 degrees.

The vertex and fragment shader files should be put in project assets “Shaders” directory.

Here is how it looks like:

1 Like