Adding Textures to Terrain Material

Hi all,



The Ssplat texture code example on this page …https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:terrain?s[]=splat&s[]=texture



… says to set textures (in various combinations) on a Terrain material like so…

[java]matRock.setTexture("m_Tex1", grass);

matRock.setFloat("m_Tex1Scale", 64f);[/java]



What parameters do I supply for the 4th Diffuse texture (to use the first alpha map), and for the Normal and other textures?



Thanks in advance,

Jon.

From the tutorial:


" DiffuseMap
NormalMap
DiffuseMap_1
NormalMap_1 An alpha map can describe where 4 textures are painted onto the terrain.
DiffuseMap_2
NormalMap_2
etc, up to …Map_11."


DiffuseMap_3
NormalMap_3
...
DiffuseMap_11

etc.

maybe you should have a look into this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:materials_overview?s[]=terrainlighting

EDIT: Posted success too soon… still working on it.

No, still can’t get it to work. Please help!


  1. The tutorial page talks about Terrain.j3md. The parameter list says use “DiffuseMap1”, etc. but the example code says “m_Tex1”, etc.



    This works with Terrain.j3md…

    [java]material.setTexture(“m_Tex1”, dirt);[/java]



    These don’t…

    [java]

    material.setTexture(“m_Tex”, dirt);

    material.setTexture(“m_DiffuseMap”, dirt);

    material.setTexture(“m_NormalMap1”, dirt);

    [/java]



    ERROR: “Material parameter is not defined: m_DiffuseMap (etc.)”




  2. The materials overview page talks about Terrain.j3md, and TerrainLighting.j3md, give different parameter names still, but also don’t work for me…



    [java]

    // Terrain.j3md

    material.setTexture(“m_Texture1”, dirt);[/java]

    ERROR: “Material parameter is not defined: m_Texture1(etc.)”



    [java]// TerrainLighting.j3md

    material.setTexture(“m_DiffuseMap_0”, dirt);

    material.setFloat(“m_DiffuseMap_0_scale”, 64f);

    [/java]

    SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

    com.jme3.renderer.RendererException: Shader link failure, shader:Shader[language=GLSL100, numSources=2, numUniforms=12, shaderSources=[ShaderSource[name=Common/MatDefs/Terrain/TerrainLighting.vert, defines, type=Vertex], ShaderSource[name=Common/MatDefs/Terrain/TerrainLighting.frag, defines, type=Fragment]]] info:Fragment shader(s) failed to link, vertex shader(s) linked.





    Could someone give me an example of how to set diffuse & normal maps on Terrain & TerrainLighting, please? This is driving me nuts!! :frowning:

Open up the file Terrain.j3md

This is a material definition file and says what parameters you can use.



And re-read the tutorial. It explicitly says that it is talking about Terrain.j3md when it mentions m_Tex1.

Do read it, actually read it, and you will see what it is talking about and it has a working example:

From the tutorial:

This example shows the simpler material definition Terrain.j3md, which only supports 1 Alpha Map, 3 Diffuse Maps, 3 Normal Maps, and does not support Phong illumination. It makes the exmaple shorter – TerrainLighting.j3md works accordingly (The list of material properties see above. Links to extended sample code see above.)



First, we load our textures and the heightmap texture for the terrain




And read and learn this tutorial: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_material

It goes over what materials are, how to supply parameters to them, etc.

Thanks again.



Yes, I’m sorry it appears I didn’t read the tutorials (I did probably too much!), and I can see now where it says clearly the code sample is for Lighting.j3md - which only supports 3 diffuse textures. Great - Terrain works fine.



As for TerrainLighting… after reading the other references and looking at the source code, I still can’t see what’s wrong with my following code…



[java]

Material matRock = new Material(assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);

matRock.setTexture(“m_AlphaMap”, this.assetManager.loadTexture(new TextureKey(“Scenes/cove_alpha.png”, false)));



// RED

