Skip to content

Commit

Permalink
WIP. Bad sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jul 26, 2024
1 parent 0cc3998 commit a1c3559
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/3d/config_scope_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -33,6 +36,15 @@ void DebugDraw3DScopeConfig::_manual_unregister() {
unregister_action = nullptr;
}

Ref<DebugDraw3DScopeConfig> DebugDraw3DScopeConfig::set_solid(bool _value) const {
data->solid = _value;
return Ref<DebugDraw3DScopeConfig>(this);
}

bool DebugDraw3DScopeConfig::is_solid() const {
return data->solid;
}

Ref<DebugDraw3DScopeConfig> DebugDraw3DScopeConfig::set_thickness(real_t _value) const {
data->thickness = Math::clamp(_value, (real_t)0, (real_t)100);
return Ref<DebugDraw3DScopeConfig>(this);
Expand Down Expand Up @@ -109,6 +121,7 @@ DebugDraw3DScopeConfig::~DebugDraw3DScopeConfig() {
}

DebugDraw3DScopeConfig::Data::Data() {
solid = false;
thickness = 0;
center_brightness = 0;
hd_sphere = false;
Expand All @@ -117,6 +130,7 @@ DebugDraw3DScopeConfig::Data::Data() {
}

DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr<Data> &p_parent) {
solid = p_parent->solid;
thickness = p_parent->thickness;
center_brightness = p_parent->center_brightness;
hd_sphere = p_parent->hd_sphere;
Expand Down
10 changes: 10 additions & 0 deletions src/3d/config_scope_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DebugDraw3DScopeConfig> 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.
*
Expand Down
7 changes: 7 additions & 0 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ std::array<Ref<ArrayMesh>, 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
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/3d/debug_geometry_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/3d/geometry_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ const std::array<int, 36> GeometryGenerator::CubeWithDiagonalsIndexes{
// 2, 5,
};

const std::array<int, 36> 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<Vector3, 2> GeometryGenerator::LineVertexes{
Vector3(0, 0, 0),
Vector3(0, 0, -1),
Expand Down
2 changes: 2 additions & 0 deletions src/3d/geometry_generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class GeometryGenerator {
const static std::array<int, 24> CubeIndexes;
const static std::array<int, 36> CubeWithDiagonalsIndexes;

const static std::array<int, 36> CubeSolidIndexes;

const static std::array<Vector3, 6> ArrowheadVertexes;
const static std::array<int, 18> ArrowheadIndexes;
const static std::array<int, 8> ArrowheadIndexesSimplified;
Expand Down
25 changes: 25 additions & 0 deletions src/3d/render_instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ void GeometryPool::add_or_update_line(const std::shared_ptr<DebugDraw3DScopeConf

GeometryType GeometryPool::_scoped_config_get_geometry_type(const std::shared_ptr<DebugDraw3DScopeConfig::Data> &p_cfg) {
// ZoneScoped;
if (p_cfg->solid) {
return GeometryType::Solid;
}
if (p_cfg->thickness != 0) {
return GeometryType::Volumetric;
}
Expand All @@ -518,6 +521,28 @@ Color GeometryPool::_scoped_config_to_custom(const std::shared_ptr<DebugDraw3DSc
InstanceType GeometryPool::_scoped_config_type_convert(ConvertableInstanceType p_type, const std::shared_ptr<DebugDraw3DScopeConfig::Data> &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:
Expand Down
7 changes: 7 additions & 0 deletions src/3d/render_instances_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
9 changes: 9 additions & 0 deletions src/resources/plane_unshaded.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a1c3559

Please sign in to comment.