Skip to content

Commit

Permalink
Slightly more correct safe_invert function
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Jun 29, 2024
1 parent 6e1d01f commit 75a637c
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion internal/CoreRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ force_inline float safe_div_neg(const float a, const float b) {

force_inline void safe_invert(const float v[3], float out_v[3]) {
for (int i = 0; i < 3; ++i) {
out_v[i] = (fabsf(v[i]) > FLT_EPS) ? (1.0f / v[i]) : copysignf(FLT_MAX, v[i]);
out_v[i] = 1.0f / ((fabsf(v[i]) > FLT_EPS) ? v[i] : copysignf(FLT_EPS, v[i]));
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/CoreSIMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1466,8 +1466,8 @@ void comp_aux_inv_values(const fvec<S> o[3], const fvec<S> d[3], fvec<S> inv_d[3

void comp_aux_inv_values(const float o[3], const float d[3], float inv_d[3], float inv_d_o[3]) {
for (int i = 0; i < 3; ++i) {
inv_d[i] = (fabsf(d[i]) > FLT_EPS) ? (1.0f / d[i]) : copysignf(FLT_MAX, d[i]);
inv_d_o[i] = (fabsf(d[i]) > FLT_EPS) ? (inv_d[i] * o[i]) : copysignf(FLT_MAX, d[i]);
inv_d[i] = 1.0f / ((fabsf(d[i]) > FLT_EPS) ? d[i] : copysignf(FLT_EPS, d[i]));
inv_d_o[i] = inv_d[i] * o[i];
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/shaders/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ float linstep(const float smin, const float smax, const float x) {
vec3 safe_invert(vec3 v) {
vec3 ret;
[[unroll]] for (int i = 0; i < 3; ++i) {
ret[i] = (abs(v[i]) > FLT_EPS) ? (1.0 / v[i]) : _copysign(FLT_MAX, v[i]);
ret[i] = 1.0 / ((abs(v[i]) > FLT_EPS) ? v[i] : _copysign(FLT_EPS, v[i]));
}
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene_indirect.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 75a637c

Please sign in to comment.