Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2020-03-06 19:18:10 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2020-03-09 16:47:59 +0300
commit598ab525da3df3fef2033c159c570688c7282a8f (patch)
treeba2bd0b8fc6ee5d264512bf655def1a6ee5d7b31 /source/blender/blenkernel/intern/studiolight.c
parentee5d7bc16b243f309c84bce5deddf3a86b7f4c14 (diff)
Cleanup: Replace ABS/SQUARE/CUBE with function calls
While it might be handy to have type-less functionality which is similar to how C++ math is implemented it can not be easily achieved with just preprocessor in a way which does not have side-effects on wrong usage. There macros where often used on a non-trivial expression, and there was at least one usage where it was causing an actual side effect/bug on Windows (see change around square_f(sh[index++]) in studiolight.c). For such cases it is handy to have a function which is guaranteed to have zero side-effects. The motivation behind actually removing the macros is that there is already a way to do similar calculation. Also, not having such macros is a way to guarantee that its usage is not changed in a way which have side-effects and that it's not used as an inspiration for cases where it should not be used. Differential Revision: https://developer.blender.org/D7051
Diffstat (limited to 'source/blender/blenkernel/intern/studiolight.c')
-rw-r--r--source/blender/blenkernel/intern/studiolight.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 4a69fcfa9d0..18d11e4d4c6 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -609,8 +609,8 @@ static void studiolight_calculate_radiance_cubemap_buffers(StudioLight *sl)
BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED);
ImBuf *ibuf = sl->equirect_radiance_buffer;
if (ibuf) {
- float *colbuf = MEM_mallocN(SQUARE(STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE) * sizeof(float[4]),
- __func__);
+ float *colbuf = MEM_malloc_arrayN(
+ square_i(STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE), sizeof(float[4]), __func__);
/* front */
studiolight_calculate_radiance_buffer(ibuf, colbuf, 0, 2, 1, 1, -1, 1);
@@ -772,11 +772,11 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
table_b[0] = 0.0f;
int index = 1;
for (int level = 1; level < STUDIOLIGHT_SH_BANDS; level++) {
- table_l[level] = (float)(SQUARE(level) * SQUARE(level + 1));
+ table_l[level] = (float)(square_i(level) * square_i(level + 1));
float b = 0.0f;
for (int m = -1; m <= level; m++) {
- b += SQUARE(sh[index++]);
+ b += square_f(sh[index++]);
}
table_b[level] = b;
}
@@ -797,9 +797,9 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
float fd = 0.0f;
for (int level = 1; level < STUDIOLIGHT_SH_BANDS; level++) {
- f += table_l[level] * table_b[level] / SQUARE(1.0f + lambda * table_l[level]);
- fd += (2.0f * SQUARE(table_l[level]) * table_b[level]) /
- CUBE(1.0f + lambda * table_l[level]);
+ f += table_l[level] * table_b[level] / square_f(1.0f + lambda * table_l[level]);
+ fd += (2.0f * square_f(table_l[level]) * table_b[level]) /
+ cube_f(1.0f + lambda * table_l[level]);
}
f = target_squared_laplacian - f;
@@ -807,7 +807,7 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
float delta = -f / fd;
lambda += delta;
- if (ABS(delta) < 1e-6f) {
+ if (fabsf(delta) < 1e-6f) {
break;
}
}
@@ -837,9 +837,11 @@ static void studiolight_spherical_harmonics_apply_windowing(float (*sh)[3], floa
int index = 0;
for (int level = 0; level < STUDIOLIGHT_SH_BANDS; level++) {
float s[3];
- s[0] = 1.0f / (1.0f + lambda_r * SQUARE(level) * SQUARE(level + 1.0f));
- s[1] = 1.0f / (1.0f + lambda_g * SQUARE(level) * SQUARE(level + 1.0f));
- s[2] = 1.0f / (1.0f + lambda_b * SQUARE(level) * SQUARE(level + 1.0f));
+ const int level_sq = square_i(level);
+ const int level_1_sq = square_i(level + 1.0f);
+ s[0] = 1.0f / (1.0f + lambda_r * level_sq * level_1_sq);
+ s[1] = 1.0f / (1.0f + lambda_g * level_sq * level_1_sq);
+ s[2] = 1.0f / (1.0f + lambda_b * level_sq * level_1_sq);
for (int m = -1; m <= level; m++) {
mul_v3_v3(sh[index++], s);
@@ -947,7 +949,8 @@ static void studiolight_spherical_harmonics_apply_band_factors(StudioLight *sl,
int index = 0, dst_idx = 0;
for (int band = 0; band < STUDIOLIGHT_SH_BANDS; band++) {
- for (int m = 0; m < SQUARE(band + 1) - SQUARE(band); m++) {
+ const int last_band = square_i(band + 1) - square_i(band);
+ for (int m = 0; m < last_band; m++) {
/* Skip L3 */
if (band != 3) {
mul_v3_v3fl(sl->spherical_harmonics_coefs[dst_idx++], sh[index], sl_sh_band_factors[band]);
@@ -1265,7 +1268,7 @@ static void sphere_normal_from_uv(float normal[3], float u, float v)
normal[0] = u * 2.0f - 1.0f;
normal[1] = v * 2.0f - 1.0f;
float dist = len_v2(normal);
- normal[2] = sqrtf(1.0f - SQUARE(dist));
+ normal[2] = sqrtf(1.0f - square_f(dist));
}
static void studiolight_radiance_preview(uint *icon_buffer, StudioLight *sl)