diff --git a/src/3d/config_scope_3d.cpp b/src/3d/config_scope_3d.cpp index 3be00ba..3db908a 100644 --- a/src/3d/config_scope_3d.cpp +++ b/src/3d/config_scope_3d.cpp @@ -6,6 +6,9 @@ void DebugDraw3DScopeConfig::_bind_methods() { #define REG_CLASS_NAME DebugDraw3DScopeConfig REG_METHOD(_manual_unregister); + REG_METHOD(set_solid, "value"); + REG_METHOD(is_solid); + REG_METHOD(set_thickness, "value"); REG_METHOD(get_thickness); @@ -33,6 +36,15 @@ void DebugDraw3DScopeConfig::_manual_unregister() { unregister_action = nullptr; } +Ref DebugDraw3DScopeConfig::set_solid(bool _value) const { + data->solid = _value; + return Ref(this); +} + +bool DebugDraw3DScopeConfig::is_solid() const { + return data->solid; +} + Ref DebugDraw3DScopeConfig::set_thickness(real_t _value) const { data->thickness = Math::clamp(_value, (real_t)0, (real_t)100); return Ref(this); @@ -109,6 +121,7 @@ DebugDraw3DScopeConfig::~DebugDraw3DScopeConfig() { } DebugDraw3DScopeConfig::Data::Data() { + solid = false; thickness = 0; center_brightness = 0; hd_sphere = false; @@ -117,6 +130,7 @@ DebugDraw3DScopeConfig::Data::Data() { } DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr &p_parent) { + solid = p_parent->solid; thickness = p_parent->thickness; center_brightness = p_parent->center_brightness; hd_sphere = p_parent->hd_sphere; diff --git a/src/3d/config_scope_3d.h b/src/3d/config_scope_3d.h index 7e80ed7..864026a 100644 --- a/src/3d/config_scope_3d.h +++ b/src/3d/config_scope_3d.h @@ -90,6 +90,7 @@ class DebugDraw3DScopeConfig : public RefCounted { /// @private struct Data { // Update the constructor if changes are made! + bool solid; real_t thickness; real_t center_brightness; bool hd_sphere; @@ -106,6 +107,15 @@ class DebugDraw3DScopeConfig : public RefCounted { // It can be used for example in C# void _manual_unregister(); + /** + * Set whether solid geometry or wireframe geometry will be used. + * + * TODO!! + * ![](docs/images/classes/LineThickness.webp) + */ + Ref set_solid(bool _value) const; + bool is_solid() const; + /** * Set the thickness of the volumetric lines. If the value is 0, the standard wireframe rendering will be used. * diff --git a/src/3d/debug_draw_3d.cpp b/src/3d/debug_draw_3d.cpp index 8d78267..e147058 100644 --- a/src/3d/debug_draw_3d.cpp +++ b/src/3d/debug_draw_3d.cpp @@ -361,6 +361,13 @@ std::array, 2> *DebugDraw3D::get_shared_meshes() { mat_type = MeshMaterialType::Plane; GEN_MESH(InstanceType::PLANE, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); + + GEN_MESH(InstanceType::CUBE_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CubeVertexes, GeometryGenerator::CubeSolidIndexes)); + GEN_MESH(InstanceType::CUBE_CENTERED_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); + GEN_MESH(InstanceType::SPHERE_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); + GEN_MESH(InstanceType::SPHERE_HD_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); + GEN_MESH(InstanceType::CYLINDER_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); + GEN_MESH(InstanceType::CYLINDER_AB_SOLID, GeometryGenerator::CreateMeshNative(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertexes, GeometryGenerator::SquareIndexes)); #undef GEN_MESH } } diff --git a/src/3d/debug_geometry_container.cpp b/src/3d/debug_geometry_container.cpp index 502cae1..b82aeff 100644 --- a/src/3d/debug_geometry_container.cpp +++ b/src/3d/debug_geometry_container.cpp @@ -74,6 +74,13 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root, bool p CreateMMI(InstanceType::BILLBOARD_SQUARE, meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]); CreateMMI(InstanceType::PLANE, meshes[(int)InstanceType::PLANE][mat_variant]); + CreateMMI(InstanceType::CUBE_SOLID, meshes[(int)InstanceType::CUBE_SOLID][mat_variant]); + CreateMMI(InstanceType::CUBE_CENTERED_SOLID, meshes[(int)InstanceType::CUBE_CENTERED_SOLID][mat_variant]); + CreateMMI(InstanceType::SPHERE_SOLID, meshes[(int)InstanceType::SPHERE_SOLID][mat_variant]); + CreateMMI(InstanceType::SPHERE_HD_SOLID, meshes[(int)InstanceType::SPHERE_HD_SOLID][mat_variant]); + CreateMMI(InstanceType::CYLINDER_SOLID, meshes[(int)InstanceType::CYLINDER_SOLID][mat_variant]); + CreateMMI(InstanceType::CYLINDER_AB_SOLID, meshes[(int)InstanceType::CYLINDER_AB_SOLID][mat_variant]); + set_render_layer_mask(1); } } diff --git a/src/3d/geometry_generators.cpp b/src/3d/geometry_generators.cpp index 26cad5d..64c369a 100644 --- a/src/3d/geometry_generators.cpp +++ b/src/3d/geometry_generators.cpp @@ -84,6 +84,26 @@ const std::array GeometryGenerator::CubeWithDiagonalsIndexes{ // 2, 5, }; +const std::array GeometryGenerator::CubeSolidIndexes{ + 0, 2, 1, + 0, 3, 2, + + 1, 6, 5, + 1, 2, 6, + + 2, 7, 6, + 2, 3, 7, + + 3, 4, 7, + 3, 0, 4, + + 5, 7, 4, + 5, 6, 7, + + 0, 5, 4, + 0, 1, 5 +}; + const std::array GeometryGenerator::LineVertexes{ Vector3(0, 0, 0), Vector3(0, 0, -1), diff --git a/src/3d/geometry_generators.h b/src/3d/geometry_generators.h index 2e06cb0..d858a43 100644 --- a/src/3d/geometry_generators.h +++ b/src/3d/geometry_generators.h @@ -32,6 +32,8 @@ class GeometryGenerator { const static std::array CubeIndexes; const static std::array CubeWithDiagonalsIndexes; + const static std::array CubeSolidIndexes; + const static std::array ArrowheadVertexes; const static std::array ArrowheadIndexes; const static std::array ArrowheadIndexesSimplified; diff --git a/src/3d/render_instances.cpp b/src/3d/render_instances.cpp index 5df2517..498ce4e 100644 --- a/src/3d/render_instances.cpp +++ b/src/3d/render_instances.cpp @@ -500,6 +500,9 @@ void GeometryPool::add_or_update_line(const std::shared_ptr &p_cfg) { // ZoneScoped; + if (p_cfg->solid) { + return GeometryType::Solid; + } if (p_cfg->thickness != 0) { return GeometryType::Volumetric; } @@ -518,6 +521,28 @@ Color GeometryPool::_scoped_config_to_custom(const std::shared_ptr &p_cfg) { // ZoneScoped; switch (_scoped_config_get_geometry_type(p_cfg)) { + case GeometryType::Solid: { + switch (p_type) { + case ConvertableInstanceType::CUBE: + return InstanceType::CUBE_SOLID; + case ConvertableInstanceType::CUBE_CENTERED: + return InstanceType::CUBE_CENTERED_SOLID; + case ConvertableInstanceType::SPHERE: + if (p_cfg->hd_sphere) { + return InstanceType::SPHERE_HD_SOLID; + } else { + return InstanceType::SPHERE_SOLID; + } + case ConvertableInstanceType::CYLINDER: + return InstanceType::CYLINDER_SOLID; + case ConvertableInstanceType::CYLINDER_AB: + return InstanceType::CYLINDER_AB_SOLID; + default: + return InstanceType::CUBE; + break; + } + break; + } case GeometryType::Wireframe: { switch (p_type) { case ConvertableInstanceType::CUBE: diff --git a/src/3d/render_instances_enums.h b/src/3d/render_instances_enums.h index 14042df..17f1187 100644 --- a/src/3d/render_instances_enums.h +++ b/src/3d/render_instances_enums.h @@ -42,6 +42,13 @@ enum class InstanceType : char { BILLBOARD_SQUARE, PLANE, + CUBE_SOLID, + CUBE_CENTERED_SOLID, + SPHERE_SOLID, + SPHERE_HD_SOLID, + CYLINDER_SOLID, + CYLINDER_AB_SOLID, + MAX, }; diff --git a/src/resources/plane_unshaded.gdshader b/src/resources/plane_unshaded.gdshader index 340be7b..93b5486 100644 --- a/src/resources/plane_unshaded.gdshader +++ b/src/resources/plane_unshaded.gdshader @@ -23,6 +23,15 @@ vec3 toLinearFast(vec3 col) { } void fragment() { + // // Use interleaved gradient noise, which is fast but still looks good. + // const vec3 magic = vec3(0.06711056f, 0.00583715f, 52.9829189f); + // float fade = COLOR.a; + // fade = 0.5; + // // Use a hard cap to prevent a few stray pixels from remaining when past the fade-out distance. + // if (fade < 0.001f || fade < fract(magic.z * fract(dot(FRAGCOORD.xy+vec2(MODEL_MATRIX[3].x, MODEL_MATRIX[3].y), magic.xy)))) { + // discard; + // } + if (FRONT_FACING){ ALBEDO = COLOR.xyz; #if !defined(FORCED_OPAQUE)