40 lines
1.1 KiB
Text
40 lines
1.1 KiB
Text
shader_type canvas_item;
|
|
render_mode blend_sub;
|
|
|
|
// Encodes negative height deltas (crater pits, dry washes, road ruts, tire ruts) into R.
|
|
uniform int brush_kind = 0;
|
|
uniform float height_delta = 0.0;
|
|
uniform float height_span = 28.0;
|
|
|
|
void fragment() {
|
|
vec2 uv_local = UV * 2.0 - 1.0;
|
|
float u = uv_local.x;
|
|
float v = uv_local.y;
|
|
float r2 = u * u + v * v;
|
|
if (r2 >= 1.0) {
|
|
discard;
|
|
}
|
|
|
|
float neg_dh = 0.0;
|
|
if (brush_kind == 0) {
|
|
// Dry wash (negative DuneRidge)
|
|
float env = 1.0 - r2;
|
|
env *= env;
|
|
float ridge = max(0.0, 1.0 - u * u);
|
|
float asym = 1.0 + 0.32 * u;
|
|
neg_dh = max(0.0, -height_delta) * env * (0.35 + 0.65 * ridge) * asym;
|
|
} else if (brush_kind == 2 || brush_kind == 3 || brush_kind == 5) {
|
|
// SalvagePad (<0), Road, Track rut
|
|
float env = 1.0 - r2;
|
|
env *= env;
|
|
neg_dh = max(0.0, -height_delta) * env;
|
|
} else if (brush_kind == 4) {
|
|
// Crater pit
|
|
float r = sqrt(r2);
|
|
float depth = abs(height_delta);
|
|
float pit_t = clamp(1.0 - r / 0.62, 0.0, 1.0);
|
|
neg_dh = depth * pit_t * pit_t * (3.0 - 2.0 * pit_t);
|
|
}
|
|
|
|
COLOR = vec4(neg_dh / height_span, 0.0, 0.0, 0.0);
|
|
}
|