Commit: 63d51d33050f80be08564b8432acf5994be6898e Author: Weizhen Huang Date: Mon Dec 19 20:22:37 2022 +0100 Branches: microfacet_hair https://developer.blender.org/rB63d51d33050f80be08564b8432acf5994be6898e
Cleanup: formatting float =================================================================== M intern/cycles/kernel/closure/bsdf_hair_microfacet.h =================================================================== diff --git a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h index 04d9837365e..05d9917dcd7 100644 --- a/intern/cycles/kernel/closure/bsdf_hair_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_hair_microfacet.h @@ -182,8 +182,8 @@ ccl_device float3 sphg_dir(float theta, float gamma, float a, float b) float cos_gamma = cosf(gamma); float tan_gamma = sin_gamma / cos_gamma; float tan_phi = b / a * tan_gamma; - float cos_phi = 1.f / sqrtf(sqr(tan_phi) + 1.f); - if (cos_gamma < 0.f) + float cos_phi = 1.0f / sqrtf(sqr(tan_phi) + 1.0f); + if (cos_gamma < 0.0f) cos_phi = -cos_phi; float sin_phi = cos_phi * tan_phi; return make_float3(sin_phi * cos_theta, sin_theta, cos_phi * cos_theta); @@ -217,7 +217,7 @@ ccl_device_inline float3 sample_wh(KernelGlobals kg, /* Check micronormal/mesonormal direct visiblity from v */ ccl_device_inline bool microfacet_visible(const float3 v, const float3 m, const float3 h) { - return (dot(v, h) > 0.f && dot(v, m) > 0.f); + return (dot(v, h) > 0.0f && dot(v, m) > 0.0f); } /* Check micronormal/mesonormal direct visiblity from wi and wo */ @@ -237,11 +237,11 @@ ccl_device_inline float smith_g1( /* Assume consistent orientation (can't see the back of the microfacet from the front and vice * versa) */ float cos_vm = dot(v, m); - if (dot(v, h) <= 0.f || cos_vm <= 0.f) - return 0.f; + if (dot(v, h) <= 0.0f || cos_vm <= 0.0f) + return 0.0f; return beckmann ? bsdf_beckmann_G1(roughness, cos_vm) : - 2.f / (1.f + sqrtf(1.0f + sqr(roughness) * (1.0f / sqr(cos_vm) - 1.0f))); + 2.0f / (1.0f + sqrtf(1.0f + sqr(roughness) * (1.0f / sqr(cos_vm) - 1.0f))); } /* Smith's separable shadowing-masking approximation */ @@ -265,14 +265,15 @@ ccl_device float D(const bool beckmann, const float roughness, const float3 m, c const float cos_theta2 = sqr(cos_theta); if (beckmann) { - result = expf((1.f - 1.f / cos_theta2) / roughness2) / (M_PI_F * roughness2 * sqr(cos_theta2)); + result = expf((1.0f - 1.0f / cos_theta2) / roughness2) / + (M_PI_F * roughness2 * sqr(cos_theta2)); } else { /* GGX */ - result = roughness2 / (M_PI_F * sqr(1.f + (roughness2 - 1.f) * cos_theta2)); + result = roughness2 / (M_PI_F * sqr(1.0f + (roughness2 - 1.0f) * cos_theta2)); } /* Prevent potential numerical issues in other stages of the model */ - return (result * cos_theta > 1e-20f) ? result : 0.f; + return (result * cos_theta > 1e-20f) ? result : 0.0f; } /* Compute fresnel reflection. Also return the dot product of the refracted ray and the normal as @@ -282,18 +283,18 @@ ccl_device float fresnel(float cos_theta_i, float eta, ccl_private float *cos_th kernel_assert(!isnan_safe(cos_theta_i)); /* Special cases. */ - if (eta == 1.f) { - return 0.f; + if (eta == 1.0f) { + return 0.0f; } - if (cos_theta_i == 0.f) { - return 1.f; + if (cos_theta_i == 0.0f) { + return 1.0f; } cos_theta_i = fabsf(cos_theta_i); /* Using Snell's law, calculate the squared cosine of the angle between the surface normal and * the transmitted ray. */ - float cos_theta_t_sqr = 1.f - (1.f - cos_theta_i * cos_theta_i) / (eta * eta); + float cos_theta_t_sqr = 1.0f - (1.0f - cos_theta_i * cos_theta_i) / (eta * eta); *cos_theta_t = safe_sqrtf(cos_theta_t_sqr); if (cos_theta_t_sqr <= 0) { @@ -305,7 +306,7 @@ ccl_device float fresnel(float cos_theta_i, float eta, ccl_private float *cos_th float a_s = (cos_theta_i - eta * (*cos_theta_t)) / (cos_theta_i + eta * (*cos_theta_t)); float a_p = (*cos_theta_t - eta * cos_theta_i) / (*cos_theta_t + eta * cos_theta_i); - float r = .5f * (sqr(a_s) + sqr(a_p)); + float r = 0.5f * (sqr(a_s) + sqr(a_p)); /* Adjust the sign of the transmitted direction to be relative to the surface normal. */ *cos_theta_t = -(*cos_theta_t); @@ -333,7 +334,7 @@ ccl_device float3 bsdf_microfacet_hair_eval_r_circular(ccl_private const ShaderC const bool analytical_ggx = (bsdf->model_type == NODE_MICROFACET_HAIR_CIRCULAR_GGX_ANALYTIC); float3 R = zero_float3(); - if (bsdf->extra->R <= 0.f) + if (bsdf->extra->R <= 0.0f) return R; const float3 wh = normalize(wi + wo); @@ -341,23 +342,23 @@ ccl_device float3 bsdf_microfacet_hair_eval_r_circular(ccl_private const ShaderC /* dot(wi, wmi) > 0 */ const float tan_tilt = tanf(tilt); - float phi_m_max1 = acosf(fmaxf(-tan_tilt * tan_theta(wi), 0.f)); + float phi_m_max1 = acosf(fmaxf(-tan_tilt * tan_theta(wi), 0.0f)); if (isnan_safe(phi_m_max1)) return R; const float phi_m_min1 = -phi_m_max1; /* dot(wo, wmi) > 0 */ - const float phi_m_max2 = acosf(fmaxf(-tan_tilt * tan_theta(wo), 0.f)) + phi_o; + const float phi_m_max2 = acosf(fmaxf(-tan_tilt * tan_theta(wo), 0.0f)) + phi_o; if (isnan_safe(phi_m_max2)) return R; - const float phi_m_min2 = -phi_m_max2 + 2.f * phi_o; + const float phi_m_min2 = -phi_m_max2 + 2.0f * phi_o; const float phi_m_min = fmaxf(phi_m_min1, phi_m_min2) + 1e-5f; const float phi_m_max = fminf(phi_m_max1, phi_m_max2) - 1e-5f; if (phi_m_min > phi_m_max) return R; - float integral = 0.f; + float integral = 0.0f; /* analytical for ggx (no masking term) */ if (analytical_ggx) { @@ -370,37 +371,39 @@ ccl_device float3 bsdf_microfacet_hair_eval_r_circular(ccl_private const ShaderC const float sm = sinf(tilt); const float cm = cosf(tilt); - const float C = sqrtf(1.f - roughness_squared); + const float C = sqrtf(1.0f - roughness_squared); const float A = cm * cos_theta(wh) * C; const float B = sm * sin_theta(wh) * C; const float A2 = sqr(A); const float B2 = sqr(B); - const float tmp1 = 1.f / sqrtf(sqr(B - 1.f) - A2); - const float tmp2 = 1.f / sqrtf(sqr(B + 1.f) - A2); + const float tmp1 = 1.0f / sqrtf(sqr(B - 1.0f) - A2); + const float tmp2 = 1.0f / sqrtf(sqr(B + 1.0f) - A2); const float smax = sinf(d_max); const float cmax = cosf(d_max); const float smin = sinf(d_min); const float cmin = cosf(d_min); - const float tmax = smax / (1.f + cmax); - const float tmin = smin / (1.f + cmin); + const float tmax = smax / (1.0f + cmax); + const float tmin = smin / (1.0f + cmin); - const float temp1 = 2.f * (A2 - B2 + 3.f * B - 2) * sqr(tmp1) * tmp1 * - (atanf((A - B + 1.f) * tmp1 * tmax) - atanf((A - B + 1.f) * tmp1 * tmin)); - const float temp2 = 2.f * (A2 - B2 - 3.f * B - 2) * sqr(tmp2) * tmp2 * - (atanf((B - A + 1.f) * tmp2 * tmax) - atanf((B - A + 1.f) * tmp2 * tmin)); + const float temp1 = 2.0f * (A2 - B2 + 3.0f * B - 2) * sqr(tmp1) * tmp1 * + (atanf((A - B + 1.0f) * tmp1 * tmax) - + atanf((A - B + 1.0f) * tmp1 * tmin)); + const float temp2 = 2.0f * (A2 - B2 - 3.0f * B - 2) * sqr(tmp2) * tmp2 * + (atanf((B - A + 1.0f) * tmp2 * tmax) - + atanf((B - A + 1.0f) * tmp2 * tmin)); const float temp3 = A * sqr(tmp1) * - (smax / (A * cmax + B - 1.f) - smin / (A * cmin + B - 1.f)); + (smax / (A * cmax + B - 1.0f) - smin / (A * cmin + B - 1.0f)); const float temp4 = A * sqr(tmp2) * - (smax / (A * cmax + B + 1.f) - smin / (A * cmin + B + 1.f)); + (smax / (A * cmax + B + 1.0f) - smin / (A * cmin + B + 1.0f)); integral = roughness_squared * M_1_PI_F * 0.5f * (temp1 + temp2 + temp3 + temp4); } else { /* falls back to numerical integration */ /* initial sample resolution */ - float res = roughness * .7f; - const float scale = (phi_m_max - phi_m_min) * .5f; + float res = roughness * 0.7f; + const float scale = (phi_m_max - phi_m_min) * 0.5f; size_t intervals = 2 * (size_t)ceilf(scale / res) + 1; /* modified resolution based on integral domain */ @@ -412,18 +415,18 @@ ccl_device float3 bsdf_microfacet_hair_eval_r_circular(ccl_private const ShaderC const float phi_m = phi_m_min + i * res; const float3 wm = sph_dir(tilt, phi_m); - if (microfacet_visible(wi, wo, make_float3(wm.x, 0.f, wm.z), wh)) { + if (microfacet_visible(wi, wo, make_float3(wm.x, 0.0f, wm.z), wh)) { const float weight = (i == 0 || i == intervals - 1) ? 0.5f : (i % 2 + 1); integral += weight * D(beckmann, roughness, wm, wh) * G(beckmann, roughness, wi, wo, wm, wh); } } - integral *= (2.f / 3.f * res); + integral *= (2.0f / 3.0f * res); } const float F = fresnel_dielectric_cos(dot(wi, wh), eta); - R = make_float3(bsdf->extra->R * 0.125f * F * fmaxf(0.f, integral)); + R = make_float3(bsdf->extra->R * 0.125f * F * fmaxf(0.0f, integral)); return R; } @@ -439,26 +442,26 @@ ccl_device float3 bsdf_microfacet_hair_eval_tt_trt_circular(KernelGlobals kg, const float eta = bsdf->eta; const bool beckmann = (bsdf->model_type == NODE_MICROFACET_HAIR_CIRCULAR_BECKMANN); - if (bsdf->extra->TT <= 0.f && bsdf->extra->TRT <= 0.f) + if (bsdf->extra->TT <= 0.0f && bsdf->extra->TRT <= 0.0f) return zero_float3(); /* dot(wi, wmi) > 0 */ const float tan_tilt = tanf(tilt); - const float phi_m_max = acosf(fmaxf(-tan_tilt * tan_theta(wi), 0.f)) - 1e-3f; + const float phi_m_max = acosf(fmaxf(-tan_tilt * tan_theta(wi), 0.0f)) - 1e-3f; if (isnan_safe(phi_m_max)) return zero_float3(); const float phi_m_min = -phi_m_max; /* dot(wo, wmo) < 0 */ - float tmp1 = acosf(fminf(tan_tilt * tan_theta(wo), 0.f)); + float tmp1 = acosf(fminf(tan_tilt * tan_theta(wo), 0.0f)); if (isnan_safe(tmp1)) return zero_float3(); const float3 mu_a = bsdf->sigma; - const float inv_eta = 1.f / eta; + const float inv_eta = 1.0f / eta; float res = roughness * .8f; - const float scale = (phi_m_max - phi_m_min) * .5f; + const float scale = (phi_m_max - phi_m_min) * 0.5f; size_t intervals = 2 * (size_t)ceilf(scale / res) + 1; res = (phi_m_max - phi_m_min) / intervals; @@ -480,39 +483,39 @@ ccl_device float3 bsdf_microfacet_hair_eval_tt_trt_circular(KernelGl @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs