[Bf-blender-cvs] [3dfc240] cycles_disney_brdf: Use reflection BSDF for glossy reflections when roughness is 0.0 to reduce computational expense and some code cleanup
Pascal Schoen
noreply at git.blender.org
Mon Nov 7 08:14:53 CET 2016
Commit: 3dfc240e61b3d4d0e7c476989792e4ada869ce91
Author: Pascal Schoen
Date: Mon Oct 31 11:31:36 2016 +0100
Branches: cycles_disney_brdf
https://developer.blender.org/rB3dfc240e61b3d4d0e7c476989792e4ada869ce91
Use reflection BSDF for glossy reflections when roughness is 0.0 to
reduce computational expense and some code cleanup
Code cleanup includes:
- Code style cleanup and removed unused code
- Consolidated code in the bsdf_microfacet_multi_impl.h to reduce
some computational expense
===================================================================
M intern/cycles/kernel/closure/bsdf_disney_diffuse.h
M intern/cycles/kernel/closure/bsdf_disney_sheen.h
M intern/cycles/kernel/closure/bsdf_microfacet.h
M intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
M intern/cycles/kernel/closure/bsdf_util.h
M intern/cycles/kernel/shaders/node_disney_bsdf.osl
M intern/cycles/kernel/svm/svm_closure.h
M source/blender/gpu/shaders/gpu_shader_material.glsl
===================================================================
diff --git a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
index 222dec4..4469646 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
@@ -46,11 +46,9 @@ ccl_device float3 calculate_disney_diffuse_brdf(const DisneyDiffuseBsdf *bsdf,
float FL = schlick_fresnel(NdotL), FV = schlick_fresnel(NdotV);
const float Fd90 = 0.5f + 2.0f * LdotH*LdotH * bsdf->roughness;
- float Fd = (1.0f * (1.0f - FL) + Fd90 * FL) * (1.0f * (1.0f - FV) + Fd90 * FV); //lerp(1.0f, Fd90, FL) * lerp(1.0f, Fd90, FV);
+ float Fd = (1.0f * (1.0f - FL) + Fd90 * FL) * (1.0f * (1.0f - FV) + Fd90 * FV);
- float value = M_1_PI_F * Fd;
-
- value *= NdotL;
+ float value = M_1_PI_F * NdotL * Fd;
return make_float3(value, value, value);
}
@@ -72,8 +70,7 @@ ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc, cons
float3 H = normalize(L + V);
if(dot(N, omega_in) > 0.0f) {
- float cos_pi = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
- *pdf = cos_pi;
+ *pdf = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
return calculate_disney_diffuse_brdf(bsdf, N, V, L, H, pdf);
}
else {
@@ -111,7 +108,7 @@ ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc,
#endif
}
else {
- *pdf = 0;
+ *pdf = 0.0f;
}
return LABEL_REFLECT|LABEL_DIFFUSE;
}
diff --git a/intern/cycles/kernel/closure/bsdf_disney_sheen.h b/intern/cycles/kernel/closure/bsdf_disney_sheen.h
index 1e274b9..65283a7 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_sheen.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_sheen.h
@@ -42,11 +42,7 @@ ccl_device float3 calculate_disney_sheen_brdf(const DisneySheenBsdf *bsdf,
float LdotH = dot(L, H);
- float FH = schlick_fresnel(LdotH);
-
- float value = FH;
-
- value *= NdotL;
+ float value = schlick_fresnel(LdotH) * NdotL;
return make_float3(value, value, value);
}
@@ -68,8 +64,7 @@ ccl_device float3 bsdf_disney_sheen_eval_reflect(const ShaderClosure *sc, const
float3 H = normalize(L + V);
if(dot(N, omega_in) > 0.0f) {
- float cos_pi = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
- *pdf = cos_pi;
+ *pdf = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
return calculate_disney_sheen_brdf(bsdf, N, V, L, H, pdf);
}
else {
@@ -107,7 +102,7 @@ ccl_device int bsdf_disney_sheen_sample(const ShaderClosure *sc,
#endif
}
else {
- *pdf = 0;
+ *pdf = 0.0f;
}
return LABEL_REFLECT|LABEL_DIFFUSE;
}
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 57e3dae..227150a 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -244,12 +244,10 @@ ccl_device_forceinline float3 microfacet_sample_stretched(
ccl_device_forceinline float3 reflection_color(const MicrofacetBsdf *bsdf, float3 L, float3 H) {
float3 F = make_float3(1.0f, 1.0f, 1.0f);
- if(bsdf->extra) {
- if(bsdf->extra->use_fresnel) {
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+ if(bsdf->extra && bsdf->extra->use_fresnel) {
+ float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- F = interpolate_fresnel_color(L, H, bsdf->ior, F0, bsdf->extra->cspec0);
- }
+ F = interpolate_fresnel_color(L, H, bsdf->ior, F0, bsdf->extra->cspec0);
}
return F;
@@ -528,7 +526,6 @@ ccl_device float3 bsdf_microfacet_ggx_eval_transmit(const ShaderClosure *sc, con
/* out = fabsf(cosHI * cosHO) * (m_eta * m_eta) * G * D / (cosNO * Ht2)
* pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2 */
float common = D * (m_eta * m_eta) / (cosNO * Ht2);
-
float out = G * fabsf(cosHI * cosHO) * common;
*pdf = G1o * fabsf(cosHO * cosHI) * common;
@@ -579,11 +576,9 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure
*eval = make_float3(1e6f, 1e6f, 1e6f);
/* if fresnel is used, calculate the color with reflection_color(...) */
- if(bsdf->extra) {
- if(bsdf->extra->use_fresnel) {
- *pdf = 1.0f;
- *eval = reflection_color(bsdf, *omega_in, m);
- }
+ if(bsdf->extra && bsdf->extra->use_fresnel) {
+ *pdf = 1.0f;
+ *eval = reflection_color(bsdf, *omega_in, m);
}
}
else {
@@ -603,14 +598,12 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure
float cosNI = dot(N, *omega_in);
/* eq. 34: now calculate G1(i,m) */
- if(bsdf->extra) {
- if(bsdf->extra->is_disney_clearcoat) {
- /* the alpha value for clearcoat is a fixed 0.25 => alpha2 = 0.25 * 0.25 */
- alpha2 = 0.0625f;
-
- /* recalculate G1o */
- G1o = 2 / (1 + safe_sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
- }
+ if(bsdf->extra && bsdf->extra->is_disney_clearcoat) {
+ /* the alpha value for clearcoat is a fixed 0.25 => alpha2 = 0.25 * 0.25 */
+ alpha2 = 0.0625f;
+
+ /* recalculate G1o */
+ G1o = 2 / (1 + safe_sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
}
G1i = 2 / (1 + safe_sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
@@ -708,7 +701,6 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure
/* see eval function for derivation */
float common = (G1o * D) * (m_eta * m_eta) / (cosNO * Ht2);
-
float out = G1i * fabsf(cosHI * cosHO) * common;
*pdf = cosHO * fabsf(cosHI) * common;
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h b/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
index efd0fae..ee70479 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
@@ -29,7 +29,7 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
float3 wi,
float3 wo,
const bool wo_outside,
- const float3 color,
+ const float3 color,
const float alpha_x,
const float alpha_y,
ccl_addr_space uint *lcg_state
@@ -38,7 +38,7 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
, bool use_fresnel
, const float3 cspec0
#elif defined(MF_MULTI_GLOSSY)
- , float3 *n, float3 *k
+ , float3 *n, float3 *k
, const float eta
, bool use_fresnel
, const float3 cspec0
@@ -76,6 +76,7 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
/* Analytically compute single scattering for lower noise. */
float3 eval;
+ float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
#ifdef MF_MULTI_GLASS
eval = mf_eval_phase_glass(-wi, lambda_r, wo, wo_outside, alpha, eta);
if(wo_outside)
@@ -83,14 +84,11 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
else
eval *= -lambda_r * beta(-lambda_r, shadowing_lambda+1.0f);
- float3 eval_fresnel;
- float3 t_color = cspec0;
- float3 throughput_fresnel = make_float3(1.0f, 1.0f, 1.0f);
float F0 = fresnel_dielectric_cos(1.0f, eta);
if(use_fresnel) {
- throughput_fresnel = interpolate_fresnel_color(wi, normalize(wi + wo), eta, F0, cspec0);
+ throughput = interpolate_fresnel_color(wi, normalize(wi + wo), eta, F0, cspec0);
- eval_fresnel = throughput_fresnel * eval;
+ eval *= throughput;
}
#elif defined(MF_MULTI_DIFFUSE)
/* Diffuse has no special closed form for the single scattering bounce */
@@ -110,14 +108,11 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
eval = make_float3(val, val, val);
}
- float3 eval_fresnel;
- float3 t_color = cspec0;
- float3 throughput_fresnel = make_float3(1.0f, 1.0f, 1.0f);
float F0 = fresnel_dielectric_cos(1.0f, eta);
if(use_fresnel) {
- throughput_fresnel = interpolate_fresnel_color(wi, normalize(wi + wo), eta, F0, cspec0);
+ throughput = interpolate_fresnel_color(wi, wh, eta, F0, cspec0);
- eval_fresnel = throughput_fresnel * val;
+ eval = throughput * val;
}
#endif
@@ -126,7 +121,6 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
float C1_r = 1.0f;
float G1_r = 0.0f;
bool outside = true;
- float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
for(int order = 0; order < 10; order++) {
/* Sample microfacet height and normal */
@@ -151,7 +145,7 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
else
phase = mf_eval_phase_glass(wr, lambda_r, -wo, !wo_outside, alpha, 1.0f / eta);
- eval_fresnel = throughput_fresnel * phase * mf_G1(wo_outside ? wo : -wo, mf_C1((outside == wo_outside) ? hr : -hr), shadowing_lambda);
+ eval = throughput * phase * mf_G1(wo_outside ? wo : -wo, mf_C1((outside == wo_outside) ? hr : -hr), shadowing_lambda);
}
#endif
if(order > 0) {
@@ -162,16 +156,10 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
phase = mf_eval_phase_glass(wr, lambda_r, wo, wo_outside, alpha, eta);
else
phase = mf_eval_phase_glass(wr, lambda_r, -wo, !wo_outside, alpha, 1.0f/eta);
-
- if(use_fresnel)
- eval_fresnel += throughput_fresnel * phase * mf_G1(wo_outside ? wo : -wo, mf_C1((outside == wo_outside) ? hr : -hr), shadowing_lambda);
#elif defined(MF_MULTI_DIFFUSE)
phase = mf_eval_phase_diffuse(wo, wm);
#else /* MF_MULTI_GLOSSY */
phase = mf_eval_phase_glossy(wr, lambda_r, wo, alpha, n, k) * throughput;
-
- if(use_fresnel)
- eval_fresnel += throughput_fresnel * phase * mf_G1(wo_outside ? wo : -wo, mf_C1((outside == wo_outside) ? hr : -hr), shadowing_lambda);
#endif
eval += throughput * phase * mf_G1(wo_outside? wo: -wo, mf_C1((outside == wo_outside)? hr: -hr), shadowing_lambda);
}
@@ -188,49 +176,36 @@ ccl_device_forceinline float3 MF_FUNCTION_FULL_NAME(mf_eval)(
}
if(use_fresnel && !next_outside) {
- throughput_fresnel *= color;
+ throughput *= color;
}
- else if(use_fresnel) {
- t_color = interpolate_fresnel_color(wi_prev
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list