How can I modify Lighting.j3md to have a tiled detail map?

Hiya,

I’m attempting to get a detail map onto my terrain. To do this, I have added an extra texture called DetailMap, and then I mix it with the DiffuseMap, to give the illusion of extra texture detail.

This works fine. If you look at this picture,


Then the texture is just pure green, and then all the rocks and other details are from a separate texture.

So, now I have extra detail, I would like to tile this to have even more detail. So, I did this:
#ifdef DIFFUSEMAP vec2 detTex = texCoord * vec2(40, 40); //Tile by 40. If I set both of them to "1", without tiling, this works fine. vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord); vec4 detailColor = texture2D(m_DetailMap, detTex); diffuseColor = mix(diffuseColor, detailColor, 0.2);

From my old days of using java and LWJGL, I thought this would work: I thought that this would cause the texture to tile multiple times over the surface.

However, it hasn’t worked. It has created a sort-of uniform stretched texture kind of thing.

What can I do to make the detail map tile?

That is either not the actual code or you have a bug where detTex is not used by newTexCoord is.

Edit: Nevermind. Read it wrong. Sorry.

What is texCoord’s relationship to newTexCoord?

Good point, I should’ve been using newTexCoord.

But it still doesn’t make a difference:

It’s tough for us to understand what the texture coordinates are on the terrain itself but the math looks right.

I presume that the texture is setup to repeat. I think that’s default in later 3.1 versions anyway.

Maybe as a test set a main texture that is just a green border and a detail texture that is just a red border and post that screen shot. It will show us what the relationship to newTexCoord and detTex is with respect to the mesh.

How do I set the texture up to repeat? It most likely isn’t, and that could be my problem.

Here is the detail map, along with the other texture:


Evidently, multiplying it is doing something wrong - As the non-multiplied coordinates fit onto the mesh perfectly.

What version of JME are you using?

JME tiles by default in later versions but either way, setting the repeat:
https://javadoc.jmonkeyengine.org/com/jme3/texture/Texture.html#setWrap(com.jme3.texture.Texture.WrapMode)

It doesn’t look like the issue, though. I’d still be interested to see the single-pixel green border and single-pixel red border example I mentioned. Would tell us more than your pictures as it’s hard to interpret what the detail texture is actually doing.

1 Like

Note: I have a test pattern texture also but if you use it, only use it for the detail texture or the main texture but not both… else it will confuse the issue:

Thank you. This was the issue, and adding tex.setWrap(WrapMode.Repeat); has solved the issue.

Detail map works now.

Many thanks!