Texture grass = assetManager.loadTexture(“Scenes/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

matRock.setTexture(“m_DiffuseMap”, grass);

matRock.setFloat(“m_DiffuseMap_0_scale”, 32f);



tmp = rootNode.getChild(“Landscape”);

tmp.setMaterial(matRock); // <- NOW THROWS ERROR:com.jme3.renderer.RendererException: Shader link failure.

[/java]



Any clue?

I would think you’d get a much longer error message than that. Please put everything in here so we can help.

@madjack said:
I would think you'd get a much longer error message than that. Please put everything in here so we can help.


Unless he has a certain ATI card... though even in that case he'd get slightly more information (at least 4 or 5 more words saying the same thing). So I agree... don't truncate the errors.

Sorry… here’s my scene init. code that’s causing problems later during update(), with the exact error below.



[java]

Material matLandscape = new Material(assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);

matLandscape.setTexture(“m_AlphaMap”, this.assetManager.loadTexture(new TextureKey(“Scenes/cove_alpha.png”, false)));



// RED

Texture grass = assetManager.loadTexture(“Scenes/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

matLandscape.setTexture(“m_DiffuseMap”, grass);

matLandscape.setFloat(“m_DiffuseMap_0_scale”, 32f);



tmp = rootNode.getChild(“Landscape”);

tmp.setMaterial(matLandscape);

[/java]







SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

com.jme3.renderer.RendererException: Shader link failure, shader:Shader[language=GLSL100, numSources=2, numUniforms=12, shaderSources=[ShaderSource[name=Common/MatDefs/Terrain/TerrainLighting.vert, defines, type=Vertex], ShaderSource[name=Common/MatDefs/Terrain/TerrainLighting.frag, defines, type=Fragment]]] info:Fragment shader(s) failed to link, vertex shader(s) linked.

at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderData(LwjglRenderer.java:1087)

at com.jme3.renderer.lwjgl.LwjglRenderer.setShader(LwjglRenderer.java:1122)

at com.jme3.material.Material.renderMultipassLighting(Material.java:799)

at com.jme3.material.Material.render(Material.java:1028)

at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:658)

at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:299)

at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:351)

at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:894)

at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:850)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1126)

at com.jme3.renderer.RenderManager.render(RenderManager.java:1168)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:254)

at mygame.Main.update(Main.java:193)





EDIT: Aslo note, I had no problems adding textures & alpha to the Terrain.j3md file, only TerrainLighting.

“Fragment shader(s) failed to link, vertex shader(s) linked.”



If I ever get to meet the ATI driver writer that considered that a good message… I think I will have some unkind things to say to him/her.



You are on an ATI GPU, right?

Yup.



EDIT: And just for clarity, I mistakenly said in my earlier post the error was being thrown from tmp.setMaterial(matRock), but it’s actually occurring during update() as you can see from the stack trace.

My gawd. As far as error message, that’s horrible. :confused:

@madjack said:
My gawd. As far as error message, that's horrible. :/


I get this one from Mythruna users on occasion, too. I almost want to buy one of these cards just to track down the error.

I do sometimes wonder if the driver writer's body parts tingle as we virtually nut-kick him. Maybe he enjoys it.

@jonmonkey, is an ATI Radeon X1300 or something? I'm trying to narrow down which cards actually have this problem.

It’s an ATI X600 (!)



Probably time I just bought a new one haha.

How to define textures for your terrain???



How to paint textures on your terrain???

@smithdavid said:
How to define textures for your terrain????

How to paint textures on your terrain???

Did you read any of the documentation?
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_terrain
The sdk also has a terrain editor with a paint can.

Probably late reply,but maybe it will be useful to someone. Problem you are having with TerrainLighting is that you are using wrong parameters. It clearly says in error msg that “parameter is not defined: m_Texture1” .
The parameters you are looking for are “AlphaMap”,“AlphaMap_1” etc. for definitions where each texture will be. (AlphaMap is a picture made from red,green and blue colors, where every color signalize 1 texture. If you use some mixed color ie yellow you will get mixed textures), “DiffuseMap”,“DiffuseMap_1” etc. for textures and “DiffuseMap_0_scale”,“DiffuseMap_1_scale” etc. for floats.

For nice example of using TerrainLighting take a look on jmonkeyengine/TerrainTestAdvanced.java at master · jMonkeyEngine/jmonkeyengine · GitHub

Hope it will help someone in the future.