From fd6ca1c1a4d24adeb771c4cbb77fd56f1eee71e2 Mon Sep 17 00:00:00 2001 From: Xtarsia <69606701+Xtarsia@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:21:23 +0000 Subject: [PATCH] Improve spray tool, fix overaly id artifacts, add inverse case --- project/addons/terrain_3d/src/ui.gd | 7 +++++-- src/terrain_3d_editor.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/project/addons/terrain_3d/src/ui.gd b/project/addons/terrain_3d/src/ui.gd index 0040dcc2f..4e9114f17 100644 --- a/project/addons/terrain_3d/src/ui.gd +++ b/project/addons/terrain_3d/src/ui.gd @@ -15,8 +15,8 @@ const COLOR_LIFT := Color.ORANGE const COLOR_FLATTEN := Color.BLUE_VIOLET const COLOR_HEIGHT := Color(0., 0.32, .4) const COLOR_SLOPE := Color.YELLOW -const COLOR_PAINT := Color.FOREST_GREEN -const COLOR_SPRAY := Color.SEA_GREEN +const COLOR_PAINT := Color.DARK_GREEN +const COLOR_SPRAY := Color.PALE_GREEN const COLOR_ROUGHNESS := Color.ROYAL_BLUE const COLOR_AUTOSHADER := Color.DODGER_BLUE const COLOR_HOLES := Color.BLACK @@ -369,6 +369,9 @@ func update_decal() -> void: Terrain3DEditor.REPLACE: decal.modulate = COLOR_PAINT decal.modulate.a = .7 + Terrain3DEditor.SUBTRACT: + decal.modulate = COLOR_PAINT + decal.modulate.a = clamp(brush_data["strength"], .2, .5) Terrain3DEditor.ADD: decal.modulate = COLOR_SPRAY decal.modulate.a = clamp(brush_data["strength"], .2, .5) diff --git a/src/terrain_3d_editor.cpp b/src/terrain_3d_editor.cpp index 3cf9d9cfa..a444f2dc7 100644 --- a/src/terrain_3d_editor.cpp +++ b/src/terrain_3d_editor.cpp @@ -320,7 +320,6 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ bool hole = is_hole(src.r); bool navigation = is_nav(src.r); bool autoshader = is_auto(src.r); - real_t alpha_clip = (brush_alpha > 0.5f) ? 1.f : 0.f; // Lookup to shift values saved to control map so that 0 (default) is the first entry // Shader scale array is aligned to match this. std::array scale_align = { 5, 6, 7, 0, 1, 2, 3, 4 }; @@ -335,10 +334,11 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ case REPLACE: { if (brush_alpha > 0.5f) { if (enable_texture) { - // Set base texture + // Set base & overlay texture base_id = asset_id; + overlay_id = asset_id; // Erase blend value - blend = Math::lerp(blend, real_t(0.f), alpha_clip); + blend = 0.f; autoshader = false; } // Set angle & scale @@ -366,22 +366,29 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ real_t spray_strength = CLAMP(strength * 0.05f, 0.004f, .25f); real_t brush_value = CLAMP(brush_alpha * spray_strength, 0.f, 1.f); if (enable_texture && brush_alpha * strength * 11.f > 0.1f) { + // Painted area, set overlay immediatley if (base_id == overlay_id && blend < 0.004f) { overlay_id = asset_id; } - // If overlay and base texture are the same, reduce blend value + // Overlay and base texture are the same, reduce blend value if (base_id == asset_id) { blend = CLAMP(blend - brush_value, 0.f, 1.f); if (blend < 0.5f && brush_alpha > 0.5f) { autoshader = false; } } else { - // Else overlay and base are separate, set overlay texture and increase blend value + // Overlay and base are separate, increase blend value blend = CLAMP(blend + brush_value, 0.f, 1.f); + // Overlay already visible, limit ID changes to high brush alpha if (blend > 0.5f && brush_alpha > 0.5f) { overlay_id = asset_id; + // Only remove auto shader when blend is past threshold. autoshader = false; } + // Overlay not visible at brush edge, write new ID ready for potential next pass + if (blend <= 0.5f && brush_alpha <= 0.5f) { + overlay_id = asset_id; + } } } if ((base_id == asset_id && blend < 0.5f) || (base_id != asset_id && blend >= 0.5f)) { @@ -405,6 +412,18 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_ break; } + // Overlay Spray reduce + case SUBTRACT: { + real_t spray_strength = CLAMP(strength * 0.05f, 0.004f, .25f); + real_t brush_value = CLAMP(brush_alpha * spray_strength, 0.f, 1.f); + blend = CLAMP(blend - brush_value, 0.f, 1.f); + // Reset to painted state + if (blend < 0.004f) { + overlay_id = base_id; + } + break; + } + default: { break; }