Skip to content

Commit

Permalink
Add painting for autoshader, holes, navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Nov 17, 2023
1 parent 969e00f commit 158eea7
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions project/addons/terrain_3d/editor/components/toolbar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
47 changes: 40 additions & 7 deletions project/addons/terrain_3d/editor/components/ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")

Expand All @@ -124,14 +129,26 @@ 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")
to_hide.push_back("height picker")
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)
Expand All @@ -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"),
Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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():
Expand All @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions project/addons/terrain_3d/icons/icon_holes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions project/addons/terrain_3d/icons/icon_holes.svg.import
Original file line number Diff line number Diff line change
@@ -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
42 changes: 42 additions & 0 deletions project/addons/terrain_3d/icons/icon_navigation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions project/addons/terrain_3d/icons/icon_navigation.svg.import
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions src/shaders/debug_views.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 158eea7

Please sign in to comment.