@Dschoonmaker said: BPC is the amout of different colors a texture will store per channel, correct? And is that what the 8 is in "RGB8"?

Yes

Also, how do I add code? I tried with that function, but it only recognized the last line.

there's two ways to format code the inline method uses the ` sign(grave accent) to encapsulate, which is what you used. And the block of code can either be done by using multiple layers of that encapsulation, three to be exact or to indent all of the code one more time.

You can do the latter either once in your IDE before copying then undoing the indentation in there after pasting here. Or you can just paste your code block here and select it to highlight it then go to the formatting menu(the paragraph icon) and pick code from there.

Cool, it works.

float get_height(vec2 pos) {
	pos -= 0.5 * heightmap_size;
	pos /= heightmap_size;
	
	return amplitude * texture(heightmap, pos).r;
}

Thanks!

BPC shouldn't be a problem, though it could be if I had a wide range of heights. The height of my grass won't change at all if I assign my heightmap texture. I know the get_height function works, some textures do displace the grass. But I think the problem is with texture format, because it works with some textures. The first image uses my heightmap and stays flat, the second uses a noise texture and works. But it also works with certain images, like normal maps. Could this have something to do with "RGB8"? If so, how can I change it?

If you mean that the second image works also with normal maps then that should be no problem, so long as it gets some data from the image to randomize the orientation of the grass, that's all that matters. Though a normal map might be a little too uniform in sections perhaps.

There should be no inherent issue with the heightmap being 8 bits per channel, only as you noted that the terrain might look very 'posterised' if the variance in elevation is too high.

I don't actually have any problems with the noisemap, it's just the heightmap. I think the reason normal maps work is because Godot automatically converts them to "RGTC RedGreen8", while the heightmap stays at "RGB8". I think it might work if I converted the heightmap to something else, but how would I do that? Should I do it in photo editing software, or maybe GDScript?

I also tried saving the image in different file formats, but that didn't work either.

Ah, you should just select the heightmap in the file browser then check the import tab. Sadly it doesn't make it clear what gets imported as what, but you can easily find out via trial and error.

I copied the same import settings the normal map uses. Sure enough, it does switch to saying "RGTC RedGreen 8", but the grass stays flat. I thought that was it, but now I don't know what it could be. My heightmap should definitely change it:

Wait, if I import it under the preset "3D", it seems to do some displacement? It certainly doesn't seem to be working correctly:

Yes, but black on the heightmap represents the lowest point on the map mesh, not necessarily a height of 0.

no I meant the terrain objects pivot point. but yeah, if your terrain height doesn't assume 0 as 0 but Olijs shaders do then that might be a cause of your issue, just modify the shaders to include some uniforms for offset values then.

I'm pretty sure the pivot point is at the center, I can make it be in blender if it isn't. I also think I should add a variable for height offset, that will be quick and easy.

Do you know what the 3D import preset is? I don't really have any clue.

In the importer? I think it's the preset that will try to detect things such as if the texture is a normal map and such.

So it's just for 3D texture as opposed to 2D sprites. Thanks, I just heard about some "3D texture" that was just a bunch of texture stuck together to be 3D.

I added a parameter called "base height", all it does is offset the whole thing. I also moved the pivot point to the middle in blender. It still doesn't seem right, and I get these weird holes: The grass in the hole isn't above or below, it looks like it's just gone.

It might be easier to analyze if you shared your scene and assets, since the original shader obviously was working for Olij as intended.

I think the problem is adjusting the scale. With my testing terrain shader, it's aligned only when the size of the plane is 100x100. I have to adjust the heightmap size parameter on both the terrain and the grass, but I don't know what to set it to. Also, note that I'm using a mesh I made in blender, the heightmap shader is just for debugging. I can send you the project, how should I do that?

5 days later

I sort of made my own heightmap generator before using this same shader.

I added a height offset, before realising that it was to do with the origin and scale of the mesh, I never went back to finish it so now looking and its still as rough as this:

float get_height(vec2 pos)
{
	//pos -= 0.5 * heightmap_size;
	//pos /= heightmap_size;
	pos /= 800.0;
	
	return (amplitude * texture(heightmap, pos).r) - 50.0;
}

My origin is in the corner and the mesh extends out positively, basically you're translating the mesh pos coords to the same in the heightmap texture.

Hope that helps