A start of a series

Visual Shaders in Godot is kind a new thing. There are very few tutorials and articles about. I wanted to learn it as it's a very important peace of engine. But there is just not enough materials on line.

I'm learning it the hard way - by experimenting, trying to look at other engines and port stuff. There is a possibility that I made something not optimal or even plane wrong. Take everything as examples not as definitive solution.

Thats where you can participate with better solution. I'm sharing everything here (and github) so others will have a easier way finding examples. And when we combine this knowledge in our community we all win by learn something new. Don't be shy to criticize and share your own solutions!

The problem to solve

How to make the procedural terrain be more natural? Take a look at this screen.

It definitely looks artificial. The ground is empty. It lacks rocks!

Making each rock different was made by two shaders. One is my "grass shader" that places particles as static objects on the terrain. The object here is a sphere. This shader do not work with other primitives yet.

Scene

What makes this clear sphere an  potato looking rock is a material with visual shader. Here is that shader.

Fragment

Fragment shader overview

The idea is to make a brown, dirt like texture. To make it look more natural I'm using noise texture.

UV is multiplied so noise will be applied with bigger less detail making the texture smoother. More like a potato.

Second part is to make parts that are closer to the center darker and vice versa.

Color brightness based on orbit size.

I'm calculating the length and then multiply it by 0.05 to make the change subtle. Lastly this is multiply with brown color.

Last part is to apply this to the albedo and set some settings for metallic, roughness and rim.

All values applied

Vertex

Vector shader overview

Vertex shader is a little bit more complicated but the basic idea is very similar to the fragment shader. It's also based on noise and position from the center. But instead of  changing the brightness it's moving vertexes.

Some noise

Here is the same idea as before - to make the noise smoother but also scaled on x/z axis.

Calculating change value

Second part is for making small change based on size. I'm taking a very small part of the length from normal.

Normalize change

Ten I multiply it by noise and by normal (to expand/collapse it in right direction).

Apply change

Last part is to add those changes to the vector.

Result

`
Rock shader screen 1
Rock shader screen 2