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
This commit is contained in:
Matt Heimlich 2018-03-28 23:18:46 +02:00 committed by Brecht Van Lommel
parent 1953de335e
commit e3f1d98098
2 changed files with 26 additions and 4 deletions

@ -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;
}
}

@ -140,7 +140,7 @@ ccl_device_inline void kernel_update_denoising_features(KernelGlobals *kg,
/* All closures contribute to the normal feature, but only diffuse-like ones to the albedo. */
normal += sc->N * sc->sample_weight;
sum_weight += sc->sample_weight;
if(bsdf_get_roughness_squared(sc) > sqr(0.075f)) {
if(bsdf_get_specular_roughness_squared(sc) > sqr(0.075f)) {
albedo += sc->weight;
sum_nonspecular_weight += sc->sample_weight;
}