Texture splatting *twitch*

There is something completely effed up about this. I’ve tried this in about 300 billions ways and it’s never giving anything close to what I expect, it’s infuriating.

I did a small splatting test.

4 textures (diffuse maps) = snow, rock, tundra and forest.
1 alpha map.
1 height map.

alphamap and heightmap are same size, 4096 x 4096

The alphamap:

The result (flying VERY high):

I’m trying to find the correlation between the alphamap and the 4 textures and I can’t. Every test I have made is a variant of that. It’s just not making ANY sense to me.

The alphamap is a simple RGB/8 with no alpha channel (no example of those alphamap has an alpha channel), but adding an alpha channel doesn’t change the result.

What I expect:

Each texture in the order given (diffuse 0, 1, 2, 3) would be applied to the RGB in the alphamap. AND, any overlap (which there is none of in this example) would blend the textures depending on the color.

Am I wrong in this assessment? (I have to be)

PLEASE before I do the unthinkable and do something I will regret to the first passerby, enlighten me!

Thanks.

EDIT: Crap I forgot the code. blink

[java]
Texture topAlpha = assetManager.loadTexture(“Textures/Terrain/rgbalphamap.png”);
terMat.setTexture(“AlphaMap”, topAlpha);

    terMat.setTexture("DiffuseMap", snow);          // snow
    terMat.setFloat("DiffuseMap_0_scale", 512);
    terMat.setTexture("DiffuseMap_1", rock);        // rock
    terMat.setFloat("DiffuseMap_1_scale", 256);
    terMat.setTexture("DiffuseMap_2", tundra);      // tundra
    terMat.setFloat("DiffuseMap_2_scale", 512);
    terMat.setTexture("DiffuseMap_3", forest);      // forest
    terMat.setFloat("DiffuseMap_3_scale", 512);

    terrain.setMaterial(terMat);

[/java]

EDIT 2:
If there is ANYTHING else than transparency around the Red Green Blue colors (as above) the WHOLE thing is painted with the forest texture. I tried white, black and gray (128, 128, 128). I… I can’t even… brain oozes out by ear canals

Edit 3:
Tagged as fixed.

I almost hate to ask but just so no one else mistakenly wonders the same thing… snow, rock, tundra, and forest are definitely loaded from different textures, right? (We can’t see that code but I know it’s probably the first thing you checked.)

Also, just to help, can we see what those textures look like on their own in case spotting them in the overhead image helps trigger something? (I don’t know much about the terrain material either but these are just things that occurred to me that I’d be curious about if I did.)

Yes Paul, they are indeed different.

[java]
Texture snow = assetManager.loadTexture(“Textures/Terrain/snow.jpg”);
snow.setWrap(Texture.WrapMode.Repeat);
Texture rock = assetManager.loadTexture(“Textures/Terrain/rock.jpg”);
rock.setWrap(Texture.WrapMode.Repeat);
Texture tundra = assetManager.loadTexture(“Textures/Terrain/tundra.png”);
tundra.setWrap(Texture.WrapMode.Repeat);
Texture forest = assetManager.loadTexture(“Textures/Terrain/forest.jpg”);
forest.setWrap(Texture.WrapMode.Repeat);
[/java]

As for the textures themselves, inside the circles it’s forest, the brown is the tundra, white is snow and grey is rock.

So the forest is also gray or is that part of the issue?

The alpha map looks sorta off to me (i.e. looks like you painted with solid red, green & blue as apposed to using color channels) The solid white background is intentional, I take it? There shouldn’t be much of a difference for testing… red should be 1,0,0 etc…

Out of curiosity, are using jpg as a file format? The blotchy white square areas around the circles in the output makes me think you are. You would likely get a more accurate image using png if you are not already. jpg compression does some really messed up shit with color…

EDIT: To test this, use a magic wand with a tolerance of 1 over the white area of your alpha map and see what is actually selected… it will be ugly… you have been warned :wink:

EDIT: Just saw your post with the file paths… don’t use jpg for a per channel alpha map if you can help it.

@t0neg0d said: The alpha map looks sorta off to me (i.e. looks like you painted with solid red, green & blue as apposed to using color channels) The solid white background is intentional, I take it? There shouldn't be much of a difference for testing... red should be 1,0,0 etc...

Out of curiosity, are using jpg as a file format? The blotchy white square areas around the circles in the output makes me think you are. You would likely get a more accurate image using png if you are not already. jpg compression does some really messed up shit with color.

EDIT: Just saw your post with the file paths… don’t use jpg for a per channel alpha map if you can help it.

His alphamap is a png. And if it’s the same one as the link he posted, then the channels look fine in photoshop. The white background is actually alpha=0 in the one posted.

@t0neg0d said:The solid white background is intentional, I take it? There shouldn't be much of a difference for testing... red should be 1,0,0 etc...

There is no white. Only the colors are opaque, nothing else. As I said, I have tried using opaque for everything around the circles (white, black and grey) and it makes ALL the terrain textured in forest.

EDIT: Just saw your post with the file paths... don't use jpg for a per channel alpha map if you can help it.
I avoid JPG like the plague in any circumstances. If an image I use is a jpeg, I haven't made it.
1 Like
@madjack said: What I expect:

Each texture in the order given (diffuse 0, 1, 2, 3) would be applied to the RGB in the alphamap. AND, any overlap (which there is none of in this example) would blend the textures depending on the color.

Am I wrong in this assessment? (I have to be)

Just because no one else has said it: yes that is indeed the expected result. Although the alphamap should be in RGBA (thus have an alpha channel) but as pspeed said, it looks right.

