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
path: root/intern
diff options
context:
space:
mode:
authorPascal Schoen <pascal_schoen@gmx.net>2016-09-08 13:24:43 +0300
committerPascal Schoen <pascal_schoen@gmx.net>2016-09-08 13:24:43 +0300
commit7cb37d711938e5626651db21f20da50edd96abaf (patch)
tree7588f5754a39c0b9052912eb50c1d494a2bb313c /intern
parentcdd29d06bb86672ed0779eefb8eee95796b8f939 (diff)
Added selection field to the Disney BSDF node for switching between
"Multiscatter GGX" and "GGX" In the "GGX" mode there is an additional parameter for changing the refraction roughness for materials with smooth surfaces and rough interns (e.g. honey). With the "Multiscatter GGX" this effect can't be produced at the moment and so here will be no separation of the two roughness values.
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/blender_shader.cpp12
-rw-r--r--intern/cycles/kernel/osl/osl_closures.cpp2
-rw-r--r--intern/cycles/kernel/shaders/node_disney_bsdf.osl11
-rw-r--r--intern/cycles/kernel/svm/svm_closure.h57
-rw-r--r--intern/cycles/kernel/svm/svm_types.h1
-rw-r--r--intern/cycles/render/graph.cpp3
-rw-r--r--intern/cycles/render/nodes.cpp101
-rw-r--r--intern/cycles/render/nodes.h19
8 files changed, 135 insertions, 71 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 171b8241280..fc13faef4d1 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -518,7 +518,17 @@ static ShaderNode *add_node(Scene *scene,
node = hair;
}
else if(b_node.is_a(&RNA_ShaderNodeBsdfDisney)) {
- node = new DisneyBsdfNode();
+ BL::ShaderNodeBsdfDisney b_disney_node(b_node);
+ DisneyBsdfNode *disney = new DisneyBsdfNode();
+ switch (b_disney_node.distribution()) {
+ case BL::ShaderNodeBsdfDisney::distribution_GGX:
+ disney->distribution = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID;
+ break;
+ case BL::ShaderNodeBsdfDisney::distribution_MULTI_GGX:
+ disney->distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
+ break;
+ }
+ node = disney;
}
else if(b_node.is_a(&RNA_ShaderNodeBsdfTranslucent)) {
node = new TranslucentBsdfNode();
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index 2e5e2898f13..9711f914ef2 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -830,7 +830,7 @@ public:
void setup(ShaderData *sd, int path_flag, float3 weight)
{
MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
- sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_setup(bsdf, false) : 0;
+ sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_setup(bsdf, true) : 0;
}
};
diff --git a/intern/cycles/kernel/shaders/node_disney_bsdf.osl b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
index 8296ce50283..ceadcb710d7 100644
--- a/intern/cycles/kernel/shaders/node_disney_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
@@ -18,6 +18,7 @@
#include "node_fresnel.h"
shader node_disney_bsdf(
+ string distribution = "Multiscatter GGX",
color BaseColor = color(0.64555527, 0.41514809, 0.01698805),
color SubsurfaceColor = color(0.64555527, 0.41514809, 0.01698805),
float Metallic = 0.0,
@@ -41,7 +42,7 @@ shader node_disney_bsdf(
float f = max(IOR, 1e-5);
float eta = backfacing() ? 1.0 / f : f;
float cosNO = dot(Normal, I);
- //float Fr = fresnel_dielectric_cos(cosNO, eta);
+ float Fr = fresnel_dielectric_cos(cosNO, eta);
float diffuse_weight = (1.0 - clamp(Metallic, 0.0, 1.0)) * (1.0 - clamp(Transparency, 0.0, 1.0));
float transp = clamp(Transparency, 0.0, 1.0) * (1.0 - clamp(Metallic, 0.0, 1.0));
float specular_weight = (1.0 - transp);
@@ -75,8 +76,12 @@ shader node_disney_bsdf(
if (transp > 1e-5) {
color Cspec0 = BaseColor * SpecularTint + color(1.0, 1.0, 1.0) * (1.0 - SpecularTint);
- //BSDF = BaseColor * microfacet_multi_ggx_glass(Normal, Roughness, eta, BaseColor);
- BSDF = BSDF + transp * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
+ if (distribution == "Multiscatter GGX") {
+ BSDF = BSDF + transp * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
+ } else {
+ BSDF = BSDF + transp * (Fr * microfacet_ggx_fresnel(Normal, Roughness, eta, BaseColor, Cspec0) +
+ (1.0 - Fr) * microfacet_ggx_refraction_fresnel(Normal, Roughness, eta, BaseColor, Cspec0));
+ }
}
if (Clearcoat > 1e-5) {
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index c2d13aaaf8d..dada2a0786f 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -78,14 +78,14 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
switch(type) {
case CLOSURE_BSDF_DISNEY_ID: {
uint specular_offset, roughness_offset, specularTint_offset, anisotropic_offset, sheen_offset,
- sheenTint_offset, clearcoat_offset, clearcoatGloss_offset, eta_offset, transparency_offset, anisotropic_rotation_offset;
- uint tmp0;
+ sheenTint_offset, clearcoat_offset, clearcoatGloss_offset, eta_offset, transparency_offset,
+ anisotropic_rotation_offset, refraction_roughness_offset;
uint4 data_node2 = read_node(kg, offset);
float3 T = stack_load_float3(stack, data_node.y);
decode_node_uchar4(data_node.z, &specular_offset, &roughness_offset, &specularTint_offset, &anisotropic_offset);
decode_node_uchar4(data_node.w, &sheen_offset, &sheenTint_offset, &clearcoat_offset, &clearcoatGloss_offset);
- decode_node_uchar4(data_node2.x, &eta_offset, &transparency_offset, &anisotropic_rotation_offset, &tmp0);
+ decode_node_uchar4(data_node2.x, &eta_offset, &transparency_offset, &anisotropic_rotation_offset, &refraction_roughness_offset);
// get disney parameters
float metallic = param1;
@@ -100,9 +100,11 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
float clearcoatGloss = stack_load_float(stack, clearcoatGloss_offset);
float transparency = stack_load_float(stack, transparency_offset);
float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
- float refraction_roughness = 0.0f; // TODO: add parameter for this!
+ float refraction_roughness = stack_load_float(stack, refraction_roughness_offset);
float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
+ ClosureType distribution = stack_valid(data_node2.y) ? (ClosureType) data_node2.y : CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
+
/* rotate tangent */
if (anisotropic_rotation != 0.0f)
T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F);
@@ -112,7 +114,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
// calculate fresnel for refraction
float cosNO = dot(N, ccl_fetch(sd, I));
- float fresnel = fresnel_dielectric_cos(cosNO, eta);
+ float fresnel = fresnel_dielectric_cos(cosNO, ior);
// calculate weights of the diffuse and specular part
float diffuse_weight = (1.0f - saturate(metallic)) * (1.0f - saturate(transparency)); // lerp(1.0f - clamp(metallic, 0.0f, 1.0f), 0.0f, lerp(clamp(transparency, 0.0f, 1.0f), 0.0f, clamp(metallic, 0.0f, 1.0f)));
@@ -214,9 +216,10 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
}
#endif
+ float sheen_diffuse_weight = diffuse_weight * 1.0f + (1.0f - diffuse_weight) * transp;
/* sheen */
- if (diffuse_weight > 0.0f && sheen != 0.0f) {
- float3 sheen_weight = weight * diffuse_weight;
+ if (sheen_diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
+ float3 sheen_weight = weight * sheen_diffuse_weight;
float sheen_sample_weight = fabsf(average(sheen_weight));
DisneySheenBsdf *bsdf = (DisneySheenBsdf*)bsdf_alloc(sd, sizeof(DisneySheenBsdf), weight);
@@ -236,7 +239,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
#ifdef __CAUSTICS_TRICKS__
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
#endif
- if (specular != 0.0f || metallic != 0.0f) {
+ if (specular > CLOSURE_WEIGHT_CUTOFF || metallic > CLOSURE_WEIGHT_CUTOFF) {
float3 spec_weight = weight * specular_weight/* * (specular * (1.0f - metallic) + metallic)*/;
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), spec_weight);
@@ -262,12 +265,10 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
bsdf->extra->color = baseColor;
/* setup bsdf */
-//#define __DISNEY_SPECULAR_MULTI_GGX__
-//#ifdef __DISNEY_SPECULAR_MULTI_GGX__
- ccl_fetch(sd, flag) |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf, true);
-//#else
-// ccl_fetch(sd, flag) |= bsdf_microfacet_ggx_aniso_setup(bsdf, true);
-//#endif
+ if (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
+ ccl_fetch(sd, flag) |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf, true);
+ else
+ ccl_fetch(sd, flag) |= bsdf_microfacet_ggx_aniso_setup(bsdf, true);
}
}
#ifdef __CAUSTICS_TRICKS__
@@ -278,12 +279,12 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
#ifdef __CAUSTICS_TRICKS__
if (kernel_data.integrator.caustics_reflective || kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0) {
#endif
- if (specular_weight < 1.0f) {
- float3 glass_weight = /*baseColor */ weight * (1.0f - specular_weight);
+ if (transp > CLOSURE_WEIGHT_CUTOFF) {
+ float3 glass_weight = /*baseColor */ weight * transp;
float3 cspec0 = baseColor * specularTint + make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specularTint);
bool frontfacing = (ccl_fetch(sd, flag) & SD_BACKFACING) == 0;
- if (refraction_roughness == 0.0f) {
+ if (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) {
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight);
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
@@ -304,14 +305,17 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
}
}
else {
+ /* reflection */
+#ifdef __CAUSTICS_TRICKS__
+ if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
+#endif
{
- MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight);
+ MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight*fresnel);
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
if (bsdf && extra) {
bsdf->N = N;
bsdf->extra = extra;
- bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
bsdf->alpha_x = roughness * roughness;
bsdf->alpha_y = roughness * roughness;
@@ -320,19 +324,21 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
bsdf->extra->color = baseColor;
bsdf->extra->cspec0 = cspec0;
- /* setup bsdf */
- ccl_fetch(sd, flag) |= bsdf_microfacet_multi_ggx_glass_setup(bsdf, true, frontfacing, false, true);
+ ccl_fetch(sd, flag) |= bsdf_microfacet_ggx_setup(bsdf, true);
}
}
+ /* refraction */
+#ifdef __CAUSTICS_TRICKS__
+ if (kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
+#endif
{
- MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight * (1.0f - fresnel));
+ MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight*(1.0f - fresnel));
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
if (bsdf && extra) {
bsdf->N = N;
bsdf->extra = extra;
- bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
refraction_roughness = 1.0f - (1.0f - roughness) * (1.0f - refraction_roughness);
@@ -343,8 +349,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
bsdf->extra->color = baseColor;
bsdf->extra->cspec0 = cspec0;
- /* setup bsdf */
- ccl_fetch(sd, flag) |= bsdf_microfacet_multi_ggx_glass_setup(bsdf, true, frontfacing, true);
+ ccl_fetch(sd, flag) |= bsdf_microfacet_ggx_refraction_setup(bsdf, true);
}
}
}
@@ -357,7 +362,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
#ifdef __CAUSTICS_TRICKS__
if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
#endif
- if (clearcoat > 0.0f) {
+ if (clearcoat > CLOSURE_WEIGHT_CUTOFF) {
float3 clearcoat_weight = 0.25f * clearcoat * weight;
float clearcoat_sample_weight = fabsf(average(clearcoat_weight));
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index d280ce32e95..bc405c18921 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -475,6 +475,7 @@ typedef enum ClosureType {
#define CLOSURE_IS_AMBIENT_OCCLUSION(type) (type == CLOSURE_AMBIENT_OCCLUSION_ID)
#define CLOSURE_IS_PHASE(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
#define CLOSURE_IS_GLASS(type) (type >= CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID && type <= CLOSURE_BSDF_SHARP_GLASS_ID)
+#define CLOSURE_IS_DISNEY(type) (type == CLOSURE_BSDF_DISNEY_ID)
#define CLOSURE_WEIGHT_CUTOFF 1e-5f
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 57256ceecd3..e93520b0a4d 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -964,6 +964,9 @@ int ShaderGraph::get_num_closures()
else if(CLOSURE_IS_BSDF_MULTISCATTER(closure_type)) {
num_closures += 2;
}
+ else if(CLOSURE_IS_DISNEY(closure_type)) {
+ num_closures += 8;
+ }
else {
++num_closures;
}
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 63fe5dcc010..1c182ddef98 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -2225,23 +2225,28 @@ NODE_DEFINE(DisneyBsdfNode)
{
NodeType* type = NodeType::add("disney_bsdf", create, NodeType::SHADER);
+ static NodeEnum distribution_enum;
+ distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
+ distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
+ SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
SOCKET_IN_COLOR(base_color, "BaseColor", make_float3(0.8f, 0.8f, 0.8f));
SOCKET_IN_COLOR(subsurface_color, "SubsurfaceColor", make_float3(0.8f, 0.8f, 0.8f));
SOCKET_IN_FLOAT(metallic, "Metallic", 0.0f);
SOCKET_IN_FLOAT(subsurface, "Subsurface", 0.0f);
SOCKET_IN_FLOAT(specular, "Specular", 0.0f);
SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f);
- SOCKET_IN_FLOAT(specularTint, "SpecularTint", 0.0f);
+ SOCKET_IN_FLOAT(specular_tint, "SpecularTint", 0.0f);
SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f);
SOCKET_IN_FLOAT(sheen, "Sheen", 0.0f);
- SOCKET_IN_FLOAT(sheenTint, "SheenTint", 0.0f);
+ SOCKET_IN_FLOAT(sheen_tint, "SheenTint", 0.0f);
SOCKET_IN_FLOAT(clearcoat, "Clearcoat", 0.0f);
- SOCKET_IN_FLOAT(clearcoatGloss, "ClearcoatGloss", 0.0f);
+ SOCKET_IN_FLOAT(clearcoat_gloss, "ClearcoatGloss", 0.0f);
SOCKET_IN_FLOAT(ior, "IOR", 0.0f);
SOCKET_IN_FLOAT(transparency, "Transparency", 0.0f);
- SOCKET_IN_FLOAT(anisotropicRotation, "AnisotropicRotation", 0.0f);
+ SOCKET_IN_FLOAT(refraction_roughness, "RefractionRoughness", 0.0f);
+ SOCKET_IN_FLOAT(anisotropic_rotation, "AnisotropicRotation", 0.0f);
SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
- SOCKET_IN_NORMAL(clearcoatNormal, "ClearcoatNormal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
+ SOCKET_IN_NORMAL(clearcoat_normal, "ClearcoatNormal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
SOCKET_IN_NORMAL(tangent, "Tangent", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TANGENT);
SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
@@ -2255,12 +2260,14 @@ DisneyBsdfNode::DisneyBsdfNode()
{
special_type = SHADER_SPECIAL_TYPE_CLOSURE;
closure = CLOSURE_BSDF_DISNEY_ID;
+ distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
+ distribution_orig = NBUILTIN_CLOSURES;
}
-void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, ShaderInput *subsurface,
- ShaderInput *specular, ShaderInput *roughness, ShaderInput *specularTint, ShaderInput *anisotropic,
- ShaderInput *sheen, ShaderInput *sheenTint, ShaderInput *clearcoat, ShaderInput *clearcoatGloss,
- ShaderInput *ior, ShaderInput *transparency, ShaderInput *anisotropicRotation)
+void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic, ShaderInput *p_subsurface,
+ ShaderInput *p_specular, ShaderInput *p_roughness, ShaderInput *p_specular_tint, ShaderInput *p_anisotropic,
+ ShaderInput *p_sheen, ShaderInput *p_sheen_tint, ShaderInput *p_clearcoat, ShaderInput *p_clearcoat_gloss,
+ ShaderInput *p_ior, ShaderInput *p_transparency, ShaderInput *p_anisotropic_rotation, ShaderInput *p_refraction_roughness)
{
ShaderInput *base_color_in = input("BaseColor");
ShaderInput *subsurface_color_in = input("SubsurfaceColor");
@@ -2270,41 +2277,38 @@ void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, Shade
float3 weight = make_float3(1.0f, 1.0f, 1.0f);
- /*if (base_color_in->link)
- compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(base_color_in));
- else
- compiler.add_node(NODE_CLOSURE_SET_WEIGHT, base_color_in->value);*/
compiler.add_node(NODE_CLOSURE_SET_WEIGHT, weight);
int normal_offset = compiler.stack_assign_if_linked(normal_in);
int clearcoat_normal_offset = compiler.stack_assign_if_linked(clearcoat_normal_in);
int tangent_offset = compiler.stack_assign_if_linked(tangent_in);
- int specular_offset = compiler.stack_assign(specular);
- int roughness_offset = compiler.stack_assign(roughness);
- int specularTint_offset = compiler.stack_assign(specularTint);
- int anisotropic_offset = compiler.stack_assign(anisotropic);
- int sheen_offset = compiler.stack_assign(sheen);
- int sheenTint_offset = compiler.stack_assign(sheenTint);
- int clearcoat_offset = compiler.stack_assign(clearcoat);
- int clearcoatGloss_offset = compiler.stack_assign(clearcoatGloss);
- int ior_offset = compiler.stack_assign(ior);
- int transparency_offset = compiler.stack_assign(transparency);
- int anisotropic_rotation_offset = compiler.stack_assign(anisotropicRotation);
+ int specular_offset = compiler.stack_assign(p_specular);
+ int roughness_offset = compiler.stack_assign(p_roughness);
+ int specular_tint_offset = compiler.stack_assign(p_specular_tint);
+ int anisotropic_offset = compiler.stack_assign(p_anisotropic);
+ int sheen_offset = compiler.stack_assign(p_sheen);
+ int sheen_tint_offset = compiler.stack_assign(p_sheen_tint);
+ int clearcoat_offset = compiler.stack_assign(p_clearcoat);
+ int clearcoat_gloss_offset = compiler.stack_assign(p_clearcoat_gloss);
+ int ior_offset = compiler.stack_assign(p_ior);
+ int transparency_offset = compiler.stack_assign(p_transparency);
+ int refraction_roughness_offset = compiler.stack_assign(p_refraction_roughness);
+ int anisotropic_rotation_offset = compiler.stack_assign(p_anisotropic_rotation);
compiler.add_node(NODE_CLOSURE_BSDF,
compiler.encode_uchar4(closure,
- compiler.stack_assign(metallic),
- compiler.stack_assign(subsurface),
+ compiler.stack_assign(p_metallic),
+ compiler.stack_assign(p_subsurface),
compiler.closure_mix_weight_offset()),
- __float_as_int((metallic) ? get_float(metallic->socket_type) : 0.0f),
- __float_as_int((subsurface) ? get_float(subsurface->socket_type) : 0.0f));
+ __float_as_int((p_metallic) ? get_float(p_metallic->socket_type) : 0.0f),
+ __float_as_int((p_subsurface) ? get_float(p_subsurface->socket_type) : 0.0f));
compiler.add_node(normal_offset, tangent_offset,
- compiler.encode_uchar4(specular_offset, roughness_offset, specularTint_offset, anisotropic_offset),
- compiler.encode_uchar4(sheen_offset, sheenTint_offset, clearcoat_offset, clearcoatGloss_offset));
+ compiler.encode_uchar4(specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset),
+ compiler.encode_uchar4(sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_gloss_offset));
- compiler.add_node(compiler.encode_uchar4(ior_offset, transparency_offset, anisotropic_rotation_offset, SVM_STACK_INVALID),
- SVM_STACK_INVALID, SVM_STACK_INVALID, SVM_STACK_INVALID);
+ compiler.add_node(compiler.encode_uchar4(ior_offset, transparency_offset, anisotropic_rotation_offset, refraction_roughness_offset),
+ distribution, SVM_STACK_INVALID, SVM_STACK_INVALID);
float3 bc_default = get_float3(base_color_in->socket_type);
@@ -2319,15 +2323,46 @@ void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, Shade
__float_as_int(ss_default.x), __float_as_int(ss_default.y), __float_as_int(ss_default.z));
}
+void DisneyBsdfNode::simplify_settings(Scene *scene)
+{
+#if 0
+ if (distribution_orig == NBUILTIN_CLOSURES) {
+ distribution_orig = distribution;
+ }
+ Integrator *integrator = scene->integrator;
+ if (integrator->filter_glossy == 0.0f) {
+ /* Fallback to Sharp closure for Roughness close to 0.
+ * Note: Keep the epsilon in sync with kernel!
+ */
+ ShaderInput *roughness_input = input("Roughness");
+ if (!roughness_input->link && roughness <= 1e-4f) {
+ distribution = CLOSURE_BSDF_SHARP_GLASS_ID;
+ }
+ }
+ else {
+ /* Rollback to original distribution when filter glossy is used. */
+ distribution = distribution_orig;
+ }
+#endif
+}
+
+bool DisneyBsdfNode::has_integrator_dependency()
+{
+ ShaderInput *roughness_input = input("Roughness");
+ return !roughness_input->link && roughness <= 1e-4f;
+}
+
void DisneyBsdfNode::compile(SVMCompiler& compiler)
{
compile(compiler, input("Metallic"), input("Subsurface"), input("Specular"), input("Roughness"),
input("SpecularTint"), input("Anisotropic"), input("Sheen"), input("SheenTint"),
- input("Clearcoat"), input("ClearcoatGloss"), input("IOR"), input("Transparency"), input("AnisotropicRotation"));
+ input("Clearcoat"), input("ClearcoatGloss"), input("IOR"), input("Transparency"),
+ input("AnisotropicRotation"), input("RefractionRoughness"));
}
void DisneyBsdfNode::compile(OSLCompiler& compiler)
{
+ compiler.parameter(this, "distribution");
compiler.add(this, "node_disney_bsdf");
}
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index dd733f73306..90319e8a741 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -370,23 +370,28 @@ public:
bool has_surface_bssrdf() { return true; }
bool has_bssrdf_bump();
void compile(SVMCompiler& compiler, ShaderInput *metallic, ShaderInput *subsurface,
- ShaderInput *specular, ShaderInput *roughness, ShaderInput *specularTint, ShaderInput *anisotropic,
- ShaderInput *sheen, ShaderInput *sheenTint, ShaderInput *clearcoat, ShaderInput *clearcoatGloss,
- ShaderInput *ior, ShaderInput *transparency, ShaderInput *anisotropicRotation);
+ ShaderInput *specular, ShaderInput *roughness, ShaderInput *specular_tint, ShaderInput *anisotropic,
+ ShaderInput *sheen, ShaderInput *sheen_tint, ShaderInput *clearcoat, ShaderInput *clearcoat_gloss,
+ ShaderInput *ior, ShaderInput *transparency, ShaderInput *anisotropic_rotation, ShaderInput *refraction_roughness);
float3 base_color;
float3 subsurface_color;
- float metallic, subsurface, specular, roughness, specularTint, anisotropic,
- sheen, sheenTint, clearcoat, clearcoatGloss, ior, transparency, anisotropicRotation;
- float3 normal, clearcoatNormal, tangent;
+ float metallic, subsurface, specular, roughness, specular_tint, anisotropic,
+ sheen, sheen_tint, clearcoat, clearcoat_gloss, ior, transparency,
+ anisotropic_rotation, refraction_roughness;
+ float3 normal, clearcoat_normal, tangent;
float surface_mix_weight;
- ClosureType closure;
+ ClosureType closure, distribution, distribution_orig;
virtual bool equals(const ShaderNode * /*other*/)
{
/* TODO(sergey): With some care BSDF nodes can be de-duplicated. */
return false;
}
+
+ ClosureType get_closure_type() { return closure; }
+ void simplify_settings(Scene *scene);
+ bool has_integrator_dependency();
};
class TranslucentBsdfNode : public BsdfNode {