[Bf-blender-cvs] [a6643ed39c5] principled-v2: Refactor SVM parameter encoding of Principled v1
Lukas Stockner
noreply at git.blender.org
Mon Jul 4 23:56:14 CEST 2022
Commit: a6643ed39c51b6fe065092f43cf7f6af1b6b321a
Author: Lukas Stockner
Date: Mon Jul 4 23:31:47 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBa6643ed39c51b6fe065092f43cf7f6af1b6b321a
Refactor SVM parameter encoding of Principled v1
===================================================================
M intern/cycles/kernel/svm/closure.h
M intern/cycles/kernel/svm/closure_principled.h
M intern/cycles/scene/shader_graph.cpp
M intern/cycles/scene/shader_nodes.cpp
M intern/cycles/scene/shader_nodes.h
===================================================================
diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h
index fe39f5d6d34..f5fdad4c8de 100644
--- a/intern/cycles/kernel/svm/closure.h
+++ b/intern/cycles/kernel/svm/closure.h
@@ -54,19 +54,6 @@ ccl_device void svm_node_glass_setup(ccl_private ShaderData *sd,
}
}
-ccl_device_inline int svm_node_closure_bsdf_skip(KernelGlobals kg, int offset, uint type)
-{
- if (type == CLOSURE_BSDF_PRINCIPLED_ID) {
- /* Read all principled BSDF extra data to get the right offset. */
- read_node(kg, &offset);
- read_node(kg, &offset);
- read_node(kg, &offset);
- read_node(kg, &offset);
- }
-
- return offset;
-}
-
template<uint node_feature_mask, ShaderType shader_type>
ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
ccl_private ShaderData *sd,
@@ -89,13 +76,21 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
IF_KERNEL_NODES_FEATURE(BSDF)
{
if ((shader_type != SHADER_TYPE_SURFACE) || mix_weight == 0.0f) {
- return svm_node_closure_bsdf_skip(kg, offset, type);
+ return offset;
}
}
else
{
- return svm_node_closure_bsdf_skip(kg, offset, type);
+ return offset;
+ }
+
+#ifdef __PRINCIPLED__
+ if (type == CLOSURE_BSDF_PRINCIPLED_ID) {
+ /* Principled BSDF uses different parameter packing. */
+ svm_node_closure_principled(kg, sd, stack, node, data_node, mix_weight, path_flag, &offset);
+ return offset;
}
+#endif /* __PRINCIPLED__ */
float3 N = stack_valid(data_node.x) ? stack_load_float3(stack, data_node.x) : sd->N;
if (!(sd->type & PRIMITIVE_CURVE)) {
@@ -108,13 +103,6 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
__uint_as_float(node.w);
switch (type) {
-#ifdef __PRINCIPLED__
- case CLOSURE_BSDF_PRINCIPLED_ID: {
- svm_node_closure_principled(
- kg, sd, stack, data_node, param1, param2, N, mix_weight, path_flag, &offset);
- break;
- }
-#endif /* __PRINCIPLED__ */
case CLOSURE_BSDF_DIFFUSE_ID: {
float3 weight = sd->svm_closure_weight * mix_weight;
ccl_private OrenNayarBsdf *bsdf = (ccl_private OrenNayarBsdf *)bsdf_alloc(
diff --git a/intern/cycles/kernel/svm/closure_principled.h b/intern/cycles/kernel/svm/closure_principled.h
index 426ddeb5294..1f0ebead9a1 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -5,25 +5,134 @@
CCL_NAMESPACE_BEGIN
+/* Principled v1 components */
+
+ccl_device_inline void principled_v1_diffuse(ccl_private ShaderData *sd,
+ float3 weight,
+ float3 base_color,
+ float diffuse_weight,
+ float3 N,
+ float roughness)
+{
+ if (diffuse_weight <= CLOSURE_WEIGHT_CUTOFF) {
+ return;
+ }
+
+ ccl_private PrincipledDiffuseBsdf *bsdf = (ccl_private PrincipledDiffuseBsdf *)bsdf_alloc(
+ sd, sizeof(PrincipledDiffuseBsdf), diffuse_weight * base_color * weight);
+
+ if (bsdf == NULL) {
+ return;
+ }
+
+ bsdf->N = N;
+ bsdf->roughness = roughness;
+
+ /* setup bsdf */
+ sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
+}
+
+ccl_device_inline void principled_v1_diffuse_sss(ccl_private ShaderData *sd,
+ ccl_private float *stack,
+ float3 weight,
+ int path_flag,
+ uint data_1,
+ uint data_2,
+ float3 base_color,
+ float diffuse_weight,
+ float3 N,
+ float roughness)
+{
+#ifdef __SUBSURFACE__
+ uint method, subsurface_offset, aniso_offset, radius_offset;
+ uint color_offset, ior_offset, dummy;
+ svm_unpack_node_uchar4(data_1, &method, &subsurface_offset, &aniso_offset, &radius_offset);
+ svm_unpack_node_uchar4(data_2, &color_offset, &ior_offset, &dummy, &dummy);
+
+ float subsurface = stack_load_float(stack, subsurface_offset);
+ float subsurface_anisotropy = stack_load_float(stack, aniso_offset);
+ float subsurface_ior = stack_load_float(stack, ior_offset);
+ float3 subsurface_color = stack_load_float3(stack, color_offset);
+ float3 subsurface_radius = stack_load_float3(stack, radius_offset);
+
+ float3 mixed_ss_base_color = lerp(base_color, subsurface_color, subsurface);
+
+ /* disable in case of diffuse ancestor, can't see it well then and
+ * adds considerably noise due to probabilities of continuing path
+ * getting lower and lower */
+ if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
+ subsurface = 0.0f;
+ }
+
+ /* diffuse */
+ if (fabsf(average(mixed_ss_base_color)) > CLOSURE_WEIGHT_CUTOFF) {
+ if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
+ float3 subsurf_weight = weight * mixed_ss_base_color * diffuse_weight;
+ ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, subsurf_weight);
+
+ if (bssrdf == NULL) {
+ return;
+ }
+
+ bssrdf->radius = subsurface_radius * subsurface;
+ bssrdf->albedo = mixed_ss_base_color;
+ bssrdf->N = N;
+ bssrdf->roughness = roughness;
+
+ /* Clamps protecting against bad/extreme and non physical values. */
+ subsurface_ior = clamp(subsurface_ior, 1.01f, 3.8f);
+ bssrdf->anisotropy = clamp(subsurface_anisotropy, 0.0f, 0.9f);
+
+ /* setup bsdf */
+ sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)method, subsurface_ior);
+ }
+ else {
+ principled_v1_diffuse(sd, weight, mixed_ss_base_color, diffuse_weight, N, roughness);
+ }
+ }
+#else
+ /* diffuse */
+ principled_v1_diffuse(sd, weight, base_color, diffuse_weight, N, roughness);
+#endif
+}
+
ccl_device_inline void principled_v1_specular(KernelGlobals kg,
ccl_private ShaderData *sd,
+ ccl_private float *stack,
float3 weight,
+ int path_flag,
ClosureType distribution,
+ uint data,
float3 base_color,
float3 N,
- float3 T,
float specular_weight,
- float specular,
float metallic,
float roughness,
- float anisotropic,
float specular_tint)
{
+#ifdef __CAUSTICS_TRICKS__
+ if (!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE)) {
+ return;
+ }
+#endif
+
+ uint specular_offset, aniso_offset, rotation_offset, tangent_offset;
+ svm_unpack_node_uchar4(data, &specular_offset, &aniso_offset, &rotation_offset, &tangent_offset);
+
+ float specular = stack_load_float(stack, specular_offset);
+
if ((specular_weight <= CLOSURE_WEIGHT_CUTOFF) ||
(specular + metallic <= CLOSURE_WEIGHT_CUTOFF)) {
return;
}
+ float anisotropic = stack_load_float(stack, aniso_offset);
+ float3 T = stack_valid(tangent_offset) ? stack_load_float3(stack, tangent_offset) :
+ zero_float3();
+ if (stack_valid(rotation_offset)) {
+ T = rotate_around_axis(T, N, stack_load_float(stack, rotation_offset) * M_2PI_F);
+ }
+
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
sd, sizeof(MicrofacetBsdf), specular_weight * weight);
if (bsdf == NULL) {
@@ -133,20 +242,26 @@ ccl_device_inline void principled_v1_glass_refr(ccl_private ShaderData *sd,
ccl_device_inline void principled_v1_glass_single(KernelGlobals kg,
ccl_private ShaderData *sd,
+ ccl_private float *stack,
float3 weight,
- ClosureType distribution,
int path_flag,
+ ClosureType distribution,
+ uint data,
float3 base_color,
float glass_weight,
float3 N,
float roughness,
- float transmission_roughness,
- float eta,
float specular_tint)
{
if (glass_weight <= CLOSURE_WEIGHT_CUTOFF) {
return;
}
+
+ uint transmission_roughness_offset, eta_offset, dummy;
+ svm_unpack_node_uchar4(data, &eta_offset, &dummy, &dummy, &transmission_roughness_offset);
+ float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
+ float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
+
/* calculate ior */
float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
@@ -179,19 +294,33 @@ ccl_device_inline void principled_v1_glass_single(KernelGlobals kg,
sd, weight, base_color, refraction_weight, N, transmission_roughness, ior);
}
-ccl_device_inline void principled_v1_glass_multi(ccl_private ShaderData *sd,
+ccl_device_inline void principled_v1_glass_multi(KernelGlobals kg,
+ ccl_private ShaderData *sd,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list