I can’t spot anything different from my code which works fine (except I mess about with normal maps also but that is optional).

Let me explain how the full thing is being used.

I have this terrain. It’s separated into 8 “layers”. From snow caps to ocean level.

The goal was to create 2 RGB(A) alphamaps that would paint the 8 textures. To create those 2 alphamaps, I used the heightmap (Greyscale) that I split into 8. I then took the first four channels, sent those into a new image, changed format to RGB/8 and colors the “snow height” Red, the next being rock Green, etc.

But… that the kind of result like above happened. I just don’t understand what’s going on.

@jmaasing said: Just because no one else has said it: yes that is indeed the expected result. Although the alphamap should be in RGBA (thus have an alpha channel) but as pspeed said, it looks right.

I almost wish you’ve said no. At least it would’ve explained the discrepancy. :confused:

I can't spot anything different from my code which works fine (except I mess about with normal maps also but that is optional).

Well, if you can find in your heart a bit of time to paste a bit of code that would ease my brain-oozing a bit. :wink:

1 Like
@madjack said: I almost wish you've said no. At least it would've explained the discrepancy. :/

Well, if you can find in your heart a bit of time to paste a bit of code that would ease my brain-oozing a bit. :wink:

Have you successfully created a terrain with 6+ Diffuse textures?
If so, would it be possible for you to post the code?
:slight_smile:

I just took a look at your alpha Map and when you remove the alpha layer from it this is whats left:

you need to somehow save your png files uncompressed (I tried it in Photoshop just now and couldn’t figure out how to do it).

@perjin
Thanks for that.

Problem is, that’s some seriously effed up shit. PNG uses a lossless compression and shouldn’t give that kind of result. So either photoshop is doing something wrong or something else is doing it. I’ll try setting this up w/o compression then using another program if that doesn’t work…

Problem is, some of those I made are somehow big… Anyway. I’ll report.

The image perjin showed is what is shown in the terrain (I was wondering where the great honking jaggies came from), so somehow the A in RGBA is lost and then all bets are off.
PNG can save with/without Alpha. I only use Gimp and then it is a checkbox when you export an image as PNG.

I can give you my code but I create the splat-map procedurally and the rest looks like your code so I doubt it’ll help.

Oh, now I see that you want to create the splat-map procedurally. I did the same (although using other criteria than “biomes”). It’s over a 1.5 years since I used wrote this so there was no ImagePainter, hence the use of BufferedImages. Here is the gist of the matter (removed a lot of cruft):

[java]
BufferedImage alphaTextureBufferedmage = // Create the alpha map as a buffered image, see below
AWTLoader awtLoader = new AWTLoader();
Image alphaTextureImage = awtLoader.load(alphaTextureBufferedmage, true);
Texture alphaTexture = new Texture2D(alphaTextureImage);
mat_terrain.setTexture(“AlphaMap”, alphaTexture);


protected BufferedImage createFromRGBAValue() {
BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
final int arrayOffset = x + y * size;

            int alpha = getAlphaValue(arrayOffset);
            int red = getRedValue(arrayOffset);
            int green = getGreenValue(arrayOffset);
            int blue = getBlueValue(arrayOffset);

            int rgb = ((alpha &lt;&lt; 24) &amp; 0xff000000)
                    | ((red &lt;&lt; 16) &amp; 0x00ff0000)
                    | ((green &lt;&lt; 8) &amp; 0x0000ff00)
                    | (blue &amp; 0x000000ff);

            image.setRGB(x, y, rgb);
        }
    }
    return image;
}


[/java]
The RGBA values are 0…255. Hope that helps.

@madjack said: @perjin Thanks for that.

Problem is, that’s some seriously effed up shit. PNG uses a lossless compression and shouldn’t give that kind of result. So either photoshop is doing something wrong or something else is doing it. I’ll try setting this up w/o compression then using another program if that doesn’t work…

Problem is, some of those I made are somehow big… Anyway. I’ll report.

Jst try a simpler format, eg one without transparency. Transparent parts make no real sense, black is the use no texture color. (except you encode a 4th channel in alpha,)
Might be an issue with the imageio loader ignoring color values where alpha is, after all it was only developed for visual results. I remember having some kind of prolem there as well wich is why i reverted to only use 3 chanell and no alpha for the layers.

@Empire Phoenix said: Jst try a simpler format, eg one without transparency. Transparent parts make no real sense, black is the use no texture color.

As previously mentioned, I tried that. Using white or black.

Tried an uncompressed PNG with and without an alpha channel. With and w/o transparency. With and w/o a transparency and an alpha channel at the same time. These all give the same result (more or less), but nothing the way it should be.

With no compression this is what it looks like: The area around each circle makes a well-defined square (WTF?) instead of a eff’ed up one (It can’t be compression loss but there’s a definitive loss here and I’m not just talking about my sanity)

Next I’ll try different image formats and different programs see where that leads us.

And now using GIMP. No alpha channel and no background color:

EDIT:
The file is the same as the previous one (you can import PSD files with Gimp).

Up next, Paint.Net

Alright, we’re getting somewhere. Still working with Gimp here.

I made a brand new image from scratch, but decided to use some antialiasing and feathering to get some gradient. 'Lo and behold! (using more contrasting textures this time)

You can clearly see the proper diffuse maps being used. Except… it’s slightly wrong. On those areas where the channels are “pure” (eg: 255, 0, 0, 1) the alpha channel diffuse map (4th) is used and NOT the channel’s defined texture. As soon as the color is changed or the alpha value of the color is lowered, the channel’s texture is properly applied (and blended if applicable).

This has to be an error in the shader.

I’m continuing my investigation.