Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit5e96992b1b

README.md

terrain_surface

What a surface shader reads of the landscape it stands on. A shader declares the terrain_* properties it reads (terrain_field_min, terrain_field_size, terrain_morph_band_start, terrain_cut_eyes_a, terrain_cut_eyes_b, terrain_cut_eye_count, terrain_normal, terrain_normal_strength, terrain_weights_lo, terrain_weights_hi) and a Terrain binds each one the shader declares from the landscape it draws; this module holds the functions that turn those values into what a pixel needs. They take their values as arguments and bind nothing, so including the module spends no texture slot, sampler or buffer.

function
zero_terrain_morph_cut(v, band_start, eyes_a, eyes_b, eye_count)The geomorph: slides a vertex onto the position it holds one LOD level coarser, by its distance to the nearest point the LOD cut was taken for, and sets uv to the landscape XZ the vertex stands on. Every view drawing the ground (another camera, a capture, a shadow map) draws the surface the cut stitched.
zero_terrain_morph(v, band_start)The same slide measured from the camera drawing the view.
zero_terrain_field_uv(xz, field_min, field_size)Where a landscape point falls in the textures covering its rect, 0 to 1.
zero_terrain_ground_normal(t, s, uv, vertex_n, strength, instance_id)The ground's own normal from the landscape's normal texture, turned by the drawn instance's normal transform (input.instance_id) into a world normal; strength 0 keeps vertex_n.
zero_terrain_weights(t, s, uv)A weight texture through a cubic B-spline. Weights stored in a block format do not keep summing to one: divide them by their sum.
#include "@builtin::systems.terrainSystem.terrain_surface"

fn vertex(v: VertexData) -> VertexData {
    return zero_terrain_morph_cut(v, material.terrain_morph_band_start, material.terrain_cut_eyes_a,
        material.terrain_cut_eyes_b, material.terrain_cut_eye_count);
}