diff --git a/docs/image_generator/preview_generator.gd b/docs/image_generator/preview_generator.gd index fb20fd0e..c0ce7ef8 100644 --- a/docs/image_generator/preview_generator.gd +++ b/docs/image_generator/preview_generator.gd @@ -15,6 +15,7 @@ enum PreviewCase { SphereDensity, IcoSphere, PlaneSize, + NoDepthTest, Line, Arrow, @@ -55,6 +56,7 @@ var case_maps = { PreviewCase.SphereDensity : CaseData.new(), PreviewCase.IcoSphere : CaseData.new(), PreviewCase.PlaneSize : CaseData.new(), + PreviewCase.NoDepthTest : CaseData.new("NoDepthTest"), PreviewCase.Line : CaseData.new(), PreviewCase.Arrow : CaseData.new("DrawMethods360Lines"), @@ -102,6 +104,10 @@ var changed_by_code := false changed_by_code = true $Control.size = val $GridRender.size = val * 2 + + if not Engine.is_editor_hint(): + $Control.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + get_tree().root.size = viewport_size changed_by_code = false @export var anim_value_1: float = 0 @@ -156,7 +162,10 @@ func _set_anim(): %AnimationPlayer.seek(0) if not Engine.is_editor_hint(): - %AnimationPlayer.callback_mode_process = AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_MANUAL + if Engine.get_version_info()["minor"] > 1: + %AnimationPlayer.callback_mode_process = 2 + else: + %AnimationPlayer.playback_process_mode = 2 if not Engine.is_editor_hint() and OS.has_feature("movie"): var anim: Animation = %AnimationPlayer.get_animation(%AnimationPlayer.current_animation) @@ -257,7 +266,7 @@ func _process(delta): %AnimationPlayer.advance(delta) # Default 3D - var _s_def = DebugDraw3D.new_scoped_config().set_thickness(0.05) + var _s_def = DebugDraw3D.new_scoped_config().set_thickness(0.05).set_viewport($GridRender) # Default 2D DebugDraw2D.custom_canvas = $Control/PanelContainer @@ -305,6 +314,9 @@ func _process(delta): PreviewCase.PlaneSize: var _s = DebugDraw3D.new_scoped_config().set_plane_size(anim_value_1) DebugDraw3D.draw_plane(plane, Color.SEA_GREEN * Color(1,1,1,0.6), pxf.origin) + PreviewCase.NoDepthTest: + var _s = DebugDraw3D.new_scoped_config().set_no_depth_test(anim_value_1 > 0.5) + DebugDraw3D.draw_box(%OriginInstances.global_position, %OriginInstances.quaternion, Vector3.ONE * Vector3(0.6, 0.3, 0.3), Color.DEEP_PINK, true) PreviewCase.Line: var _s = DebugDraw3D.new_scoped_config().set_center_brightness(0.7).set_thickness(0.2) diff --git a/docs/image_generator/preview_generator.tscn b/docs/image_generator/preview_generator.tscn index 68653744..1ec25ae4 100644 --- a/docs/image_generator/preview_generator.tscn +++ b/docs/image_generator/preview_generator.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=31 format=3 uid="uid://davayb2hh6h3u"] +[gd_scene load_steps=35 format=3 uid="uid://davayb2hh6h3u"] [ext_resource type="Script" path="res://image_generator/preview_generator.gd" id="1_1iqys"] @@ -2131,6 +2131,154 @@ tracks/9/keys = { "times": PackedFloat32Array(0, 0.6, 0.75, 1.35) } +[sub_resource type="Animation" id="Animation_hhbl7"] +resource_name = "NoDepthTest" +length = 2.0 +loop_mode = 1 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:viewport_size") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [Vector2i(256, 128)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath(".:single_image") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath(".:lossless") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("GridRender/CameraOrigin/Camera3D:position") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, -0.150017, 1.72116)] +} +tracks/4/type = "value" +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/path = NodePath("GridRender/CameraOrigin/Camera3D:rotation") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0.296706, 0, 0)] +} +tracks/5/type = "value" +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/path = NodePath("GridRender/CameraOrigin:rotation") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(-0.698132, 0, 0)] +} +tracks/6/type = "value" +tracks/6/imported = false +tracks/6/enabled = true +tracks/6/path = NodePath("OriginInstances:position") +tracks/6/interp = 1 +tracks/6/loop_wrap = true +tracks/6/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 0.44, 0)] +} +tracks/7/type = "value" +tracks/7/imported = false +tracks/7/enabled = true +tracks/7/path = NodePath("OriginInstances:rotation") +tracks/7/interp = 1 +tracks/7/loop_wrap = true +tracks/7/keys = { +"times": PackedFloat32Array(0, 2), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector3(0, 0, 0), Vector3(0, -6.28319, 0)] +} +tracks/8/type = "value" +tracks/8/imported = false +tracks/8/enabled = true +tracks/8/path = NodePath("OriginInstances:scale") +tracks/8/interp = 1 +tracks/8/loop_wrap = true +tracks/8/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0.65, 0.65, 0.65)] +} +tracks/9/type = "value" +tracks/9/imported = false +tracks/9/enabled = true +tracks/9/path = NodePath("OriginUpVector:rotation") +tracks/9/interp = 1 +tracks/9/loop_wrap = true +tracks/9/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0.261799, 0, 0)] +} +tracks/10/type = "value" +tracks/10/imported = false +tracks/10/enabled = true +tracks/10/path = NodePath("NoDepthTestBox:visible") +tracks/10/interp = 1 +tracks/10/loop_wrap = true +tracks/10/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [true] +} +tracks/11/type = "bezier" +tracks/11/imported = false +tracks/11/enabled = true +tracks/11/path = NodePath(".:anim_value_1") +tracks/11/interp = 1 +tracks/11/loop_wrap = true +tracks/11/keys = { +"handle_modes": PackedInt32Array(0, 0, 0), +"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0), +"times": PackedFloat32Array(0, 1, 2) +} + [sub_resource type="Animation" id="Animation_a5v07"] resource_name = "PlaneSize" loop_mode = 1 @@ -2459,6 +2607,18 @@ tracks/16/keys = { "update": 0, "values": [Vector3(0.308753, 0.314478, -0.54646)] } +tracks/17/type = "value" +tracks/17/imported = false +tracks/17/enabled = true +tracks/17/path = NodePath("NoDepthTestBox:visible") +tracks/17/interp = 1 +tracks/17/loop_wrap = true +tracks/17/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} [sub_resource type="Animation" id="Animation_2pssc"] resource_name = "SphereDensity" @@ -2628,11 +2788,28 @@ _data = { "LineBevel": SubResource("Animation_1l2uk"), "LineCenterBrightness": SubResource("Animation_dj0n6"), "LineThickness": SubResource("Animation_4yn7h"), +"NoDepthTest": SubResource("Animation_hhbl7"), "PlaneSize": SubResource("Animation_a5v07"), "RESET": SubResource("Animation_hchms"), "SphereDensity": SubResource("Animation_2pssc") } +[sub_resource type="Shader" id="Shader_t34go"] +code = "shader_type spatial; +render_mode unshaded; + +void fragment() { + ALBEDO = vec3(0); +} +" + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_aonqq"] +render_priority = 0 +shader = SubResource("Shader_t34go") + +[sub_resource type="BoxMesh" id="BoxMesh_bwerf"] +material = SubResource("ShaderMaterial_aonqq") + [node name="PreviewGenerator" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -2641,7 +2818,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_1iqys") -preview_case = 5 +preview_case = 6 anim_value_1 = 0.1 metadata/movie_file = "C:/My/Projects/GE/Addons/godot_debug_draw_3d/docs/images/classes/temp/_.png" @@ -2695,7 +2872,6 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_qjyty") [node name="AnimationPlayer" type="AnimationPlayer" parent="."] unique_name_in_owner = true -callback_mode_method = 1 libraries = { "": SubResource("AnimationLibrary_ce374") } @@ -2704,6 +2880,12 @@ libraries = { unique_name_in_owner = true transform = Transform3D(3.72127, 0, 3.72127, 0.0105216, 5.26265, -0.0105216, -3.72126, 0.0148798, 3.72126, 0, 0, 0) +[node name="NoDepthTestBox" type="MeshInstance3D" parent="."] +unique_name_in_owner = true +transform = Transform3D(0.382746, 0, 0, 0, 0.666283, 0, 0, 0, 0.382746, 0, 0.440512, 0) +visible = false +mesh = SubResource("BoxMesh_bwerf") + [node name="OriginLine" type="Node3D" parent="."] unique_name_in_owner = true transform = Transform3D(0.591832, 0.579682, -0.560092, -0.568178, 0.792886, 0.220241, 0.571759, 0.187886, 0.798618, 0, 0.46, 0) @@ -2743,7 +2925,7 @@ transform = Transform3D(1, 6.25849e-07, 1.19209e-07, 2.98023e-08, 1, -3.72529e-0 transform = Transform3D(1, 3.12924e-07, 1.19209e-07, 2.98023e-08, 1, -3.72529e-07, 2.98023e-08, 2.98023e-07, 1, 0.308753, 0.314478, -0.54646) [node name="OriginCameraFrustum" type="Node3D" parent="."] -transform = Transform3D(-0.619366, 0, 0.197195, 0, 0.65, 0, -0.197195, 0, -0.619366, 0, 0.44, 0) +transform = Transform3D(0.65, 0, 0, 0, 0.65, 0, 0, 0, 0.65, 0, 0.44, 0) [node name="Camera3D" type="Camera3D" parent="OriginCameraFrustum"] transform = Transform3D(-6.72483e-08, 0, 1.53846, 0, 1.53846, 0, -1.53846, 0, -6.72483e-08, 1.71191, 0, 0) diff --git a/docs/images/classes/NoDepthTest.webp b/docs/images/classes/NoDepthTest.webp new file mode 100644 index 00000000..d8043f87 Binary files /dev/null and b/docs/images/classes/NoDepthTest.webp differ diff --git a/examples_dd3d/DebugDrawDemoScene.gd b/examples_dd3d/DebugDrawDemoScene.gd index db7577c5..b6fa12ed 100644 --- a/examples_dd3d/DebugDrawDemoScene.gd +++ b/examples_dd3d/DebugDrawDemoScene.gd @@ -75,7 +75,7 @@ func _physics_process(delta: float) -> void: ## Additional drawing in the Viewport if true: - var _w1 = DebugDraw3D.new_scoped_config().set_viewport(%OtherWorldBox.get_viewport()).set_thickness(0.01).set_center_brightness(1) + var _w1 = DebugDraw3D.new_scoped_config().set_viewport(%OtherWorldBox.get_viewport()).set_thickness(0.01).set_center_brightness(1).set_no_depth_test(true) DebugDraw3D.draw_box_xf(Transform3D(Basis() .scaled(Vector3.ONE*0.3) .rotated(Vector3(0,0,1), PI/4) @@ -265,7 +265,7 @@ func main_update(delta: float) -> void: DebugDraw3D.draw_gizmo($Misc/GizmoTransform.global_transform, DebugDraw3D.empty_color, true) DebugDraw3D.draw_gizmo($Misc/GizmoOneColor.global_transform, Color.BROWN, true) if true: - var _s123 = DebugDraw3D.new_scoped_config().set_center_brightness(0.5) + var _s123 = DebugDraw3D.new_scoped_config().set_center_brightness(0.5).set_no_depth_test(true) DebugDraw3D.draw_gizmo($Misc/GizmoNormal.global_transform.orthonormalized(), DebugDraw3D.empty_color, false) var tg : Transform3D = $Grids/Grid.global_transform @@ -442,6 +442,7 @@ func _draw_array_of_boxes(): cubes_max_time = 60 if timer_cubes < 0: + var start_time = Time.get_ticks_usec() for x in x_size: for y in y_size: for z in z_size: @@ -449,6 +450,7 @@ func _draw_array_of_boxes(): cfg.set_thickness(randf_range(0, 0.1)) #var size = Vector3(randf_range(0.1, 100),randf_range(0.1, 100),randf_range(0.1, 100)) DebugDraw3D.draw_box(Vector3(x * mul, (-4-z) * mul, y * mul), Quaternion.IDENTITY, size, DebugDraw3D.empty_color, false, cubes_max_time) + #print("Draw Cubes: %fms" % ((Time.get_ticks_usec() - start_time) / 1000.0)) timer_cubes = cubes_max_time diff --git a/examples_dd3d/DebugDrawDemoScene.tscn b/examples_dd3d/DebugDrawDemoScene.tscn index f4bc7d1c..0ddef81f 100644 --- a/examples_dd3d/DebugDrawDemoScene.tscn +++ b/examples_dd3d/DebugDrawDemoScene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=35 format=3 uid="uid://c3sccy6x0ht5j"] +[gd_scene load_steps=36 format=3 uid="uid://c3sccy6x0ht5j"] [ext_resource type="Script" path="res://examples_dd3d/DebugDrawDemoScene.gd" id="1"] [ext_resource type="FontFile" uid="uid://erdgllynwqkw" path="res://examples_dd3d/Roboto-Bold.ttf" id="2_aedbq"] @@ -169,6 +169,10 @@ _data = { } [sub_resource type="CapsuleMesh" id="CapsuleMesh_tigpa"] +radius = 0.395 +height = 1.825 + +[sub_resource type="BoxMesh" id="BoxMesh_b14rm"] [sub_resource type="SphereShape3D" id="4"] radius = 1.0 @@ -514,7 +518,7 @@ current = true far = 5.0 [node name="MeshInstance3D" type="MeshInstance3D" parent="OtherWorld/SubViewport"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.57063, 0.6, 4.85623) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.57063, 0.6, 5.72253) mesh = SubResource("CapsuleMesh_tigpa") [node name="OtherWorldBox" type="Node3D" parent="OtherWorld/SubViewport"] @@ -531,10 +535,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.403353, -0.331599, 2.22542) transform = Transform3D(0.802141, -0.286294, -0.524028, -0.539546, 0.0285125, -0.841473, 0.25585, 0.957718, -0.131597, -0.475607, -0.670307, 2.30581) [node name="Position" type="Node3D" parent="Misc"] -transform = Transform3D(1.51514, 0.589536, 1.00858, -1.34875, 0.662262, 1.133, 0, -0.462445, 2.90833, 0.853743, -0.331599, -1.73676) +transform = Transform3D(1.51514, 0.589536, 1.00858, -1.34875, 0.662262, 1.133, 0, -0.462445, 2.90833, 0.853743, 0.0843356, -1.73676) [node name="GizmoNormal" type="Node3D" parent="Misc"] -transform = Transform3D(1.95938, 0, -0.848962, 0, 0.999999, 0, 0.525014, 0, 3.16837, 0.890203, -0.306246, 0.356159) +transform = Transform3D(0.965926, 0, -0.258819, 0, 1, 0, 0.258819, 0, 0.965926, 0.890203, -0.306246, 0.356159) + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Misc/GizmoNormal"] +transform = Transform3D(0.591801, 0, 4.47035e-08, 0, 0.591801, 0, -4.47035e-08, 0, 0.591801, 0, 0, 0) +mesh = SubResource("BoxMesh_b14rm") [node name="GizmoTransform" type="Node3D" parent="Misc"] transform = Transform3D(0.879881, 0.248446, -0.405072, -0.346604, 0.918688, -0.189411, 0.325077, 0.307059, 0.894449, -0.838587, -0.458, -0.176491) diff --git a/src/3d/config_scope_3d.cpp b/src/3d/config_scope_3d.cpp index 7833accc..451ca346 100644 --- a/src/3d/config_scope_3d.cpp +++ b/src/3d/config_scope_3d.cpp @@ -20,6 +20,9 @@ void DebugDraw3DScopeConfig::_bind_methods() { REG_METHOD(set_viewport, "value"); REG_METHOD(get_viewport); + + REG_METHOD(set_no_depth_test, "value"); + REG_METHOD(is_no_depth_test); #undef REG_CLASS_NAME } @@ -30,7 +33,7 @@ void DebugDraw3DScopeConfig::_manual_unregister() { unregister_action = nullptr; } -Ref DebugDraw3DScopeConfig::set_thickness(real_t _value) { +Ref DebugDraw3DScopeConfig::set_thickness(real_t _value) const { data->thickness = Math::clamp(_value, (real_t)0, (real_t)100); return Ref(this); } @@ -39,7 +42,7 @@ real_t DebugDraw3DScopeConfig::get_thickness() const { return data->thickness; } -Ref DebugDraw3DScopeConfig::set_center_brightness(real_t _value) { +Ref DebugDraw3DScopeConfig::set_center_brightness(real_t _value) const { data->center_brightness = Math::clamp(_value, (real_t)0, (real_t)1); return Ref(this); } @@ -48,31 +51,40 @@ real_t DebugDraw3DScopeConfig::get_center_brightness() const { return data->center_brightness; } -Ref DebugDraw3DScopeConfig::set_hd_sphere(bool _value) { +Ref DebugDraw3DScopeConfig::set_hd_sphere(bool _value) const { data->hd_sphere = _value; - return this; + return Ref(this); } bool DebugDraw3DScopeConfig::is_hd_sphere() const { return data->hd_sphere; } -Ref DebugDraw3DScopeConfig::set_plane_size(real_t _value) { +Ref DebugDraw3DScopeConfig::set_plane_size(real_t _value) const { data->plane_size = _value; - return this; + return Ref(this); } real_t DebugDraw3DScopeConfig::get_plane_size() const { return data->plane_size; } -Ref DebugDraw3DScopeConfig::set_viewport(Viewport *_value) { - data->viewport = _value; - return this; +Ref DebugDraw3DScopeConfig::set_viewport(Viewport *_value) const { + data->dgcd.viewport = _value; + return Ref(this); } Viewport *DebugDraw3DScopeConfig::get_viewport() const { - return data->viewport; + return data->dgcd.viewport; +} + +Ref DebugDraw3DScopeConfig::set_no_depth_test(bool _value) const { + data->dgcd.no_depth_test = _value; + return Ref(this); +} + +bool DebugDraw3DScopeConfig::is_no_depth_test() const { + return data->dgcd.no_depth_test; } DebugDraw3DScopeConfig::DebugDraw3DScopeConfig() { @@ -101,7 +113,7 @@ DebugDraw3DScopeConfig::Data::Data() { center_brightness = 0; hd_sphere = false; plane_size = INFINITY; - viewport = nullptr; + dgcd = {}; } DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr &p_parent) { @@ -109,5 +121,7 @@ DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr &p_parent) { center_brightness = p_parent->center_brightness; hd_sphere = p_parent->hd_sphere; plane_size = p_parent->plane_size; - viewport = p_parent->viewport; + + dgcd.viewport = p_parent->dgcd.viewport; + dgcd.no_depth_test = p_parent->dgcd.no_depth_test; } diff --git a/src/3d/config_scope_3d.h b/src/3d/config_scope_3d.h index 04f5049a..46fcfe58 100644 --- a/src/3d/config_scope_3d.h +++ b/src/3d/config_scope_3d.h @@ -69,6 +69,22 @@ class DebugDraw3DScopeConfig : public RefCounted { unregister_func unregister_action; public: + /// @private + struct DebugContainerDependent { + Viewport *viewport; + bool no_depth_test; + + DebugContainerDependent() : + viewport(nullptr), + no_depth_test(false) { + } + + DebugContainerDependent(Viewport *p_viewport, bool p_no_depth_test) : + viewport(p_viewport), + no_depth_test(p_no_depth_test) { + } + }; + /// @private struct Data { // Update the constructor if changes are made! @@ -76,7 +92,7 @@ class DebugDraw3DScopeConfig : public RefCounted { real_t center_brightness; bool hd_sphere; real_t plane_size; - Viewport *viewport; + DebugContainerDependent dgcd; Data(); Data(const std::shared_ptr &parent); @@ -93,7 +109,7 @@ class DebugDraw3DScopeConfig : public RefCounted { * * ![](docs/images/classes/LineThickness.webp) */ - Ref set_thickness(real_t _value); + Ref set_thickness(real_t _value) const; real_t get_thickness() const; /** @@ -101,7 +117,7 @@ class DebugDraw3DScopeConfig : public RefCounted { * * ![](docs/images/classes/LineCenterBrightness.webp) */ - Ref set_center_brightness(real_t _value); + Ref set_center_brightness(real_t _value) const; real_t get_center_brightness() const; /** @@ -109,7 +125,7 @@ class DebugDraw3DScopeConfig : public RefCounted { * * ![](docs/images/classes/SphereDensity.webp) */ - Ref set_hd_sphere(bool _value); + Ref set_hd_sphere(bool _value) const; bool is_hd_sphere() const; /** @@ -117,7 +133,7 @@ class DebugDraw3DScopeConfig : public RefCounted { * * ![](docs/images/classes/PlaneSize.webp) */ - Ref set_plane_size(real_t _value); + Ref set_plane_size(real_t _value) const; real_t get_plane_size() const; /** @@ -130,9 +146,20 @@ class DebugDraw3DScopeConfig : public RefCounted { * @note * Objects created for a specific Viewport will use only one camera related to that Viewport for culling. */ - Ref set_viewport(Viewport *_value); + Ref set_viewport(Viewport *_value) const; Viewport *get_viewport() const; + /** + * Set whether the `depth_test_disabled` flag is added or not in the shaders of the debug shapes. + * + * @note + * It may cause artifacts when drawing volumetric objects. + * + * ![](docs/images/classes/NoDepthTest.webp) + */ + Ref set_no_depth_test(bool _value) const; + bool is_no_depth_test() const; + /// @private DebugDraw3DScopeConfig(); diff --git a/src/3d/cpp.hint b/src/3d/cpp.hint new file mode 100644 index 00000000..630d2d86 --- /dev/null +++ b/src/3d/cpp.hint @@ -0,0 +1,4 @@ +// Hint files help the Visual Studio IDE interpret Visual C++ identifiers +// such as names of functions and macros. +// For more information see https://go.microsoft.com/fwlink/?linkid=865984 +#define FAKE_FUNC_IMPL diff --git a/src/3d/debug_draw_3d.cpp b/src/3d/debug_draw_3d.cpp index 924e59b6..ed52d183 100644 --- a/src/3d/debug_draw_3d.cpp +++ b/src/3d/debug_draw_3d.cpp @@ -180,7 +180,11 @@ void DebugDraw3D::process(double p_delta) { // Update 3D debug for (const auto &p : debug_containers) { - p.second->update_geometry(p_delta); + for (const auto &dgc : p.second) { + if (dgc) { + dgc->update_geometry(p_delta); + } + } } _clear_scoped_configs(); @@ -196,7 +200,11 @@ void DebugDraw3D::physics_process_start(double p_delta) { FrameMarkStart("3D Physics Step"); for (const auto &p : debug_containers) { - p.second->update_geometry_physics_start(p_delta); + for (const auto &dgc : p.second) { + if (dgc) { + dgc->update_geometry_physics_start(p_delta); + } + } } #endif } @@ -205,7 +213,11 @@ void DebugDraw3D::physics_process_end(double p_delta) { ZoneScoped; #ifndef DISABLE_DEBUG_RENDERING for (const auto &p : debug_containers) { - p.second->update_geometry_physics_end(p_delta); + for (const auto &dgc : p.second) { + if (dgc) { + dgc->update_geometry_physics_end(p_delta); + } + } } FrameMarkEnd("3D Physics Step"); @@ -292,7 +304,7 @@ Node *DebugDraw3D::get_root_node() { return root_node; } -Ref *DebugDraw3D::get_shared_meshes() { +std::array, 2> *DebugDraw3D::get_shared_meshes() { LOCK_GUARD(datalock); if (!shared_generated_meshes.size()) { bool p_add_bevel = PS()->get_setting(root_settings_section + s_add_bevel_to_volumetric); @@ -300,72 +312,90 @@ Ref *DebugDraw3D::get_shared_meshes() { bool p_use_icosphere_hd = PS()->get_setting(root_settings_section + s_use_icosphere_hd); shared_generated_meshes.resize((int)InstanceType::MAX); - - // WIREFRAME - - shared_generated_meshes[(int)InstanceType::CUBE] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CubeVertexes, GeometryGenerator::CubeIndexes); - shared_generated_meshes[(int)InstanceType::CUBE_CENTERED] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CenteredCubeVertexes, GeometryGenerator::CubeIndexes); - shared_generated_meshes[(int)InstanceType::ARROWHEAD] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::ArrowheadVertexes, GeometryGenerator::ArrowheadIndexes); - shared_generated_meshes[(int)InstanceType::POSITION] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::PositionVertexes, GeometryGenerator::PositionIndexes); - shared_generated_meshes[(int)InstanceType::SPHERE] = p_use_icosphere ? GeometryGenerator::CreateIcosphereLines(0.5f, 1) : GeometryGenerator::CreateSphereLines(8, 8, 0.5f, 2); - shared_generated_meshes[(int)InstanceType::SPHERE_HD] = p_use_icosphere_hd ? GeometryGenerator::CreateIcosphereLines(0.5f, 2) : GeometryGenerator::CreateSphereLines(16, 16, 0.5f, 2); - shared_generated_meshes[(int)InstanceType::CYLINDER] = GeometryGenerator::CreateCylinderLines(16, 1, 1, 2); - shared_generated_meshes[(int)InstanceType::CYLINDER_AB] = GeometryGenerator::RotatedMesh(GeometryGenerator::CreateCylinderLines(16, 1, 1, 2), Vector3_RIGHT, Math::deg_to_rad(90.f)); - - // VOLUMETRIC - - shared_generated_meshes[(int)InstanceType::LINE_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::LineVertexes), p_add_bevel); - shared_generated_meshes[(int)InstanceType::CUBE_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CUBE], p_add_bevel); - shared_generated_meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CUBE_CENTERED], p_add_bevel); - shared_generated_meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC] = GeometryGenerator::CreateVolumetricArrowHead(.25f, 1.f, 1.f, p_add_bevel); - shared_generated_meshes[(int)InstanceType::POSITION_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::POSITION], p_add_bevel); - shared_generated_meshes[(int)InstanceType::SPHERE_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::SPHERE], false); - shared_generated_meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::SPHERE_HD], false); - shared_generated_meshes[(int)InstanceType::CYLINDER_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CYLINDER], false); - shared_generated_meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC] = GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CYLINDER_AB], false); - - // SOLID - - shared_generated_meshes[(int)InstanceType::BILLBOARD_SQUARE] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareBackwardsIndexes); - shared_generated_meshes[(int)InstanceType::PLANE] = GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes); + for (int i = 0; i < 2; i++) { + MeshMaterialType mat_type = MeshMaterialType::Wireframe; + +#define GEN_MESH(_type, _gen) \ + shared_generated_meshes[(int)_type][i] = _gen; \ + shared_generated_meshes[(int)_type][i]->surface_set_material(0, get_material_variant(mat_type, i == 0 ? MeshMaterialVariant::Normal : MeshMaterialVariant::NoDepth)); + + // WIREFRAME + + mat_type = MeshMaterialType::Wireframe; + GEN_MESH(InstanceType::CUBE, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CubeVertexes, GeometryGenerator::CubeIndexes)); + GEN_MESH(InstanceType::CUBE_CENTERED, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CenteredCubeVertexes, GeometryGenerator::CubeIndexes)); + GEN_MESH(InstanceType::ARROWHEAD, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::ArrowheadVertexes, GeometryGenerator::ArrowheadIndexes)); + GEN_MESH(InstanceType::POSITION, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::PositionVertexes, GeometryGenerator::PositionIndexes)); + GEN_MESH(InstanceType::SPHERE, p_use_icosphere ? GeometryGenerator::CreateIcosphereLines(0.5f, 1) : GeometryGenerator::CreateSphereLines(8, 8, 0.5f, 2)); + GEN_MESH(InstanceType::SPHERE_HD, p_use_icosphere_hd ? GeometryGenerator::CreateIcosphereLines(0.5f, 2) : GeometryGenerator::CreateSphereLines(16, 16, 0.5f, 2)); + GEN_MESH(InstanceType::CYLINDER, GeometryGenerator::CreateCylinderLines(16, 1, 1, 2)); + GEN_MESH(InstanceType::CYLINDER_AB, GeometryGenerator::RotatedMesh(GeometryGenerator::CreateCylinderLines(16, 1, 1, 2), Vector3_RIGHT, Math::deg_to_rad(90.f))); + + // VOLUMETRIC + + mat_type = MeshMaterialType::Extendable; + GEN_MESH(InstanceType::LINE_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::LineVertexes), p_add_bevel)); + GEN_MESH(InstanceType::CUBE_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CUBE][i], p_add_bevel)); + GEN_MESH(InstanceType::CUBE_CENTERED_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CUBE_CENTERED][i], p_add_bevel)); + GEN_MESH(InstanceType::ARROWHEAD_VOLUMETRIC, GeometryGenerator::CreateVolumetricArrowHead(.25f, 1.f, 1.f, p_add_bevel)); + GEN_MESH(InstanceType::POSITION_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::POSITION][i], p_add_bevel)); + GEN_MESH(InstanceType::SPHERE_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::SPHERE][i], false)); + GEN_MESH(InstanceType::SPHERE_HD_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::SPHERE_HD][i], false)); + GEN_MESH(InstanceType::CYLINDER_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CYLINDER][i], false)); + GEN_MESH(InstanceType::CYLINDER_AB_VOLUMETRIC, GeometryGenerator::ConvertWireframeToVolumetric(shared_generated_meshes[(int)InstanceType::CYLINDER_AB][i], false)); + + // SOLID + + mat_type = MeshMaterialType::Billboard; + GEN_MESH(InstanceType::BILLBOARD_SQUARE, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareBackwardsIndexes)); + + mat_type = MeshMaterialType::Plane; + GEN_MESH(InstanceType::PLANE, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); +#undef GEN_MESH + } } return shared_generated_meshes.data(); } -std::shared_ptr DebugDraw3D::create_debug_container() { - return std::make_shared(this); +std::shared_ptr DebugDraw3D::create_debug_container(bool p_no_depth_test) { + return std::make_shared(this, p_no_depth_test); } -std::shared_ptr DebugDraw3D::get_debug_container(Viewport *p_vp) { +std::shared_ptr DebugDraw3D::get_debug_container(const DebugDraw3DScopeConfig::DebugContainerDependent &p_dgcd) { ZoneScoped; LOCK_GUARD(datalock); - if (!p_vp) { + if (!p_dgcd.viewport) { return nullptr; } - if (const auto &cached_world = viewport_to_world_cache.find(p_vp); - cached_world != viewport_to_world_cache.end()) { - return cached_world->second.dgc; + int dgc_depth = !!p_dgcd.no_depth_test; + + if (const auto &cached_world = viewport_to_world_cache.find(p_dgcd.viewport); + cached_world != viewport_to_world_cache.end() && cached_world->second.dgcs[dgc_depth]) { + return cached_world->second.dgcs[dgc_depth]; } - Ref vp_world = p_vp->find_world_3d(); + Ref vp_world = p_dgcd.viewport->find_world_3d(); uint64_t vp_world_id = vp_world->get_instance_id(); - if (const auto &dgc = debug_containers.find(vp_world_id); - dgc != debug_containers.end()) { + if (const auto &dgc_pair = debug_containers.find(vp_world_id); + dgc_pair != debug_containers.end() && dgc_pair->second[dgc_depth]) { - viewport_to_world_cache[p_vp] = { dgc->first, dgc->second }; - return dgc->second; + viewport_to_world_cache[p_dgcd.viewport].world_id = dgc_pair->first; + viewport_to_world_cache[p_dgcd.viewport].dgcs[dgc_depth] = dgc_pair->second[dgc_depth]; + return dgc_pair->second[dgc_depth]; } - auto dgc = create_debug_container(); + auto dgc = create_debug_container(p_dgcd.no_depth_test); dgc->set_world(vp_world); - debug_containers[vp_world_id] = dgc; - viewport_to_world_cache[p_vp] = { vp_world_id, dgc }; + debug_containers[vp_world_id][dgc_depth] = dgc; + + viewport_to_world_cache[p_dgcd.viewport].world_id = vp_world_id; + viewport_to_world_cache[p_dgcd.viewport].dgcs[dgc_depth] = dgc; - call_deferred(NAMEOF(_register_viewport_world_deferred), _get_root_world_viewport(p_vp), vp_world_id); + call_deferred(NAMEOF(_register_viewport_world_deferred), _get_root_world_viewport(p_dgcd.viewport), vp_world_id); return dgc; } @@ -453,16 +483,27 @@ Ref DebugDraw3D::scoped_config() { void DebugDraw3D::_load_materials() { ZoneScoped; #ifndef DISABLE_DEBUG_RENDERING -#define LOAD_SHADER(code, mat, source) \ - code.instantiate(); \ - code->set_code(source); \ - mat.instantiate(); \ - mat->set_shader(code); - - LOAD_SHADER(shader_wireframe_code, shader_wireframe_mat, DD3DResources::src_resources_wireframe_unshaded_gdshader); - LOAD_SHADER(shader_billboard_code, shader_billboard_mat, DD3DResources::src_resources_billboard_unshaded_gdshader); - LOAD_SHADER(shader_plane_code, shader_plane_mat, DD3DResources::src_resources_plane_unshaded_gdshader); - LOAD_SHADER(shader_extendable_code, shader_extendable_mat, DD3DResources::src_resources_extendable_meshes_gdshader); +#define LOAD_SHADER(mat, source) \ + { \ + Ref code; \ + code.instantiate(); \ + code->set_code(source); \ + mat.instantiate(); \ + mat->set_shader(code); \ + } + + for (int variant = 0; variant < (int)MeshMaterialVariant::MAX; variant++) { + String prefix = ""; + if (variant == (int)MeshMaterialVariant::NoDepth) { + prefix = "#define NO_DEPTH\n"; + } + + LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Wireframe][variant], prefix + DD3DResources::src_resources_wireframe_unshaded_gdshader); + LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Billboard][variant], prefix + DD3DResources::src_resources_billboard_unshaded_gdshader); + LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Plane][variant], prefix + DD3DResources::src_resources_plane_unshaded_gdshader); + LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Extendable][variant], prefix + DD3DResources::src_resources_extendable_meshes_gdshader); + } +#undef LOAD_SHADER #endif } @@ -478,33 +519,9 @@ std::vector DebugDraw3D::get_custom_editor_viewports() { return custom_editor_viewports; } -Ref DebugDraw3D::get_wireframe_material() { +Ref DebugDraw3D::get_material_variant(MeshMaterialType p_type, MeshMaterialVariant p_var) { #ifndef DISABLE_DEBUG_RENDERING - return shader_wireframe_mat; -#else - return Ref(); -#endif -} - -Ref DebugDraw3D::get_billboard_material() { -#ifndef DISABLE_DEBUG_RENDERING - return shader_billboard_mat; -#else - return Ref(); -#endif -} - -Ref DebugDraw3D::get_plane_material() { -#ifndef DISABLE_DEBUG_RENDERING - return shader_plane_mat; -#else - return Ref(); -#endif -} - -Ref DebugDraw3D::get_extendable_material() { -#ifndef DISABLE_DEBUG_RENDERING - return shader_extendable_mat; + return mesh_shaders[(int)p_type][(int)p_var]; #else return Ref(); #endif @@ -553,11 +570,11 @@ Ref DebugDraw3D::get_render_stats() { stats_3d.instantiate(); for (const auto &p : debug_containers) { - const auto &dgc = p.second; - - if (dgc) { - dgc->get_render_stats(stats_3d); - res->combine_with(stats_3d); + for (const auto &dgc : p.second) { + if (dgc) { + dgc->get_render_stats(stats_3d); + res->combine_with(stats_3d); + } } } res->set_scoped_config_stats(scoped_stats_3d.created, scoped_stats_3d.orphans); @@ -566,15 +583,21 @@ Ref DebugDraw3D::get_render_stats() { } Ref DebugDraw3D::get_render_stats_for_world(Viewport *viewport) { + Ref res; + res.instantiate(); +#ifndef DISABLE_DEBUG_RENDERING Ref stats_3d; stats_3d.instantiate(); -#ifndef DISABLE_DEBUG_RENDERING - auto dgc = get_debug_container(viewport); - if (dgc) - dgc->get_render_stats(stats_3d); + for (int i = 0; i < 2; i++) { + auto dgc = get_debug_container(DebugDraw3DScopeConfig::DebugContainerDependent(viewport, !!i)); + if (dgc) { + dgc->get_render_stats(stats_3d); + res->combine_with(stats_3d); + } + } #endif - return stats_3d; + return res; } void DebugDraw3D::regenerate_geometry_meshes() { @@ -585,10 +608,15 @@ void DebugDraw3D::regenerate_geometry_meshes() { shared_generated_meshes.clear(); for (auto &p : debug_containers) { - Ref old_world = p.second->get_world(); + for (int i = 0; i < 2; i++) { + if (p.second[i]) { + Ref old_world = p.second[i]->get_world(); + bool no_depth = p.second[i]->is_no_depth_test(); - p.second = create_debug_container(); - p.second->set_world(old_world); + p.second[i] = create_debug_container(no_depth); + p.second[i]->set_world(old_world); + } + } } #endif } @@ -597,7 +625,11 @@ void DebugDraw3D::clear_all() { ZoneScoped; #ifndef DISABLE_DEBUG_RENDERING for (auto &p : debug_containers) { - p.second->clear_3d_objects(); + for (const auto &dgc : p.second) { + if (dgc) { + dgc->clear_3d_objects(); + } + } } #else return; @@ -613,7 +645,7 @@ void DebugDraw3D::clear_all() { #define GET_SCOPED_CFG_AND_DGC() \ auto scfg = scoped_config_for_current_thread(); \ - auto dgc = get_debug_container(scfg->viewport); \ + auto dgc = get_debug_container(scfg->dgcd); \ if (!dgc) return #ifndef DISABLE_DEBUG_RENDERING @@ -1064,7 +1096,7 @@ void DebugDraw3D::draw_plane(const Plane &plane, const Color &color, const Vecto LOCK_GUARD(datalock); GET_SCOPED_CFG_AND_DGC(); - Camera3D *cam = scfg->viewport ? scfg->viewport->get_camera_3d() : nullptr; + Camera3D *cam = scfg->dgcd.viewport ? scfg->dgcd.viewport->get_camera_3d() : nullptr; Vector3 center_pos = plane.project(anchor_point == Vector3_INF ? (cam ? cam->get_global_position() : Vector3()) : anchor_point); real_t plane_size = scfg->plane_size != INFINITY ? scfg->plane_size : (cam ? (real_t)cam->get_far() : 1000); diff --git a/src/3d/debug_draw_3d.h b/src/3d/debug_draw_3d.h index e30cfc6d..c97b09a6 100644 --- a/src/3d/debug_draw_3d.h +++ b/src/3d/debug_draw_3d.h @@ -30,6 +30,22 @@ class DebugGeometryContainer; struct DelayedRendererLine; #endif +/// @private +enum class MeshMaterialType : char { + Wireframe, + Billboard, + Plane, + Extendable, + MAX, +}; + +/// @private +enum class MeshMaterialVariant : char { + Normal, + NoDepth, + MAX, +}; + #ifndef DISABLE_DEBUG_RENDERING /// @private class _DD3D_WorldWatcher : public Node3D { @@ -154,36 +170,26 @@ class DebugDraw3D : public Object, public IScopeStorage > shared_generated_meshes; + std::vector, 2> > shared_generated_meshes; /// Store World3D id and debug container - std::unordered_map > debug_containers; + std::unordered_map[2]> debug_containers; struct viewportToWorldCache { uint64_t world_id = 0; - std::shared_ptr dgc; + std::shared_ptr dgcs[2]; }; std::unordered_map viewport_to_world_cache; // Default materials and shaders - Ref shader_wireframe_mat; - Ref shader_wireframe_code; - - Ref shader_billboard_mat; - Ref shader_billboard_code; - - Ref shader_plane_mat; - Ref shader_plane_code; - - Ref shader_extendable_mat; - Ref shader_extendable_code; + Ref mesh_shaders[(int)MeshMaterialType::MAX][(int)MeshMaterialVariant::MAX]; // Inherited via IScopeStorage void _register_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id, DebugDraw3DScopeConfig *p_cfg) override; void _unregister_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id) override; void _clear_scoped_configs() override; - Ref *get_shared_meshes(); - std::shared_ptr create_debug_container(); - std::shared_ptr get_debug_container(Viewport *p_vp); + std::array, 2> *get_shared_meshes(); + std::shared_ptr create_debug_container(bool p_no_depth_test); + std::shared_ptr get_debug_container(const DebugDraw3DScopeConfig::DebugContainerDependent &p_dgcd); void _register_viewport_world_deferred(Viewport *p_vp, const uint64_t p_world_id); Viewport *_get_root_world_viewport(Viewport *p_vp); void _remove_debug_container(const uint64_t &p_world_id); @@ -201,10 +207,7 @@ class DebugDraw3D : public Object, public IScopeStorage p_viewports); std::vector get_custom_editor_viewports(); - Ref get_wireframe_material(); - Ref get_billboard_material(); - Ref get_plane_material(); - Ref get_extendable_material(); + Ref get_material_variant(MeshMaterialType p_type, MeshMaterialVariant p_var); void _load_materials(); inline bool _is_enabled_override() const; diff --git a/src/3d/debug_geometry_container.cpp b/src/3d/debug_geometry_container.cpp index 477322b5..1078b115 100644 --- a/src/3d/debug_geometry_container.cpp +++ b/src/3d/debug_geometry_container.cpp @@ -16,10 +16,11 @@ GODOT_WARNING_DISABLE() GODOT_WARNING_RESTORE() using namespace godot; -DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root) { +DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root, bool p_no_depth_test) { ZoneScoped; owner = p_root; RenderingServer *rs = RenderingServer::get_singleton(); + no_depth_test = p_no_depth_test; // Create wireframe mesh drawer { @@ -32,7 +33,7 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root) { rs->instance_geometry_set_flag(_immediate_instance, RenderingServer::INSTANCE_FLAG_USE_DYNAMIC_GI, false); rs->instance_geometry_set_flag(_immediate_instance, RenderingServer::INSTANCE_FLAG_USE_BAKED_LIGHT, false); - Ref mat = owner->get_wireframe_material(); + Ref mat = owner->get_material_variant(MeshMaterialType::Wireframe, no_depth_test ? MeshMaterialVariant::NoDepth : MeshMaterialVariant::Normal); rs->instance_geometry_set_material_override(_immediate_instance, mat->get_rid()); immediate_mesh_storage.instance = _immediate_instance; @@ -43,32 +44,33 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root) { // Generate geometry and create MMI's in RenderingServer { auto *meshes = owner->get_shared_meshes(); + int mat_variant = !!no_depth_test; - CreateMMI(InstanceType::CUBE, UsingShaderType::Wireframe, NAMEOF(mmi_cubes), meshes[(int)InstanceType::CUBE]); - CreateMMI(InstanceType::CUBE_CENTERED, UsingShaderType::Wireframe, NAMEOF(mmi_cubes_centered), meshes[(int)InstanceType::CUBE_CENTERED]); - CreateMMI(InstanceType::ARROWHEAD, UsingShaderType::Wireframe, NAMEOF(mmi_arrowheads), meshes[(int)InstanceType::ARROWHEAD]); - CreateMMI(InstanceType::POSITION, UsingShaderType::Wireframe, NAMEOF(mmi_positions), meshes[(int)InstanceType::POSITION]); - CreateMMI(InstanceType::SPHERE, UsingShaderType::Wireframe, NAMEOF(mmi_spheres), meshes[(int)InstanceType::SPHERE]); - CreateMMI(InstanceType::SPHERE_HD, UsingShaderType::Wireframe, NAMEOF(mmi_spheres_hd), meshes[(int)InstanceType::SPHERE_HD]); - CreateMMI(InstanceType::CYLINDER, UsingShaderType::Wireframe, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER]); - CreateMMI(InstanceType::CYLINDER_AB, UsingShaderType::Wireframe, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER_AB]); + CreateMMI(InstanceType::CUBE, NAMEOF(mmi_cubes), meshes[(int)InstanceType::CUBE][mat_variant]); + CreateMMI(InstanceType::CUBE_CENTERED, NAMEOF(mmi_cubes_centered), meshes[(int)InstanceType::CUBE_CENTERED][mat_variant]); + CreateMMI(InstanceType::ARROWHEAD, NAMEOF(mmi_arrowheads), meshes[(int)InstanceType::ARROWHEAD][mat_variant]); + CreateMMI(InstanceType::POSITION, NAMEOF(mmi_positions), meshes[(int)InstanceType::POSITION][mat_variant]); + CreateMMI(InstanceType::SPHERE, NAMEOF(mmi_spheres), meshes[(int)InstanceType::SPHERE][mat_variant]); + CreateMMI(InstanceType::SPHERE_HD, NAMEOF(mmi_spheres_hd), meshes[(int)InstanceType::SPHERE_HD][mat_variant]); + CreateMMI(InstanceType::CYLINDER, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER][mat_variant]); + CreateMMI(InstanceType::CYLINDER_AB, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER_AB][mat_variant]); // VOLUMETRIC - CreateMMI(InstanceType::LINE_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::LINE_VOLUMETRIC]); - CreateMMI(InstanceType::CUBE_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::CUBE_VOLUMETRIC]); - CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_cubes_centered_volumetric), meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC]); - CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_arrowheads_volumetric), meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC]); - CreateMMI(InstanceType::POSITION_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_positions_volumetric), meshes[(int)InstanceType::POSITION_VOLUMETRIC]); - CreateMMI(InstanceType::SPHERE_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_spheres_volumetric), meshes[(int)InstanceType::SPHERE_VOLUMETRIC]); - CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_spheres_hd_volumetric), meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC]); - CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_VOLUMETRIC]); - CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, UsingShaderType::Expandable, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC]); + CreateMMI(InstanceType::LINE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::LINE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CUBE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::CUBE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, NAMEOF(mmi_cubes_centered_volumetric), meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, NAMEOF(mmi_arrowheads_volumetric), meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::POSITION_VOLUMETRIC, NAMEOF(mmi_positions_volumetric), meshes[(int)InstanceType::POSITION_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::SPHERE_VOLUMETRIC, NAMEOF(mmi_spheres_volumetric), meshes[(int)InstanceType::SPHERE_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, NAMEOF(mmi_spheres_hd_volumetric), meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_VOLUMETRIC][mat_variant]); + CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC][mat_variant]); // SOLID - CreateMMI(InstanceType::BILLBOARD_SQUARE, UsingShaderType::Billboard, NAMEOF(mmi_billboard_squares), meshes[(int)InstanceType::BILLBOARD_SQUARE]); - CreateMMI(InstanceType::PLANE, UsingShaderType::Solid, NAMEOF(mmi_planes), meshes[(int)InstanceType::PLANE]); + CreateMMI(InstanceType::BILLBOARD_SQUARE, NAMEOF(mmi_billboard_squares), meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]); + CreateMMI(InstanceType::PLANE, NAMEOF(mmi_planes), meshes[(int)InstanceType::PLANE][mat_variant]); set_render_layer_mask(1); } @@ -81,7 +83,11 @@ DebugGeometryContainer::~DebugGeometryContainer() { geometry_pool.clear_pool(); } -void DebugGeometryContainer::CreateMMI(InstanceType p_type, UsingShaderType p_shader, const String &p_name, Ref p_mesh) { +bool DebugGeometryContainer::is_no_depth_test() const { + return no_depth_test; +} + +void DebugGeometryContainer::CreateMMI(InstanceType p_type, const String &p_name, Ref p_mesh) { ZoneScoped; RenderingServer *rs = RenderingServer::get_singleton(); @@ -99,24 +105,6 @@ void DebugGeometryContainer::CreateMMI(InstanceType p_type, UsingShaderType p_sh rs->instance_set_base(mmi, new_mm->get_rid()); - Ref mat; - switch (p_shader) { - case UsingShaderType::Wireframe: - mat = owner->get_wireframe_material(); - break; - case UsingShaderType::Billboard: - mat = owner->get_billboard_material(); - break; - case UsingShaderType::Solid: - mat = owner->get_plane_material(); - break; - case UsingShaderType::Expandable: - mat = owner->get_extendable_material(); - break; - } - - p_mesh->surface_set_material(0, mat); - rs->instance_geometry_set_cast_shadows_setting(mmi, RenderingServer::SHADOW_CASTING_SETTING_OFF); rs->instance_geometry_set_flag(mmi, RenderingServer::INSTANCE_FLAG_USE_DYNAMIC_GI, false); rs->instance_geometry_set_flag(mmi, RenderingServer::INSTANCE_FLAG_USE_BAKED_LIGHT, false); @@ -286,7 +274,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) { // Draw custom sphere for 1 frame for (auto &i : new_instances) { - cfg->viewport = vp; + cfg->dgcd.viewport = vp; Vector3 diag = i.max - i.min; Vector3 center = i.center; real_t radius = i.radius; @@ -318,7 +306,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) { Vector3 center = o->bounds.center; real_t radius = o->bounds.radius; - cfg->viewport = vp; + cfg->dgcd.viewport = vp; geometry_pool.add_or_update_instance( cfg, InstanceType::CUBE_CENTERED, diff --git a/src/3d/debug_geometry_container.h b/src/3d/debug_geometry_container.h index 1c8ea78c..9c0d5c91 100644 --- a/src/3d/debug_geometry_container.h +++ b/src/3d/debug_geometry_container.h @@ -13,18 +13,12 @@ GODOT_WARNING_RESTORE() using namespace godot; class DebugDraw3DStats; +enum class MeshMaterialType : char; class DebugGeometryContainer { friend class DebugDraw3D; class DebugDraw3D *owner; - enum class UsingShaderType { - Wireframe, - Billboard, - Solid, - Expandable, - }; - struct MultiMeshStorage { RID instance; Ref mesh; @@ -53,13 +47,16 @@ class DebugGeometryContainer { Ref base_world_viewport; int32_t render_layers = 1; bool is_frame_rendered = false; + bool no_depth_test = false; - void CreateMMI(InstanceType p_type, UsingShaderType p_shader, const String &p_name, Ref p_mesh); + void CreateMMI(InstanceType p_type, const String &p_name, Ref p_mesh); public: - DebugGeometryContainer(class DebugDraw3D *p_root); + DebugGeometryContainer(class DebugDraw3D *p_root, bool p_no_depth_test); ~DebugGeometryContainer(); + bool is_no_depth_test() const; + void set_world(Ref p_new_world); Ref get_world(); diff --git a/src/3d/render_instances.cpp b/src/3d/render_instances.cpp index d1451c0a..0c92272e 100644 --- a/src/3d/render_instances.cpp +++ b/src/3d/render_instances.cpp @@ -465,9 +465,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr &p_cfg, InstanceType p_type, const real_t &p_exp_time, const ProcessType &p_proc, const Transform3D &p_transform, const Color &p_col, const SphereBounds &p_bounds, const Color *p_custom_col) { ZoneScoped; - auto &proc = pools[p_cfg->viewport][(int)p_proc]; + auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc]; DelayedRendererInstance *inst = proc.instances[(int)p_type].get(p_exp_time > 0); - viewport_ids[p_cfg->viewport] = p_cfg->viewport->get_instance_id(); + viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id(); SphereBounds thick_sphere = p_bounds; thick_sphere.radius += p_cfg->thickness * 0.5f; @@ -481,9 +481,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr &p_cfg, const real_t &p_exp_time, const ProcessType &p_proc, std::unique_ptr p_lines, const size_t p_line_count, const Color &p_col) { ZoneScoped; - auto &proc = pools[p_cfg->viewport][(int)p_proc]; + auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc]; DelayedRendererLine *inst = proc.lines.get(p_exp_time > 0); - viewport_ids[p_cfg->viewport] = p_cfg->viewport->get_instance_id(); + viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id(); inst->lines = std::move(p_lines); inst->lines_count = p_line_count; diff --git a/src/cpp.hint b/src/cpp.hint new file mode 100644 index 00000000..001508dd --- /dev/null +++ b/src/cpp.hint @@ -0,0 +1 @@ +#define GDCLASS(m_class, m_inherits) \ No newline at end of file diff --git a/src/dev_debug_draw_3d_Library.vcxproj b/src/dev_debug_draw_3d_Library.vcxproj index 91b0e638..9754feef 100644 --- a/src/dev_debug_draw_3d_Library.vcxproj +++ b/src/dev_debug_draw_3d_Library.vcxproj @@ -284,6 +284,11 @@ + + Document + false + + diff --git a/src/dev_debug_draw_3d_Library.vcxproj.filters b/src/dev_debug_draw_3d_Library.vcxproj.filters index 5f95a140..b860016e 100644 --- a/src/dev_debug_draw_3d_Library.vcxproj.filters +++ b/src/dev_debug_draw_3d_Library.vcxproj.filters @@ -154,6 +154,10 @@ + + 3d + + diff --git a/src/resources/billboard_unshaded.gdshader b/src/resources/billboard_unshaded.gdshader index d6b484a9..eb5677c4 100644 --- a/src/resources/billboard_unshaded.gdshader +++ b/src/resources/billboard_unshaded.gdshader @@ -1,5 +1,12 @@ +//#define NO_DEPTH + shader_type spatial; -render_mode cull_back, shadows_disabled, unshaded; +render_mode cull_back, shadows_disabled, unshaded +#if defined(NO_DEPTH) +,depth_test_disabled; +#else +; +#endif uniform sampler2D depth_value : hint_depth_texture; diff --git a/src/resources/extendable_meshes.gdshader b/src/resources/extendable_meshes.gdshader index 35bc882c..86b4e84d 100644 --- a/src/resources/extendable_meshes.gdshader +++ b/src/resources/extendable_meshes.gdshader @@ -1,5 +1,12 @@ +//#define NO_DEPTH + shader_type spatial; -render_mode cull_disabled, shadows_disabled, unshaded, world_vertex_coords; +render_mode cull_disabled, shadows_disabled, unshaded, world_vertex_coords +#if defined(NO_DEPTH) +,depth_test_disabled; +#else +; +#endif varying float brightness_of_center; diff --git a/src/resources/plane_unshaded.gdshader b/src/resources/plane_unshaded.gdshader index 5de09ebd..69d8e991 100644 --- a/src/resources/plane_unshaded.gdshader +++ b/src/resources/plane_unshaded.gdshader @@ -1,5 +1,12 @@ +//#define NO_DEPTH + shader_type spatial; -render_mode cull_disabled, shadows_disabled, unshaded; +render_mode cull_disabled, shadows_disabled, unshaded +#if defined(NO_DEPTH) +,depth_test_disabled; +#else +; +#endif varying vec4 custom; diff --git a/src/resources/wireframe_unshaded.gdshader b/src/resources/wireframe_unshaded.gdshader index a13a4bed..9ea3008c 100644 --- a/src/resources/wireframe_unshaded.gdshader +++ b/src/resources/wireframe_unshaded.gdshader @@ -1,5 +1,12 @@ +//#define NO_DEPTH + shader_type spatial; -render_mode cull_disabled, shadows_disabled, unshaded; +render_mode cull_disabled, shadows_disabled, unshaded +#if defined(NO_DEPTH) +,depth_test_disabled; +#else +; +#endif vec3 toLinearFast(vec3 col) { return vec3(col.rgb*col.rgb); diff --git a/src/version.h b/src/version.h index 80af5aea..fd6779ab 100644 --- a/src/version.h +++ b/src/version.h @@ -2,7 +2,7 @@ #define DD3D_MAJOR 1 #define DD3D_MINOR 4 -#define DD3D_PATCH 0 +#define DD3D_PATCH 1 #define DD3D_VERSION ((DD3D_MAJOR << (8 * 3)) + (DD3D_MINOR << (8 * 2)) + (DD3D_PATCH << (8 * 1))) #define _DD3D_VERSION_STR_TEXT(text) #text