I’m using HillHeightMap
to generate a heightmap. I found a way to generate an alphamap based on a heightmap.
This is how I create the material
/** Add texture into the red layer */
val red: Texture = assetManager.loadTexture(redTexturePath)
red.setWrap(WrapMode.Repeat)
material.setTexture("AlbedoMap_0", red)
material.setTexture(
"NormalMap_0",
assetManager.loadTexture(redTextureNormalPath)
)
material.setFloat("AlbedoMap_0_scale", 64f)
/** Add texture into the green layer */
val green: Texture = assetManager.loadTexture(greenTexturePath)
green.setWrap(WrapMode.Repeat)
material.setTexture("AlbedoMap_1", green)
material.setTexture(
"NormalMap_1",
assetManager.loadTexture(greenTextureNormalPath)
)
material.setFloat("AlbedoMap_1_scale", 32f)
/** Add texture into the blue layer */
val blue: Texture = assetManager.loadTexture(blueTexturePath)
blue.setWrap(WrapMode.Repeat)
material.setTexture("AlbedoMap_2", blue)
material.setTexture(
"NormalMap_2",
assetManager.loadTexture(blueTextureNormalPath)
)
material.setFloat("AlbedoMap_2_scale", 128f)
HillHeightMap.NORMALIZE_RANGE = 100f
This is how I generate the alphamap
private var alphamap: WeakReference<Image>? = null
private var rendered: Boolean = false
private val tex1Height = 0f
private val tex2Height = 75f
private val tex3Height = 80f
private val maxHeight = 300f
if (rendered && alphamap != null && alphamap?.get() != null) return alphamap!!.get()!!
val height = heightmap.size
val width = heightmap.size
val data = BufferUtils.createByteBuffer(width * height * 4)
for (x in 0 until width) {
for (z in 0 until height) {
var alpha = 255
var red = 0
var green = 0
var blue = 0
val pointHeight = heightmap.getScaledHeightAtPoint(z, width-(x + 1))
if (pointHeight < maxHeight) {
if (pointHeight > tex3Height) blue = 255
else if (pointHeight > tex2Height) green = 255
else if (pointHeight > tex1Height) red = 255
else if (pointHeight < tex1Height) alpha = 0
} else alpha = 0
data
.put(red.toByte())
.put(green.toByte())
.put(blue.toByte())
.put(alpha.toByte())
}
}
val image = Image(Image.Format.RGBA8, width, height, data)
alphamap = WeakReference(image)
rendered = true
return image
How can I make the transition between textures smoother/less noticeable?