From 9d53d4a734718d0bbb0034697dc5c7c21d8518c9 Mon Sep 17 00:00:00 2001
From: Cory Petkovsek <632766+TokisanGames@users.noreply.github.com>
Date: Sat, 18 Nov 2023 00:00:56 +0700
Subject: [PATCH] Add painting for autoshader, holes, navigation
---
.../editor/components/tool_settings.gd | 1 +
.../terrain_3d/editor/components/toolbar.gd | 15 ++-
.../addons/terrain_3d/editor/components/ui.gd | 47 ++++++--
.../addons/terrain_3d/icons/icon_holes.svg | 10 ++
.../terrain_3d/icons/icon_holes.svg.import | 37 ++++++
.../terrain_3d/icons/icon_navigation.svg | 42 +++++++
.../icons/icon_navigation.svg.import | 37 ++++++
src/shaders/debug_views.glsl | 12 ++
src/shaders/main.glsl | 3 +
src/terrain_3d_editor.cpp | 112 ++++++++++++------
src/terrain_3d_editor.h | 12 +-
src/terrain_3d_material.cpp | 48 +++++++-
src/terrain_3d_material.h | 9 ++
13 files changed, 327 insertions(+), 58 deletions(-)
create mode 100644 project/addons/terrain_3d/icons/icon_holes.svg
create mode 100644 project/addons/terrain_3d/icons/icon_holes.svg.import
create mode 100644 project/addons/terrain_3d/icons/icon_navigation.svg
create mode 100644 project/addons/terrain_3d/icons/icon_navigation.svg.import
diff --git a/project/addons/terrain_3d/editor/components/tool_settings.gd b/project/addons/terrain_3d/editor/components/tool_settings.gd
index 7d30902da..3254674c3 100644
--- a/project/addons/terrain_3d/editor/components/tool_settings.gd
+++ b/project/addons/terrain_3d/editor/components/tool_settings.gd
@@ -45,6 +45,7 @@ func _ready() -> void:
add_setting(SettingType.SLIDER, "size", 50, list, "m", 2, 200)
add_setting(SettingType.SLIDER, "opacity", 10, list, "%", 1, 100)
+ add_setting(SettingType.CHECKBOX, "enable", true, list)
add_setting(SettingType.SLIDER, "height", 50, list, "m", -500, 500, 0.1, ALLOW_OUT_OF_BOUNDS)
add_setting(SettingType.PICKER, "height picker", Terrain3DEditor.HEIGHT, list)
add_setting(SettingType.DOUBLE_SLIDER, "slope", 0, list, "°", 0, 180, 1)
diff --git a/project/addons/terrain_3d/editor/components/toolbar.gd b/project/addons/terrain_3d/editor/components/toolbar.gd
index bc969b273..e7f08587c 100644
--- a/project/addons/terrain_3d/editor/components/toolbar.gd
+++ b/project/addons/terrain_3d/editor/components/toolbar.gd
@@ -13,8 +13,11 @@ const ICON_HEIGHT_FLAT: String = "res://addons/terrain_3d/icons/icon_height_flat
const ICON_HEIGHT_SMOOTH: String = "res://addons/terrain_3d/icons/icon_height_smooth.svg"
const ICON_PAINT_TEXTURE: String = "res://addons/terrain_3d/icons/icon_brush.svg"
const ICON_SPRAY_TEXTURE: String = "res://addons/terrain_3d/icons/icon_spray.svg"
-const ICON_PAINT_COLOR: String = "res://addons/terrain_3d/icons/icon_color.svg"
-const ICON_PAINT_ROUGHNESS: String = "res://addons/terrain_3d/icons/icon_roughness.svg"
+const ICON_COLOR: String = "res://addons/terrain_3d/icons/icon_color.svg"
+const ICON_ROUGHNESS: String = "res://addons/terrain_3d/icons/icon_roughness.svg"
+const ICON_AUTOSHADER: String = "res://addons/terrain_3d/icons/icon_terrain_material.svg"
+const ICON_HOLES: String = "res://addons/terrain_3d/icons/icon_holes.svg"
+const ICON_NAVIGATION: String = "res://addons/terrain_3d/icons/icon_navigation.svg"
var tool_group: ButtonGroup = ButtonGroup.new()
@@ -39,8 +42,12 @@ func _ready() -> void:
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.REPLACE, "Paint Base Texture", load(ICON_PAINT_TEXTURE), tool_group)
add_tool_button(Terrain3DEditor.TEXTURE, Terrain3DEditor.ADD, "Spray Overlay Texture", load(ICON_SPRAY_TEXTURE), tool_group)
add_child(HSeparator.new())
- add_tool_button(Terrain3DEditor.COLOR, Terrain3DEditor.REPLACE, "Paint Color", load(ICON_PAINT_COLOR), tool_group)
- add_tool_button(Terrain3DEditor.ROUGHNESS, Terrain3DEditor.REPLACE, "Paint Roughness", load(ICON_PAINT_ROUGHNESS), tool_group)
+ add_tool_button(Terrain3DEditor.COLOR, Terrain3DEditor.REPLACE, "Paint Color", load(ICON_COLOR), tool_group)
+ add_tool_button(Terrain3DEditor.ROUGHNESS, Terrain3DEditor.REPLACE, "Paint Roughness", load(ICON_ROUGHNESS), tool_group)
+ add_child(HSeparator.new())
+ add_tool_button(Terrain3DEditor.AUTOSHADER, Terrain3DEditor.REPLACE, "Automatic / Manual Textures", load(ICON_AUTOSHADER), tool_group)
+ add_tool_button(Terrain3DEditor.HOLES, Terrain3DEditor.REPLACE, "Create / Fill Holes", load(ICON_HOLES), tool_group)
+ add_tool_button(Terrain3DEditor.NAVIGATION, Terrain3DEditor.REPLACE, "Define Navigable Areas", load(ICON_NAVIGATION), tool_group)
var buttons: Array[BaseButton] = tool_group.get_buttons()
buttons[0].set_pressed(true)
diff --git a/project/addons/terrain_3d/editor/components/ui.gd b/project/addons/terrain_3d/editor/components/ui.gd
index a74c9567f..f39a06c92 100644
--- a/project/addons/terrain_3d/editor/components/ui.gd
+++ b/project/addons/terrain_3d/editor/components/ui.gd
@@ -11,11 +11,14 @@ const COLOR_RAISE := Color.WHITE
const COLOR_LOWER := Color.BLACK
const COLOR_SMOOTH := Color(0.5, 0, .1)
const COLOR_EXPAND := Color.ORANGE
-const COLOR_REDUCE := Color.PURPLE
+const COLOR_REDUCE := Color.BLUE_VIOLET
const COLOR_FLATTEN := Color(0., 0.32, .4)
const COLOR_PAINT := Color.FOREST_GREEN
const COLOR_SPRAY := Color.SEA_GREEN
const COLOR_ROUGHNESS := Color.ROYAL_BLUE
+const COLOR_AUTOSHADER := Color.DODGER_BLUE
+const COLOR_HOLES := Color.BLACK
+const COLOR_NAVIGATION := Color.REBECCA_PURPLE
const COLOR_PICK_COLOR := Color.WHITE
const COLOR_PICK_HEIGHT := Color.DARK_RED
const COLOR_PICK_ROUGH := Color.ROYAL_BLUE
@@ -103,6 +106,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")
+ to_hide.push_back("enable")
if p_operation != Terrain3DEditor.REPLACE:
to_hide.push_back("height")
to_hide.push_back("height picker")
@@ -115,6 +119,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")
+ to_hide.push_back("enable")
if p_operation == Terrain3DEditor.REPLACE:
to_hide.push_back("opacity")
@@ -124,6 +129,7 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
to_hide.push_back("roughness")
to_hide.push_back("roughness picker")
to_hide.push_back("slope")
+ to_hide.push_back("enable")
elif p_tool == Terrain3DEditor.ROUGHNESS:
to_hide.push_back("height")
@@ -131,7 +137,18 @@ func _on_tool_changed(p_tool: Terrain3DEditor.Tool, p_operation: Terrain3DEditor
to_hide.push_back("color")
to_hide.push_back("color picker")
to_hide.push_back("slope")
+ to_hide.push_back("enable")
+ elif p_tool in [ Terrain3DEditor.AUTOSHADER, Terrain3DEditor.HOLES, Terrain3DEditor.NAVIGATION ]:
+ to_hide.push_back("height")
+ to_hide.push_back("height picker")
+ to_hide.push_back("color")
+ to_hide.push_back("color picker")
+ to_hide.push_back("roughness")
+ to_hide.push_back("roughness picker")
+ to_hide.push_back("slope")
+ to_hide.push_back("opacity")
+
toolbar_settings.hide_settings(to_hide)
toolbar_settings.set_visible(p_tool != Terrain3DEditor.REGION)
@@ -146,9 +163,10 @@ func _on_setting_changed() -> void:
"size": int(toolbar_settings.get_setting("size")),
"opacity": toolbar_settings.get_setting("opacity") / 100.0,
"height": toolbar_settings.get_setting("height"),
+ "texture_index": plugin.texture_dock.get_selected_index(),
"color": toolbar_settings.get_setting("color"),
"roughness": toolbar_settings.get_setting("roughness"),
- "texture_index": plugin.texture_dock.get_selected_index(),
+ "enable": toolbar_settings.get_setting("enable"),
"automatic_regions": toolbar_settings.get_setting("automatic_regions"),
"align_to_view": toolbar_settings.get_setting("align_to_view"),
"show_cursor_while_painting": toolbar_settings.get_setting("show_cursor_while_painting"),
@@ -158,6 +176,7 @@ func _on_setting_changed() -> void:
var brush_imgs: Array = toolbar_settings.get_setting("brush")
brush_data["image"] = brush_imgs[0]
brush_data["texture"] = brush_imgs[1]
+
update_decal()
plugin.editor.set_brush_data(brush_data)
@@ -181,7 +200,7 @@ func update_decal() -> void:
if brush_data["align_to_view"]:
var cam: Camera3D = plugin.terrain.get_camera();
if (cam):
- decal.rotation.y =cam.rotation.y
+ decal.rotation.y = cam.rotation.y
else:
decal.rotation.y = 0
@@ -196,6 +215,7 @@ func update_decal() -> void:
decal.modulate = COLOR_PICK_COLOR
Terrain3DEditor.ROUGHNESS:
decal.modulate = COLOR_PICK_ROUGH
+ decal.modulate.a = 1.0
else:
decal.texture_albedo = brush_data["texture"]
match plugin.editor.get_tool():
@@ -215,22 +235,35 @@ func update_decal() -> void:
decal.modulate = COLOR_SMOOTH
_:
decal.modulate = Color.WHITE
+ decal.modulate.a = max(.3, brush_data["opacity"])
Terrain3DEditor.TEXTURE:
match plugin.editor.get_operation():
- Terrain3DEditor.ADD:
- decal.modulate = COLOR_SPRAY
Terrain3DEditor.REPLACE:
decal.modulate = COLOR_PAINT
+ decal.modulate.a = 1.0
+ Terrain3DEditor.ADD:
+ decal.modulate = COLOR_SPRAY
+ decal.modulate.a = max(.3, brush_data["opacity"])
_:
decal.modulate = Color.WHITE
Terrain3DEditor.COLOR:
decal.modulate = brush_data["color"].srgb_to_linear()*.5
+ decal.modulate.a = max(.3, brush_data["opacity"])
Terrain3DEditor.ROUGHNESS:
decal.modulate = COLOR_ROUGHNESS
+ decal.modulate.a = max(.3, brush_data["opacity"])
+ Terrain3DEditor.AUTOSHADER:
+ decal.modulate = COLOR_AUTOSHADER
+ decal.modulate.a = 1.0
+ Terrain3DEditor.HOLES:
+ decal.modulate = COLOR_HOLES
+ decal.modulate.a = 1.0
+ Terrain3DEditor.NAVIGATION:
+ decal.modulate = COLOR_NAVIGATION
+ decal.modulate.a = 1.0
_:
decal.modulate = Color.WHITE
-
- decal.modulate.a = max(.3, brush_data["opacity"])
+ decal.modulate.a = max(.3, brush_data["opacity"])
decal.albedo_mix = 1.0
decal_timer.start()
diff --git a/project/addons/terrain_3d/icons/icon_holes.svg b/project/addons/terrain_3d/icons/icon_holes.svg
new file mode 100644
index 000000000..da639d9f1
--- /dev/null
+++ b/project/addons/terrain_3d/icons/icon_holes.svg
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/project/addons/terrain_3d/icons/icon_holes.svg.import b/project/addons/terrain_3d/icons/icon_holes.svg.import
new file mode 100644
index 000000000..cd00a66b2
--- /dev/null
+++ b/project/addons/terrain_3d/icons/icon_holes.svg.import
@@ -0,0 +1,37 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bqktati6gi08q"
+path="res://.godot/imported/icon_holes.svg-fadd8eef4df4cdc393621d5ff25aa8e3.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/terrain_3d/icons/icon_holes.svg"
+dest_files=["res://.godot/imported/icon_holes.svg-fadd8eef4df4cdc393621d5ff25aa8e3.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/project/addons/terrain_3d/icons/icon_navigation.svg b/project/addons/terrain_3d/icons/icon_navigation.svg
new file mode 100644
index 000000000..1056202f4
--- /dev/null
+++ b/project/addons/terrain_3d/icons/icon_navigation.svg
@@ -0,0 +1,42 @@
+
+
+
+
diff --git a/project/addons/terrain_3d/icons/icon_navigation.svg.import b/project/addons/terrain_3d/icons/icon_navigation.svg.import
new file mode 100644
index 000000000..ef0bf8e1b
--- /dev/null
+++ b/project/addons/terrain_3d/icons/icon_navigation.svg.import
@@ -0,0 +1,37 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://c0sprba3li1x4"
+path="res://.godot/imported/icon_navigation.svg-35e49ee3c403c103a0079d4156b0d168.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://addons/terrain_3d/icons/icon_navigation.svg"
+dest_files=["res://.godot/imported/icon_navigation.svg-35e49ee3c403c103a0079d4156b0d168.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
+svg/scale=1.0
+editor/scale_with_editor_scale=false
+editor/convert_colors_with_editor_theme=false
diff --git a/src/shaders/debug_views.glsl b/src/shaders/debug_views.glsl
index 5c7aa240b..78f433640 100644
--- a/src/shaders/debug_views.glsl
+++ b/src/shaders/debug_views.glsl
@@ -63,6 +63,18 @@ R"(
ROUGHNESS = 1.0;
NORMAL_MAP = vec3(0.5, 0.5, 1.0);
+//INSERT: DEBUG_AUTOSHADER
+ float autoshader = float(control00 & 0x1u);
+ ALBEDO = vec3(autoshader);
+
+//INSERT: DEBUG_HOLES
+ float holes = float(control00 >>2u & 0x1u);
+ ALBEDO = vec3(holes);
+
+//INSERT: DEBUG_NAVIGATION
+ float navigation = float(control00 >>1u & 0x1u);
+ ALBEDO = vec3(navigation);
+
//INSERT: DEBUG_TEXTURE_HEIGHT
// Show height textures
ALBEDO = vec3(albedo_height.a);
diff --git a/src/shaders/main.glsl b/src/shaders/main.glsl
index 46eba06cc..82d1784b8 100644
--- a/src/shaders/main.glsl
+++ b/src/shaders/main.glsl
@@ -293,6 +293,9 @@ void fragment() {
//INSERT: DEBUG_ROUGHMAP
//INSERT: DEBUG_CONTROL_TEXTURE
//INSERT: DEBUG_CONTROL_BLEND
+//INSERT: DEBUG_AUTOSHADER
+//INSERT: DEBUG_HOLES
+//INSERT: DEBUG_NAVIGATION
//INSERT: DEBUG_TEXTURE_HEIGHT
//INSERT: DEBUG_TEXTURE_NORMAL
//INSERT: DEBUG_TEXTURE_ROUGHNESS
diff --git a/src/terrain_3d_editor.cpp b/src/terrain_3d_editor.cpp
index 63799cc1f..01cd79d49 100644
--- a/src/terrain_3d_editor.cpp
+++ b/src/terrain_3d_editor.cpp
@@ -27,9 +27,10 @@ void Terrain3DEditor::Brush::set_data(Dictionary p_data) {
_size = p_data["size"];
_opacity = p_data["opacity"];
_height = p_data["height"];
+ _texture_index = p_data["texture_index"];
_color = p_data["color"];
_roughness = p_data["roughness"];
- _texture_index = p_data["texture_index"];
+ _enable = p_data["enable"];
_auto_regions = p_data["automatic_regions"];
_align_to_view = p_data["align_to_view"];
@@ -90,11 +91,12 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
map_type = Terrain3DStorage::TYPE_HEIGHT;
break;
case TEXTURE:
+ case AUTOSHADER:
+ case HOLES:
+ case NAVIGATION:
map_type = Terrain3DStorage::TYPE_CONTROL;
break;
case COLOR:
- map_type = Terrain3DStorage::TYPE_COLOR;
- break;
case ROUGHNESS:
map_type = Terrain3DStorage::TYPE_COLOR;
break;
@@ -110,6 +112,7 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
real_t height = _brush.get_height();
Color color = _brush.get_color();
real_t roughness = _brush.get_roughness();
+ bool enable = _brush.get_enable();
real_t gamma = _brush.get_gamma();
real_t randf = UtilityFunctions::randf();
@@ -179,7 +182,7 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
case REPLACE:
destf = Math::lerp(srcf, height, brush_alpha * opacity);
break;
- case Terrain3DEditor::AVERAGE: {
+ case AVERAGE: {
Vector3 left_position = brush_global_position - Vector3(1, 0, 0);
Vector3 right_position = brush_global_position + Vector3(1, 0, 0);
Vector3 down_position = brush_global_position - Vector3(0, 0, 1);
@@ -206,46 +209,74 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
// Get bit field from pixel
uint32_t bits;
*(float *)&bits = src.r; // Must be a 32-bit float, no double/real_t
- uint32_t base_index = bits >> 27 & 0x1F;
- uint32_t overlay_index = bits >> 22 & 0x1F;
- real_t blend = real_t(bits >> 14 & 0xFF) / 255.0f;
+ uint32_t base_id = bits >> 27 & 0x1F; // 5 bits #32-28
+ uint32_t overlay_id = bits >> 22 & 0x1F; // 5 bits #27-23
+ real_t blend = real_t(bits >> 14 & 0xFF) / 255.0f; // 8 bits #22-15
+ // Reserved 11 bits #4-14
+ uint8_t holes = bits >> 2 & 0x1; // 1 bit #3
+ uint8_t navigation = bits >> 1 & 0x1; // 1 bit #2
+ uint8_t autoshader = bits & 0x1; // 1 bit #1
- real_t alpha_clip = (brush_alpha < 0.1f) ? 0.0f : 1.0f;
- uint32_t dest_index = uint32_t(Math::lerp(base_index, texture_id, alpha_clip));
+ real_t alpha_clip = (brush_alpha > 0.1f) ? 1.0f : 0.0f;
+ uint32_t dest_id = uint32_t(Math::lerp(base_id, texture_id, alpha_clip));
- switch (_operation) {
- // Base Paint
- case Terrain3DEditor::REPLACE: {
- // Set base texture
- base_index = dest_index;
- // Erase blend value
- blend = Math::lerp(blend, real_t(0.0f), alpha_clip);
- } break;
-
- // Overlay Spray
- case Terrain3DEditor::ADD: {
- real_t spray_opacity = CLAMP(opacity * 0.025f, 0.003f, 0.025f);
- real_t brush_value = CLAMP(brush_alpha * spray_opacity, 0.0f, 1.0f);
- // If overlay and base texture are the same, reduce blend value
- if (dest_index == base_index) {
- blend = CLAMP(blend - brush_value, 0.0f, 1.0f);
- } else {
- // Else overlay and base are separate, set overlay texture and increase blend value
- overlay_index = dest_index;
- blend = CLAMP(blend + brush_value, 0.0f, 1.0f);
+ switch (_tool) {
+ case TEXTURE:
+ switch (_operation) {
+ // Base Paint
+ case REPLACE: {
+ // Set base texture
+ base_id = dest_id;
+ // Erase blend value
+ blend = Math::lerp(blend, real_t(0.0f), alpha_clip);
+ } break;
+
+ // Overlay Spray
+ case ADD: {
+ real_t spray_opacity = CLAMP(opacity * 0.025f, 0.003f, 0.025f);
+ real_t brush_value = CLAMP(brush_alpha * spray_opacity, 0.0f, 1.0f);
+ // If overlay and base texture are the same, reduce blend value
+ if (dest_id == base_id) {
+ blend = CLAMP(blend - brush_value, 0.0f, 1.0f);
+ } else {
+ // Else overlay and base are separate, set overlay texture and increase blend value
+ overlay_id = dest_id;
+ blend = CLAMP(blend + brush_value, 0.0f, 1.0f);
+ }
+ } break;
+
+ default: {
+ } break;
}
- } break;
-
- default: {
- } break;
+ break;
+ case AUTOSHADER:
+ if (brush_alpha > 0.1f) {
+ autoshader = enable;
+ }
+ break;
+ case HOLES:
+ if (brush_alpha > 0.1f) {
+ holes = enable;
+ }
+ break;
+ case NAVIGATION:
+ if (brush_alpha > 0.1f) {
+ navigation = enable;
+ }
+ break;
+ default:
+ break;
}
// Convert back to bit field
- uint32_t base = (base_index & 0x1F) << 27; // 5 bits 32-28
- uint32_t over = (overlay_index & 0x1F) << 22; // 5 bits 27-23
+ base_id = (base_id & 0x1F) << 27;
+ overlay_id = (overlay_id & 0x1F) << 22;
uint32_t blend_int = uint32_t(CLAMP(Math::round(blend * 255.0f), 0.0f, 255.0f));
- blend_int = (blend_int & 0xFF) << 14; // 8 bits 22-15
- bits = base | over | blend_int;
+ blend_int = (blend_int & 0xFF) << 14;
+ holes = (holes & 0x1) << 2;
+ navigation = (navigation & 0x1) << 1;
+ autoshader = (autoshader & 0x1);
+ bits = base_id | overlay_id | blend_int | holes | navigation | autoshader;
// Write back to pixel in FORMAT_RF
float out_float = *(float *)&bits; // Must be a 32-bit float, no double/real_t
@@ -309,7 +340,7 @@ Vector2 Terrain3DEditor::_rotate_uv(Vector2 p_uv, real_t p_angle) {
void Terrain3DEditor::_setup_undo() {
ERR_FAIL_COND_MSG(_terrain == nullptr, "terrain is null, returning");
ERR_FAIL_COND_MSG(_terrain->get_plugin() == nullptr, "terrain->plugin is null, returning");
- if (_tool < 0 || _tool > REGION) {
+ if (_tool < 0 || _tool >= TOOL_MAX) {
return;
}
LOG(INFO, "Setting up undo snapshot...");
@@ -327,7 +358,7 @@ void Terrain3DEditor::_setup_undo() {
void Terrain3DEditor::_store_undo() {
ERR_FAIL_COND_MSG(_terrain == nullptr, "terrain is null, returning");
ERR_FAIL_COND_MSG(_terrain->get_plugin() == nullptr, "terrain->plugin is null, returning");
- if (_tool < 0 || _tool > REGION) {
+ if (_tool < 0 || _tool >= TOOL_MAX) {
return;
}
LOG(INFO, "Storing undo snapshot...");
@@ -452,6 +483,9 @@ void Terrain3DEditor::_bind_methods() {
BIND_ENUM_CONSTANT(TEXTURE);
BIND_ENUM_CONSTANT(COLOR);
BIND_ENUM_CONSTANT(ROUGHNESS);
+ BIND_ENUM_CONSTANT(AUTOSHADER);
+ BIND_ENUM_CONSTANT(HOLES);
+ BIND_ENUM_CONSTANT(NAVIGATION);
BIND_ENUM_CONSTANT(REGION);
BIND_ENUM_CONSTANT(TOOL_MAX);
diff --git a/src/terrain_3d_editor.h b/src/terrain_3d_editor.h
index c2536d6c2..7bd37e406 100644
--- a/src/terrain_3d_editor.h
+++ b/src/terrain_3d_editor.h
@@ -42,6 +42,9 @@ class Terrain3DEditor : public Object {
TEXTURE,
COLOR,
ROUGHNESS,
+ AUTOSHADER,
+ HOLES,
+ NAVIGATION,
REGION,
TOOL_MAX,
};
@@ -51,6 +54,9 @@ class Terrain3DEditor : public Object {
"Texture",
"Color",
"Roughness",
+ "Auto Shader",
+ "Holes",
+ "Navigation",
"Region",
"TOOL_MAX",
};
@@ -64,9 +70,10 @@ class Terrain3DEditor : public Object {
int _size = 0;
real_t _opacity = 0.0;
real_t _height = 0.0;
+ int _texture_index = 0;
Color _color = COLOR_ROUGHNESS;
real_t _roughness = 0.5;
- int _texture_index = 0;
+ bool _enable = false;
bool _auto_regions = false;
bool _align_to_view = false;
@@ -84,9 +91,10 @@ class Terrain3DEditor : public Object {
int get_size() const { return _size; }
real_t get_opacity() const { return _opacity; }
real_t get_height() const { return _height; }
+ int get_texture_index() const { return _texture_index; }
Color get_color() const { return _color; }
real_t get_roughness() const { return _roughness; }
- int get_texture_index() const { return _texture_index; }
+ real_t get_enable() const { return _enable; }
bool auto_regions_enabled() const { return _auto_regions; }
bool is_aligned_to_view() const { return _align_to_view; }
diff --git a/src/terrain_3d_material.cpp b/src/terrain_3d_material.cpp
index cc8c16c84..ab79bab8d 100644
--- a/src/terrain_3d_material.cpp
+++ b/src/terrain_3d_material.cpp
@@ -110,6 +110,21 @@ String Terrain3DMaterial::_generate_shader_code() {
if (!_debug_view_roughmap) {
excludes.push_back("DEBUG_ROUGHMAP");
}
+ if (!_debug_view_control_texture) {
+ excludes.push_back("DEBUG_CONTROL_TEXTURE");
+ }
+ if (!_debug_view_control_blend) {
+ excludes.push_back("DEBUG_CONTROL_BLEND");
+ }
+ if (!_debug_view_autoshader) {
+ excludes.push_back("DEBUG_AUTOSHADER");
+ }
+ if (!_debug_view_holes) {
+ excludes.push_back("DEBUG_HOLES");
+ }
+ if (!_debug_view_navigation) {
+ excludes.push_back("DEBUG_NAVIGATION");
+ }
if (!_debug_view_tex_height) {
excludes.push_back("DEBUG_TEXTURE_HEIGHT");
}
@@ -119,12 +134,6 @@ String Terrain3DMaterial::_generate_shader_code() {
if (!_debug_view_tex_rough) {
excludes.push_back("DEBUG_TEXTURE_ROUGHNESS");
}
- if (!_debug_view_control_texture) {
- excludes.push_back("DEBUG_CONTROL_TEXTURE");
- }
- if (!_debug_view_control_blend) {
- excludes.push_back("DEBUG_CONTROL_BLEND");
- }
if (!_debug_view_vertex_grid) {
excludes.push_back("DEBUG_VERTEX_GRID");
}
@@ -470,6 +479,24 @@ void Terrain3DMaterial::set_show_control_blend(bool p_enabled) {
_update_shader();
}
+void Terrain3DMaterial::set_show_autoshader(bool p_enabled) {
+ LOG(INFO, "Enable show_autoshader: ", p_enabled);
+ _debug_view_autoshader = p_enabled;
+ _update_shader();
+}
+
+void Terrain3DMaterial::set_show_holes(bool p_enabled) {
+ LOG(INFO, "Enable show_holes: ", p_enabled);
+ _debug_view_holes = p_enabled;
+ _update_shader();
+}
+
+void Terrain3DMaterial::set_show_navigation(bool p_enabled) {
+ LOG(INFO, "Enable show_navigation: ", p_enabled);
+ _debug_view_navigation = p_enabled;
+ _update_shader();
+}
+
void Terrain3DMaterial::set_show_texture_height(bool p_enabled) {
LOG(INFO, "Enable show_texture_height: ", p_enabled);
_debug_view_tex_height = p_enabled;
@@ -671,6 +698,12 @@ void Terrain3DMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_show_control_texture"), &Terrain3DMaterial::get_show_control_texture);
ClassDB::bind_method(D_METHOD("set_show_control_blend", "enabled"), &Terrain3DMaterial::set_show_control_blend);
ClassDB::bind_method(D_METHOD("get_show_control_blend"), &Terrain3DMaterial::get_show_control_blend);
+ ClassDB::bind_method(D_METHOD("set_show_autoshader", "enabled"), &Terrain3DMaterial::set_show_autoshader);
+ ClassDB::bind_method(D_METHOD("get_show_autoshader"), &Terrain3DMaterial::get_show_autoshader);
+ ClassDB::bind_method(D_METHOD("set_show_holes", "enabled"), &Terrain3DMaterial::set_show_holes);
+ ClassDB::bind_method(D_METHOD("get_show_holes"), &Terrain3DMaterial::get_show_holes);
+ ClassDB::bind_method(D_METHOD("set_show_navigation", "enabled"), &Terrain3DMaterial::set_show_navigation);
+ ClassDB::bind_method(D_METHOD("get_show_navigation"), &Terrain3DMaterial::get_show_navigation);
ClassDB::bind_method(D_METHOD("set_show_texture_height", "enabled"), &Terrain3DMaterial::set_show_texture_height);
ClassDB::bind_method(D_METHOD("get_show_texture_height"), &Terrain3DMaterial::get_show_texture_height);
ClassDB::bind_method(D_METHOD("set_show_texture_normal", "enabled"), &Terrain3DMaterial::set_show_texture_normal);
@@ -692,6 +725,9 @@ void Terrain3DMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_roughmap", PROPERTY_HINT_NONE), "set_show_roughmap", "get_show_roughmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_texture", PROPERTY_HINT_NONE), "set_show_control_texture", "get_show_control_texture");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_blend", PROPERTY_HINT_NONE), "set_show_control_blend", "get_show_control_blend");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_autoshader", PROPERTY_HINT_NONE), "set_show_autoshader", "get_show_autoshader");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_holes", PROPERTY_HINT_NONE), "set_show_holes", "get_show_holes");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_navigation", PROPERTY_HINT_NONE), "set_show_navigation", "get_show_navigation");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_height", PROPERTY_HINT_NONE), "set_show_texture_height", "get_show_texture_height");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_normal", PROPERTY_HINT_NONE), "set_show_texture_normal", "get_show_texture_normal");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_rough", PROPERTY_HINT_NONE), "set_show_texture_rough", "get_show_texture_rough");
diff --git a/src/terrain_3d_material.h b/src/terrain_3d_material.h
index c0197534e..8e1e28ca5 100644
--- a/src/terrain_3d_material.h
+++ b/src/terrain_3d_material.h
@@ -35,6 +35,9 @@ class Terrain3DMaterial : public Resource {
bool _debug_view_roughmap = false;
bool _debug_view_control_texture = false;
bool _debug_view_control_blend = false;
+ bool _debug_view_autoshader = false;
+ bool _debug_view_holes = false;
+ bool _debug_view_navigation = false;
bool _debug_view_tex_height = false;
bool _debug_view_tex_normal = false;
bool _debug_view_tex_rough = false;
@@ -96,6 +99,12 @@ class Terrain3DMaterial : public Resource {
bool get_show_control_texture() const { return _debug_view_control_texture; }
void set_show_control_blend(bool p_enabled);
bool get_show_control_blend() const { return _debug_view_control_blend; }
+ void set_show_autoshader(bool p_enabled);
+ bool get_show_autoshader() const { return _debug_view_autoshader; }
+ void set_show_holes(bool p_enabled);
+ bool get_show_holes() const { return _debug_view_holes; }
+ void set_show_navigation(bool p_enabled);
+ bool get_show_navigation() const { return _debug_view_navigation; }
void set_show_texture_height(bool p_enabled);
bool get_show_texture_height() const { return _debug_view_tex_height; }
void set_show_texture_normal(bool p_enabled);