Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JME3 - Splatting more than three textures

The following tutorial explains how to perform basic texture splatting with height maps.

http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_terrain

I was able to follow this tutorial and exercises with excellent results. However, I am wondering how to add more than three textures. I see in the material parameters of the Terrain.j3md file there are only three texture layers: Tex1, Tex2, Tex3 so I don't believe you can do this using the Terrain.j3md.

It is my assumption that you have to use the TerrainLighting.j3md. However, this is structured very differently with parameters such as NormalMap and DiffuseMap and I cannot find any documentation/tutorials explaining what exactly these are.

like image 541
jzacharuk Avatar asked Jan 23 '12 18:01

jzacharuk


2 Answers

More recently, a new material definition for texture splatting has been released, supporting up to 12 textures, with optionally additional glow and specular textures.

The name of the material is TerrainLighting.j3md, and this is a (very nice) example using it.

like image 131
guido Avatar answered Nov 02 '22 15:11

guido


JME3 is an OpenGL based library using GLSL shaders for rendering. You must write your custom shader, or modify an existing one, to perform custom rendering.

Shaders are an advanced topic. You can find an introduction to shaders on SDK documentation. But probably you would like to read full articles about "Materials, Light, Shadow".

JME3 uses three files to manage them:

  • A .vert file with the GLSL vertex shader code
  • A .frag file with the GLSL fragment shader code
  • A .j3md file with the shader program definition

Both vertex and fragment shaders are just piece of code using the GLSL language. Vertex shader is executed once for each vertex in the view to compute screen coordinates. Fragment shader is executed once for each pixel on the screen to compute colors. .j3md file have definitions about input parameters (materials), techniques (shaders), and so on.

The number and the type of the parameters are fixed. But you can modify Terrain.j3m to add a new texture parameter:

Texture2D tex4

Add a new input parameter to Terrain.frag:

uniform sampler2D m_Tex4;

And modify the fragment shader code to use that new texture parameter as you like.

like image 31
Juan Mellado Avatar answered Nov 02 '22 14:11

Juan Mellado