How do you use Mathf.PerlinNoise in a compute shader?

Hello there,

I made a terrain generator and a texture generator for the terrain, but the performance wasn’t really good.
And since the texture is 10x more detailed then the terrain (because I didn’t want the terrain to be really detailed) I wanted to move my texture script to a compute shader, but as you can see from the question I couldn’t find a way to use Mathf.PerlinNoise in a compute shader.
Does someone know a way to use the function?
If not it’s not the biggest problem, but differently I have to

  • First generate the terrain and store the height in a low resolution image to pass to my compute shader
    or
  • Create a perlin noise function myself that I can write in both c# and HLSL

If you need a bit more detail about what I actually want to make you can view my devlogs on Devlogs - YouTube
Devlog number 2 gives the best information about the terrain

Here's [perlin in C][1] [1]: https://gist.github.com/nowl/828013

2 Answers

2

Just add this one to your shader.

Also you can try this one

Thank you for the answer The crazy thing is I just made a perlin noise script for a standard surface shader and a script (see https://codeboy124.itch.io/that-traveling-guy-test-1-world for the result) about at the time you as posted your answer

Either use the noise function or implement one yourself. There are plenty of examples out there.