Skip to content

Commit d599946

Browse files
committed
Merge pull request #107151 from retrotails/fix_inf
Revert some instances of `Math::INF` back to 1e20
2 parents b6f04cb + ae06a2d commit d599946

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

core/math/geometry_3d.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ Vector<Vector3> Geometry3D::compute_convex_mesh_points(const Plane *p_planes, in
862862
}
863863

864864
#define square(m_s) ((m_s) * (m_s))
865+
#define BIG_VAL 1e20
865866

866867
/* dt of 1d function using squared distance */
867868
static void edt(float *f, int stride, int n) {
@@ -871,8 +872,8 @@ static void edt(float *f, int stride, int n) {
871872

872873
int k = 0;
873874
v[0] = 0;
874-
z[0] = -Math::INF;
875-
z[1] = +Math::INF;
875+
z[0] = -BIG_VAL;
876+
z[1] = +BIG_VAL;
876877
for (int q = 1; q <= n - 1; q++) {
877878
float s = ((f[q * stride] + square(q)) - (f[v[k] * stride] + square(v[k]))) / (2 * q - 2 * v[k]);
878879
while (s <= z[k]) {
@@ -883,7 +884,7 @@ static void edt(float *f, int stride, int n) {
883884
v[k] = q;
884885

885886
z[k] = s;
886-
z[k + 1] = +Math::INF;
887+
z[k + 1] = +BIG_VAL;
887888
}
888889

889890
k = 0;
@@ -908,7 +909,7 @@ Vector<uint32_t> Geometry3D::generate_edf(const Vector<bool> &p_voxels, const Ve
908909

909910
float *work_memory = memnew_arr(float, float_count);
910911
for (uint32_t i = 0; i < float_count; i++) {
911-
work_memory[i] = Math::INF;
912+
work_memory[i] = BIG_VAL;
912913
}
913914

914915
uint32_t y_mult = p_size.x;
@@ -967,6 +968,8 @@ Vector<uint32_t> Geometry3D::generate_edf(const Vector<bool> &p_voxels, const Ve
967968
return ret;
968969
}
969970

971+
#undef BIG_VAL
972+
970973
Vector<int8_t> Geometry3D::generate_sdf8(const Vector<uint32_t> &p_positive, const Vector<uint32_t> &p_negative) {
971974
ERR_FAIL_COND_V(p_positive.size() != p_negative.size(), Vector<int8_t>());
972975
Vector<int8_t> sdf8;

scene/3d/voxelizer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ Vector<int> Voxelizer::get_voxel_gi_level_cell_count() const {
816816
// https://prideout.net/blog/distance_fields/
817817

818818
#define square(m_s) ((m_s) * (m_s))
819+
#define BIG_VAL 1e20
819820

820821
/* dt of 1d function using squared distance */
821822
static void edt(float *f, int stride, int n) {
@@ -825,8 +826,8 @@ static void edt(float *f, int stride, int n) {
825826

826827
int k = 0;
827828
v[0] = 0;
828-
z[0] = -Math::INF;
829-
z[1] = +Math::INF;
829+
z[0] = -BIG_VAL;
830+
z[1] = +BIG_VAL;
830831
for (int q = 1; q <= n - 1; q++) {
831832
float s = ((f[q * stride] + square(q)) - (f[v[k] * stride] + square(v[k]))) / (2 * q - 2 * v[k]);
832833
while (s <= z[k]) {
@@ -837,7 +838,7 @@ static void edt(float *f, int stride, int n) {
837838
v[k] = q;
838839

839840
z[k] = s;
840-
z[k + 1] = +Math::INF;
841+
z[k + 1] = +BIG_VAL;
841842
}
842843

843844
k = 0;
@@ -861,7 +862,7 @@ Voxelizer::BakeResult Voxelizer::get_sdf_3d_image(Vector<uint8_t> &r_image, Bake
861862
uint32_t float_count = octree_size.x * octree_size.y * octree_size.z;
862863
float *work_memory = memnew_arr(float, float_count);
863864
for (uint32_t i = 0; i < float_count; i++) {
864-
work_memory[i] = Math::INF;
865+
work_memory[i] = BIG_VAL;
865866
}
866867

867868
uint32_t y_mult = octree_size.x;
@@ -944,6 +945,8 @@ Voxelizer::BakeResult Voxelizer::get_sdf_3d_image(Vector<uint8_t> &r_image, Bake
944945
return BAKE_RESULT_OK;
945946
}
946947

948+
#undef BIG_VAL
949+
947950
void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx) {
948951
if (p_level == cell_subdiv - 1) {
949952
Vector3 center = p_aabb.get_center();

0 commit comments

Comments
 (0)