Skip to content

Commit

Permalink
Improve spray tool, fix overaly id artifacts, add inverse case
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtarsia authored and TokisanGames committed Nov 3, 2024
1 parent bbced6d commit 5dc2f25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
7 changes: 5 additions & 2 deletions project/addons/terrain_3d/src/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 24 additions & 5 deletions src/terrain_3d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, 8> scale_align = { 5, 6, 7, 0, 1, 2, 3, 4 };
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 5dc2f25

Please sign in to comment.