- Home /
Procedural terrain in shader graph
I've created a procedural terrain generator using perlin noise in C#.
Now I want to improve the noise itself in order to make a more complex terrain but it is kinda hard to visualize in code.
I've seen people using shader graphs with noise and I liked the way it shows you how the noise is looking in every step.
Can I do this process in a shader graph?
I know that shaders are calculated in the GPU so it would make the process more efficient, but I'm not sure if the terrain would be calculated just once or in every frame.
Answer by SteveTheodore · Nov 08, 2021 at 05:21 PM
You can generate terrain in a shadergraph by plugging a displacement into the vertex stage. However unless your terrain is dynamic and changes from frame to frame you'll be wasting a lot of of GPU power doing the same calculations over and over every frame. Also, if you generate the terrain on the GPU you'll still need a "copy" of it on the CPU so that you can feed the results to a Terrain Collider to support things like physics and navigation.
Depending on your needs, you could certainly use Shadergraph to prototype the displacements you want quickly in 3d. Then when you are happy with the results, you can either (a) rebuild the logic in C#, now that you know what you want or (b) change the shader so it outputs displacement into a texture -- then you can use graphics.Blit()
to render the displacement into a render texture, convert the render texture to a regular texture2D, and apply the texture2D as a height map using the TerrainTools package.
If you are more interested in getting the final result than in learning, you might find it faster to just install TerrainTools and use the visual noise editor there. That will let you generate your noise and apply it to terrain with extra no runtime costs.
Your answer
Follow this Question
Related Questions
Does the Web Player support PBR? 0 Answers
How to add true transparancy to this Wireframe Shader? 1 Answer
Leaves spotlight issue 0 Answers
Standart shader problem on Android device (HTC One X) 0 Answers
Double side texture, data retrived from binary file 0 Answers