TerraMonkey: TerrainLighting diffuse map appears twice, normal map not at all

Hello everyone,

I am working on a small day/night system including directional lights and an ambient light.
For that, I need a texture applied to my heightmap-generated terrain, as without one, the ambient light would make the entire view flat (if no directional light is given).
With that in mind, I went came up with the following code, hoping it would apply the texture at the given scale and repeat it across the terrain. Additionally, I generated a crude normal map to go along with it.

What I get is the diffuse map, twice. Once across the entirety of the terrain, and once repeated in the scaling I defined. I’m not sure what I got wrong here, but debug as I may, I can’t figure out what I dun goofed.
The same confusion arises with the normal map: It seems as though the normal map isn’t utilized at all.
Below you will find a screenshot of the given scene (using an orthogonal, isometric camera) illuminated with a directional light and a white ambient light at 0.1f total brightness. Below the screenshot you will find the setup for the material.

I’m thankful for any advice I can get on how to solve my problems!

        var assetManager = app.getAssetManager();
        var material = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
        Texture uv = assetManager.loadTexture("Textures/uv.png");
        Texture uvNormal = assetManager.loadTexture("Textures/uv-normal.png");
        material.setColor("AlphaMap", ColorRGBA.White);
        material.setTexture("DiffuseMap", uv);
        material.setTexture("NormalMap", uvNormal);
        material.setFloat("DiffuseMap_0_scale", 128f);
        var heightMapImage = assetManager.loadTexture("Textures/Terrain/land2big.png");
        AbstractHeightMap heightmap = null;
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.4f);
        terrain = new TerrainQuad("terrain", 65, heightmap.getSize() + 1, heightmap.getScaledHeightMap());

i have no answer to your code(why diffuse is twice, i belive its not diffuse, but other texture like normalmap, since it also have scale as i remember). But day/night cycle is so easy to make. I dont see problem.

Level easy solution: You can just change AmbientLight/DirectionalLight params in-game.(low for night, high for day)
This is the standard solution for day/night cycle along with skybox changes(if there is skybox)

Just lower intensity of it and its all, why not?

Level hard solution: but if you want disable directional light, then just do it in shader. Just disable it.(using Material parameter you can setup in-game like “useDirectionalLight” for material)
Editing shader is not so hard when you learn basics.

Anyway i suggest you to use modern version:

that support PBR material.


The day / night cycling is already implemented on my side, I just want to be able to debug it better with a textured terrain.
I think you may be right about the normal map being the one applied as-is over the entire terrain. I tried NormalMap_0_scale, NormalMap_1_scale and NormalMap_scale, but all of them crash the engine due to, well, not existing.

Actually, correction - it can’t be the normal map, as the problem persists even if I don’t set the normal texture.

Well, I just checked it out.
It should be part of jME since 3.4, right?

ext.jmonkeyengineVersion = '3.5.2-stable'
    implementation 'org.jmonkeyengine:jme3-core:' + jmonkeyengineVersion
    runtimeOnly 'org.jmonkeyengine:jme3-jogg:' + jmonkeyengineVersion
    runtimeOnly 'org.jmonkeyengine:jme3-plugins:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-effects:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-terrain:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-jbullet:' + jmonkeyengineVersion
    implementation 'org.jmonkeyengine:jme3-networking:' + jmonkeyengineVersion

Despite my configuration, I cannot locate the shader.
If the wiki is actually declaring every material there is, then it might be outdated.

According to the example in the GitHub repo, it should be:
But this fails to be found when trying to load the file.
Following the pattern I saw with Terrain and TerrainLighting, I tried the following, with no success:
It’d be great if you could point out to me what I am missing here. :slight_smile:

I haven’t looked at this material but it’s very strange to pass a color to a “map” parameter and may show a misunderstanding about how this material is supposed to work.

The name of the shaders were changed when i merged them into the official jme-terrain library to remove the word afflicted, but here is the examples that uses the version of the shader in the engine.

So this is the correct path you’d want to use to load the basic PBRTerrainMaterial: "Common/MatDefs/Terrain/PBRTerrain.j3md"