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:
authorMatt Heimlich <m9105826>2018-03-29 00:18:46 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-03-29 00:45:15 +0300
commite3f1d980982b1c0da7853a960cbd3e9a3f434376 (patch)
tree673b43b4aaa6c6fec513538b73e32324bfc26673 /intern/cycles/kernel/closure/bsdf.h
parent1953de335e887a13a53b4b704ea1ac702ad5eea8 (diff)
Cycles: take into account diffuse roughness for roughness baking.
Roughness baking previously defaulted to 1.0 for all diffuse materials, now we also bake roughness values of Oren-Nayer and Principled Diffuse. Differential Revision: https://developer.blender.org/D3115
Diffstat (limited to 'intern/cycles/kernel/closure/bsdf.h')
-rw-r--r--intern/cycles/kernel/closure/bsdf.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h
index e3beff6675a..d8ff69ca241 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -36,20 +36,42 @@ CCL_NAMESPACE_BEGIN
/* Returns the square of the roughness of the closure if it has roughness,
* 0 for singular closures and 1 otherwise. */
-ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
+ccl_device_inline float bsdf_get_specular_roughness_squared(const ShaderClosure *sc)
{
if(CLOSURE_IS_BSDF_SINGULAR(sc->type)) {
return 0.0f;
}
if(CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
- MicrofacetBsdf *bsdf = (MicrofacetBsdf*) sc;
+ MicrofacetBsdf *bsdf = (MicrofacetBsdf*)sc;
return bsdf->alpha_x*bsdf->alpha_y;
}
return 1.0f;
}
+ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
+{
+ /* This version includes diffuse, mainly for baking Principled BSDF
+ * where specular and metallic zero otherwise does not bake the
+ * specified roughness parameter. */
+ if(sc->type == CLOSURE_BSDF_OREN_NAYAR_ID) {
+ OrenNayarBsdf *bsdf = (OrenNayarBsdf*)sc;
+ return sqr(sqr(bsdf->roughness));
+ }
+
+ if(sc->type == CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID) {
+ PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf*)sc;
+ return sqr(sqr(bsdf->roughness));
+ }
+
+ if(CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
+ return 0.0f;
+ }
+
+ return bsdf_get_specular_roughness_squared(sc);
+}
+
ccl_device_forceinline int bsdf_sample(KernelGlobals *kg,
ShaderData *sd,
const ShaderClosure *sc,
@@ -176,7 +198,7 @@ ccl_device_forceinline int bsdf_sample(KernelGlobals *kg,
float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold;
if(threshold_squared >= 0.0f) {
- if(bsdf_get_roughness_squared(sc) <= threshold_squared) {
+ if(bsdf_get_specular_roughness_squared(sc) <= threshold_squared) {
label |= LABEL_TRANSMIT_TRANSPARENT;
}
}