diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /intern/cycles/kernel/closure/bsdf_util.h | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
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
Diffstat (limited to 'intern/cycles/kernel/closure/bsdf_util.h')
-rw-r--r-- | intern/cycles/kernel/closure/bsdf_util.h | 183 |
1 files changed, 95 insertions, 88 deletions
diff --git a/intern/cycles/kernel/closure/bsdf_util.h b/intern/cycles/kernel/closure/bsdf_util.h index 4f3453675c7..a9a27edd7de 100644 --- a/intern/cycles/kernel/closure/bsdf_util.h +++ b/intern/cycles/kernel/closure/bsdf_util.h @@ -35,127 +35,134 @@ CCL_NAMESPACE_BEGIN -ccl_device float fresnel_dielectric( - float eta, const float3 N, - const float3 I, float3 *R, float3 *T, +ccl_device float fresnel_dielectric(float eta, + const float3 N, + const float3 I, + float3 *R, + float3 *T, #ifdef __RAY_DIFFERENTIALS__ - const float3 dIdx, const float3 dIdy, - float3 *dRdx, float3 *dRdy, - float3 *dTdx, float3 *dTdy, + const float3 dIdx, + const float3 dIdy, + float3 *dRdx, + float3 *dRdy, + float3 *dTdx, + float3 *dTdy, #endif - bool *is_inside) + bool *is_inside) { - float cos = dot(N, I), neta; - float3 Nn; + float cos = dot(N, I), neta; + float3 Nn; - // check which side of the surface we are on - if(cos > 0) { - // we are on the outside of the surface, going in - neta = 1 / eta; - Nn = N; - *is_inside = false; - } - else { - // we are inside the surface - cos = -cos; - neta = eta; - Nn = -N; - *is_inside = true; - } + // check which side of the surface we are on + if (cos > 0) { + // we are on the outside of the surface, going in + neta = 1 / eta; + Nn = N; + *is_inside = false; + } + else { + // we are inside the surface + cos = -cos; + neta = eta; + Nn = -N; + *is_inside = true; + } - // compute reflection - *R = (2 * cos)* Nn - I; + // compute reflection + *R = (2 * cos) * Nn - I; #ifdef __RAY_DIFFERENTIALS__ - *dRdx = (2 * dot(Nn, dIdx)) * Nn - dIdx; - *dRdy = (2 * dot(Nn, dIdy)) * Nn - dIdy; + *dRdx = (2 * dot(Nn, dIdx)) * Nn - dIdx; + *dRdy = (2 * dot(Nn, dIdy)) * Nn - dIdy; #endif - float arg = 1 -(neta * neta *(1 -(cos * cos))); - if(arg < 0) { - *T = make_float3(0.0f, 0.0f, 0.0f); + float arg = 1 - (neta * neta * (1 - (cos * cos))); + if (arg < 0) { + *T = make_float3(0.0f, 0.0f, 0.0f); #ifdef __RAY_DIFFERENTIALS__ - *dTdx = make_float3(0.0f, 0.0f, 0.0f); - *dTdy = make_float3(0.0f, 0.0f, 0.0f); + *dTdx = make_float3(0.0f, 0.0f, 0.0f); + *dTdy = make_float3(0.0f, 0.0f, 0.0f); #endif - return 1; // total internal reflection - } - else { - float dnp = max(sqrtf(arg), 1e-7f); - float nK = (neta * cos)- dnp; - *T = -(neta * I)+(nK * Nn); + return 1; // total internal reflection + } + else { + float dnp = max(sqrtf(arg), 1e-7f); + float nK = (neta * cos) - dnp; + *T = -(neta * I) + (nK * Nn); #ifdef __RAY_DIFFERENTIALS__ - *dTdx = -(neta * dIdx) + ((neta - neta * neta * cos / dnp) * dot(dIdx, Nn)) * Nn; - *dTdy = -(neta * dIdy) + ((neta - neta * neta * cos / dnp) * dot(dIdy, Nn)) * Nn; + *dTdx = -(neta * dIdx) + ((neta - neta * neta * cos / dnp) * dot(dIdx, Nn)) * Nn; + *dTdy = -(neta * dIdy) + ((neta - neta * neta * cos / dnp) * dot(dIdy, Nn)) * Nn; #endif - // compute Fresnel terms - float cosTheta1 = cos; // N.R - float cosTheta2 = -dot(Nn, *T); - float pPara = (cosTheta1 - eta * cosTheta2)/(cosTheta1 + eta * cosTheta2); - float pPerp = (eta * cosTheta1 - cosTheta2)/(eta * cosTheta1 + cosTheta2); - return 0.5f * (pPara * pPara + pPerp * pPerp); - } + // compute Fresnel terms + float cosTheta1 = cos; // N.R + float cosTheta2 = -dot(Nn, *T); + float pPara = (cosTheta1 - eta * cosTheta2) / (cosTheta1 + eta * cosTheta2); + float pPerp = (eta * cosTheta1 - cosTheta2) / (eta * cosTheta1 + cosTheta2); + return 0.5f * (pPara * pPara + pPerp * pPerp); + } } ccl_device float fresnel_dielectric_cos(float cosi, float eta) { - // compute fresnel reflectance without explicitly computing - // the refracted direction - float c = fabsf(cosi); - float g = eta * eta - 1 + c * c; - if(g > 0) { - g = sqrtf(g); - float A = (g - c)/(g + c); - float B = (c *(g + c)- 1)/(c *(g - c)+ 1); - return 0.5f * A * A *(1 + B * B); - } - return 1.0f; // TIR(no refracted component) + // compute fresnel reflectance without explicitly computing + // the refracted direction + float c = fabsf(cosi); + float g = eta * eta - 1 + c * c; + if (g > 0) { + g = sqrtf(g); + float A = (g - c) / (g + c); + float B = (c * (g + c) - 1) / (c * (g - c) + 1); + return 0.5f * A * A * (1 + B * B); + } + return 1.0f; // TIR(no refracted component) } ccl_device float3 fresnel_conductor(float cosi, const float3 eta, const float3 k) { - float3 cosi2 = make_float3(cosi*cosi, cosi*cosi, cosi*cosi); - float3 one = make_float3(1.0f, 1.0f, 1.0f); - float3 tmp_f = eta * eta + k * k; - float3 tmp = tmp_f * cosi2; - float3 Rparl2 = (tmp - (2.0f * eta * cosi) + one) / - (tmp + (2.0f * eta * cosi) + one); - float3 Rperp2 = (tmp_f - (2.0f * eta * cosi) + cosi2) / - (tmp_f + (2.0f * eta * cosi) + cosi2); - return(Rparl2 + Rperp2) * 0.5f; + float3 cosi2 = make_float3(cosi * cosi, cosi * cosi, cosi * cosi); + float3 one = make_float3(1.0f, 1.0f, 1.0f); + float3 tmp_f = eta * eta + k * k; + float3 tmp = tmp_f * cosi2; + float3 Rparl2 = (tmp - (2.0f * eta * cosi) + one) / (tmp + (2.0f * eta * cosi) + one); + float3 Rperp2 = (tmp_f - (2.0f * eta * cosi) + cosi2) / (tmp_f + (2.0f * eta * cosi) + cosi2); + return (Rparl2 + Rperp2) * 0.5f; } ccl_device float schlick_fresnel(float u) { - float m = clamp(1.0f - u, 0.0f, 1.0f); - float m2 = m * m; - return m2 * m2 * m; // pow(m, 5) + float m = clamp(1.0f - u, 0.0f, 1.0f); + float m2 = m * m; + return m2 * m2 * m; // pow(m, 5) } ccl_device float smooth_step(float edge0, float edge1, float x) { - float result; - if(x < edge0) result = 0.0f; - else if(x >= edge1) result = 1.0f; - else { - float t = (x - edge0)/(edge1 - edge0); - result = (3.0f-2.0f*t)*(t*t); - } - return result; + float result; + if (x < edge0) + result = 0.0f; + else if (x >= edge1) + result = 1.0f; + else { + float t = (x - edge0) / (edge1 - edge0); + result = (3.0f - 2.0f * t) * (t * t); + } + return result; } /* Calculate the fresnel color which is a blend between white and the F0 color (cspec0) */ -ccl_device_forceinline float3 interpolate_fresnel_color(float3 L, float3 H, float ior, float F0, float3 cspec0) { - /* Calculate the fresnel interpolation factor - * The value from fresnel_dielectric_cos(...) has to be normalized because - * the cspec0 keeps the F0 color - */ - float F0_norm = 1.0f / (1.0f - F0); - float FH = (fresnel_dielectric_cos(dot(L, H), ior) - F0) * F0_norm; +ccl_device_forceinline float3 +interpolate_fresnel_color(float3 L, float3 H, float ior, float F0, float3 cspec0) +{ + /* Calculate the fresnel interpolation factor + * The value from fresnel_dielectric_cos(...) has to be normalized because + * the cspec0 keeps the F0 color + */ + float F0_norm = 1.0f / (1.0f - F0); + float FH = (fresnel_dielectric_cos(dot(L, H), ior) - F0) * F0_norm; - /* Blend between white and a specular color with respect to the fresnel */ - return cspec0 * (1.0f - FH) + make_float3(1.0f, 1.0f, 1.0f) * FH; + /* Blend between white and a specular color with respect to the fresnel */ + return cspec0 * (1.0f - FH) + make_float3(1.0f, 1.0f, 1.0f) * FH; } CCL_NAMESPACE_END -#endif /* __BSDF_UTIL_H__ */ +#endif /* __BSDF_UTIL_H__ */ |