From e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2019 06:17:24 +0200 Subject: ClangFormat: apply to source, most of intern Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat --- intern/cycles/util/util_sky_model.cpp | 402 ++++++++++++++++------------------ 1 file changed, 191 insertions(+), 211 deletions(-) (limited to 'intern/cycles/util/util_sky_model.cpp') diff --git a/intern/cycles/util/util_sky_model.cpp b/intern/cycles/util/util_sky_model.cpp index 526bce4ff88..4a6a9f32607 100644 --- a/intern/cycles/util/util_sky_model.cpp +++ b/intern/cycles/util/util_sky_model.cpp @@ -111,23 +111,23 @@ CCL_NAMESPACE_BEGIN // replicated to make this a stand-alone module. #ifndef MATH_PI -#define MATH_PI 3.141592653589793 +# define MATH_PI 3.141592653589793 #endif #ifndef MATH_DEG_TO_RAD -#define MATH_DEG_TO_RAD ( MATH_PI / 180.0 ) +# define MATH_DEG_TO_RAD (MATH_PI / 180.0) #endif #ifndef DEGREES -#define DEGREES * MATH_DEG_TO_RAD +# define DEGREES *MATH_DEG_TO_RAD #endif #ifndef TERRESTRIAL_SOLAR_RADIUS -#define TERRESTRIAL_SOLAR_RADIUS ( ( 0.51 DEGREES ) / 2.0 ) +# define TERRESTRIAL_SOLAR_RADIUS ((0.51 DEGREES) / 2.0) #endif #ifndef ALLOC -#define ALLOC(_struct) ((_struct *)malloc(sizeof(_struct))) +# define ALLOC(_struct) ((_struct *)malloc(sizeof(_struct))) #endif // internal definitions @@ -137,233 +137,213 @@ typedef const double *ArHosekSkyModel_Radiance_Dataset; // internal functions -static void ArHosekSkyModel_CookConfiguration( - ArHosekSkyModel_Dataset dataset, - ArHosekSkyModelConfiguration config, - double turbidity, - double albedo, - double solar_elevation) +static void ArHosekSkyModel_CookConfiguration(ArHosekSkyModel_Dataset dataset, + ArHosekSkyModelConfiguration config, + double turbidity, + double albedo, + double solar_elevation) { - const double * elev_matrix; - - int int_turbidity = (int)turbidity; - double turbidity_rem = turbidity - (double)int_turbidity; - - solar_elevation = pow(solar_elevation / (MATH_PI / 2.0), (1.0 / 3.0)); - - // alb 0 low turb - - elev_matrix = dataset + ( 9 * 6 * (int_turbidity-1)); - - for(unsigned int i = 0; i < 9; ++i) { - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - config[i] = - (1.0-albedo) * (1.0 - turbidity_rem) - * ( pow(1.0-solar_elevation, 5.0) * elev_matrix[i] + - 5.0 * pow(1.0-solar_elevation, 4.0) * solar_elevation * elev_matrix[i+9] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[i+18] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[i+27] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[i+36] + - pow(solar_elevation, 5.0) * elev_matrix[i+45]); - } - - // alb 1 low turb - elev_matrix = dataset + (9*6*10 + 9*6*(int_turbidity-1)); - for(unsigned int i = 0; i < 9; ++i) { - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - config[i] += - (albedo) * (1.0 - turbidity_rem) - * ( pow(1.0-solar_elevation, 5.0) * elev_matrix[i] + - 5.0 * pow(1.0-solar_elevation, 4.0) * solar_elevation * elev_matrix[i+9] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[i+18] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[i+27] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[i+36] + - pow(solar_elevation, 5.0) * elev_matrix[i+45]); - } - - if(int_turbidity == 10) - return; - - // alb 0 high turb - elev_matrix = dataset + (9*6*(int_turbidity)); - for(unsigned int i = 0; i < 9; ++i) { - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - config[i] += - (1.0-albedo) * (turbidity_rem) - * ( pow(1.0-solar_elevation, 5.0) * elev_matrix[i] + - 5.0 * pow(1.0-solar_elevation, 4.0) * solar_elevation * elev_matrix[i+9] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[i+18] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[i+27] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[i+36] + - pow(solar_elevation, 5.0) * elev_matrix[i+45]); - } - - // alb 1 high turb - elev_matrix = dataset + (9*6*10 + 9*6*(int_turbidity)); - for(unsigned int i = 0; i < 9; ++i) { - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - config[i] += - (albedo) * (turbidity_rem) - * ( pow(1.0-solar_elevation, 5.0) * elev_matrix[i] + - 5.0 * pow(1.0-solar_elevation, 4.0) * solar_elevation * elev_matrix[i+9] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[i+18] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[i+27] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[i+36] + - pow(solar_elevation, 5.0) * elev_matrix[i+45]); - } + const double *elev_matrix; + + int int_turbidity = (int)turbidity; + double turbidity_rem = turbidity - (double)int_turbidity; + + solar_elevation = pow(solar_elevation / (MATH_PI / 2.0), (1.0 / 3.0)); + + // alb 0 low turb + + elev_matrix = dataset + (9 * 6 * (int_turbidity - 1)); + + for (unsigned int i = 0; i < 9; ++i) { + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + config[i] = + (1.0 - albedo) * (1.0 - turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[i] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[i + 9] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[i + 18] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[i + 27] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[i + 36] + + pow(solar_elevation, 5.0) * elev_matrix[i + 45]); + } + + // alb 1 low turb + elev_matrix = dataset + (9 * 6 * 10 + 9 * 6 * (int_turbidity - 1)); + for (unsigned int i = 0; i < 9; ++i) { + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + config[i] += + (albedo) * (1.0 - turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[i] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[i + 9] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[i + 18] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[i + 27] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[i + 36] + + pow(solar_elevation, 5.0) * elev_matrix[i + 45]); + } + + if (int_turbidity == 10) + return; + + // alb 0 high turb + elev_matrix = dataset + (9 * 6 * (int_turbidity)); + for (unsigned int i = 0; i < 9; ++i) { + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + config[i] += + (1.0 - albedo) * (turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[i] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[i + 9] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[i + 18] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[i + 27] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[i + 36] + + pow(solar_elevation, 5.0) * elev_matrix[i + 45]); + } + + // alb 1 high turb + elev_matrix = dataset + (9 * 6 * 10 + 9 * 6 * (int_turbidity)); + for (unsigned int i = 0; i < 9; ++i) { + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + config[i] += + (albedo) * (turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[i] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[i + 9] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[i + 18] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[i + 27] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[i + 36] + + pow(solar_elevation, 5.0) * elev_matrix[i + 45]); + } } -static double ArHosekSkyModel_CookRadianceConfiguration( - ArHosekSkyModel_Radiance_Dataset dataset, - double turbidity, - double albedo, - double solar_elevation) +static double ArHosekSkyModel_CookRadianceConfiguration(ArHosekSkyModel_Radiance_Dataset dataset, + double turbidity, + double albedo, + double solar_elevation) { - const double* elev_matrix; - - int int_turbidity = (int)turbidity; - double turbidity_rem = turbidity - (double)int_turbidity; - double res; - solar_elevation = pow(solar_elevation / (MATH_PI / 2.0), (1.0 / 3.0)); - - // alb 0 low turb - elev_matrix = dataset + (6*(int_turbidity-1)); - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - res = (1.0-albedo) * (1.0 - turbidity_rem) * - ( pow(1.0-solar_elevation, 5.0) * elev_matrix[0] + - 5.0*pow(1.0-solar_elevation, 4.0)*solar_elevation * elev_matrix[1] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[2] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[3] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[4] + - pow(solar_elevation, 5.0) * elev_matrix[5]); - - // alb 1 low turb - elev_matrix = dataset + (6*10 + 6*(int_turbidity-1)); - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - res += (albedo) * (1.0 - turbidity_rem) * - ( pow(1.0-solar_elevation, 5.0) * elev_matrix[0] + - 5.0*pow(1.0-solar_elevation, 4.0)*solar_elevation * elev_matrix[1] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[2] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[3] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[4] + - pow(solar_elevation, 5.0) * elev_matrix[5]); - if(int_turbidity == 10) - return res; - - // alb 0 high turb - elev_matrix = dataset + (6*(int_turbidity)); - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - res += (1.0-albedo) * (turbidity_rem) * - ( pow(1.0-solar_elevation, 5.0) * elev_matrix[0] + - 5.0*pow(1.0-solar_elevation, 4.0)*solar_elevation * elev_matrix[1] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[2] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[3] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[4] + - pow(solar_elevation, 5.0) * elev_matrix[5]); - - // alb 1 high turb - elev_matrix = dataset + (6*10 + 6*(int_turbidity)); - //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; - res += (albedo) * (turbidity_rem) * - ( pow(1.0-solar_elevation, 5.0) * elev_matrix[0] + - 5.0*pow(1.0-solar_elevation, 4.0)*solar_elevation * elev_matrix[1] + - 10.0*pow(1.0-solar_elevation, 3.0)*pow(solar_elevation, 2.0) * elev_matrix[2] + - 10.0*pow(1.0-solar_elevation, 2.0)*pow(solar_elevation, 3.0) * elev_matrix[3] + - 5.0*(1.0-solar_elevation)*pow(solar_elevation, 4.0) * elev_matrix[4] + - pow(solar_elevation, 5.0) * elev_matrix[5]); - return res; + const double *elev_matrix; + + int int_turbidity = (int)turbidity; + double turbidity_rem = turbidity - (double)int_turbidity; + double res; + solar_elevation = pow(solar_elevation / (MATH_PI / 2.0), (1.0 / 3.0)); + + // alb 0 low turb + elev_matrix = dataset + (6 * (int_turbidity - 1)); + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + res = (1.0 - albedo) * (1.0 - turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[0] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[1] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[2] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[3] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[4] + + pow(solar_elevation, 5.0) * elev_matrix[5]); + + // alb 1 low turb + elev_matrix = dataset + (6 * 10 + 6 * (int_turbidity - 1)); + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + res += (albedo) * (1.0 - turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[0] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[1] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[2] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[3] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[4] + + pow(solar_elevation, 5.0) * elev_matrix[5]); + if (int_turbidity == 10) + return res; + + // alb 0 high turb + elev_matrix = dataset + (6 * (int_turbidity)); + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + res += (1.0 - albedo) * (turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[0] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[1] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[2] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[3] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[4] + + pow(solar_elevation, 5.0) * elev_matrix[5]); + + // alb 1 high turb + elev_matrix = dataset + (6 * 10 + 6 * (int_turbidity)); + //(1-t).^3* A1 + 3*(1-t).^2.*t * A2 + 3*(1-t) .* t .^ 2 * A3 + t.^3 * A4; + res += (albedo) * (turbidity_rem) * + (pow(1.0 - solar_elevation, 5.0) * elev_matrix[0] + + 5.0 * pow(1.0 - solar_elevation, 4.0) * solar_elevation * elev_matrix[1] + + 10.0 * pow(1.0 - solar_elevation, 3.0) * pow(solar_elevation, 2.0) * elev_matrix[2] + + 10.0 * pow(1.0 - solar_elevation, 2.0) * pow(solar_elevation, 3.0) * elev_matrix[3] + + 5.0 * (1.0 - solar_elevation) * pow(solar_elevation, 4.0) * elev_matrix[4] + + pow(solar_elevation, 5.0) * elev_matrix[5]); + return res; } -static double ArHosekSkyModel_GetRadianceInternal( - ArHosekSkyModelConfiguration configuration, - double theta, - double gamma) +static double ArHosekSkyModel_GetRadianceInternal(ArHosekSkyModelConfiguration configuration, + double theta, + double gamma) { - const double expM = exp(configuration[4] * gamma); - const double rayM = cos(gamma)*cos(gamma); - const double mieM = (1.0 + cos(gamma)*cos(gamma)) / pow((1.0 + configuration[8]*configuration[8] - 2.0*configuration[8]*cos(gamma)), 1.5); - const double zenith = sqrt(cos(theta)); - - return (1.0 + configuration[0] * exp(configuration[1] / (cos(theta) + 0.01))) * - (configuration[2] + configuration[3] * expM + configuration[5] * rayM + configuration[6] * mieM + configuration[7] * zenith); + const double expM = exp(configuration[4] * gamma); + const double rayM = cos(gamma) * cos(gamma); + const double mieM = + (1.0 + cos(gamma) * cos(gamma)) / + pow((1.0 + configuration[8] * configuration[8] - 2.0 * configuration[8] * cos(gamma)), 1.5); + const double zenith = sqrt(cos(theta)); + + return (1.0 + configuration[0] * exp(configuration[1] / (cos(theta) + 0.01))) * + (configuration[2] + configuration[3] * expM + configuration[5] * rayM + + configuration[6] * mieM + configuration[7] * zenith); } -void arhosekskymodelstate_free(ArHosekSkyModelState * state) +void arhosekskymodelstate_free(ArHosekSkyModelState *state) { - free(state); + free(state); } -double arhosekskymodel_radiance(ArHosekSkyModelState *state, +double arhosekskymodel_radiance(ArHosekSkyModelState *state, double theta, double gamma, double wavelength) { - int low_wl = (int)((wavelength - 320.0) / 40.0); - - if(low_wl < 0 || low_wl >= 11) - return 0.0; - - double interp = fmod((wavelength - 320.0 ) / 40.0, 1.0); - - double val_low = - ArHosekSkyModel_GetRadianceInternal( - state->configs[low_wl], - theta, - gamma) - * state->radiances[low_wl] - * state->emission_correction_factor_sky[low_wl]; - - if(interp < 1e-6) - return val_low; - - double result = ( 1.0 - interp ) * val_low; - - if(low_wl+1 < 11) { - result += - interp - * ArHosekSkyModel_GetRadianceInternal( - state->configs[low_wl+1], - theta, - gamma) - * state->radiances[low_wl+1] - * state->emission_correction_factor_sky[low_wl+1]; - } - - return result; -} + int low_wl = (int)((wavelength - 320.0) / 40.0); + + if (low_wl < 0 || low_wl >= 11) + return 0.0; + + double interp = fmod((wavelength - 320.0) / 40.0, 1.0); + + double val_low = ArHosekSkyModel_GetRadianceInternal(state->configs[low_wl], theta, gamma) * + state->radiances[low_wl] * state->emission_correction_factor_sky[low_wl]; + + if (interp < 1e-6) + return val_low; + + double result = (1.0 - interp) * val_low; + if (low_wl + 1 < 11) { + result += interp * + ArHosekSkyModel_GetRadianceInternal(state->configs[low_wl + 1], theta, gamma) * + state->radiances[low_wl + 1] * state->emission_correction_factor_sky[low_wl + 1]; + } + + return result; +} // xyz and rgb versions -ArHosekSkyModelState * arhosek_xyz_skymodelstate_alloc_init( - const double turbidity, - const double albedo, - const double elevation) +ArHosekSkyModelState *arhosek_xyz_skymodelstate_alloc_init(const double turbidity, + const double albedo, + const double elevation) { - ArHosekSkyModelState * state = ALLOC(ArHosekSkyModelState); - - state->solar_radius = TERRESTRIAL_SOLAR_RADIUS; - state->turbidity = turbidity; - state->albedo = albedo; - state->elevation = elevation; - - for(unsigned int channel = 0; channel < 3; ++channel) { - ArHosekSkyModel_CookConfiguration( - datasetsXYZ[channel], - state->configs[channel], - turbidity, - albedo, - elevation); - - state->radiances[channel] = - ArHosekSkyModel_CookRadianceConfiguration( - datasetsXYZRad[channel], - turbidity, - albedo, - elevation); - } - - return state; + ArHosekSkyModelState *state = ALLOC(ArHosekSkyModelState); + + state->solar_radius = TERRESTRIAL_SOLAR_RADIUS; + state->turbidity = turbidity; + state->albedo = albedo; + state->elevation = elevation; + + for (unsigned int channel = 0; channel < 3; ++channel) { + ArHosekSkyModel_CookConfiguration( + datasetsXYZ[channel], state->configs[channel], turbidity, albedo, elevation); + + state->radiances[channel] = ArHosekSkyModel_CookRadianceConfiguration( + datasetsXYZRad[channel], turbidity, albedo, elevation); + } + + return state; } CCL_NAMESPACE_END -- cgit v1.2.3