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:
authorLukas Stockner <lukas.stockner@freenet.de>2019-09-08 16:26:45 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-09-08 16:32:08 +0300
commitc3be14e15196e0ddf2d8223b9322aa1094a19e29 (patch)
treed7cc2ed2c59c375c360370259ac5af2c608b1b6c /intern/cycles/kernel/closure/bsdf.h
parentad21a6c2246185f9fe42968434035dfaed0b434d (diff)
Cycles: add bump map shadow terminator softening term for diffuse BSDFs
This avoids artifacts for bump mapping and diffuse BSDFs, where the bump normal deviates far from the actual normal. Differential Revision: https://developer.blender.org/D5399
Diffstat (limited to 'intern/cycles/kernel/closure/bsdf.h')
-rw-r--r--intern/cycles/kernel/closure/bsdf.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h
index 5e26f90a878..c83e97d94c2 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -73,6 +73,28 @@ ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
return bsdf_get_specular_roughness_squared(sc);
}
+/* An additional term to smooth illumination on grazing angles when using bump mapping.
+ * Based on "Taming the Shadow Terminator" by Matt Jen-Yuan Chiang,
+ * Yining Karl Li and Brent Burley. */
+ccl_device_inline float bump_shadowing_term(float3 Ng, float3 N, float3 I)
+{
+ float g = safe_divide(dot(Ng, I), dot(N, I) * dot(Ng, N));
+
+ /* If the incoming light is on the unshadowed side, return full brightness. */
+ if (g >= 1.0f) {
+ return 1.0f;
+ }
+
+ /* If the incoming light points away from the surface, return black. */
+ if (g < 0.0f) {
+ return 0.0f;
+ }
+
+ /* Return smoothed value to avoid discontinuity at perpendicular angle. */
+ float g2 = sqr(g);
+ return -g2 * g + g2 + g;
+}
+
ccl_device_inline int bsdf_sample(KernelGlobals *kg,
ShaderData *sd,
const ShaderClosure *sc,
@@ -424,6 +446,11 @@ ccl_device_inline int bsdf_sample(KernelGlobals *kg,
}
}
}
+ else if (label & LABEL_DIFFUSE) {
+ if (sc->N != sd->N) {
+ *eval *= bump_shadowing_term((label & LABEL_TRANSMIT) ? -sd->N : sd->N, sc->N, *omega_in);
+ }
+ }
return label;
}
@@ -535,6 +562,9 @@ ccl_device_inline
eval = make_float3(0.0f, 0.0f, 0.0f);
break;
}
+ if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
+ eval *= bump_shadowing_term(sd->N, sc->N, omega_in);
+ }
}
else {
switch (sc->type) {
@@ -621,6 +651,9 @@ ccl_device_inline
eval = make_float3(0.0f, 0.0f, 0.0f);
break;
}
+ if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
+ eval *= bump_shadowing_term(-sd->N, sc->N, omega_in);
+ }
}
return eval;