Home Books Knowledge Recipes Tutorials Me
 

Terrain Generation

Godot Terrain

1 The Basics

shader_type spatial;

uniform float noise_strength : hint_range(0.01, 0.1) = 0.05;
uniform sampler2D noise_img : source_color, filter_linear_mipmap, repeat_disable;
varying float height_mask;
uniform vec3 base_color : source_color = vec3(0.1, 0.3, 0.2);

void vertex() {
    height_mask = texture(noise_img, UV).r;
    VERTEX.y += height_mask * noise_strength * 10.0;

    float e = 0.01;
    float h_l = texture(noise_img, UV + vec2(-e, 0.0)).r;
    float h_r = texture(noise_img, UV + vec2(e, 0.0)).r;
    float h_u = texture(noise_img, UV + vec2(0.0, -e)).r;
    float h_d = texture(noise_img, UV + vec2(0.0, e)).r;

    NORMAL = normalize(vec3(h_l - h_r, 2.0 * e, h_u - h_d));
}

void fragment() {
    ALBEDO = base_color;
}

Terrain