I'm working on a grass shader using particles. I'm starting with the source code from https://github.com/BastiaanOlij/godot-grass-tutorial/blob/master/materials-and-shaders/particle.shader. It has a sampler2D used to set the height of the grass. The problem is, if I try to add an image, the grass stays flat. It seems that certain images will displace the grass but not others. If I add a different texture, it works and the grass is displaced. It works with types of textures other than StreamTextures, (e.g. NoiseTextures) but it also works with some StreamTextures (it works with normal maps). I think it might have something to do with the format of the texture or something like that. In the top right corner of the texture, it says the dimensions of the image and something else, usually RGB8. On other textures, it sometimes says something else (normal maps say RGTC RedGreen8). Does anyone know what the problem might be and how it could be solved?

This discussion was caught in the moderation queue since you have not confirmed your account yet.

Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.

If you need any help, please let us know! Thanks! :smile:

In case you haven't watched his youtube video on it, you might want to do so. And if you have, perhaps watching it again as a refresher might be good:

@Dschoonmaker - The Godot email server is unable to send emails to the address you associated with your account. It seems the email address is misspelled or off in some way. Please send a message to forum staff with your email address so we can update your profile details, so you can confirm your account.

(You can also email me needed. My email can be found on this topic and on my profile page)

Thanks for the fast replies! I did get my email address wrong, how can I change that?

@Megalomaniak , I did watch that video, but maybe I should check it again to be sure I didn't miss anything he might have said about that.

@Dschoonmaker said: Thanks for the fast replies! I did get my email address wrong, how can I change that?

At the top of the page, assuming the default forum theme, there should be a blue banner/bar. Towards the right of it is the userbox, that is the area showing your avatar, username and the expandable menus/panels for messages and such, last among them is a white gearwheel icon. press it and the menu that opens should say edit profile in there.

I clicked the gear icon, it gives me two options: View Profile and Preferences. I searched through both of them, but I didn't see anywhere I could change my email. Which is it under?

Okay, so I've checked the video multiple times. He doesn't really say anything about problems you might have, he just slapped on a texture and it worked. Nobody in the comments had any problems, either...

No but he explains that the heightmap texture is the same grayscale heightmap he is using for the terrain, and that the noisemap is just a random color noise just to get the grass oriented randomly.

Note that heightmaps are typically 16bpc and unless you are dealing with vector displacement it's just a single color channel. Say red for an example.

Yes, I also have a greyscale heightmap I'm using. I just rendered it in blender because I'm using mesh + custom terrain shader. The code does just use the red channel, this is the function to get the height at the current position:

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

The pos parameter should be the x and z position of the current grass blade.

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

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

@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: