OverviewFilesCommitsIssuesDocsReleasesPeers

dc-terrain commits / c5d4001

erosion: field_half_range property, wired to the wrapper and the CPU twin
Exposes the field's half-relief so the map can set the SLOPE's vertical unit (proc-nodes: the play band is 2.1x the field's actual relief). 0 falls back to y_range*0.5, so existing graphs are unchanged. Both ProcNodesBridge::evaluate call sites pass it, because collision reads the CPU field while rendering reads the shader's.
c5d400142683d670f02e82bdf27c2d07f7db62a4
by plankatron <fleeky@gmail.com> · 2026-09-02T14:20:24.000Z

Changed files (2) +20 -4

src/dc_terrain_generator_procnodes.cpp +15 -4
……@@ -60,6 +60,9 @@ void DCTerrainGeneratorProcNodes::_bind_methods() {
6060 ClassDB::bind_method(D_METHOD("set_erosion_scale", "value"), &DCTerrainGeneratorProcNodes::set_erosion_scale);
6161 ClassDB::bind_method(D_METHOD("get_erosion_scale"), &DCTerrainGeneratorProcNodes::get_erosion_scale);
6262 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "erosion_scale"), "set_erosion_scale", "get_erosion_scale");
63 ClassDB::bind_method(D_METHOD("set_field_half_range", "value"), &DCTerrainGeneratorProcNodes::set_field_half_range);
64 ClassDB::bind_method(D_METHOD("get_field_half_range"), &DCTerrainGeneratorProcNodes::get_field_half_range);
65 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "field_half_range"), "set_field_half_range", "get_field_half_range");
6366 ClassDB::bind_method(D_METHOD("set_input_height_amplitude", "value"), &DCTerrainGeneratorProcNodes::set_input_height_amplitude);
6467 ClassDB::bind_method(D_METHOD("get_input_height_amplitude"), &DCTerrainGeneratorProcNodes::get_input_height_amplitude);
6568 ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "input_height_amplitude"), "set_input_height_amplitude", "get_input_height_amplitude");
……@@ -246,6 +249,13 @@ void DCTerrainGeneratorProcNodes::set_erosion_scale(float p_val) {
246249 emit_changed();
247250}
248251
252void DCTerrainGeneratorProcNodes::set_field_half_range(float p_val) {
253 if (field_half_range_ == p_val) return;
254 field_half_range_ = p_val;
255 _recompile_glsl();
256 emit_changed();
257}
258
249259void DCTerrainGeneratorProcNodes::set_input_height_amplitude(float p_val) {
250260 if (input_height_amplitude_ == p_val) return;
251261 input_height_amplitude_ = p_val;
……@@ -889,6 +899,7 @@ void DCTerrainGeneratorProcNodes::_recompile_glsl() {
889899 wp.detail_gain = detail_gain_;
890900 wp.detail_octaves = detail_octaves_;
891901 wp.en_erosion_scale = erosion_scale_;
902 wp.field_half_range = field_half_range_;
892903 wp.voxel_size = 1.0f;
893904 wp.heightmap_source = true;
894905 wp.heightmap_step = hblk_mpp_;
……@@ -1314,8 +1325,8 @@ float DCTerrainGeneratorProcNodes::ProcNodesBridge::evaluate(
13141325 };
13151326 float oh, odx, odz;
13161327 erosion_heightmap_gn_cpu(x, z, floor_y, ceiling_y, terrain_height,
1317 /* height_amp */ 0.25f, owner_->erosion_scale_, hmpp, sample,
1318 oh, odx, odz);
1328 /* height_amp */ 0.25f, owner_->erosion_scale_,
1329 owner_->field_half_range_, hmpp, sample, oh, odx, odz);
13191330 terrain_offset = vec3(oh, odx, odz);
13201331 }
13211332 // THE SAME SUBSTITUTION THE GLSL MAKES, and it must stay the same one:
……@@ -1342,8 +1353,8 @@ float DCTerrainGeneratorProcNodes::ProcNodesBridge::evaluate(
13421353 };
13431354 float oh, odx, odz;
13441355 erosion_heightmap_gn_cpu(x, z, floor_y, ceiling_y, terrain_height,
1345 /* height_amp */ 0.25f, owner_->erosion_scale_, hmpp, sample,
1346 oh, odx, odz);
1356 /* height_amp */ 0.25f, owner_->erosion_scale_,
1357 owner_->field_half_range_, hmpp, sample, oh, odx, odz);
13471358 terrain_offset = vec3(oh, odx, odz);
13481359 }
13491360 // Detail rides on TOP and is NOT folded in — MUST stay identical to the GLSL.
src/dc_terrain_generator_procnodes.h +5 -0
……@@ -216,6 +216,9 @@ class DCTerrainGeneratorProcNodes : public DCTerrainGenerator {
216216 float detail_gain_ = 0.5f;
217217 float noise_lacunarity_ = 2.0f;
218218 float erosion_scale_ = 0.15f;
219 // The FIELD's half-relief in metres, for the SLOPE normalisation only.
220 // 0 = fall back to the playable y_range. See erosion_wrapper_glsl.h.
221 float field_half_range_ = 0.0f;
219222 float input_height_amplitude_ = 0.25f;
220223 float octave_lacunarity_ = 2.0f;
221224 float gully_depth_ = 0.5f;
……@@ -335,6 +338,8 @@ public:
335338 float get_noise_lacunarity() const { return noise_lacunarity_; }
336339 void set_erosion_scale(float p_val);
337340 float get_erosion_scale() const { return erosion_scale_; }
341 void set_field_half_range(float p_val);
342 float get_field_half_range() const { return field_half_range_; }
338343 void set_input_height_amplitude(float p_val);
339344 float get_input_height_amplitude() const { return input_height_amplitude_; }
340345 void set_octave_lacunarity(float p_val);