Skip to content

Commit 0846f2e

Browse files
committed
Fix the infamous white edge of death
1 parent e6876d1 commit 0846f2e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

model/mesh/material_4d.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ Color Material4D::get_albedo_color_of_edge(const int64_t p_edge_index, const Ref
1010
}
1111
return Color(1, 1, 1, 1);
1212
}
13+
// If the above if statement was not hit, then we are using the albedo color array.
14+
// Check if we have already cached the per-edge albedo colors.
1315
if (p_edge_index < _edge_albedo_color_cache.size()) {
1416
return _edge_albedo_color_cache[p_edge_index];
1517
}
18+
// If not, we need to compute and cache them depending on the source flags.
1619
ERR_FAIL_COND_V_MSG(p_for_mesh.is_null(), _albedo_color, "Material4D: Mesh is null.");
1720
const PackedInt32Array edge_indices = p_for_mesh->get_edge_indices();
1821
const int64_t edge_count = edge_indices.size() / 2;
@@ -48,7 +51,8 @@ Color Material4D::get_albedo_color_of_edge(const int64_t p_edge_index, const Ref
4851
_edge_albedo_color_cache.resize(edge_count);
4952
_edge_albedo_color_cache.fill(Color(1, 1, 1, 1));
5053
}
51-
return _albedo_color;
54+
// Now that we have cached the per-edge albedo colors, return the requested one.
55+
return _edge_albedo_color_cache[p_edge_index];
5256
}
5357

5458
bool Material4D::is_default_material() const {

render/wireframe_canvas/wireframe_canvas_rendering_engine_4d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../../model/mesh/wire/wire_material_4d.h"
44
#include "wireframe_render_canvas_4d.h"
55

6-
Color _get_material_edge_color(const Ref<Material4D> &p_material, const Ref<Mesh4D> &p_mesh, int p_edge_index) {
6+
Color WireframeCanvasRenderingEngine4D::_get_material_edge_color(const Ref<Material4D> &p_material, const Ref<Mesh4D> &p_mesh, int p_edge_index) {
77
if (p_material.is_null()) {
88
return Color(1.0f, 1.0f, 1.0f);
99
}
@@ -46,7 +46,7 @@ void WireframeCanvasRenderingEngine4D::render_frame() {
4646
for (int mesh_index = 0; mesh_index < mesh_instances.size(); mesh_index++) {
4747
MeshInstance4D *mesh_inst = Object::cast_to<MeshInstance4D>(mesh_instances[mesh_index]);
4848
ERR_CONTINUE(mesh_inst == nullptr);
49-
Ref<Material4D> material = mesh_inst->get_active_material();
49+
const Ref<Material4D> material = mesh_inst->get_active_material();
5050
Projection mesh_relative_basis = mesh_relative_basises[mesh_index];
5151
Vector4 mesh_relative_position = mesh_relative_positions[mesh_index];
5252
const PackedVector4Array camera_relative_vertices = Transform4D(mesh_relative_basis, mesh_relative_position).xform_many(mesh_inst->get_mesh()->get_vertices());
@@ -141,7 +141,7 @@ void WireframeCanvasRenderingEngine4D::render_frame() {
141141
continue;
142142
}
143143
edge_colors_to_draw.push_back(edge_colors);
144-
Ref<WireMaterial4D> wire_material = material;
144+
const Ref<WireMaterial4D> wire_material = material;
145145
if (wire_material.is_valid()) {
146146
edge_thicknesses_to_draw.push_back(wire_material->get_line_thickness() > 0.0f ? wire_material->get_line_thickness() : -1.0f);
147147
} else {

render/wireframe_canvas/wireframe_canvas_rendering_engine_4d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class WireframeCanvasRenderingEngine4D : public RenderingEngine4D {
99
GDCLASS(WireframeCanvasRenderingEngine4D, RenderingEngine4D);
1010

11+
Color _get_material_edge_color(const Ref<Material4D> &p_material, const Ref<Mesh4D> &p_mesh, int p_edge_index);
12+
1113
protected:
1214
static void _bind_methods() {}
1315

0 commit comments

Comments
 (0)