[Bf-blender-cvs] [329eeacc66d] master: Cleanup: Cycles: Remove isotropic microfacet closure setup functions

2023-02-05 Thread Lukas Stockner
Commit: 329eeacc66d13c9007e22f200304ebe902737abb
Author: Lukas Stockner
Date:   Mon Feb 6 02:01:17 2023 +0100
Branches: master
https://developer.blender.org/rB329eeacc66d13c9007e22f200304ebe902737abb

Cleanup: Cycles: Remove isotropic microfacet closure setup functions

Turns out these are 100% redundant, so get rid of them.

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/osl/closures_setup.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index f16c753d9e2..d7c3d3651fc 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -519,14 +519,6 @@ ccl_device int bsdf_microfacet_ggx_setup(ccl_private 
MicrofacetBsdf *bsdf)
   return SD_BSDF | SD_BSDF_HAS_EVAL;
 }
 
-/* Required to maintain OSL interface. */
-ccl_device int bsdf_microfacet_ggx_isotropic_setup(ccl_private MicrofacetBsdf 
*bsdf)
-{
-  bsdf->alpha_y = bsdf->alpha_x;
-
-  return bsdf_microfacet_ggx_setup(bsdf);
-}
-
 ccl_device int bsdf_microfacet_ggx_fresnel_setup(ccl_private MicrofacetBsdf 
*bsdf,
  ccl_private const ShaderData 
*sd)
 {
@@ -613,14 +605,6 @@ ccl_device int bsdf_microfacet_beckmann_setup(ccl_private 
MicrofacetBsdf *bsdf)
   return SD_BSDF | SD_BSDF_HAS_EVAL;
 }
 
-/* Required to maintain OSL interface. */
-ccl_device int bsdf_microfacet_beckmann_isotropic_setup(ccl_private 
MicrofacetBsdf *bsdf)
-{
-  bsdf->alpha_y = bsdf->alpha_x;
-
-  return bsdf_microfacet_beckmann_setup(bsdf);
-}
-
 ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private 
MicrofacetBsdf *bsdf)
 {
   bsdf->alpha_x = saturatef(bsdf->alpha_x);
diff --git a/intern/cycles/kernel/osl/closures_setup.h 
b/intern/cycles/kernel/osl/closures_setup.h
index aa44132da5e..5ea8f080410 100644
--- a/intern/cycles/kernel/osl/closures_setup.h
+++ b/intern/cycles/kernel/osl/closures_setup.h
@@ -209,14 +209,7 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals 
kg,
   if (closure->distribution == make_string("ggx", 11253504724482777663ull) ||
   closure->distribution == make_string("default", 4430693559278735917ull)) 
{
 if (!closure->refract) {
-  if (closure->alpha_x == closure->alpha_y) {
-/* Isotropic */
-sd->flag |= bsdf_microfacet_ggx_isotropic_setup(bsdf);
-  }
-  else {
-/* Anisotropic */
-sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
-  }
+  sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
 }
 else {
   sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
@@ -225,14 +218,7 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals 
kg,
   /* Beckmann */
   else {
 if (!closure->refract) {
-  if (closure->alpha_x == closure->alpha_y) {
-/* Isotropic */
-sd->flag |= bsdf_microfacet_beckmann_isotropic_setup(bsdf);
-  }
-  else {
-/* Anisotropic */
-sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
-  }
+  sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
 }
 else {
   sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
@@ -258,9 +244,9 @@ ccl_device void osl_closure_microfacet_ggx_setup(
   }
 
   bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
-  bsdf->alpha_x = closure->alpha_x;
+  bsdf->alpha_x = bsdf->alpha_y = closure->alpha_x;
 
-  sd->flag |= bsdf_microfacet_ggx_isotropic_setup(bsdf);
+  sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
 }
 
 ccl_device void osl_closure_microfacet_ggx_aniso_setup(
@@ -652,9 +638,9 @@ ccl_device void osl_closure_microfacet_beckmann_setup(
   }
 
   bsdf->N = ensure_valid_reflection(sd->Ng, sd->wi, closure->N);
-  bsdf->alpha_x = closure->alpha_x;
+  bsdf->alpha_x = bsdf->alpha_y = closure->alpha_x;
 
-  sd->flag |= bsdf_microfacet_beckmann_isotropic_setup(bsdf);
+  sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
 }
 
 ccl_device void osl_closure_microfacet_beckmann_aniso_setup(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] SVN commit: bf-blender [63202] trunk/lib/tests/render/render_layer/cycles_renders: Cycles Tests: Update glossy color render pass

2023-02-03 Thread Lukas Stockner
Revision: 63202
  https://developer.blender.org/rBL63202
Author:   lukasstockner97
Date: 2023-02-03 21:18:07 +0100 (Fri, 03 Feb 2023)
Log Message:
---
Cycles Tests: Update glossy color render pass

Modified Paths:
--

trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_color.png

trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_direct.png

trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_indirect.png

Modified: 
trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_color.png
===
(Binary files differ)

Modified: 
trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_direct.png
===
(Binary files differ)

Modified: 
trunk/lib/tests/render/render_layer/cycles_renders/render_passes_specular_indirect.png
===
(Binary files differ)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [73000c792d4] master: Cycles: Reorganize Fresnel handling in Microfacet closures

2023-02-03 Thread Lukas Stockner
Commit: 73000c792d40e61df5e118b25757e37e6c6017b9
Author: Lukas Stockner
Date:   Tue Jan 24 03:53:32 2023 +0100
Branches: master
https://developer.blender.org/rB73000c792d40e61df5e118b25757e37e6c6017b9

Cycles: Reorganize Fresnel handling in Microfacet closures

This is both a cleanup and a preparation for the Principled v2 changes.
Notable changes:
- Clearcoat weight is now folded into the closure weight, there's no reason
  to track this separately.
- There's a general-purpose helper for computing a Closure's albedo, which is
  currently used by the denoising albedo and diffuse/gloss/transmission color
  passes.
- The d/g/t color passes didn't account for closure albedo before, this means
  that e.g. metallic shaders with Principled v2 now have their color texture
  included in the glossy color pass. Also fixes T104041 (sheen albedo).
- Instead of precomputing and storing the albedo during shader setup, compute
  it when needed. This is technically redundant since we still need to compute
  it on shader setup to adjust the sample weight, but the operation is cheap
  enough that freeing up the storage seems worth it.
- Future changes (Principled v2) are easier to integrate since the Fresnel
  handling isn't all over the place anymore.
- Fresnel handling in the Multiscattering GGX code is still ugly, but since
  removing that entirely is the next step, putting effort into cleaning it up
  doesn't seem worth it.
- Apart from the d/g/t color passes, no changes to render results are expected.

Differential Revision: https://developer.blender.org/D17101

===

M   intern/cycles/kernel/closure/bsdf.h
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_multi.h
M   intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
M   intern/cycles/kernel/closure/bsdf_util.h
M   intern/cycles/kernel/film/denoising_passes.h
M   intern/cycles/kernel/integrator/surface_shader.h
M   intern/cycles/kernel/osl/closures_setup.h
M   intern/cycles/kernel/svm/closure.h
M   intern/cycles/kernel/svm/types.h

===

diff --git a/intern/cycles/kernel/closure/bsdf.h 
b/intern/cycles/kernel/closure/bsdf.h
index b0d01c427de..28829262ac9 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -661,4 +661,37 @@ ccl_device void bsdf_blur(KernelGlobals kg, ccl_private 
ShaderClosure *sc, float
 #endif
 }
 
+ccl_device_inline Spectrum bsdf_albedo(ccl_private const ShaderData *sd, 
ccl_private const ShaderClosure *sc)
+{
+  Spectrum albedo = sc->weight;
+  /* Some closures include additional components such as Fresnel terms that 
cause their albedo to
+   * be below 1. The point of this function is to return a best-effort 
estimation of their albedo,
+   * meaning the amount of reflected/refracted light that would be expected 
when illuminated by a
+   * uniform white background.
+   * This is used for the denoising albedo pass and 
diffuse/glossy/transmission color passes.
+   * NOTE: This should always match the sample_weight of the closure - as in, 
if there's an albedo
+   * adjustment in here, the sample_weight should also be reduced accordingly.
+   * TODO(lukas): Consider calling this function to determine the 
sample_weight? Would be a bit of
+   * extra overhead though. */
+#if defined(__SVM__) || defined(__OSL__)
+  switch (sc->type) {
+case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
+case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
+case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
+case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
+  albedo *= microfacet_fresnel((ccl_private const MicrofacetBsdf *)sc, 
sd->wi, sc->N);
+  break;
+case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
+  albedo *= ((ccl_private const PrincipledSheenBsdf *)sc)->avg_value;
+  break;
+case CLOSURE_BSDF_HAIR_PRINCIPLED_ID:
+  albedo *= bsdf_principled_hair_albedo(sc);
+  break;
+default:
+  break;
+  }
+#endif
+  return albedo;
+}
+
 CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index be21bcd720e..f16c753d9e2 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -23,8 +23,6 @@ enum MicrofacetType {
 
 typedef struct MicrofacetExtra {
   Spectrum color, cspec0;
-  Spectrum fresnel_color;
-  float clearcoat;
 } MicrofacetExtra;
 
 typedef struct MicrofacetBsdf {
@@ -184,26 +182,25 @@ ccl_device_forceinline float3 
microfacet_ggx_sample_vndf(const float3 wi,
  *
  * Else it is simply white
  */
-ccl_device_forceinline Spectrum reflection_color(ccl_private const 
MicrofacetBsdf *bsdf,
- float3 L,
- float3 H)
+ccl_dev

[Bf-blender-cvs] [0220bdc2d54] master: Cycles: Tests: Add option to increase SPP for manual comparisons

2023-02-03 Thread Lukas Stockner
Commit: 0220bdc2d542be046fe358ef6129ecf1fd517dff
Author: Lukas Stockner
Date:   Tue Jan 24 17:02:25 2023 +0100
Branches: master
https://developer.blender.org/rB0220bdc2d542be046fe358ef6129ecf1fd517dff

Cycles: Tests: Add option to increase SPP for manual comparisons

Useful for validating changes when sampling/noise changes:
- First run with BLENDER_TEST_UPDATE=1 and e.g. CYCLESTEST_SPP_MULTIPLIER=32
- Apply your change
- Run with only CYCLESTEST_SPP_MULTIPLIER=32
- Compare
- Reset the SVN repo

Differential Revision: https://developer.blender.org/D17107

===

M   tests/python/cycles_render_tests.py

===

diff --git a/tests/python/cycles_render_tests.py 
b/tests/python/cycles_render_tests.py
index c7e12dd5b7c..1d30a696e98 100644
--- a/tests/python/cycles_render_tests.py
+++ b/tests/python/cycles_render_tests.py
@@ -85,6 +85,10 @@ def get_arguments(filepath, output_filepath):
 if custom_args:
 args.extend(shlex.split(custom_args))
 
+spp_multiplier = os.getenv('CYCLESTEST_SPP_MULTIPLIER')
+if spp_multiplier:
+args.extend(["--python-expr", f"import bpy; 
bpy.context.scene.cycles.samples *= {spp_multiplier}"])
+
 if subject == 'bake':
 args.extend(['--python', os.path.join(basedir, "util", 
"render_bake.py")])
 elif subject == 'denoise_animation':

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ce25e3e5814] master: Cycles: Cleanup: Add general-purpose conversion between sin and cos

2023-01-24 Thread Lukas Stockner
Commit: ce25e3e58145b703f5aeacc9f906b7ac2ca3c9c8
Author: Lukas Stockner
Date:   Tue Jan 24 17:33:10 2023 +0100
Branches: master
https://developer.blender.org/rBce25e3e58145b703f5aeacc9f906b7ac2ca3c9c8

Cycles: Cleanup: Add general-purpose conversion between sin and cos

===

M   intern/cycles/kernel/closure/bsdf_hair_principled.h
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_multi.h
M   intern/cycles/kernel/closure/volume.h
M   intern/cycles/kernel/geom/curve_intersect.h
M   intern/cycles/kernel/integrator/mnee.h
M   intern/cycles/kernel/integrator/subsurface_random_walk.h
M   intern/cycles/kernel/light/area.h
M   intern/cycles/kernel/light/tree.h
M   intern/cycles/kernel/light/triangle.h
M   intern/cycles/kernel/sample/mapping.h
M   intern/cycles/util/math.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_hair_principled.h 
b/intern/cycles/kernel/closure/bsdf_hair_principled.h
index a9e8abe0475..f7cf3b716f6 100644
--- a/intern/cycles/kernel/closure/bsdf_hair_principled.h
+++ b/intern/cycles/kernel/closure/bsdf_hair_principled.h
@@ -41,11 +41,6 @@ static_assert(sizeof(ShaderClosure) >= 
sizeof(PrincipledHairBSDF),
 static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledHairExtra),
   "PrincipledHairExtra is too large!");
 
-ccl_device_inline float cos_from_sin(const float s)
-{
-  return safe_sqrtf(1.0f - s * s);
-}
-
 /* Gives the change in direction in the normal plane for the given angles and 
p-th-order
  * scattering. */
 ccl_device_inline float delta_phi(int p, float gamma_o, float gamma_t)
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 80c47bc9542..db53a29cfc3 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -200,7 +200,7 @@ ccl_device_forceinline float3 
microfacet_sample_stretched(KernelGlobals kg,
 
   if (wi_.z < 0.9f) {
 costheta_ = wi_.z;
-sintheta_ = safe_sqrtf(1.0f - costheta_ * costheta_);
+sintheta_ = sin_from_cos(costheta_);
 
 float invlen = 1.0f / sintheta_;
 cosphi_ = wi_.x * invlen;
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_multi.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
index 51fcd3340c6..defc46a389f 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
@@ -43,7 +43,7 @@ ccl_device_forceinline float2 mf_sampleP22_11(const float 
cosI,
 return make_float2(r * cosf(phi), r * sinf(phi));
   }
 
-  const float sinI = safe_sqrtf(1.0f - cosI * cosI);
+  const float sinI = sin_from_cos(cosI);
   const float tanI = sinI / cosI;
   const float projA = 0.5f * (cosI + 1.0f);
   if (projA < 0.0001f)
diff --git a/intern/cycles/kernel/closure/volume.h 
b/intern/cycles/kernel/closure/volume.h
index e6af2c01fcc..a9a28c2fa4a 100644
--- a/intern/cycles/kernel/closure/volume.h
+++ b/intern/cycles/kernel/closure/volume.h
@@ -88,7 +88,7 @@ henyey_greenstrein_sample(float3 D, float g, float randu, 
float randv, ccl_priva
 }
   }
 
-  float sin_theta = safe_sqrtf(1.0f - cos_theta * cos_theta);
+  float sin_theta = sin_from_cos(cos_theta);
   float phi = M_2PI_F * randv;
   float3 dir = make_float3(sin_theta * cosf(phi), sin_theta * sinf(phi), 
cos_theta);
 
diff --git a/intern/cycles/kernel/geom/curve_intersect.h 
b/intern/cycles/kernel/geom/curve_intersect.h
index 747d4ba4c3f..e8ce0c58c1e 100644
--- a/intern/cycles/kernel/geom/curve_intersect.h
+++ b/intern/cycles/kernel/geom/curve_intersect.h
@@ -720,7 +720,7 @@ ccl_device_inline void curve_shader_setup(KernelGlobals kg,
 const float3 tangent = normalize(dPdu);
 const float3 bitangent = normalize(cross(tangent, -D));
 const float sine = sd->v;
-const float cosine = safe_sqrtf(1.0f - sine * sine);
+const float cosine = cos_from_sin(sine);
 
 sd->N = normalize(sine * bitangent - cosine * normalize(cross(tangent, 
bitangent)));
 #  if 0
diff --git a/intern/cycles/kernel/integrator/mnee.h 
b/intern/cycles/kernel/integrator/mnee.h
index b6b07ad83a1..f50e3bc6e0c 100644
--- a/intern/cycles/kernel/integrator/mnee.h
+++ b/intern/cycles/kernel/integrator/mnee.h
@@ -704,9 +704,9 @@ ccl_device_forceinline bool 
mnee_compute_transfer_matrix(ccl_private const Shade
 float ilo = -eta * ilh;
 
 float cos_theta = dot(wo, m.n);
-float sin_theta = safe_sqrtf(1.f - sqr(cos_theta));
+float sin_theta = sin_from_cos(cos_theta);
 float cos_phi = dot(wo, s);
-float sin_phi = safe_sqrtf(1.f - sqr(cos_phi));
+float sin_phi = sin_from_cos(cos_phi);
 
 /* Wo = (cos_phi * sin_theta) * s + (sin_phi * sin_theta) * t + cos_theta 
* n. */
 float3 dH_dtheta = ilo * (cos_theta * (cos_phi * s

[Bf-blender-cvs] [b1c8889396c] master: Cleanup: format

2023-01-24 Thread Lukas Stockner
Commit: b1c8889396c044a460be619c501ed789fe5cf3be
Author: Lukas Stockner
Date:   Tue Jan 24 17:58:58 2023 +0100
Branches: master
https://developer.blender.org/rBb1c8889396c044a460be619c501ed789fe5cf3be

Cleanup: format

===

M   release/scripts/startup/bl_ui/properties_data_armature.py
M   release/scripts/startup/bl_ui/properties_data_bone.py
M   release/scripts/startup/bl_ui/properties_data_camera.py
M   release/scripts/startup/bl_ui/properties_data_curve.py
M   release/scripts/startup/bl_ui/properties_data_curves.py
M   release/scripts/startup/bl_ui/properties_data_lattice.py
M   release/scripts/startup/bl_ui/properties_data_light.py
M   release/scripts/startup/bl_ui/properties_data_mesh.py
M   release/scripts/startup/bl_ui/properties_data_metaball.py
M   release/scripts/startup/bl_ui/properties_data_pointcloud.py
M   release/scripts/startup/bl_ui/properties_data_speaker.py
M   release/scripts/startup/bl_ui/properties_data_volume.py
M   release/scripts/startup/bl_ui/properties_freestyle.py
M   release/scripts/startup/bl_ui/properties_material.py
M   release/scripts/startup/bl_ui/properties_material_gpencil.py
M   release/scripts/startup/bl_ui/properties_object.py
M   release/scripts/startup/bl_ui/properties_output.py
M   release/scripts/startup/bl_ui/properties_particle.py
M   release/scripts/startup/bl_ui/properties_physics_cloth.py
M   release/scripts/startup/bl_ui/properties_physics_common.py
M   release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
M   release/scripts/startup/bl_ui/properties_physics_field.py
M   release/scripts/startup/bl_ui/properties_physics_fluid.py
M   release/scripts/startup/bl_ui/properties_physics_rigidbody.py
M   release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
M   release/scripts/startup/bl_ui/properties_physics_softbody.py
M   release/scripts/startup/bl_ui/properties_render.py
M   release/scripts/startup/bl_ui/properties_texture.py
M   release/scripts/startup/bl_ui/properties_view_layer.py
M   release/scripts/startup/bl_ui/properties_world.py
M   release/scripts/startup/bl_ui/space_node.py
M   release/scripts/startup/bl_ui/space_sequencer.py
M   source/blender/draw/intern/smaa_textures.h
M   source/blender/editors/sculpt_paint/sculpt.cc

===

diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py 
b/release/scripts/startup/bl_ui/properties_data_armature.py
index aefcb53fb56..06e44f7f09f 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -248,7 +248,7 @@ class 
DATA_PT_motion_paths_display(MotionPathButtonsPanel_display, Panel):
 
 
 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
-COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 
'BLENDER_WORKBENCH','BLENDER_WORKBENCH_NEXT'}
+COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH', 
'BLENDER_WORKBENCH_NEXT'}
 _context_path = "object.data"
 _property_type = bpy.types.Armature
 
diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py 
b/release/scripts/startup/bl_ui/properties_data_bone.py
index 465a1854528..8eedcc4961b 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -444,7 +444,12 @@ class BONE_PT_deform(BoneButtonsPanel, Panel):
 
 
 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
-COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_EEVEE_NEXT', 
'BLENDER_WORKBENCH','BLENDER_WORKBENCH_NEXT'}
+COMPAT_ENGINES = {
+'BLENDER_RENDER',
+'BLENDER_EEVEE',
+'BLENDER_EEVEE_NEXT',
+'BLENDER_WORKBENCH',
+'BLENDER_WORKBENCH_NEXT'}
 _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
 
 @property
diff --git a/release/scripts/startup/bl_ui/properties_data_camera.py 
b/release/scripts/startup/bl_ui/properties_data_camera.py
index 6ecfa9dfbb4..7043c24ace1 100644
--- a/release/scripts/startup/bl_ui/properties_data_camera.py
+++ b/release/scripts/startup/bl_ui/properties_data_camera.py
@@ -21,7 +21,12 @@ class CAMERA_PT_presets(PresetPanel, Panel):
 preset_subdir = "camera"
 preset_operator = "script.execute_preset"
 preset_add_operator = "camera.preset_add"
-COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_EEVEE_NEXT', 
'BLENDER_WORKBENCH','BLENDER_WORKBENCH_NEXT'}
+COMPAT_ENGINES = {
+'BLENDER_RENDER',
+'BLENDER_EEVEE',
+'BLENDER_EEVEE_NEXT',
+'BLENDER_WORKBENCH',
+'BLENDER_WORKBENCH_NEXT'}
 
 
 class CAMERA_PT_safe_areas_presets(PresetPanel, Panel):
@@ -29,13 +34,

[Bf-blender-cvs] [e308b891c88] master: Cycles: Use faster and exact GGX VNDF sampling algorithm

2023-01-24 Thread Lukas Stockner
Commit: e308b891c8829e08ad023eff7ed43f7acac3ae03
Author: Lukas Stockner
Date:   Tue Jan 24 17:34:24 2023 +0100
Branches: master
https://developer.blender.org/rBe308b891c8829e08ad023eff7ed43f7acac3ae03

Cycles: Use faster and exact GGX VNDF sampling algorithm

Based on "Sampling the GGX Distribution of Visible Normals" by Eric Heitz
(https://jcgt.org/published/0007/04/01/).

Also, this removes the lambdaI computation from the Beckmann sampling code and
just recomputes it below. We already need to recompute for two other cases
(GGX and clearcoat), so this makes the code more consistent.

In terms of performance, I don't expect a notable impact since the earlier
computation also was non-trivial, and while it probably was slightly more
accurate, I'd argue that being consistent between evaluation and sampling is
more important than absolute numerical accuracy anyways.

Differential Revision: https://developer.blender.org/D17100

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/util/math_float2.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 75167b9d816..8cf4cfa244d 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -37,189 +37,100 @@ typedef struct MicrofacetBsdf {
 
 static_assert(sizeof(ShaderClosure) >= sizeof(MicrofacetBsdf), "MicrofacetBsdf 
is too large!");
 
-/* Beckmann and GGX microfacet importance sampling. */
-
-ccl_device_inline void microfacet_beckmann_sample_slopes(KernelGlobals kg,
- const float 
cos_theta_i,
- const float 
sin_theta_i,
- float randu,
- float randv,
- ccl_private float 
*slope_x,
- ccl_private float 
*slope_y,
- ccl_private float 
*lambda_i)
-{
-  /* Special case (normal incidence). */
-  if (cos_theta_i >= 0.9f) {
-const float r = sqrtf(-logf(randu));
-const float phi = M_2PI_F * randv;
-*slope_x = r * cosf(phi);
-*slope_y = r * sinf(phi);
-*lambda_i = 0.0f;
-
-return;
-  }
-
-  /* Precomputations. */
-  const float tan_theta_i = sin_theta_i / cos_theta_i;
-  const float inv_a = tan_theta_i;
-  const float cot_theta_i = 1.0f / tan_theta_i;
-  const float erf_a = fast_erff(cot_theta_i);
-  const float exp_a2 = expf(-cot_theta_i * cot_theta_i);
-  const float SQRT_PI_INV = 0.56418958354f;
-  const float Lambda = 0.5f * (erf_a - 1.0f) + (0.5f * SQRT_PI_INV) * (exp_a2 
* inv_a);
-
-  *lambda_i = Lambda;
-
-  /* Based on paper from Wenzel Jakob
-   * An Improved Visible Normal Sampling Routine for the Beckmann Distribution
-   *
-   * http://www.mitsuba-renderer.org/~wenzel/files/visnormal.pdf
-   *
-   * Reformulation from OpenShadingLanguage which avoids using inverse
-   * trigonometric functions.
-   */
-
-  /* Sample slope X.
-   *
-   * Compute a coarse approximation using the approximation:
-   *   exp(-ierf(x)^2) ~= 1 - x * x
-   *   solve y = 1 + b + K * (1 - b * b)
-   */
-  const float K = tan_theta_i * SQRT_PI_INV;
-  const float y_approx = randu * (1.0f + erf_a + K * (1 - erf_a * erf_a));
-  const float y_exact = randu * (1.0f + erf_a + K * exp_a2);
-  float b = K > 0 ? (0.5f - sqrtf(K * (K - y_approx + 1.0f) + 0.25f)) / K : 
y_approx - 1.0f;
-
-  float inv_erf = fast_ierff(b);
-  float2 begin = make_float2(-1.0f, -y_exact);
-  float2 end = make_float2(erf_a, 1.0f + erf_a + K * exp_a2 - y_exact);
-  float2 current = make_float2(b, 1.0f + b + K * expf(-sqr(inv_erf)) - 
y_exact);
-
-  /* Find root in a monotonic interval using newton method, under given 
precision and maximal
-   * iterations. Falls back to bisection if newton step produces results 
outside of the valid
-   * interval.*/
-  const float precision = 1e-6f;
-  const int max_iter = 3;
-  int iter = 0;
-  while (fabsf(current.y) > precision && iter++ < max_iter) {
-if (signf(begin.y) == signf(current.y)) {
-  begin.x = current.x;
-  begin.y = current.y;
-}
-else {
-  end.x = current.x;
-}
-const float newton_x = current.x - current.y / (1.0f - inv_erf * 
tan_theta_i);
-current.x = (newton_x >= begin.x && newton_x <= end.x) ? newton_x : 0.5f * 
(begin.x + end.x);
-inv_erf = fast_ierff(current.x);
-current.y = 1.0f + current.x + K * expf(-sqr(inv_erf)) - y_exact;
-  }
-
-  *slope_x = inv_erf;
-  *slope_y = fast_ierff(2.0f * randv - 1.0f);
-}
-
-/* GGX microfacet importance sampling from:
- *
+/* Beckman

[Bf-blender-cvs] [fdcb55b2859] master: Cycles: Switch microfacet code to non-separable shadowing-masking term

2023-01-24 Thread Lukas Stockner
Commit: fdcb55b28593f82b1d96c6df8f22de9ad5fdd2fa
Author: Lukas Stockner
Date:   Tue Jan 24 00:03:50 2023 +0100
Branches: master
https://developer.blender.org/rBfdcb55b28593f82b1d96c6df8f22de9ad5fdd2fa

Cycles: Switch microfacet code to non-separable shadowing-masking term

This gives closer results to what I've seen in papers and other renderers when
using the code to precompute albedo later (to replace MultiGGX).

It's usually a tiny difference, the only case where I've seen it matter is
in the `shader/node_group_float.blend` test - but that's a (single-scatter) GGX
closure with 0.9 roughness, so it's not too surprising. In any case, the new
result looks closer to Eevee, so that's good I guess.

Differential Revision: https://developer.blender.org/D17099

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index db53a29cfc3..75167b9d816 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -46,7 +46,7 @@ ccl_device_inline void 
microfacet_beckmann_sample_slopes(KernelGlobals kg,
  float randv,
  ccl_private float 
*slope_x,
  ccl_private float 
*slope_y,
- ccl_private float 
*G1i)
+ ccl_private float 
*lambda_i)
 {
   /* Special case (normal incidence). */
   if (cos_theta_i >= 0.9f) {
@@ -54,7 +54,7 @@ ccl_device_inline void 
microfacet_beckmann_sample_slopes(KernelGlobals kg,
 const float phi = M_2PI_F * randv;
 *slope_x = r * cosf(phi);
 *slope_y = r * sinf(phi);
-*G1i = 1.0f;
+*lambda_i = 0.0f;
 
 return;
   }
@@ -67,9 +67,8 @@ ccl_device_inline void 
microfacet_beckmann_sample_slopes(KernelGlobals kg,
   const float exp_a2 = expf(-cot_theta_i * cot_theta_i);
   const float SQRT_PI_INV = 0.56418958354f;
   const float Lambda = 0.5f * (erf_a - 1.0f) + (0.5f * SQRT_PI_INV) * (exp_a2 
* inv_a);
-  const float G1 = 1.0f / (1.0f + Lambda); /* masking */
 
-  *G1i = G1;
+  *lambda_i = Lambda;
 
   /* Based on paper from Wenzel Jakob
* An Improved Visible Normal Sampling Routine for the Beckmann Distribution
@@ -132,7 +131,7 @@ ccl_device_inline void microfacet_ggx_sample_slopes(const 
float cos_theta_i,
 float randv,
 ccl_private float *slope_x,
 ccl_private float *slope_y,
-ccl_private float *G1i)
+ccl_private float 
*lambda_i)
 {
   /* Special case (normal incidence). */
   if (cos_theta_i >= 0.9f) {
@@ -140,7 +139,7 @@ ccl_device_inline void microfacet_ggx_sample_slopes(const 
float cos_theta_i,
 const float phi = M_2PI_F * randv;
 *slope_x = r * cosf(phi);
 *slope_y = r * sinf(phi);
-*G1i = 1.0f;
+*lambda_i = 0.0f;
 
 return;
   }
@@ -149,7 +148,7 @@ ccl_device_inline void microfacet_ggx_sample_slopes(const 
float cos_theta_i,
   const float tan_theta_i = sin_theta_i / cos_theta_i;
   const float G1_inv = 0.5f * (1.0f + safe_sqrtf(1.0f + tan_theta_i * 
tan_theta_i));
 
-  *G1i = 1.0f / G1_inv;
+  *lambda_i = G1_inv - 1.0f;
 
   /* Sample slope_x. */
   const float A = 2.0f * randu * G1_inv - 1.0f;
@@ -186,7 +185,7 @@ ccl_device_forceinline float3 
microfacet_sample_stretched(KernelGlobals kg,
   const float alpha_y,
   const float randu,
   const float randv,
-  ccl_private float 
*G1i)
+  ccl_private float 
*lambda_i)
 {
   /* 1. stretch wi */
   float3 wi_ = make_float3(alpha_x * wi.x, alpha_y * wi.y, wi.z);
@@ -212,10 +211,10 @@ ccl_device_forceinline float3 
microfacet_sample_stretched(KernelGlobals kg,
 
   if (m_type == MicrofacetType::BECKMANN) {
 microfacet_beckmann_sample_slopes(
-kg, costheta_, sintheta_, randu, randv, _x, _y, G1i);
+kg, costheta_, sintheta_, randu, randv, _x, _y, lambda_i);
   }
   else {
-microfacet_ggx_sample_slopes(costheta_, sintheta_, randu, randv, _x, 
_y, G1i);
+microfacet_ggx_sample_slopes(costheta_, sintheta_, randu, randv, _x, 
_y, lambda_i);
   }
 
   /* 3. rotate */
@@ -271,37 +270,48 @@ ccl_device_forceinline float bsdf_clearcoat_D(float 
alpha2, float 

[Bf-blender-cvs] [f72969f377a] master: Fix T103888: Regression: Side-by-side stereo renders ignore color management

2023-01-23 Thread Lukas Stockner
Commit: f72969f377a05741ded8f8bfa325d5980a58d1a6
Author: Lukas Stockner
Date:   Mon Jan 23 22:10:40 2023 +0100
Branches: master
https://developer.blender.org/rBf72969f377a05741ded8f8bfa325d5980a58d1a6

Fix T103888: Regression: Side-by-side stereo renders ignore color management

Looks like rB42937493d8253a295a97092315288f961e8c6dba accidentally dropped the
colorspace copy.

===

M   source/blender/imbuf/intern/stereoimbuf.c

===

diff --git a/source/blender/imbuf/intern/stereoimbuf.c 
b/source/blender/imbuf/intern/stereoimbuf.c
index eb2701b5b9c..0c064a3ccc3 100644
--- a/source/blender/imbuf/intern/stereoimbuf.c
+++ b/source/blender/imbuf/intern/stereoimbuf.c
@@ -765,9 +765,11 @@ ImBuf *IMB_stereo3d_ImBuf(const ImageFormatData 
*im_format, ImBuf *ibuf_left, Im
 
   if (is_float) {
 imb_addrectfloatImBuf(ibuf_stereo, ibuf_left->channels);
+ibuf_stereo->float_colorspace = ibuf_left->float_colorspace;
   }
   else {
 imb_addrectImBuf(ibuf_stereo);
+ibuf_stereo->rect_colorspace = ibuf_left->rect_colorspace;
   }
 
   ibuf_stereo->flags = ibuf_left->flags;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [faca2c614b6] blender-v3.3-release: Fix T103507: Distant lights partially contribute to wrong lightgroup

2023-01-13 Thread Lukas Stockner
Commit: faca2c614b67a1b66e55ad20df5eb30cb009a757
Author: Lukas Stockner
Date:   Fri Jan 6 01:08:17 2023 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rBfaca2c614b67a1b66e55ad20df5eb30cb009a757

Fix T103507: Distant lights partially contribute to wrong lightgroup

The the BSDF-sampling half of MIS next-event estimation for distant lights was
using the background lightgroup instead of the lamp's lightgroup.

===

M   intern/cycles/kernel/integrator/shade_background.h

===

diff --git a/intern/cycles/kernel/integrator/shade_background.h 
b/intern/cycles/kernel/integrator/shade_background.h
index a7edfffd175..cfae6805f17 100644
--- a/intern/cycles/kernel/integrator/shade_background.h
+++ b/intern/cycles/kernel/integrator/shade_background.h
@@ -185,8 +185,7 @@ ccl_device_inline void 
integrate_distant_lights(KernelGlobals kg,
 
   /* Write to render buffer. */
   const float3 throughput = INTEGRATOR_STATE(state, path, throughput);
-  kernel_accum_emission(
-  kg, state, throughput * light_eval, render_buffer, 
kernel_data.background.lightgroup);
+  kernel_accum_emission(kg, state, throughput * light_eval, render_buffer, 
ls.group);
 }
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d290b8b2b9e] blender-v3.3-release: Fix T103403: Lightgroup passes can contain lighting on shadow catchers

2023-01-13 Thread Lukas Stockner
Commit: d290b8b2b9ecaa5c9b477aa1868b69db15a84cd3
Author: Lukas Stockner
Date:   Fri Jan 6 02:32:03 2023 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rBd290b8b2b9ecaa5c9b477aa1868b69db15a84cd3

Fix T103403: Lightgroup passes can contain lighting on shadow catchers

===

M   intern/cycles/kernel/film/accumulate.h

===

diff --git a/intern/cycles/kernel/film/accumulate.h 
b/intern/cycles/kernel/film/accumulate.h
index 33c35a68ad0..52116eb2dd8 100644
--- a/intern/cycles/kernel/film/accumulate.h
+++ b/intern/cycles/kernel/film/accumulate.h
@@ -348,7 +348,9 @@ ccl_device_inline void 
kernel_accum_emission_or_background_pass(
   }
 #  endif /* __DENOISING_FEATURES__ */
 
-  if (lightgroup != LIGHTGROUP_NONE && kernel_data.film.pass_lightgroup != 
PASS_UNUSED) {
+  const bool is_shadowcatcher = (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) != 0;
+  if (!is_shadowcatcher && lightgroup != LIGHTGROUP_NONE &&
+  kernel_data.film.pass_lightgroup != PASS_UNUSED) {
 kernel_write_pass_float3(buffer + kernel_data.film.pass_lightgroup + 3 * 
lightgroup,
  contribution);
   }
@@ -357,13 +359,12 @@ ccl_device_inline void 
kernel_accum_emission_or_background_pass(
 /* Directly visible, write to emission or background pass. */
 pass_offset = pass;
   }
-  else if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
+  else if (is_shadowcatcher) {
 /* Don't write any light passes for shadow catcher, for easier
  * compositing back together of the combined pass. */
-if (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) {
-  return;
-}
-
+return;
+  }
+  else if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
 if (path_flag & PATH_RAY_SURFACE_PASS) {
   /* Indirectly visible through reflection. */
   const float3 diffuse_weight = INTEGRATOR_STATE(state, path, 
pass_diffuse_weight);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2b4bf586ade] master: Fix T102920: Cycles doesn't support multiple outputs on muted nodes

2023-01-11 Thread Lukas Stockner
Commit: 2b4bf586ade5a5941f116383074871941a629f23
Author: Lukas Stockner
Date:   Thu Jan 12 00:48:56 2023 +0100
Branches: master
https://developer.blender.org/rB2b4bf586ade5a5941f116383074871941a629f23

Fix T102920: Cycles doesn't support multiple outputs on muted nodes

Cycles converts internal links to converter nodes which don't do anything and
later on get collapsed by the graph optimization. However, the previous code
assumed that one Blender input socket maps to one Cycles input socket.

When a node is muted, there might be internal links from one input to multiple
outputs. In Cycles, this meant that one Blender input socket now mapped to
multiple input sockets on all the converter nodes, so only the last one 
survived.

THe fix is simple, just make the mapping a MultiMap.

===

M   intern/cycles/blender/shader.cpp

===

diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index f25e98469fb..5220e680a50 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -26,7 +26,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-typedef map PtrInputMap;
+typedef unordered_multimap PtrInputMap;
 typedef map PtrOutputMap;
 typedef map ProxyMap;
 
@@ -1251,7 +1251,9 @@ static void add_nodes(Scene *scene,
 
 ConvertNode *proxy = graph->create_node(to_socket_type, 
to_socket_type, true);
 
-input_map[b_link.from_socket().ptr.data] = proxy->inputs[0];
+/* Muted nodes can result in multiple Cycles input sockets mapping to 
the same Blender
+ * input socket, so this needs to be a multimap. */
+input_map.emplace(b_link.from_socket().ptr.data, proxy->inputs[0]);
 output_map[b_link.to_socket().ptr.data] = proxy->outputs[0];
 
 graph->add(proxy);
@@ -1286,7 +1288,7 @@ static void add_nodes(Scene *scene,
 /* register the proxy node for internal binding */
 group_proxy_input_map[b_input.identifier()] = proxy;
 
-input_map[b_input.ptr.data] = proxy->inputs[0];
+input_map.emplace(b_input.ptr.data, proxy->inputs[0]);
 
 set_default_value(proxy->inputs[0], b_input, b_data, b_ntree);
   }
@@ -1338,7 +1340,7 @@ static void add_nodes(Scene *scene,
   if (proxy_it != proxy_output_map.end()) {
 ConvertNode *proxy = proxy_it->second;
 
-input_map[b_input.ptr.data] = proxy->inputs[0];
+input_map.emplace(b_input.ptr.data, proxy->inputs[0]);
 
 set_default_value(proxy->inputs[0], b_input, b_data, b_ntree);
   }
@@ -1369,7 +1371,7 @@ static void add_nodes(Scene *scene,
 /* XXX should not happen, report error? */
 continue;
   }
-  input_map[b_input.ptr.data] = input;
+  input_map.emplace(b_input.ptr.data, input);
 
   set_default_value(input, b_input, b_data, b_ntree);
 }
@@ -1401,20 +1403,23 @@ static void add_nodes(Scene *scene,
 BL::NodeSocket b_from_sock = b_link.from_socket();
 BL::NodeSocket b_to_sock = b_link.to_socket();
 
-ShaderOutput *output = 0;
-ShaderInput *input = 0;
-
+ShaderOutput *output = nullptr;
 PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data);
 if (output_it != output_map.end())
   output = output_it->second;
-PtrInputMap::iterator input_it = input_map.find(b_to_sock.ptr.data);
-if (input_it != input_map.end())
-  input = input_it->second;
 
-/* either node may be NULL when the node was not exported, typically
+/* either socket may be NULL when the node was not exported, typically
  * because the node type is not supported */
-if (output && input)
-  graph->connect(output, input);
+if (output != nullptr) {
+  ShaderOutput *output = output_it->second;
+  auto inputs = input_map.equal_range(b_to_sock.ptr.data);
+  for (PtrInputMap::iterator input_it = inputs.first; input_it != 
inputs.second; ++input_it) {
+ShaderInput *input = input_it->second;
+if (input != nullptr) {
+  graph->connect(output, input);
+}
+  }
+}
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ff86573d72c] master: Fix T102313: Enabling shadow catcher in viewport render shows self-shadowing

2023-01-11 Thread Lukas Stockner
Commit: ff86573d72cadf431c6f39aac9c8ebb78853acdc
Author: Lukas Stockner
Date:   Wed Jan 11 21:35:09 2023 +0100
Branches: master
https://developer.blender.org/rBff86573d72cadf431c6f39aac9c8ebb78853acdc

Fix T102313: Enabling shadow catcher in viewport render shows self-shadowing

The problem here is that whether an object is a shadow catcher or not affects 
the
visibility flags, but changes to the shadow catcher property did not trigger a
visibility flag update.

===

M   intern/cycles/scene/object.cpp

===

diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp
index c788c6f4a8c..dc98389575a 100644
--- a/intern/cycles/scene/object.cpp
+++ b/intern/cycles/scene/object.cpp
@@ -217,6 +217,7 @@ void Object::tag_update(Scene *scene)
 
 if (is_shadow_catcher_is_modified()) {
   scene->tag_shadow_catcher_modified();
+  flag |= ObjectManager::VISIBILITY_MODIFIED;
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c41601becd7] master: Fix T89037: Cycles: Backfacing node can be wrong for lights with negative scale

2023-01-09 Thread Lukas Stockner
Commit: c41601becd73ef67d041ed9cbb9b189fddd183d0
Author: Lukas Stockner
Date:   Tue Jan 10 02:32:16 2023 +0100
Branches: master
https://developer.blender.org/rBc41601becd73ef67d041ed9cbb9b189fddd183d0

Fix T89037: Cycles: Backfacing node can be wrong for lights with negative scale

When rendering in the viewport (or probably on instanced objects, but I didn't
test that), emissive objects whose scale is negative give the wrong value on the
"backfacing" input when multiple sampling is enabled.

The underlying problem was a corner case in how normal transformation is 
handled,
which is generally a bit messy.

From what I can tell, the pattern appears to be:
- If you first transform vertices to world space and then compute the normal 
from
  them (as triangle light samping, MNEE and light tree do), you need to flip
  whenever the transform has negative scale regardless of whether the transform
  has been applied
- If you compute the normal in object space and then transform it to world space
  (as the regular shader_setup_from_ray path does), you only need to flip if the
  transform was already applied and was negative
- If you get the normal from a local intersection result (as bevel and SSS do),
  you only need to flip if the transform was already applied and was negative
- If you get the normal from vertex normals, you don't need to do anything since
  the host-side code does the flip for you (arguably it'd be more consistent to
  do this in the kernel as well, but meh, not worth the potential slowdown)

So, this patch fixes the logic in the triangle emission code.

Also, turns out that the MNEE code had the same problem and was also having
problems in the viewport on negative-scale objects, this is also fixed now.

Differential Revision: https://developer.blender.org/D16952

===

M   intern/cycles/kernel/geom/motion_triangle_shader.h
M   intern/cycles/kernel/geom/object.h
M   intern/cycles/kernel/geom/triangle.h
M   intern/cycles/kernel/integrator/mnee.h
M   intern/cycles/kernel/integrator/subsurface_disk.h
M   intern/cycles/kernel/light/triangle.h
M   intern/cycles/kernel/svm/bevel.h
M   intern/cycles/kernel/types.h
M   intern/cycles/scene/object.cpp

===

diff --git a/intern/cycles/kernel/geom/motion_triangle_shader.h 
b/intern/cycles/kernel/geom/motion_triangle_shader.h
index 413a61b380a..0ec5e29f480 100644
--- a/intern/cycles/kernel/geom/motion_triangle_shader.h
+++ b/intern/cycles/kernel/geom/motion_triangle_shader.h
@@ -58,7 +58,7 @@ ccl_device_noinline void 
motion_triangle_shader_setup(KernelGlobals kg,
   sd->P = motion_triangle_point_from_uv(kg, sd, isect_object, isect_prim, 
sd->u, sd->v, verts);
   /* Compute face normal. */
   float3 Ng;
-  if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
+  if (object_negative_scale_applied(sd->object_flag)) {
 Ng = normalize(cross(verts[2] - verts[0], verts[1] - verts[0]));
   }
   else {
diff --git a/intern/cycles/kernel/geom/object.h 
b/intern/cycles/kernel/geom/object.h
index 14ceb636e2e..f5f3c36f208 100644
--- a/intern/cycles/kernel/geom/object.h
+++ b/intern/cycles/kernel/geom/object.h
@@ -201,6 +201,11 @@ ccl_device_inline void 
object_normal_transform(KernelGlobals kg,
   *N = normalize(transform_direction_transposed(, *N));
 }
 
+ccl_device_inline bool object_negative_scale_applied(const int object_flag)
+{
+  return ((object_flag & SD_OBJECT_NEGATIVE_SCALE) && (object_flag & 
SD_OBJECT_TRANSFORM_APPLIED));
+}
+
 /* Transform direction vector from object to world space */
 
 ccl_device_inline void object_dir_transform(KernelGlobals kg,
diff --git a/intern/cycles/kernel/geom/triangle.h 
b/intern/cycles/kernel/geom/triangle.h
index 6b9450d59ef..b5fb67260a9 100644
--- a/intern/cycles/kernel/geom/triangle.h
+++ b/intern/cycles/kernel/geom/triangle.h
@@ -21,7 +21,7 @@ ccl_device_inline float3 triangle_normal(KernelGlobals kg, 
ccl_private ShaderDat
   const float3 v2 = kernel_data_fetch(tri_verts, tri_vindex.w + 2);
 
   /* return normal */
-  if (sd->object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
+  if (object_negative_scale_applied(sd->object_flag)) {
 return normalize(cross(v2 - v0, v1 - v0));
   }
   else {
@@ -50,7 +50,7 @@ ccl_device_inline void triangle_point_normal(KernelGlobals kg,
   /* get object flags */
   int object_flag = kernel_data_fetch(object_flag, object);
   /* compute normal */
-  if (object_flag & SD_OBJECT_NEGATIVE_SCALE_APPLIED) {
+  if (object_negative_scale_applied(object_flag)) {
 *Ng = normalize(cross(v2 - v0, v1 - v0));
   }
   else {
diff --git a/intern/cycles/kernel/integrator/mnee.h 
b/intern/cycles/kernel/integrator/mnee.h
index 7f5f2c97497..debbce497dc 100644
--- a/intern/cycles/kernel/integrator/mnee.h
+++ b/intern/cycles/kernel/integrator/mnee.h
@@ -176,8 +176,9 @@ ccl_device

[Bf-blender-cvs] [39c30f69830] master: Cycles: Account for negative scale when using one-sided light tree sampling

2023-01-09 Thread Lukas Stockner
Commit: 39c30f6983009847d010856bee8a193a8ee3e73c
Author: Lukas Stockner
Date:   Tue Jan 10 02:44:12 2023 +0100
Branches: master
https://developer.blender.org/rB39c30f6983009847d010856bee8a193a8ee3e73c

Cycles: Account for negative scale when using one-sided light tree sampling

Differential Revision: https://developer.blender.org/D16952

===

M   intern/cycles/kernel/light/tree.h
M   intern/cycles/scene/light_tree.cpp

===

diff --git a/intern/cycles/kernel/light/tree.h 
b/intern/cycles/kernel/light/tree.h
index 3c6f118ace3..423879bcddc 100644
--- a/intern/cycles/kernel/light/tree.h
+++ b/intern/cycles/kernel/light/tree.h
@@ -223,11 +223,16 @@ ccl_device bool 
compute_emitter_centroid_and_dir(KernelGlobals kg,
 triangle_world_space_vertices(kg, object, prim_id, -1.0f, vertices);
 centroid = (vertices[0] + vertices[1] + vertices[2]) / 3.0f;
 
-if (kemitter->emission_sampling == EMISSION_SAMPLING_FRONT) {
+const bool is_front_only = (kemitter->emission_sampling == 
EMISSION_SAMPLING_FRONT);
+const bool is_back_only = (kemitter->emission_sampling == 
EMISSION_SAMPLING_BACK);
+if (is_front_only || is_back_only) {
   dir = safe_normalize(cross(vertices[1] - vertices[0], vertices[2] - 
vertices[0]));
-}
-else if (kemitter->emission_sampling == EMISSION_SAMPLING_BACK) {
-  dir = -safe_normalize(cross(vertices[1] - vertices[0], vertices[2] - 
vertices[0]));
+  if (is_back_only) {
+dir = -dir;
+  }
+  if (kernel_data_fetch(object_flag, object) & SD_OBJECT_NEGATIVE_SCALE) {
+dir = -dir;
+  }
 }
 else {
   /* Double-sided: any vector in the plane. */
diff --git a/intern/cycles/scene/light_tree.cpp 
b/intern/cycles/scene/light_tree.cpp
index f9bd479cf1c..4fa4755479b 100644
--- a/intern/cycles/scene/light_tree.cpp
+++ b/intern/cycles/scene/light_tree.cpp
@@ -94,14 +94,17 @@ LightTreePrimitive::LightTreePrimitive(Scene *scene, int 
prim_id, int object_id)
  * seems to work fine */
 centroid = (vertices[0] + vertices[1] + vertices[2]) / 3.0f;
 
-if (shader->emission_sampling == EMISSION_SAMPLING_FRONT) {
-  /* Front only. */
+const bool is_front_only = (shader->emission_sampling == 
EMISSION_SAMPLING_FRONT);
+const bool is_back_only = (shader->emission_sampling == 
EMISSION_SAMPLING_BACK);
+if (is_front_only || is_back_only) {
+  /* One-sided. */
   bcone.axis = safe_normalize(cross(vertices[1] - vertices[0], vertices[2] 
- vertices[0]));
-  bcone.theta_o = 0;
-}
-else if (shader->emission_sampling == EMISSION_SAMPLING_BACK) {
-  /* Back only. */
-  bcone.axis = -safe_normalize(cross(vertices[1] - vertices[0], 
vertices[2] - vertices[0]));
+  if (is_back_only) {
+bcone.axis = -bcone.axis;
+  }
+  if (transform_negative_scale(object->get_tfm())) {
+bcone.axis = -bcone.axis;
+  }
   bcone.theta_o = 0;
 }
 else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [317a5f61f00] master: Cycles: Fix recently introduced off-by-one error in an assert

2023-01-09 Thread Lukas Stockner
Commit: 317a5f61f00b06dfbd2b5140149e588db36b3c60
Author: Lukas Stockner
Date:   Tue Jan 10 02:07:00 2023 +0100
Branches: master
https://developer.blender.org/rB317a5f61f00b06dfbd2b5140149e588db36b3c60

Cycles: Fix recently introduced off-by-one error in an assert

This was added in rB95696d09bc07, but I got the index wrong.

===

M   intern/cycles/util/math_cdf.cpp

===

diff --git a/intern/cycles/util/math_cdf.cpp b/intern/cycles/util/math_cdf.cpp
index a009652d8c8..cc02d630977 100644
--- a/intern/cycles/util/math_cdf.cpp
+++ b/intern/cycles/util/math_cdf.cpp
@@ -16,7 +16,9 @@ void util_cdf_invert(const int resolution,
  const bool make_symmetric,
  vector _cdf)
 {
-  assert(cdf[0] == 0.0f && cdf[resolution] == 1.0f);
+  const int cdf_size = cdf.size();
+  assert(cdf[0] == 0.0f && cdf[cdf_size - 1] == 1.0f);
+
   const float inv_resolution = 1.0f / (float)resolution;
   const float range = to - from;
   inv_cdf.resize(resolution);
@@ -26,12 +28,12 @@ void util_cdf_invert(const int resolution,
   float x = i / (float)half_size;
   int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin();
   float t;
-  if (index < cdf.size() - 1) {
+  if (index < cdf_size - 1) {
 t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
   }
   else {
 t = 0.0f;
-index = cdf.size() - 1;
+index = cdf_size - 1;
   }
   float y = ((index + t) / (resolution - 1)) * (2.0f * range);
   inv_cdf[half_size + i] = 0.5f * (1.0f + y);
@@ -43,7 +45,7 @@ void util_cdf_invert(const int resolution,
   float x = (i + 0.5f) * inv_resolution;
   int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1;
   float t;
-  if (index < cdf.size() - 1) {
+  if (index < cdf_size - 1) {
 t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
   }
   else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4546e35c920] master: Fix T95244: Cycles produces incorrect AO pass for shadow catchers

2023-01-08 Thread Lukas Stockner
Commit: 4546e35c92022997dacc322c8ab43df23bf98ca3
Author: Lukas Stockner
Date:   Sun Jan 8 21:38:54 2023 +0100
Branches: master
https://developer.blender.org/rB4546e35c92022997dacc322c8ab43df23bf98ca3

Fix T95244: Cycles produces incorrect AO pass for shadow catchers

Differential Revision: https://developer.blender.org/D16951

===

M   intern/cycles/kernel/integrator/shade_surface.h

===

diff --git a/intern/cycles/kernel/integrator/shade_surface.h 
b/intern/cycles/kernel/integrator/shade_surface.h
index 19bec243757..3410195cd19 100644
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@ -502,8 +502,15 @@ ccl_device_forceinline void 
integrate_surface_ao(KernelGlobals kg,
  rng_state,
  ccl_global float 
*ccl_restrict render_buffer)
 {
+  const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
+
   if (!(kernel_data.kernel_features & KERNEL_FEATURE_AO_ADDITIVE) &&
-  !(INTEGRATOR_STATE(state, path, flag) & PATH_RAY_CAMERA)) {
+  !(path_flag & PATH_RAY_CAMERA)) {
+return;
+  }
+
+  /* Skip AO for paths that were split off for shadow catchers to avoid 
double-counting. */
+  if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) {
 return;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [95696d09bc0] master: Fix T88849: Motion blur in cycles leaves bright edge on trailing end of blur

2023-01-08 Thread Lukas Stockner
Commit: 95696d09bc0725e49b5caf79db00927183fe569b
Author: Lukas Stockner
Date:   Mon Jan 9 03:05:57 2023 +0100
Branches: master
https://developer.blender.org/rB95696d09bc0725e49b5caf79db00927183fe569b

Fix T88849: Motion blur in cycles leaves bright edge on trailing end of blur

The code that computes and inverts the shutter CDF had some issues that caused
the result to be asymmetric, this tweaks it to be more robust and produce
symmetric outputs for symmetric inputs.

===

M   intern/cycles/scene/camera.cpp
M   intern/cycles/util/math_cdf.cpp
M   intern/cycles/util/math_cdf.h

===

diff --git a/intern/cycles/scene/camera.cpp b/intern/cycles/scene/camera.cpp
index 255dd320ec7..6eda0b7ab55 100644
--- a/intern/cycles/scene/camera.cpp
+++ b/intern/cycles/scene/camera.cpp
@@ -32,7 +32,7 @@ static float shutter_curve_eval(float x, array 
_curve)
 return 1.0f;
   }
 
-  x *= shutter_curve.size();
+  x = saturatef(x) * shutter_curve.size() - 1;
   int index = (int)x;
   float frac = x - index;
   if (index < shutter_curve.size() - 1) {
diff --git a/intern/cycles/util/math_cdf.cpp b/intern/cycles/util/math_cdf.cpp
index 928cd6a1932..a009652d8c8 100644
--- a/intern/cycles/util/math_cdf.cpp
+++ b/intern/cycles/util/math_cdf.cpp
@@ -16,6 +16,7 @@ void util_cdf_invert(const int resolution,
  const bool make_symmetric,
  vector _cdf)
 {
+  assert(cdf[0] == 0.0f && cdf[resolution] == 1.0f);
   const float inv_resolution = 1.0f / (float)resolution;
   const float range = to - from;
   inv_cdf.resize(resolution);
@@ -39,8 +40,8 @@ void util_cdf_invert(const int resolution,
   }
   else {
 for (int i = 0; i < resolution; i++) {
-  float x = from + range * (float)i * inv_resolution;
-  int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin();
+  float x = (i + 0.5f) * inv_resolution;
+  int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1;
   float t;
   if (index < cdf.size() - 1) {
 t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
@@ -49,7 +50,7 @@ void util_cdf_invert(const int resolution,
 t = 0.0f;
 index = resolution;
   }
-  inv_cdf[i] = (index + t) * inv_resolution;
+  inv_cdf[i] = from + range * (index + t) * inv_resolution;
 }
   }
 }
diff --git a/intern/cycles/util/math_cdf.h b/intern/cycles/util/math_cdf.h
index 82e6a69c04b..2555f194b2e 100644
--- a/intern/cycles/util/math_cdf.h
+++ b/intern/cycles/util/math_cdf.h
@@ -26,9 +26,11 @@ void util_cdf_evaluate(
 cdf[i + 1] = cdf[i] + fabsf(y);
   }
   /* Normalize the CDF. */
+  float fac = (cdf[resolution] == 0.0f) ? 0.0f : 1.0f / cdf[resolution];
   for (int i = 0; i <= resolution; i++) {
-cdf[i] /= cdf[resolution];
+cdf[i] *= fac;
   }
+  cdf[resolution] = 1.0f;
 }
 
 /* Invert pre-calculated CDF function. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d8e01150d63] master: Fix T94752: Cycles renders stereoscopic panoramas incorrectly

2023-01-08 Thread Lukas Stockner
Commit: d8e01150d6356b171f03021dd6abcae39f3a7c81
Author: Lukas Stockner
Date:   Sat Jan 7 21:55:37 2023 +0100
Branches: master
https://developer.blender.org/rBd8e01150d6356b171f03021dd6abcae39f3a7c81

Fix T94752: Cycles renders stereoscopic panoramas incorrectly

The bug is caused by rBb66b3f547c43e841a7d5da0ecb2c911628339f56.
From what I can see, that fix was intended to enable manual lens shift for
panorama cameras, but it appears that it also unintentionally applies
interocular shift.

This fix disables the multiview shift for panorama cameras, that way manual lens
shift still works but we get the 2.x behavior for stereoscopic renders back.

Differential Revision: https://developer.blender.org/D16950

===

M   source/blender/blenkernel/intern/camera.c

===

diff --git a/source/blender/blenkernel/intern/camera.c 
b/source/blender/blenkernel/intern/camera.c
index 7c1193d80ab..2d5dc9010bf 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -1119,6 +1119,9 @@ float BKE_camera_multiview_shift_x(const RenderData *rd,
   if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW) {
 return data->shiftx;
   }
+  if (data->type == CAM_PANO) {
+return data->shiftx;
+  }
   /* SCE_VIEWS_SETUP_BASIC */
   return camera_stereo3d_shift_x(camera, viewname);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e7a554e551e] master: Fix T94698: Cycles: Volume-scattered light is always counted as diffuse

2023-01-08 Thread Lukas Stockner
Commit: e7a554e551e45332292aefebfedf5edf08c7400b
Author: Lukas Stockner
Date:   Sun Jan 8 22:54:51 2023 +0100
Branches: master
https://developer.blender.org/rBe7a554e551e45332292aefebfedf5edf08c7400b

Fix T94698: Cycles: Volume-scattered light is always counted as diffuse

At the first bounce, the diffuse/glossy/transmission weights are stored so that
contributions along the path can be split into the d/g/t indirect passes.

However, volume bounces always set the weight even at indirect bounces, so
even paths that had their first bounce on a purely glossy object would suddenly
start counting towards the diffuse indirect pass after a secondary volume 
bounce.

===

M   intern/cycles/kernel/integrator/shade_volume.h

===

diff --git a/intern/cycles/kernel/integrator/shade_volume.h 
b/intern/cycles/kernel/integrator/shade_volume.h
index 456bebe771a..624aeb5edee 100644
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@ -979,8 +979,10 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
   INTEGRATOR_STATE_WRITE(state, path, throughput) = throughput_phase;
 
   if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
-INTEGRATOR_STATE_WRITE(state, path, pass_diffuse_weight) = one_spectrum();
-INTEGRATOR_STATE_WRITE(state, path, pass_glossy_weight) = zero_spectrum();
+if (INTEGRATOR_STATE(state, path, bounce) == 0) {
+  INTEGRATOR_STATE_WRITE(state, path, pass_diffuse_weight) = 
one_spectrum();
+  INTEGRATOR_STATE_WRITE(state, path, pass_glossy_weight) = 
zero_spectrum();
+}
   }
 
   /* Update path state */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2895c670865] master: Fix T103408: Cycles deadlock during GPU viewport rendering

2023-01-07 Thread Lukas Stockner
Commit: 2895c6708656b749b76331a907b539654ca125e1
Author: Lukas Stockner
Date:   Sat Jan 7 20:27:23 2023 +0100
Branches: master
https://developer.blender.org/rB2895c6708656b749b76331a907b539654ca125e1

Fix T103408: Cycles deadlock during GPU viewport rendering

This was caused by rB0d73d5c1a2, which releases the scene mutex during kernel
loading. However, the reset mutex was still held, which can cause a deadlock
if another thread tries to reset the session, since it will acquire the
released scene mutex and then wait for the reset mutex.

Turns out there's no point in keeping the reset mutex locked after the delayed
reset section, so now we just release it earlier, which resolves the deadlock.

===

M   intern/cycles/session/session.cpp

===

diff --git a/intern/cycles/session/session.cpp 
b/intern/cycles/session/session.cpp
index 9fa7f5da296..9e7e0e6e2a4 100644
--- a/intern/cycles/session/session.cpp
+++ b/intern/cycles/session/session.cpp
@@ -289,19 +289,24 @@ RenderWork Session::run_update_for_next_iteration()
   RenderWork render_work;
 
   thread_scoped_lock scene_lock(scene->mutex);
-  thread_scoped_lock reset_lock(delayed_reset_.mutex);
 
   bool have_tiles = true;
   bool switched_to_new_tile = false;
+  bool did_reset = false;
 
-  const bool did_reset = delayed_reset_.do_reset;
-  if (delayed_reset_.do_reset) {
-thread_scoped_lock buffers_lock(buffers_mutex_);
-do_delayed_reset();
+  /* Perform delayed reset if requested. */
+  {
+thread_scoped_lock reset_lock(delayed_reset_.mutex);
+if (delayed_reset_.do_reset) {
+  did_reset = true;
 
-/* After reset make sure the tile manager is at the first big tile. */
-have_tiles = tile_manager_.next();
-switched_to_new_tile = true;
+  thread_scoped_lock buffers_lock(buffers_mutex_);
+  do_delayed_reset();
+
+  /* After reset make sure the tile manager is at the first big tile. */
+  have_tiles = tile_manager_.next();
+  switched_to_new_tile = true;
+}
   }
 
   /* Update number of samples in the integrator.

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [00a20aec074] master: Fix T103403: Lightgroup passes can contain lighting on shadow catchers

2023-01-05 Thread Lukas Stockner
Commit: 00a20aec074c3a10a2d2e1142c14cc533c90a6b3
Author: Lukas Stockner
Date:   Fri Jan 6 02:32:03 2023 +0100
Branches: master
https://developer.blender.org/rB00a20aec074c3a10a2d2e1142c14cc533c90a6b3

Fix T103403: Lightgroup passes can contain lighting on shadow catchers

===

M   intern/cycles/kernel/film/light_passes.h

===

diff --git a/intern/cycles/kernel/film/light_passes.h 
b/intern/cycles/kernel/film/light_passes.h
index dbc527f2d5d..4cfd1aef43a 100644
--- a/intern/cycles/kernel/film/light_passes.h
+++ b/intern/cycles/kernel/film/light_passes.h
@@ -364,7 +364,9 @@ ccl_device_inline void 
film_write_emission_or_background_pass(
   }
 #  endif /* __DENOISING_FEATURES__ */
 
-  if (lightgroup != LIGHTGROUP_NONE && kernel_data.film.pass_lightgroup != 
PASS_UNUSED) {
+  const bool is_shadowcatcher = (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) != 0;
+  if (!is_shadowcatcher && lightgroup != LIGHTGROUP_NONE &&
+  kernel_data.film.pass_lightgroup != PASS_UNUSED) {
 film_write_pass_spectrum(buffer + kernel_data.film.pass_lightgroup + 3 * 
lightgroup,
  contribution);
   }
@@ -373,13 +375,12 @@ ccl_device_inline void 
film_write_emission_or_background_pass(
 /* Directly visible, write to emission or background pass. */
 pass_offset = pass;
   }
-  else if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
+  else if (is_shadowcatcher) {
 /* Don't write any light passes for shadow catcher, for easier
  * compositing back together of the combined pass. */
-if (path_flag & PATH_RAY_SHADOW_CATCHER_HIT) {
-  return;
-}
-
+return;
+  }
+  else if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
 if (path_flag & PATH_RAY_SURFACE_PASS) {
   /* Indirectly visible through reflection. */
   const Spectrum diffuse_weight = INTEGRATOR_STATE(state, path, 
pass_diffuse_weight);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bc5337a05a2] master: Fix T103507: Distant lights partially contribute to wrong lightgroup

2023-01-05 Thread Lukas Stockner
Commit: bc5337a05a22518051f71f26ac1948e327c2ebd9
Author: Lukas Stockner
Date:   Fri Jan 6 01:08:17 2023 +0100
Branches: master
https://developer.blender.org/rBbc5337a05a22518051f71f26ac1948e327c2ebd9

Fix T103507: Distant lights partially contribute to wrong lightgroup

The the BSDF-sampling half of MIS next-event estimation for distant lights was
using the background lightgroup instead of the lamp's lightgroup.

===

M   intern/cycles/kernel/integrator/shade_background.h

===

diff --git a/intern/cycles/kernel/integrator/shade_background.h 
b/intern/cycles/kernel/integrator/shade_background.h
index a3dec6a7c74..3c01a162d01 100644
--- a/intern/cycles/kernel/integrator/shade_background.h
+++ b/intern/cycles/kernel/integrator/shade_background.h
@@ -180,8 +180,7 @@ ccl_device_inline void 
integrate_distant_lights(KernelGlobals kg,
 
   /* Write to render buffer. */
   guiding_record_background(kg, state, light_eval, mis_weight);
-  film_write_surface_emission(
-  kg, state, light_eval, mis_weight, render_buffer, 
kernel_data.background.lightgroup);
+  film_write_surface_emission(kg, state, light_eval, mis_weight, 
render_buffer, ls.group);
 }
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4c295276f00] master: Cycles: Fix Metal kernel compilation

2022-12-20 Thread Lukas Stockner
Commit: 4c295276f001ff9729496fe024ddf96d5ab51d31
Author: Lukas Stockner
Date:   Wed Dec 21 04:24:22 2022 +0100
Branches: master
https://developer.blender.org/rB4c295276f001ff9729496fe024ddf96d5ab51d31

Cycles: Fix Metal kernel compilation

===

M   intern/cycles/kernel/integrator/init_from_bake.h

===

diff --git a/intern/cycles/kernel/integrator/init_from_bake.h 
b/intern/cycles/kernel/integrator/init_from_bake.h
index 308f708380f..0d25c6493fe 100644
--- a/intern/cycles/kernel/integrator/init_from_bake.h
+++ b/intern/cycles/kernel/integrator/init_from_bake.h
@@ -27,8 +27,8 @@ CCL_NAMESPACE_BEGIN
  * For triangles that are smaller than a texel, this might take too many 
attempts, so eventually
  * we just give up and don't jitter in that case.
  * This is not a particularly elegant solution, but it's probably the best we 
can do. */
-ccl_device_inline void bake_jitter_barycentric(float ,
-   float ,
+ccl_device_inline void bake_jitter_barycentric(ccl_private float ,
+   ccl_private float ,
float2 rand_filter,
const float dudx,
const float dudy,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7c85f11c427] master: Cycles: Change bake jittering to avoid issues with skinny triangles

2022-12-16 Thread Lukas Stockner
Commit: 7c85f11c427d0d07444d99c34acae5ece56d987e
Author: Lukas Stockner
Date:   Fri Dec 9 02:27:40 2022 +0100
Branches: master
https://developer.blender.org/rB7c85f11c427d0d07444d99c34acae5ece56d987e

Cycles: Change bake jittering to avoid issues with skinny triangles

Partially addresses T72011.

The problem here is that the previous barycentric clamping did not deal well
with skinny triangles and would end up generating "sub-pixel jittering"
locations that were actually >20 pixels away.

Differential Revision: https://developer.blender.org/D16727

===

M   intern/cycles/kernel/integrator/init_from_bake.h

===

diff --git a/intern/cycles/kernel/integrator/init_from_bake.h 
b/intern/cycles/kernel/integrator/init_from_bake.h
index cc3fbe3fe39..2a5bda50fb3 100644
--- a/intern/cycles/kernel/integrator/init_from_bake.h
+++ b/intern/cycles/kernel/integrator/init_from_bake.h
@@ -16,18 +16,40 @@
 
 CCL_NAMESPACE_BEGIN
 
-/* This helps with AA but it's not the real solution as it does not AA the 
geometry
- * but it's better than nothing, thus committed. */
-ccl_device_inline float bake_clamp_mirror_repeat(float u, float max)
+/* In order to perform anti-aliasing during baking, we jitter the input 
barycentric coordinates
+ * (which are for the center of the texel) within the texel.
+ * However, the baking code corrently doesn't support going to neighboring 
triangle, so if the
+ * jittered location falls outside of the input triangle, we need to bring it 
back in somehow.
+ * Clamping is a bad choice here since it can produce noticeable artifacts at 
triangle edges,
+ * but properly uniformly sampling the intersection of triangle and texel 
would be very
+ * performance-heavy, so cheat by just trying different jittering until we end 
up inside the
+ * triangle.
+ * For triangles that are smaller than a texel, this might take too many 
attempts, so eventually
+ * we just give up and don't jitter in that case.
+ * This is not a particularly elegant solution, but it's probably the best we 
can do. */
+ccl_device_inline void bake_jitter_barycentric(float ,
+   float ,
+   float2 rand_filter,
+   const float dudx,
+   const float dudy,
+   const float dvdx,
+   const float dvdy)
 {
-  /* use mirror repeat (like opengl texture) so that if the barycentric
-   * coordinate goes past the end of the triangle it is not always clamped
-   * to the same value, gives ugly patterns */
-  u /= max;
-  float fu = floorf(u);
-  u = u - fu;
-
-  return int)fu) & 1) ? 1.0f - u : u) * max;
+  for (int i = 0; i < 10; i++) {
+/* Offset UV according to differentials. */
+float jitterU = u + (rand_filter.x - 0.5f) * dudx + (rand_filter.y - 0.5f) 
* dudy;
+float jitterV = v + (rand_filter.x - 0.5f) * dvdx + (rand_filter.y - 0.5f) 
* dvdy;
+/* If this location is inside the triangle, return. */
+if (jitterU > 0.0f && jitterV > 0.0f && jitterU + jitterV < 1.0f) {
+  u = jitterU;
+  v = jitterV;
+  return;
+}
+/* Retry with new jitter value. */
+rand_filter = hash_float2_to_float2(rand_filter);
+  }
+  /* Retries exceeded, give up and just use center value. */
+  return;
 }
 
 /* Offset towards center of triangle to avoid ray-tracing precision issues. */
@@ -144,12 +166,7 @@ ccl_device bool integrator_init_from_bake(KernelGlobals kg,
   }
 
   /* Sub-pixel offset. */
-  if (sample > 0) {
-u = bake_clamp_mirror_repeat(u + dudx * (rand_filter.x - 0.5f) + dudy * 
(rand_filter.y - 0.5f),
- 1.0f);
-v = bake_clamp_mirror_repeat(v + dvdx * (rand_filter.x - 0.5f) + dvdy * 
(rand_filter.y - 0.5f),
- 1.0f - u);
-  }
+  bake_jitter_barycentric(u, v, rand_filter, dudx, dudy, dvdx, dvdy);
 
   /* Convert from Blender to Cycles/Embree/OptiX barycentric convention. */
   const float tmp = u;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [347c82be6db] master: Fix T98951: Shadow catcher objects are double-counting data passes

2022-12-16 Thread Lukas Stockner
Commit: 347c82be6dba0e35aca1e9fe2e417b256998786f
Author: Lukas Stockner
Date:   Sun Nov 27 02:40:11 2022 +0100
Branches: master
https://developer.blender.org/rB347c82be6dba0e35aca1e9fe2e417b256998786f

Fix T98951: Shadow catcher objects are double-counting data passes

Differential Revision: https://developer.blender.org/D16627

===

M   intern/cycles/kernel/film/data_passes.h
M   intern/cycles/kernel/film/denoising_passes.h

===

diff --git a/intern/cycles/kernel/film/data_passes.h 
b/intern/cycles/kernel/film/data_passes.h
index 3c538a74978..0ed5828ff30 100644
--- a/intern/cycles/kernel/film/data_passes.h
+++ b/intern/cycles/kernel/film/data_passes.h
@@ -33,6 +33,12 @@ ccl_device_inline void film_write_data_passes(KernelGlobals 
kg,
 return;
   }
 
+  /* Don't write data passes for paths that were split off for shadow catchers
+   * to avoid double-counting. */
+  if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) {
+return;
+  }
+
   const int flag = kernel_data.film.pass_flag;
 
   if (!(flag & PASS_ANY)) {
diff --git a/intern/cycles/kernel/film/denoising_passes.h 
b/intern/cycles/kernel/film/denoising_passes.h
index dfc21d787f2..0a32df19a3e 100644
--- a/intern/cycles/kernel/film/denoising_passes.h
+++ b/intern/cycles/kernel/film/denoising_passes.h
@@ -16,7 +16,8 @@ ccl_device_forceinline void 
film_write_denoising_features_surface(KernelGlobals
   ccl_global 
float *ccl_restrict
   
render_buffer)
 {
-  if (!(INTEGRATOR_STATE(state, path, flag) & PATH_RAY_DENOISING_FEATURES)) {
+  const uint32_t path_flag = INTEGRATOR_STATE(state, path, flag);
+  if (!(path_flag & PATH_RAY_DENOISING_FEATURES)) {
 return;
   }
 
@@ -25,6 +26,12 @@ ccl_device_forceinline void 
film_write_denoising_features_surface(KernelGlobals
 return;
   }
 
+  /* Don't write denoising passes for paths that were split off for shadow 
catchers
+   * to avoid double-counting. */
+  if (path_flag & PATH_RAY_SHADOW_CATCHER_PASS) {
+return;
+  }
+
   ccl_global float *buffer = film_pass_pixel_render_buffer(kg, state, 
render_buffer);
 
   if (kernel_data.film.pass_denoising_depth != PASS_UNUSED) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [389b0869292] blender-v3.4-release: Fix T103067: Regression: Workbench render crash in 3.4

2022-12-14 Thread Lukas Stockner
Commit: 389b0869292915166e0dfb38aa0c846b8b0b66f5
Author: Lukas Stockner
Date:   Tue Dec 13 01:45:52 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB389b0869292915166e0dfb38aa0c846b8b0b66f5

Fix T103067: Regression: Workbench render crash in 3.4

The workbench engine assumes that the Z pass exists, but didn't register it 
before.
Since rB3411a96e7493, this is mandatory.

===

M   source/blender/draw/engines/workbench/workbench_render.c

===

diff --git a/source/blender/draw/engines/workbench/workbench_render.c 
b/source/blender/draw/engines/workbench/workbench_render.c
index 931f6a2dc92..6f4ddbdb10e 100644
--- a/source/blender/draw/engines/workbench/workbench_render.c
+++ b/source/blender/draw/engines/workbench/workbench_render.c
@@ -214,4 +214,7 @@ void workbench_render(void *ved, RenderEngine *engine, 
RenderLayer *render_layer
 void workbench_render_update_passes(RenderEngine *engine, Scene *scene, 
ViewLayer *view_layer)
 {
   RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_COMBINED, 4, 
"RGBA", SOCK_RGBA);
+  if ((view_layer->passflag & SCE_PASS_Z) != 0) {
+RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_Z, 1, "Z", 
SOCK_FLOAT);
+  }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [485c5abedc3] master: Fix T103067: Regression: Workbench render crash in 3.4

2022-12-12 Thread Lukas Stockner
Commit: 485c5abedc3abda3118e5ba280243093a30b4143
Author: Lukas Stockner
Date:   Tue Dec 13 01:45:52 2022 +0100
Branches: master
https://developer.blender.org/rB485c5abedc3abda3118e5ba280243093a30b4143

Fix T103067: Regression: Workbench render crash in 3.4

The workbench engine assumes that the Z pass exists, but didn't register it 
before.
Since rB3411a96e7493, this is mandatory.

===

M   source/blender/draw/engines/workbench/workbench_render.c

===

diff --git a/source/blender/draw/engines/workbench/workbench_render.c 
b/source/blender/draw/engines/workbench/workbench_render.c
index c49578ff170..1ed391400b6 100644
--- a/source/blender/draw/engines/workbench/workbench_render.c
+++ b/source/blender/draw/engines/workbench/workbench_render.c
@@ -217,4 +217,7 @@ void workbench_render(void *ved, RenderEngine *engine, 
RenderLayer *render_layer
 void workbench_render_update_passes(RenderEngine *engine, Scene *scene, 
ViewLayer *view_layer)
 {
   RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_COMBINED, 4, 
"RGBA", SOCK_RGBA);
+  if ((view_layer->passflag & SCE_PASS_Z) != 0) {
+RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_Z, 1, "Z", 
SOCK_FLOAT);
+  }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [90055a1f2c1] blender-v3.3-release: Fix T101329: EXR 'JPG Preview' doesn't use color space anymore

2022-11-28 Thread Lukas Stockner
Commit: 90055a1f2c194769a403e6525d371bf6db40fa8a
Author: Lukas Stockner
Date:   Sat Oct 22 18:15:02 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB90055a1f2c194769a403e6525d371bf6db40fa8a

Fix T101329: EXR 'JPG Preview' doesn't use color space anymore

For the JPG preview, the only thing that was changed in the image
format was the format itself. However, the colorspace code now also
checks the bitdepth through BKE_image_format_is_byte, so the depth
needs to be explicitly set to 8-bit for the JPG preview output.

===

M   source/blender/blenkernel/intern/image_save.cc

===

diff --git a/source/blender/blenkernel/intern/image_save.cc 
b/source/blender/blenkernel/intern/image_save.cc
index c24731efb41..ce77564ecaf 100644
--- a/source/blender/blenkernel/intern/image_save.cc
+++ b/source/blender/blenkernel/intern/image_save.cc
@@ -959,6 +959,7 @@ bool BKE_image_render_write(ReportList *reports,
 /* optional preview images for exr */
 if (ok && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
   image_format.imtype = R_IMF_IMTYPE_JPEG90;
+  image_format.depth = R_IMF_CHAN_DEPTH_8;
 
   if (BLI_path_extension_check(filepath, ".exr")) {
 filepath[strlen(filepath) - 4] = 0;
@@ -1016,6 +1017,7 @@ bool BKE_image_render_write(ReportList *reports,
   /* optional preview images for exr */
   if (ok && is_exr_rr && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
 image_format.imtype = R_IMF_IMTYPE_JPEG90;
+image_format.depth = R_IMF_CHAN_DEPTH_8;
 
 if (BLI_path_extension_check(filepath, ".exr")) {
   filepath[strlen(filepath) - 4] = 0;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d5acb2b2fea] blender-v3.3-release: Fix T94136: Cycles: No Hair Shadows with Transparent BSDF

2022-11-28 Thread Lukas Stockner
Commit: d5acb2b2fea613a36943fdd40f8af919582fb5d0
Author: Lukas Stockner
Date:   Thu Oct 20 04:38:50 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rBd5acb2b2fea613a36943fdd40f8af919582fb5d0

Fix T94136: Cycles: No Hair Shadows with Transparent BSDF

===

M   intern/cycles/kernel/bvh/shadow_all.h
M   intern/cycles/kernel/bvh/util.h
M   intern/cycles/kernel/device/cpu/bvh.h
M   intern/cycles/kernel/device/metal/kernel.metal
M   intern/cycles/kernel/device/optix/bvh.h

===

diff --git a/intern/cycles/kernel/bvh/shadow_all.h 
b/intern/cycles/kernel/bvh/shadow_all.h
index 2ffe1496c72..b31ba479e4f 100644
--- a/intern/cycles/kernel/bvh/shadow_all.h
+++ b/intern/cycles/kernel/bvh/shadow_all.h
@@ -229,7 +229,7 @@ ccl_device_inline
   /* Always use baked shadow transparency for curves. */
   if (isect.type & PRIMITIVE_CURVE) {
 *r_throughput *= intersection_curve_shadow_transparency(
-kg, isect.object, isect.prim, isect.u);
+kg, isect.object, isect.prim, isect.type, isect.u);
 
 if (*r_throughput < CURVE_SHADOW_TRANSPARENCY_CUTOFF) {
   return true;
diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h
index a57703a8b8c..9ba787550c5 100644
--- a/intern/cycles/kernel/bvh/util.h
+++ b/intern/cycles/kernel/bvh/util.h
@@ -190,10 +190,8 @@ ccl_device_inline int 
intersection_find_attribute(KernelGlobals kg,
 /* Cut-off value to stop transparent shadow tracing when practically opaque. */
 #define CURVE_SHADOW_TRANSPARENCY_CUTOFF 0.001f
 
-ccl_device_inline float intersection_curve_shadow_transparency(KernelGlobals 
kg,
-   const int 
object,
-   const int prim,
-   const float u)
+ccl_device_inline float intersection_curve_shadow_transparency(
+KernelGlobals kg, const int object, const int prim, const int type, const 
float u)
 {
   /* Find attribute. */
   const int offset = intersection_find_attribute(kg, object, 
ATTR_STD_SHADOW_TRANSPARENCY);
@@ -204,7 +202,7 @@ ccl_device_inline float 
intersection_curve_shadow_transparency(KernelGlobals kg,
 
   /* Interpolate transparency between curve keys. */
   const KernelCurve kcurve = kernel_data_fetch(curves, prim);
-  const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(kcurve.type);
+  const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(type);
   const int k1 = k0 + 1;
 
   const float f0 = kernel_data_fetch(attributes_float, offset + k0);
diff --git a/intern/cycles/kernel/device/cpu/bvh.h 
b/intern/cycles/kernel/device/cpu/bvh.h
index d9267e1cd6d..2d7d8c2d704 100644
--- a/intern/cycles/kernel/device/cpu/bvh.h
+++ b/intern/cycles/kernel/device/cpu/bvh.h
@@ -252,7 +252,7 @@ ccl_device void kernel_embree_filter_occluded_func(const 
RTCFilterFunctionNArgum
   /* Always use baked shadow transparency for curves. */
   if (current_isect.type & PRIMITIVE_CURVE) {
 ctx->throughput *= intersection_curve_shadow_transparency(
-kg, current_isect.object, current_isect.prim, current_isect.u);
+kg, current_isect.object, current_isect.prim, current_isect.type, 
current_isect.u);
 
 if (ctx->throughput < CURVE_SHADOW_TRANSPARENCY_CUTOFF) {
   ctx->opaque_hit = true;
diff --git a/intern/cycles/kernel/device/metal/kernel.metal 
b/intern/cycles/kernel/device/metal/kernel.metal
index 5646c7446db..8b69ee025cd 100644
--- a/intern/cycles/kernel/device/metal/kernel.metal
+++ b/intern/cycles/kernel/device/metal/kernel.metal
@@ -228,7 +228,7 @@ bool metalrt_shadow_all_hit(constant KernelParamsMetal 
_params_metal,
   /* Always use baked shadow transparency for curves. */
   if (type & PRIMITIVE_CURVE) {
 float throughput = payload.throughput;
-throughput *= context.intersection_curve_shadow_transparency(nullptr, 
object, prim, u);
+throughput *= context.intersection_curve_shadow_transparency(nullptr, 
object, prim, type, u);
 payload.throughput = throughput;
 payload.num_hits += 1;
 
diff --git a/intern/cycles/kernel/device/optix/bvh.h 
b/intern/cycles/kernel/device/optix/bvh.h
index fb9907709ce..6d81b44660c 100644
--- a/intern/cycles/kernel/device/optix/bvh.h
+++ b/intern/cycles/kernel/device/optix/bvh.h
@@ -202,7 +202,7 @@ extern "C" __global__ void 
__anyhit__kernel_optix_shadow_all_hit()
   /* Always use baked shadow transparency for curves. */
   if (type & PRIMITIVE_CURVE) {
 float throughput = __uint_as_float(optixGetPayload_1());
-throughput *= intersection_curve_shadow_transparency(nullptr, object, 
prim, u);
+throughput *= intersection_curve_shadow_tra

[Bf-blender-cvs] [a51cc1120d6] principled-v2: Add initial version of Node Sections to keep sockets more manageable

2022-11-27 Thread Lukas Stockner
Commit: a51cc1120d6a0dd54ffc268d78f990b44297f32c
Author: Lukas Stockner
Date:   Mon Nov 28 02:13:36 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBa51cc1120d6a0dd54ffc268d78f990b44297f32c

Add initial version of Node Sections to keep sockets more manageable

Nodes can now have sections, and each socket can belong to a section.

These only affect how the node is displayed. In the Node Editor, the node first
shows all sockets without a section as usual, and following that the sections
are shown.
Each section can be expanded or collapsed, hiding the sockets inside.

Node links are still drawn if the socket they're going to is invisible -
in that case, they'll be going to the section header instead. However,
dragging them or connecting a link to a hidden socket via dragging is not
possible.

Node Groups can also have sections defined by the user, which are reflected
in their group input/output and in the group nodes that use them.

Note that the code for hidden nodes is still missing, I'm not sure yet how
to handle this there.
Also, we might eventually support drawing node properties (such as SSS type
for the principled BSDF) inside a section.
Similarly, especially for custom groups it might be nice to support nested
sections.

===

M   release/scripts/startup/bl_ui/space_node.py
M   source/blender/blenkernel/BKE_node.h
M   source/blender/blenkernel/intern/node.cc
M   source/blender/blenloader/intern/versioning_300.cc
M   source/blender/editors/space_node/node_draw.cc
M   source/blender/editors/space_node/node_edit.cc
M   source/blender/editors/space_node/node_intern.hh
M   source/blender/editors/space_node/node_ops.cc
M   source/blender/editors/space_node/node_templates.cc
M   source/blender/makesdna/DNA_node_types.h
M   source/blender/makesrna/intern/rna_nodetree.c
M   source/blender/nodes/NOD_node_declaration.hh
M   source/blender/nodes/intern/node_common.cc
M   source/blender/nodes/intern/node_declaration.cc
M   source/blender/nodes/intern/node_socket.cc
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git a/release/scripts/startup/bl_ui/space_node.py 
b/release/scripts/startup/bl_ui/space_node.py
index da94350b428..02b9f392c7a 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -813,6 +813,18 @@ class NODE_UL_interface_sockets(bpy.types.UIList):
 layout.template_node_socket(color=color)
 
 
+class NODE_UL_interface_sections(bpy.types.UIList):
+def draw_item(self, context, layout, _data, item, icon, _active_data, 
_active_propname, _index):
+socket = item
+
+if self.layout_type in {'DEFAULT', 'COMPACT'}:
+row = layout.row(align=True)
+
+row.prop(item, "name", text="", emboss=False, icon_value=icon)
+elif self.layout_type == 'GRID':
+layout.alignment = 'CENTER'
+
+
 class NodeTreeInterfacePanel(Panel):
 
 @classmethod
@@ -881,6 +893,7 @@ class NodeTreeInterfacePanel(Panel):
 layout.use_property_split = True
 layout.use_property_decorate = False
 
+layout.prop_search(active_socket, "section", tree, "sections")
 layout.prop(active_socket, "name")
 # Display descriptions only for Geometry Nodes, since it's only 
used in the modifier panel.
 if tree.type == 'GEOMETRY':
@@ -923,6 +936,37 @@ class 
NODE_PT_node_tree_interface_outputs(NodeTreeInterfacePanel):
 self.draw_socket_list(context, "OUT", "outputs", "active_output")
 
 
+class NODE_PT_node_tree_interface_sections(NodeTreeInterfacePanel):
+bl_space_type = 'NODE_EDITOR'
+bl_region_type = 'UI'
+bl_category = "Group"
+bl_label = "Sections"
+
+def draw(self, context):
+layout = self.layout
+
+snode = context.space_data
+tree = snode.edit_tree
+
+split = layout.row()
+
+split.template_list("NODE_UL_interface_sections", "", tree, 
"sections", tree, "active_section")
+
+ops_col = split.column()
+
+add_remove_col = ops_col.column(align=True)
+props = add_remove_col.operator("node.tree_section_add", icon='ADD', 
text="")
+props = add_remove_col.operator("node.tree_section_remove", 
icon='REMOVE', text="")
+
+ops_col.separator()
+
+up_down_col = ops_col.column(align=True)
+props = up_down_col.operator("node.tree_section_move", icon='TRIA_UP', 
text="")
+props.direction = 'UP'
+props = up_down_col.operator("node.tree_section_move", 
icon='TRIA_DOWN', text="&

[Bf-blender-cvs] [fc3be9d772a] principled-v2: Merge remote-tracking branch 'origin/master' into temp

2022-11-27 Thread Lukas Stockner
Commit: fc3be9d772a3feee120a5ae2b3b2560ffd80ae59
Author: Lukas Stockner
Date:   Mon Nov 28 02:10:33 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBfc3be9d772a3feee120a5ae2b3b2560ffd80ae59

Merge remote-tracking branch 'origin/master' into temp

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3c69e952be5] principled-v2: Cleanup: Formatting

2022-11-27 Thread Lukas Stockner
Commit: 3c69e952be53d7f73fe087421f68ccca1724518b
Author: Lukas Stockner
Date:   Mon Nov 28 01:29:21 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB3c69e952be53d7f73fe087421f68ccca1724518b

Cleanup: Formatting

===

M   source/blender/makesrna/intern/rna_nodetree.c
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
M   source/blender/nodes/shader/nodes/node_shader_wavelength.cc

===

diff --git a/source/blender/makesrna/intern/rna_nodetree.c 
b/source/blender/makesrna/intern/rna_nodetree.c
index ecbf8ad158a..64c2ab82e71 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -11951,10 +11951,8 @@ static void 
rna_def_node_socket_standard_types(BlenderRNA *brna)
 PROP_TIME_ABSOLUTE);
   rna_def_node_socket_float(
   brna, "NodeSocketFloatDistance", "NodeSocketInterfaceFloatDistance", 
PROP_DISTANCE);
-  rna_def_node_socket_float(brna,
-"NodeSocketFloatWavelength",
-"NodeSocketInterfaceFloatWavelength",
-PROP_WAVELENGTH);
+  rna_def_node_socket_float(
+  brna, "NodeSocketFloatWavelength", "NodeSocketInterfaceFloatWavelength", 
PROP_WAVELENGTH);
 
   rna_def_node_socket_int(brna, "NodeSocketInt", "NodeSocketInterfaceInt", 
PROP_NONE);
   rna_def_node_socket_int(
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc 
b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index 3b1fddcd4f9..fdd9cc59695 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -98,7 +98,11 @@ static void node_declare(NodeDeclarationBuilder )
   .subtype(PROP_FACTOR);
   /* TODO: Also add support to Principled v1? Would remain compatible and 
reduce differences. */
   b.add_input(N_("Clearcoat Tint")).default_value({1.0f, 1.0f, 
1.0f, 1.0f});
-  b.add_input(N_("Thin Film 
Thickness")).default_value(0.0f).min(0.0f).max(1.0f).subtype(PROP_WAVELENGTH);
+  b.add_input(N_("Thin Film Thickness"))
+  .default_value(0.0f)
+  .min(0.0f)
+  .max(1.0f)
+  .subtype(PROP_WAVELENGTH);
   b.add_input(N_("Thin Film 
IOR")).default_value(1.5f).min(1.0f).max(10.0f);
   /* TODO: Restrict min/max (e.g. 0.1 to 10) */
   
b.add_input(N_("IOR")).default_value(1.45f).min(0.0f).max(1000.0f);
diff --git a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc 
b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
index fb7bdf82ce5..dc33bc201e2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_wavelength.cc
@@ -9,7 +9,11 @@ namespace blender::nodes::node_shader_wavelength_cc {
 
 static void node_declare(NodeDeclarationBuilder )
 {
-  
b.add_input(N_("Wavelength")).default_value(500.0f).min(380.0f).max(780.0f).subtype(PROP_WAVELENGTH);
+  b.add_input(N_("Wavelength"))
+  .default_value(500.0f)
+  .min(380.0f)
+  .max(780.0f)
+  .subtype(PROP_WAVELENGTH);
   b.add_output(N_("Color"));
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e768b4bb76e] principled-v2: Another Metal compilation fix

2022-11-27 Thread Lukas Stockner
Commit: e768b4bb76e5231eb840ea9f609dbff78ff8aa85
Author: Lukas Stockner
Date:   Thu Nov 17 01:28:57 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBe768b4bb76e5231eb840ea9f609dbff78ff8aa85

Another Metal compilation fix

Thanks to @Alaska for providing this.

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 8e4e4345a14..d0b8a23e7a7 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -64,7 +64,7 @@ ccl_device_forceinline Spectrum reflection_color(ccl_private 
const MicrofacetBsd
 Spectrum F = zero_spectrum();
 float cosHL = dot(H, L);
 
-if (extra->dielectric != zero_spectrum()) {
+if (!is_zero(extra->dielectric)) {
   if (extra->thin_film_thickness == 0.0f) {
 /* Dielectric Fresnel, just basic IOR control. */
 F += extra->dielectric * fresnel_dielectric_cos(cosHL, bsdf->ior);
@@ -76,7 +76,7 @@ ccl_device_forceinline Spectrum reflection_color(ccl_private 
const MicrofacetBsd
   }
 }
 
-if (extra->metallic != zero_spectrum()) {
+if (!is_zero(extra->metallic)) {
   /* Fresnel term with edge color control, see fresnel_metallic for 
details. */
   F += extra->metallic * fresnel_metallic(extra->metal_base, 
extra->metal_edge_factor, cosHL);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0409b40f640] principled-v2: Merge remote-tracking branch 'origin/master' into principled-v2

2022-11-27 Thread Lukas Stockner
Commit: 0409b40f640ba9611489952c668119ad13025d68
Author: Lukas Stockner
Date:   Thu Nov 17 01:18:29 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB0409b40f640ba9611489952c668119ad13025d68

Merge remote-tracking branch 'origin/master' into principled-v2

===



===

diff --cc intern/cycles/kernel/osl/closures_setup.h
index 23f62ec2f3d,ceaf56ccba6..ded0b31ea97
--- a/intern/cycles/kernel/osl/closures_setup.h
+++ b/intern/cycles/kernel/osl/closures_setup.h
@@@ -211,13 -205,18 +206,11 @@@ ccl_device void osl_closure_microfacet_
bsdf->ior = closure->ior;
bsdf->T = closure->T;
  
-   static OSL::ustring u_ggx("ggx");
-   static OSL::ustring u_default("default");
- 
/* GGX */
-   if (closure->distribution == u_ggx || closure->distribution == u_default) {
+   if (closure->distribution == make_string("ggx", 11253504724482777663ull) ||
+   closure->distribution == make_string("default", 
4430693559278735917ull)) {
  if (!closure->refract) {
 -  if (closure->alpha_x == closure->alpha_y) {
 -/* Isotropic */
 -sd->flag |= bsdf_microfacet_ggx_isotropic_setup(bsdf);
 -  }
 -  else {
 -/* Anisotropic */
 -sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
 -  }
 +  sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
  }
  else {
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
diff --cc intern/cycles/util/math_float2.h
index 60686561f9b,ad806d0f08a..bf85c506753
--- a/intern/cycles/util/math_float2.h
+++ b/intern/cycles/util/math_float2.h
@@@ -170,17 -118,29 +118,24 @@@ ccl_device_inline bool is_zero(const fl
return (a.x == 0.0f && a.y == 0.0f);
  }
  
- ccl_device_inline float distance(const float2 , const float2 )
 -ccl_device_inline float average(const float2 a)
 -{
 -  return (a.x + a.y) * (1.0f / 2.0f);
 -}
 -
+ ccl_device_inline float dot(const float2 a, const float2 b)
  {
-   return len(a - b);
+   return a.x * b.x + a.y * b.y;
  }
+ #endif
  
- ccl_device_inline float dot(const float2 , const float2 )
+ ccl_device_inline float len(const float2 a)
  {
-   return a.x * b.x + a.y * b.y;
+   return sqrtf(dot(a, a));
  }
  
- ccl_device_inline float cross(const float2 , const float2 )
+ #if !defined(__KERNEL_METAL__)
+ ccl_device_inline float distance(const float2 a, const float2 b)
+ {
+   return len(a - b);
+ }
+ 
+ ccl_device_inline float cross(const float2 a, const float2 b)
  {
return (a.x * b.y - a.y * b.x);
  }
@@@ -227,12 -187,7 +182,12 @@@ ccl_device_inline float2 as_float2(cons
return make_float2(a.x, a.y);
  }
  
- ccl_device_inline float2 sqrt(const float2 )
++ccl_device_inline float2 sqrt(const float2 a)
 +{
 +  return make_float2(sqrtf(a.x), sqrtf(a.y));
 +}
 +
- ccl_device_inline float2 interp(const float2 , const float2 , float t)
+ ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
  {
return a + t * (b - a);
  }
@@@ -249,31 -204,11 +204,26 @@@ ccl_device_inline float2 floor(const fl
  
  #endif /* !__KERNEL_METAL__ */
  
- ccl_device_inline float len(const float2 a)
- {
-   return sqrtf(dot(a, a));
- }
- 
 +ccl_device_inline float len_squared(const float2 a)
 +{
 +  return dot(a, a);
 +}
 +
  ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float 
b)
  {
return (b != 0.0f) ? a / b : zero_float2();
  }
  
- ccl_device_inline float average(const float2 )
++ccl_device_inline float average(const float2 a)
 +{
 +  return (a.x + a.y) * (1.0f / 2.0f);
 +}
 +
- ccl_device_inline float2 sqr(const float2 )
++ccl_device_inline float2 sqr(const float2 a)
 +{
 +  return a * a;
 +}
 +
  CCL_NAMESPACE_END
  
  #endif /* __UTIL_MATH_FLOAT2_H__ */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1c27cc55294] blender-v3.4-release: Fix T92416: First render with unknown image colorspace looks different

2022-11-17 Thread Lukas Stockner
Commit: 1c27cc55294a88a9472c8a4f7727fce4ebce6f30
Author: Lukas Stockner
Date:   Tue Nov 8 22:05:20 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB1c27cc55294a88a9472c8a4f7727fce4ebce6f30

Fix T92416: First render with unknown image colorspace looks different

The issue here was that the Barbershop benchmark scene was saved with a
custom OCIO config, which leads to some textures having a unknown
colorspace when loading with a default installation.

This is automatically fixed by Blender during image loading, but since
Cycles queried the colorspace before actually loading the image, it
didn't get the updated value in the first render.

To fix this, just re-query the colorspace after the image is loaded.

Note that non-packed images still get treated as raw data if the
colorspace is unknown, but this is at least consistent and doesn't
magically change when you press F12 a second time.

Differential Revision: https://developer.blender.org/D16427

===

M   intern/cycles/blender/image.cpp

===

diff --git a/intern/cycles/blender/image.cpp b/intern/cycles/blender/image.cpp
index aea79ad60ad..ecea06fb1cd 100644
--- a/intern/cycles/blender/image.cpp
+++ b/intern/cycles/blender/image.cpp
@@ -72,6 +72,11 @@ bool BlenderImageLoader::load_metadata(const 
ImageDeviceFeatures &, ImageMetaDat
 metadata.colorspace = u_colorspace_raw;
   }
   else {
+/* In some cases (e.g. T94135), the colorspace setting in Blender gets 
updated as part of the
+ * metadata queries in this function, so update the colorspace setting 
here. */
+PointerRNA colorspace_ptr = b_image.colorspace_settings().ptr;
+metadata.colorspace = get_enum_identifier(colorspace_ptr, "name");
+
 if (metadata.channels == 1) {
   metadata.type = IMAGE_DATA_TYPE_BYTE;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [15b2b53b87a] blender-v3.3-release: Fix T92416: First render with unknown image colorspace looks different

2022-11-17 Thread Lukas Stockner
Commit: 15b2b53b87ab088e4869dfb0af991c9eb2be2d68
Author: Lukas Stockner
Date:   Tue Nov 8 22:05:20 2022 +0100
Branches: blender-v3.3-release
https://developer.blender.org/rB15b2b53b87ab088e4869dfb0af991c9eb2be2d68

Fix T92416: First render with unknown image colorspace looks different

The issue here was that the Barbershop benchmark scene was saved with a
custom OCIO config, which leads to some textures having a unknown
colorspace when loading with a default installation.

This is automatically fixed by Blender during image loading, but since
Cycles queried the colorspace before actually loading the image, it
didn't get the updated value in the first render.

To fix this, just re-query the colorspace after the image is loaded.

Note that non-packed images still get treated as raw data if the
colorspace is unknown, but this is at least consistent and doesn't
magically change when you press F12 a second time.

Differential Revision: https://developer.blender.org/D16427

===

M   intern/cycles/blender/image.cpp

===

diff --git a/intern/cycles/blender/image.cpp b/intern/cycles/blender/image.cpp
index aea79ad60ad..ecea06fb1cd 100644
--- a/intern/cycles/blender/image.cpp
+++ b/intern/cycles/blender/image.cpp
@@ -72,6 +72,11 @@ bool BlenderImageLoader::load_metadata(const 
ImageDeviceFeatures &, ImageMetaDat
 metadata.colorspace = u_colorspace_raw;
   }
   else {
+/* In some cases (e.g. T94135), the colorspace setting in Blender gets 
updated as part of the
+ * metadata queries in this function, so update the colorspace setting 
here. */
+PointerRNA colorspace_ptr = b_image.colorspace_settings().ptr;
+metadata.colorspace = get_enum_identifier(colorspace_ptr, "name");
+
 if (metadata.channels == 1) {
   metadata.type = IMAGE_DATA_TYPE_BYTE;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cacfaaa9a51] master: Fix T92416: First render with unknown image colorspace looks different

2022-11-16 Thread Lukas Stockner
Commit: cacfaaa9a5114752daca709a19e85bb0ee5c26d3
Author: Lukas Stockner
Date:   Tue Nov 8 22:05:20 2022 +0100
Branches: master
https://developer.blender.org/rBcacfaaa9a5114752daca709a19e85bb0ee5c26d3

Fix T92416: First render with unknown image colorspace looks different

The issue here was that the Barbershop benchmark scene was saved with a
custom OCIO config, which leads to some textures having a unknown
colorspace when loading with a default installation.

This is automatically fixed by Blender during image loading, but since
Cycles queried the colorspace before actually loading the image, it
didn't get the updated value in the first render.

To fix this, just re-query the colorspace after the image is loaded.

Note that non-packed images still get treated as raw data if the
colorspace is unknown, but this is at least consistent and doesn't
magically change when you press F12 a second time.

Differential Revision: https://developer.blender.org/D16427

===

M   intern/cycles/blender/image.cpp

===

diff --git a/intern/cycles/blender/image.cpp b/intern/cycles/blender/image.cpp
index aea79ad60ad..ecea06fb1cd 100644
--- a/intern/cycles/blender/image.cpp
+++ b/intern/cycles/blender/image.cpp
@@ -72,6 +72,11 @@ bool BlenderImageLoader::load_metadata(const 
ImageDeviceFeatures &, ImageMetaDat
 metadata.colorspace = u_colorspace_raw;
   }
   else {
+/* In some cases (e.g. T94135), the colorspace setting in Blender gets 
updated as part of the
+ * metadata queries in this function, so update the colorspace setting 
here. */
+PointerRNA colorspace_ptr = b_image.colorspace_settings().ptr;
+metadata.colorspace = get_enum_identifier(colorspace_ptr, "name");
+
 if (metadata.channels == 1) {
   metadata.type = IMAGE_DATA_TYPE_BYTE;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1eca4371979] master: Color Management: Parallelize ImBuf conversion to float

2022-11-08 Thread Lukas Stockner
Commit: 1eca4371979b45f6443446f8c7483aca8d9dc3b0
Author: Lukas Stockner
Date:   Tue Nov 8 20:39:40 2022 +0100
Branches: master
https://developer.blender.org/rB1eca4371979b45f6443446f8c7483aca8d9dc3b0

Color Management: Parallelize ImBuf conversion to float

Motivated by long loading times in T101969, reduces render preparation time 
from 14sec to 6sec.

Another possible improvement would be to use C++ and template based on OCIO vs. 
sRGB,
but moving the file to C++ seems nontrivial (and opens up the question whether 
ocio_capi
makes any sense then or we should just use OCIO directly) so I left it at a 
direct 1:1
parallelization of the existing code for now.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D16317

===

M   source/blender/imbuf/intern/colormanagement.c

===

diff --git a/source/blender/imbuf/intern/colormanagement.c 
b/source/blender/imbuf/intern/colormanagement.c
index 5e132826a4c..0678c224e6b 100644
--- a/source/blender/imbuf/intern/colormanagement.c
+++ b/source/blender/imbuf/intern/colormanagement.c
@@ -31,6 +31,7 @@
 #include "BLI_math_color.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
+#include "BLI_task.h"
 #include "BLI_threads.h"
 
 #include "BKE_appdir.h"
@@ -2249,6 +2250,43 @@ void IMB_colormanagement_imbuf_to_byte_texture(uchar 
*out_buffer,
   }
 }
 
+typedef struct ImbufByteToFloatData {
+  OCIO_ConstCPUProcessorRcPtr *processor;
+  int width;
+  int offset, stride;
+  const uchar *in_buffer;
+  float *out_buffer;
+  bool use_premultiply;
+} ImbufByteToFloatData;
+
+static void imbuf_byte_to_float_cb(void *__restrict userdata,
+   const int y,
+   const TaskParallelTLS *__restrict 
UNUSED(tls))
+{
+  ImbufByteToFloatData *data = userdata;
+
+  const size_t in_offset = data->offset + y * data->stride;
+  const size_t out_offset = y * data->width;
+  const uchar *in = data->in_buffer + in_offset * 4;
+  float *out = data->out_buffer + out_offset * 4;
+
+  /* Convert to scene linear, to sRGB and premultiply. */
+  for (int x = 0; x < data->width; x++, in += 4, out += 4) {
+float pixel[4];
+rgba_uchar_to_float(pixel, in);
+if (data->processor) {
+  OCIO_cpuProcessorApplyRGB(data->processor, pixel);
+}
+else {
+  srgb_to_linearrgb_v3_v3(pixel, pixel);
+}
+if (data->use_premultiply) {
+  mul_v3_fl(pixel, pixel[3]);
+}
+copy_v4_v4(out, pixel);
+  }
+}
+
 void IMB_colormanagement_imbuf_to_float_texture(float *out_buffer,
 const int offset_x,
 const int offset_y,
@@ -2307,34 +2345,25 @@ void IMB_colormanagement_imbuf_to_float_texture(float 
*out_buffer,
 const uchar *in_buffer = (uchar *)ibuf->rect;
 const bool use_premultiply = IMB_alpha_affects_rgb(ibuf) && 
store_premultiplied;
 
-/* TODO(brecht): make this multi-threaded, or at least process in batches. 
*/
 OCIO_ConstCPUProcessorRcPtr *processor = (ibuf->rect_colorspace) ?
  
colorspace_to_scene_linear_cpu_processor(
  ibuf->rect_colorspace) :
  NULL;
 
-for (int y = 0; y < height; y++) {
-  const size_t in_offset = (offset_y + y) * ibuf->x + offset_x;
-  const size_t out_offset = y * width;
-  const uchar *in = in_buffer + in_offset * 4;
-  float *out = out_buffer + out_offset * 4;
-
-  /* Convert to scene linear, to sRGB and premultiply. */
-  for (int x = 0; x < width; x++, in += 4, out += 4) {
-float pixel[4];
-rgba_uchar_to_float(pixel, in);
-if (processor) {
-  OCIO_cpuProcessorApplyRGB(processor, pixel);
-}
-else {
-  srgb_to_linearrgb_v3_v3(pixel, pixel);
-}
-if (use_premultiply) {
-  mul_v3_fl(pixel, pixel[3]);
-}
-copy_v4_v4(out, pixel);
-  }
-}
+ImbufByteToFloatData data = {
+.processor = processor,
+.width = width,
+.offset = offset_y * ibuf->x + offset_x,
+.stride = ibuf->x,
+.in_buffer = in_buffer,
+.out_buffer = out_buffer,
+.use_premultiply = use_premultiply,
+};
+
+TaskParallelSettings settings;
+BLI_parallel_range_settings_defaults();
+settings.use_threading = (height > 128);
+BLI_task_parallel_range(0, height, , imbuf_byte_to_float_cb, 
);
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cbe28509c74] principled-v2: Fix base unit for wavelengths

2022-10-31 Thread Lukas Stockner
Commit: cbe28509c7434f9095eabe9e3481cea6544e660e
Author: Lukas Stockner
Date:   Mon Oct 31 20:25:54 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBcbe28509c7434f9095eabe9e3481cea6544e660e

Fix base unit for wavelengths

===

M   source/blender/blenkernel/intern/unit.c

===

diff --git a/source/blender/blenkernel/intern/unit.c 
b/source/blender/blenkernel/intern/unit.c
index e84c7a3ccd4..0d109130b4d 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -341,7 +341,7 @@ static struct bUnitDef buWavelengthLenDef[] = {
   {"picometer",  "picometers",  "pm",  NULL, "Picometers", NULL, 1e-3f, 
0.0, B_UNIT_DEF_NONE},
   NULL_UNIT,
 };
-static const struct bUnitCollection buWavelengthLenCollection = 
{buWavelengthLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buWavelengthLenDef)};
+static const struct bUnitCollection buWavelengthLenCollection = 
{buWavelengthLenDef, 2, 0, UNIT_COLLECTION_LENGTH(buWavelengthLenDef)};
 
 /* clang-format on */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [619250f7f1d] principled-v2: Attempt to fix Metal compilation issues

2022-10-31 Thread Lukas Stockner
Commit: 619250f7f1de9358461881a02327cd5e7b8f8754
Author: Lukas Stockner
Date:   Mon Oct 31 20:16:42 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB619250f7f1de9358461881a02327cd5e7b8f8754

Attempt to fix Metal compilation issues

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/closure/bsdf_principled_sheen.h
M   intern/cycles/kernel/closure/bsdf_util.h
M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/util/math_float2.h
M   intern/cycles/util/math_float3.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 13729df2985..8e4e4345a14 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -60,7 +60,7 @@ ccl_device_forceinline Spectrum reflection_color(ccl_private 
const MicrofacetBsd
 return make_spectrum(f);
   }
   else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID) {
-MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
+ccl_private MicrofacetExtrav2 *extra = (ccl_private MicrofacetExtrav2 
*)bsdf->extra;
 Spectrum F = zero_spectrum();
 float cosHL = dot(H, L);
 
@@ -173,7 +173,7 @@ ccl_device int 
bsdf_microfacet_ggx_fresnel_v2_setup(KernelGlobals kg,
   bsdf->alpha_x = saturatef(bsdf->alpha_x);
   bsdf->alpha_y = saturatef(bsdf->alpha_y);
 
-  MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
+  ccl_private MicrofacetExtrav2 *extra = (ccl_private MicrofacetExtrav2 
*)bsdf->extra;
 
   if (metallic > 0.0f) {
 Spectrum metal_Fss = fresnel_metallic_Fss(extra->metal_base, 
extra->metal_edge_factor);
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 160a9a8b76c..ad986eb15a6 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -68,7 +68,7 @@ ccl_device int 
bsdf_microfacet_multi_ggx_glass_fresnel_setup(KernelGlobals kg,
 
 ccl_device_inline Spectrum glass_fresnel(ccl_private const MicrofacetBsdf 
*bsdf,
  float cosTheta,
- float *reflect_pdf)
+ ccl_private float *reflect_pdf)
 {
   if (bsdf->T.x > 0.0f) {
 Spectrum F = fresnel_dielectric_thin_film(cosTheta, bsdf->ior, bsdf->T.y, 
bsdf->T.x);
@@ -155,7 +155,7 @@ ccl_device Spectrum 
bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Mi
   float reflect_pdf;
   Spectrum F = glass_fresnel(bsdf, cosMO, _pdf);
 
-  if (F == one_spectrum()) {
+  if (is_one(F)) {
 /* TIR */
 *pdf = 0.0f;
 return zero_spectrum();
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 4a41155b3f7..661a8e87d33 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -162,7 +162,7 @@ ccl_device_inline float dielectric_fresnel_Fss(float eta)
  */
 
 ccl_device_inline void fresnel_dielectric_complex(
-float cosTheta1, float eta1, float eta2, float2 *R, float2 *phi)
+float cosTheta1, float eta1, float eta2, ccl_private float2 *R, 
ccl_private float2 *phi)
 {
 
   float sinTheta1Sqr = 1.0f - sqr(cosTheta1);
diff --git a/intern/cycles/kernel/closure/bsdf_principled_sheen.h 
b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
index 949a6f8f567..6374c86d010 100644
--- a/intern/cycles/kernel/closure/bsdf_principled_sheen.h
+++ b/intern/cycles/kernel/closure/bsdf_principled_sheen.h
@@ -73,7 +73,7 @@ ccl_device_inline float sheen_v2_lambda(float mu, float w)
 }
 
 ccl_device_inline Spectrum
-sheen_v2_eval(float3 N, float3 V, float3 L, float3 H, float r, float *pdf)
+sheen_v2_eval(float3 N, float3 V, float3 L, float3 H, float r, ccl_private 
float *pdf)
 {
   float cosNH = dot(N, H), cosNV = dot(N, V), cosNL = dot(N, L);
 
diff --git a/intern/cycles/kernel/closure/bsdf_util.h 
b/intern/cycles/kernel/closure/bsdf_util.h
index 47a37a43c87..b1c5a9375dd 100644
--- a/intern/cycles/kernel/closure/bsdf_util.h
+++ b/intern/cycles/kernel/closure/bsdf_util.h
@@ -105,7 +105,7 @@ ccl_device float schlick_fresnel(float u)
  */
 ccl_device Spectrum metallic_edge_factor(Spectrum F0, Spectrum F82)
 {
-  if (F82 == one_spectrum()) {
+  if (is_one(F82)) {
 return zero_spectrum();
   }
 
diff --git a/intern/cycles/kernel/svm/closure_principled.h 
b/intern/cycles/kernel/svm/closure_principled.h
index 115d4aff12d..db1d850f5a2 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycl

[Bf-blender-cvs] [b96c86ec371] principled-v2: Remove redundant angle check

2022-10-30 Thread Lukas Stockner
Commit: b96c86ec3710a276b83b9255d4c1a06bcdd1330b
Author: Lukas Stockner
Date:   Sun Oct 30 13:47:42 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBb96c86ec3710a276b83b9255d4c1a06bcdd1330b

Remove redundant angle check

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index a60f24965d0..13729df2985 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -264,13 +264,8 @@ ccl_device Spectrum 
bsdf_microfacet_ggx_eval_reflect(ccl_private const Microface
  const float cosNI)
 {
   float alpha2 = alpha_x * alpha_y;
-  if (!(cosNI > 0 && cosNO > 0)) {
-*pdf = 0.0f;
-return zero_spectrum();
-  }
-
   /* Ensure that both direction are in the upper hemisphere */
-  if (cosNI <= 0 || cosNO <= 0) {
+  if (!(cosNI > 0 && cosNO > 0)) {
 *pdf = 0.0f;
 return zero_spectrum();
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [31012b5417b] principled-v2: Formatting fixes

2022-10-30 Thread Lukas Stockner
Commit: 31012b5417b5603f8f6487740a6c5685b483bc71
Author: Lukas Stockner
Date:   Sun Oct 30 14:50:28 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB31012b5417b5603f8f6487740a6c5685b483bc71

Formatting fixes

===

M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git 
a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl 
b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
index ec9ff909940..8f91ded3f82 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
@@ -47,8 +47,8 @@ void node_bsdf_principled(vec4 base_color,
   float weight,
   const float do_diffuse,
   const float do_clearcoat,
-  //const float do_refraction,
-  //const float do_multiscatter,
+  // const float do_refraction,
+  // const float do_multiscatter,
   float do_sss,
   out Closure result)
 {
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc 
b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index c33440a9edc..ad0b545aabf 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -98,10 +98,7 @@ static void node_declare(NodeDeclarationBuilder )
   .subtype(PROP_FACTOR);
   /* TODO: Also add support to Principled v1? Would remain compatible and 
reduce differences. */
   b.add_input(N_("Clearcoat Tint")).default_value({1.0f, 1.0f, 
1.0f, 1.0f});
-  b.add_input(N_("Thin Film Thickness"))
-  .default_value(0.0f)
-  .min(0.0f)
-  .max(1.0f);
+  b.add_input(N_("Thin Film 
Thickness")).default_value(0.0f).min(0.0f).max(1.0f);
   b.add_input(N_("Thin Film 
IOR")).default_value(1.5f).min(1.0f).max(10.0f);
   /* TODO: Restrict min/max (e.g. 0.1 to 10) */
   
b.add_input(N_("IOR")).default_value(1.45f).min(0.0f).max(1000.0f);
@@ -227,16 +224,17 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial 
*mat,
 
   GPU_material_flag_set(mat, flag);
 
-  return GPU_stack_link(mat,
-node,
-"node_bsdf_principled",
-in,
-out,
-GPU_constant(_diffuse_f),
-GPU_constant(_clear_f),
-//GPU_constant(_refract_f),
-//GPU_constant(_multi_scatter),  // TODO: Disabled 
because of GLSL argument limit
-GPU_uniform(_sss));
+  return GPU_stack_link(
+  mat,
+  node,
+  "node_bsdf_principled",
+  in,
+  out,
+  GPU_constant(_diffuse_f),
+  GPU_constant(_clear_f),
+  // GPU_constant(_refract_f),
+  // GPU_constant(_multi_scatter),  // TODO: Disabled because of GLSL 
argument limit
+  GPU_uniform(_sss));
 }
 
 static void node_shader_update_principled(bNodeTree *ntree, bNode *node)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [513b4b44239] principled-v2: Rework temporary Eevee fix

2022-10-30 Thread Lukas Stockner
Commit: 513b4b44239b98f274e62e5941b18eddad36995e
Author: Lukas Stockner
Date:   Sun Oct 30 15:08:00 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB513b4b44239b98f274e62e5941b18eddad36995e

Rework temporary Eevee fix

===

M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git 
a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl 
b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
index 8f91ded3f82..0833809cc42 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
@@ -15,13 +15,11 @@ float principled_sheen(float NV)
 
 void node_bsdf_principled(vec4 base_color,
   float subsurface,
-  float subsurface_scale_TODO,
   vec3 subsurface_radius,
   vec4 subsurface_color,
   float subsurface_ior,
   float subsurface_anisotropy,
   float metallic,
-  vec4 metallic_edge_TODO,
   float specular,
   float specular_tint,
   float roughness,
@@ -29,12 +27,8 @@ void node_bsdf_principled(vec4 base_color,
   float anisotropic_rotation,
   float sheen,
   float sheen_tint,
-  float sheen_roughness_TODO,
   float clearcoat,
   float clearcoat_roughness,
-  vec4 clearcoat_tint_TODO,
-  float thin_film_thickness_TODO,
-  float thin_film_ior_TODO,
   float ior,
   float transmission,
   float transmission_roughness,
@@ -47,15 +41,11 @@ void node_bsdf_principled(vec4 base_color,
   float weight,
   const float do_diffuse,
   const float do_clearcoat,
-  // const float do_refraction,
-  // const float do_multiscatter,
+  const float do_refraction,
+  const float do_multiscatter,
   float do_sss,
   out Closure result)
 {
-  // TODO: Disabled because of GLSL argument limit
-  float do_multiscatter = 0.0f;
-  float do_refraction = 0.0f;
-
   /* Match cycles. */
   metallic = clamp(metallic, 0.0, 1.0);
   transmission = clamp(transmission, 0.0, 1.0) * (1.0 - metallic);
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc 
b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index ad0b545aabf..13165bf11be 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -149,30 +149,37 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial 
*mat,
GPUNodeStack *in,
GPUNodeStack *out)
 {
+  in[2].type = GPU_NONE;
+  in[8].type = GPU_NONE;
+  in[16].type = GPU_NONE;
+  in[19].type = GPU_NONE;
+  in[20].type = GPU_NONE;
+  in[21].type = GPU_NONE;
+
   /* Normals */
-  if (!in[22].link) {
-GPU_link(mat, "world_normals_get", [22].link);
+  if (!in[28].link) {
+GPU_link(mat, "world_normals_get", [28].link);
   }
 
   /* Clearcoat Normals */
-  if (!in[23].link) {
-GPU_link(mat, "world_normals_get", [23].link);
+  if (!in[29].link) {
+GPU_link(mat, "world_normals_get", [29].link);
   }
 
 #if 0 /* Not used at the moment. */
   /* Tangents */
-  if (!in[24].link) {
+  if (!in[30].link) {
 GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
-GPU_link(mat, "tangent_orco_z", orco, [24].link);
-GPU_link(mat, "node_tangent", in[24].link, [24].link);
+GPU_link(mat, "tangent_orco_z", orco, [30].link);
+GPU_link(mat, "node_tangent", in[30].link, [30].link);
   }
 #endif
 
-  bool use_diffuse = socket_not_one(6) && socket_not_one(17);
+  bool use_diffuse = socket_not_one(7) && socket_not_one(23);
   bool use_subsurf = socket_not_zero(1) && use_diffuse;
-  bool use_refract = socket_not_one(6) && socket_not_zero(17);
-  bool use_transparency = socket_not_one(21);
-  bool use_clear = socket_not_zero(14);
+  bool use_refract = socket_not_one(7) && socket_not_zero(23);
+  bool use_transparency = socket_not_one(27);

[Bf-blender-cvs] [45cd4c9c829] principled-v2: Add Wavelength unit type for Thin Film and Wavelength sockets

2022-10-30 Thread Lukas Stockner
Commit: 45cd4c9c829c903c2596c6c2054ebda5e31f7c44
Author: Lukas Stockner
Date:   Sun Oct 30 16:33:15 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB45cd4c9c829c903c2596c6c2054ebda5e31f7c44

Add Wavelength unit type for Thin Film and Wavelength sockets

===

M   source/blender/blenkernel/BKE_unit.h
M   source/blender/blenkernel/intern/node.cc
M   source/blender/blenkernel/intern/scene.cc
M   source/blender/blenkernel/intern/unit.c
M   source/blender/makesrna/RNA_types.h
M   source/blender/makesrna/intern/makesrna.c
M   source/blender/makesrna/intern/rna_nodetree.c
M   source/blender/makesrna/intern/rna_rna.c
M   source/blender/nodes/intern/node_socket.cc
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
M   source/blender/nodes/shader/nodes/node_shader_wavelength.cc
M   source/blender/python/intern/bpy_utils_units.c

===

diff --git a/source/blender/blenkernel/BKE_unit.h 
b/source/blender/blenkernel/BKE_unit.h
index f051335fc41..8cf92d07037 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -110,7 +110,8 @@ enum {
   B_UNIT_CAMERA = 10,
   B_UNIT_POWER = 11,
   B_UNIT_TEMPERATURE = 12,
-  B_UNIT_TYPE_TOT = 13,
+  B_UNIT_WAVELENGTH = 13,
+  B_UNIT_TYPE_TOT = 14,
 };
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index 3e3a8355f98..a4437e8058e 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1748,6 +1748,8 @@ const char *nodeStaticSocketType(int type, int subtype)
   return "NodeSocketFloatTimeAbsolute";
 case PROP_DISTANCE:
   return "NodeSocketFloatDistance";
+case PROP_WAVELENGTH:
+  return "NodeSocketFloatWavelength";
 case PROP_NONE:
 default:
   return "NodeSocketFloat";
@@ -1825,6 +1827,8 @@ const char *nodeStaticSocketInterfaceType(int type, int 
subtype)
   return "NodeSocketInterfaceFloatTimeAbsolute";
 case PROP_DISTANCE:
   return "NodeSocketInterfaceFloatDistance";
+case PROP_WAVELENGTH:
+  return "NodeSocketInterfaceFloatWavelength";
 case PROP_NONE:
 default:
   return "NodeSocketInterfaceFloat";
diff --git a/source/blender/blenkernel/intern/scene.cc 
b/source/blender/blenkernel/intern/scene.cc
index bd26075f81f..7cf7de1a593 100644
--- a/source/blender/blenkernel/intern/scene.cc
+++ b/source/blender/blenkernel/intern/scene.cc
@@ -3079,6 +3079,7 @@ double BKE_scene_unit_scale(const UnitSettings *unit, 
const int unit_type, doubl
 case B_UNIT_MASS:
   return value * pow(unit->scale_length, 3);
 case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal 
lens! See T42026. */
+case B_UNIT_WAVELENGTH:
 default:
   return value;
   }
diff --git a/source/blender/blenkernel/intern/unit.c 
b/source/blender/blenkernel/intern/unit.c
index f7ea4c81fbf..e84c7a3ccd4 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -42,6 +42,7 @@
 #define UN_SC_CM0.01f
 #define UN_SC_MM0.001f
 #define UN_SC_UM0.01f
+#define UN_SC_NM0.1f
 
 #define UN_SC_MI1609.344f
 #define UN_SC_FUR   201.168f
@@ -332,6 +333,16 @@ static struct bUnitDef buImperialTempDef[] = {
 static struct bUnitCollection buImperialTempCollection = {
 buImperialTempDef, 1, 0, UNIT_COLLECTION_LENGTH(buImperialTempDef)};
 
+/* Wavelengths (separate from distance and Camera to be scene-independent and 
to have nm as base unit). */
+static struct bUnitDef buWavelengthLenDef[] = {
+  {"millimeter", "millimeters", "mm",  NULL, "Millimeters",NULL, 1e6f,  
0.0, B_UNIT_DEF_NONE},
+  {"micrometer", "micrometers", "µm",  "um", "Micrometers",NULL, 1e3f,  
0.0, B_UNIT_DEF_NONE},
+  {"nanometer",  "nanometers",  "nm",  NULL, "Nanometers", NULL, 1.0f,  
0.0, B_UNIT_DEF_NONE}, /* Base unit. */
+  {"picometer",  "picometers",  "pm",  NULL, "Picometers", NULL, 1e-3f, 
0.0, B_UNIT_DEF_NONE},
+  NULL_UNIT,
+};
+static const struct bUnitCollection buWavelengthLenCollection = 
{buWavelengthLenDef, 3, 0, UNIT_COLLECTION_LENGTH(buWavelengthLenDef)};
+
 /* clang-format on */
 
 #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / 
sizeof(void *)) - 1)
@@ -363,7 +374,8 @@ static const struct bUnitCollection 
*bUnitSystems[][B_UNIT_TYPE_TOT] = {
  ,
  ,
  ,
- },
+ ,
+ },
 /* Imperial. */
 {NULL,
  ,
@@ -377,7 +389,8 @@ static const s

[Bf-blender-cvs] [e59a4130910] principled-v2: Fix broken thin film refraction for base IOR=1

2022-10-30 Thread Lukas Stockner
Commit: e59a413091010c80963959095dc6b774a3c513fc
Author: Lukas Stockner
Date:   Sun Oct 30 15:39:31 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBe59a413091010c80963959095dc6b774a3c513fc

Fix broken thin film refraction for base IOR=1

===

M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index c6ab2e385e0..160a9a8b76c 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -132,6 +132,12 @@ ccl_device Spectrum 
bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Mi
 return zero_spectrum();
   }
 
+  /* For IOR very close to 1.0, the transmission component becomes singular. */
+  if (fabsf(bsdf->ior - 1.0f) < 1e-5f) {
+*pdf = 0.0f;
+return zero_spectrum();
+  }
+
   float eta = bsdf->ior;
   float3 ht = -(eta * omega_in + I);
   float3 m = normalize(ht);
@@ -299,20 +305,30 @@ ccl_device int 
bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
   return LABEL_NONE;
 }
 
-label = LABEL_TRANSMIT | LABEL_GLOSSY;
+label = LABEL_TRANSMIT;
 *omega_in = T;
 *pdf = 1.0f - reflect_pdf;
 *eval = one_spectrum() - F;
 
+/* For IOR very close to 1.0, the transmission component becomes singular. 
*/
+label |= (fabsf(bsdf->ior - 1.0f) < 1e-5f) ? LABEL_SINGULAR : LABEL_GLOSSY;
+
 /* Compute microfacet common term. */
 float cosMI = dot(m, *omega_in);
 float Ht2 = sqr(bsdf->ior * cosMI + cosMO);
 common = D * fabsf(cosMI * cosMO) * sqr(bsdf->ior) / (cosNO * Ht2);
   }
 
-  float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
-  *eval *= common / (1 + lambdaO + lambdaI);
-  *pdf *= common / (1 + lambdaO);
+  if (label & LABEL_GLOSSY) {
+float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
+*eval *= common / (1 + lambdaO + lambdaI);
+*pdf *= common / (1 + lambdaO);
+  }
+  else {
+/* Specular case, just return some high number for MIS */
+*eval *= 1e6f;
+*pdf *= 1e6f;
+  }
 
   if (bsdf->type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID) {
 *eval *= do_reflect ? reflection_color(bsdf, *omega_in, m) : 
bsdf->extra->color;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8715b550f89] principled-v2: Disable Thin Film controls with Principled v1

2022-10-30 Thread Lukas Stockner
Commit: 8715b550f898f0273def8e0025e484e2030ce72e
Author: Lukas Stockner
Date:   Sun Oct 30 13:47:59 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB8715b550f898f0273def8e0025e484e2030ce72e

Disable Thin Film controls with Principled v1

===

M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc 
b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index 6282fb99fa6..c33440a9edc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -276,7 +276,9 @@ static void node_shader_update_principled(bNodeTree *ntree, 
bNode *node)
  "Subsurface Scale",
  "Clearcoat Tint",
  "Sheen Roughness",
- "Metallic Edge")) {
+ "Metallic Edge",
+ "Thin Film Thickness",
+ "Thin Film IOR")) {
   /* Sockets exclusive to Principled v2. */
   nodeSetSocketAvailability(ntree, sock, is_v2);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5a230fccc58] principled-v2: Fix NaNs with thin film on glass

2022-10-30 Thread Lukas Stockner
Commit: 5a230fccc588be922246b6920d8b4aaea1de0e19
Author: Lukas Stockner
Date:   Sun Oct 30 14:50:00 2022 +0100
Branches: principled-v2
https://developer.blender.org/rB5a230fccc588be922246b6920d8b4aaea1de0e19

Fix NaNs with thin film on glass

===

M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 68688ffa922..c6ab2e385e0 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -138,6 +138,14 @@ ccl_device Spectrum 
bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Mi
   float cosMO = dot(m, I);
   float cosMI = dot(m, omega_in);
 
+  kernel_assert(dot(m, N) >= 0.0f);  // TODO: Is this assert to aggressive?
+  /* Avoid backfacing microfacets.
+   * TODO: Also check this in sample? */
+  if (cosMO < 0.0f || cosMI > 0.0f) {
+*pdf = 0.0f;
+return zero_spectrum();
+  }
+
   float reflect_pdf;
   Spectrum F = glass_fresnel(bsdf, cosMO, _pdf);
 
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 733084a3228..4a41155b3f7 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -231,12 +231,14 @@ ccl_device_inline float3 
fresnel_dielectric_thin_film(float cosThetaOuter,
 I += Cm.x * SmSh + Cm.y * SmPh;
   }
 
+  kernel_assert(isfinite_safe(I));
+
   /* CIE XYZ -> sRGB incl. whitepoint adaption E -> D65
* TODO: Somehow properly handle color management here?
* Does OCIO have anything for handling reflectances? */
-  return make_float3(3.17482107f, -0.98993255f, 0.06047909f) * I.x +
- make_float3(-1.6974f, 1.94998695f, -0.20891802f) * I.y +
- make_float3(-0.47752224f, 0.04004475f, 1.14851336f) * I.z;
+  return saturate(make_float3(3.17482107f, -0.98993255f, 0.06047909f) * I.x +
+  make_float3(-1.6974f, 1.94998695f, -0.20891802f) * I.y +
+  make_float3(-0.47752224f, 0.04004475f, 1.14851336f) * I.z);
 }
 
 CCL_NAMESPACE_END

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [dc415a8dc94] principled-v2: Fix missing GGX Fresnel v2 closure evaluation

2022-10-30 Thread Lukas Stockner
Commit: dc415a8dc94ac2a0c0917e7757cd51eeca1b862e
Author: Lukas Stockner
Date:   Sun Oct 30 13:59:21 2022 +0100
Branches: principled-v2
https://developer.blender.org/rBdc415a8dc94ac2a0c0917e7757cd51eeca1b862e

Fix missing GGX Fresnel v2 closure evaluation

===

M   intern/cycles/kernel/closure/bsdf.h

===

diff --git a/intern/cycles/kernel/closure/bsdf.h 
b/intern/cycles/kernel/closure/bsdf.h
index b0be0c80ee7..f2626f33b1b 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -549,6 +549,7 @@ ccl_device_inline
   break;
 case CLOSURE_BSDF_MICROFACET_GGX_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
+case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
   eval = bsdf_microfacet_ggx_eval(sc, sd->I, omega_in, pdf);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a8869c97646] principled-v2: Implement initial version of iridescence, not on metals yet

2022-10-29 Thread Lukas Stockner
Commit: a8869c97646b6cc253cd23088f52149de0f87c4b
Author: Lukas Stockner
Date:   Sun Oct 30 00:14:03 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBa8869c97646b6cc253cd23088f52149de0f87c4b

Implement initial version of iridescence, not on metals yet

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/scene/shader_nodes.cpp
M   intern/cycles/scene/shader_nodes.h
M   intern/cycles/util/math_float2.h
M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 35f94d8615d..ee8f95f2e17 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -290,7 +290,8 @@ static float precompute_ggx_dielectric_E(float rough, float 
mu, float eta, float
   float E = microfacet_ggx_E(mu, rough), E_avg = microfacet_ggx_E_avg(rough);
   float Fss = dielectric_fresnel_Fss(eta);
   float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
-  extra.dielectric = 1.0f + Fms * ((1.0f - E) / E);
+  extra.dielectric = make_spectrum(1.0f + Fms * ((1.0f - E) / E));
+  extra.thin_film_thickness = 0.0f;
 
   float3 omega_in;
   Spectrum eval;
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 64e3ce7ba50..a60f24965d0 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -20,8 +20,10 @@ typedef struct MicrofacetExtra {
 typedef struct MicrofacetExtrav2 {
   /* Metallic fresnel control */
   Spectrum metal_base, metal_edge_factor;
-  Spectrum metallic;
-  float dielectric;
+  /* Albedo scaling */
+  Spectrum metallic, dielectric;
+  /* Thin film controls */
+  float thin_film_thickness, thin_film_ior;
 } MicrofacetExtrav2;
 
 // TODO probably remove this for the final code
@@ -62,9 +64,16 @@ ccl_device_forceinline Spectrum reflection_color(ccl_private 
const MicrofacetBsd
 Spectrum F = zero_spectrum();
 float cosHL = dot(H, L);
 
-if (extra->dielectric > 0.0f) {
-  /* Dielectric Fresnel, just basic IOR control. */
-  F += make_spectrum(extra->dielectric * fresnel_dielectric_cos(cosHL, 
bsdf->ior));
+if (extra->dielectric != zero_spectrum()) {
+  if (extra->thin_film_thickness == 0.0f) {
+/* Dielectric Fresnel, just basic IOR control. */
+F += extra->dielectric * fresnel_dielectric_cos(cosHL, bsdf->ior);
+  }
+  else {
+F += extra->dielectric *
+ fresnel_dielectric_thin_film(
+ cosHL, bsdf->ior, extra->thin_film_ior, 
extra->thin_film_thickness);
+  }
 }
 
 if (extra->metallic != zero_spectrum()) {
@@ -110,19 +119,6 @@ ccl_device_inline Spectrum 
microfacet_ggx_albedo_scaling(KernelGlobals kg,
   /* TODO: Ensure that increase in weight does not mess up glossy color, 
albedo etc. passes */
 }
 
-ccl_device_inline float microfacet_ggx_albedo_scaling_float(KernelGlobals kg,
-ccl_private const 
MicrofacetBsdf *bsdf,
-ccl_private const 
ShaderData *sd,
-const float Fss)
-{
-  // TOOD: Deduplicate somehow?
-  float mu = dot(sd->I, bsdf->N);
-  float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
-  float E = microfacet_ggx_E(kg, mu, rough), E_avg = microfacet_ggx_E_avg(kg, 
rough);
-  float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
-  return 1.0f + Fms * ((1.0f - E) / E);
-}
-
 ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
 {
   bsdf->extra = NULL;
@@ -190,12 +186,11 @@ ccl_device int 
bsdf_microfacet_ggx_fresnel_v2_setup(KernelGlobals kg,
   }
 
   if (dielectric > 0.0f) {
-float dielectric_Fss = dielectric_fresnel_Fss(bsdf->ior);
-extra->dielectric = dielectric *
-microfacet_ggx_albedo_scaling_float(kg, bsdf, sd, 
dielectric_Fss);
+Spectrum dielectric_Fss = 
make_spectrum(dielectric_fresnel_Fss(bsdf->ior));  // TODO
+extra->dielectric = dielectric * microfacet_ggx_albedo_scaling(kg, bsdf, 
sd, dielectric_Fss);
   }
   else {
-extra->dielectric = 0.0f;
+extra->dielectric = zero_spectrum();
   }
 
   bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID;
@@ -230,7 +225,8 @@ ccl_device int 
bsdf_microfacet_ggx_clearcoat_v2_setup(KernelGlobal

[Bf-blender-cvs] [cacd74fb3f5] principled-v2: Merge v1 and v2 clearcoat closures

2022-10-29 Thread Lukas Stockner
Commit: cacd74fb3f545cfac183995a73ad5bee49d4e706
Author: Lukas Stockner
Date:   Sun Oct 30 00:14:03 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBcacd74fb3f545cfac183995a73ad5bee49d4e706

Merge v1 and v2 clearcoat closures

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf.h
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/svm/types.h

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index b55246e9e91..322a9631491 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -71,7 +71,7 @@ static float precompute_clearcoat_E(float rough, float mu, 
float u1, float u2)
 {
   MicrofacetBsdf bsdf;
   bsdf.weight = one_float3();
-  bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID;
+  bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID;
   bsdf.sample_weight = 1.0f;
   bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
   bsdf.alpha_x = bsdf.alpha_y = sqr(rough);
diff --git a/intern/cycles/kernel/closure/bsdf.h 
b/intern/cycles/kernel/closure/bsdf.h
index fbda52d74c4..b0be0c80ee7 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -171,7 +171,6 @@ ccl_device_inline int bsdf_sample(KernelGlobals kg,
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
   label = bsdf_microfacet_ggx_sample(
   sc, Ng, sd->I, randu, randv, eval, omega_in, pdf, sampled_roughness, 
eta);
@@ -324,7 +323,6 @@ ccl_device_inline void bsdf_roughness_eta(const 
KernelGlobals kg,
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID: {
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const 
MicrofacetBsdf *)sc;
   *roughness = make_float2(bsdf->alpha_x, bsdf->alpha_y);
@@ -439,7 +437,6 @@ ccl_device_inline int bsdf_label(const KernelGlobals kg,
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID:
 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID: {
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const 
MicrofacetBsdf *)sc;
   label = (bsdf->alpha_x * bsdf->alpha_y <= 1e-7f) ? LABEL_REFLECT | 
LABEL_SINGULAR :
@@ -552,9 +549,7 @@ ccl_device_inline
   break;
 case CLOSURE_BSDF_MICROFACET_GGX_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
   eval = bsdf_microfacet_ggx_eval(sc, sd->I, omega_in, pdf);
   break;
@@ -631,7 +626,6 @@ ccl_device void bsdf_blur(KernelGlobals kg, ccl_private 
ShaderClosure *sc, float
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
-case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID:
 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index e0b513b69f1..64e3ce7ba50 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -54,24 +54,25 @@ ccl_device_forceinline Spectrum 
reflection_color(ccl_private const MicrofacetBsd
 return interpolate_fresnel_color(L, H, bsdf->ior, bsdf->extra->cspec0);
   }
   else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID) {
-return interpolate_fresnel_color(L, H, bsdf->ior, make_spectrum(0.04f));
-  }
-  else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID) {
 float f = fresnel_dielectric_cos(dot(H, L), bsdf->ior);
 return make_spectrum(f);
   }
   else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID) {
 MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
+Spectrum F = zero_spectrum();
 float cosHL = dot(H, L);
-/* Metallic Fresnel: Kinda Schlick-Fresnel-like with configurable F0 and 
F90
- * as well as falloff control. F90=white and falloff=0.2 gives classic 
Schlick Fresnel.
-  

[Bf-blender-cvs] [4b21e2f0ae5] principled-v2: Fix Precomputation code

2022-10-29 Thread Lukas Stockner
Commit: 4b21e2f0ae52f3c4b6039a505d8bd99f2f054fd8
Author: Lukas Stockner
Date:   Sun Oct 30 00:14:03 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB4b21e2f0ae52f3c4b6039a505d8bd99f2f054fd8

Fix Precomputation code

===

M   intern/cycles/app/cycles_precompute.cpp

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 322a9631491..35f94d8615d 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -15,10 +15,56 @@
 #include "kernel/closure/bsdf_microfacet_glass.h"
 #include "kernel/closure/bsdf_principled_sheen.h"
 
+#include "scene/shader.tables"
+
 #include 
 
 CCL_NAMESPACE_BEGIN
 
+/* TODO: Is there a way to not duplicate the regular microfacet_ggx_E
+ * without setting up an entire fake KernelGlobals? */
+static float lookup_table_read(const float *table, float x, int size)
+{
+  x = clamp(x * size - 0.5f, 0.0f, (float)size);
+
+  int index = min(float_to_int(x), size - 1);
+  int nindex = min(index + 1, size - 1);
+  float t = x - index;
+
+  float data0 = table[index];
+  if (t == 0.0f)
+return data0;
+
+  float data1 = table[nindex];
+  return mix(data0, data1, t);
+}
+
+static float lookup_table_read_2D(const float *table, float x, float y, int 
xsize, int ysize)
+{
+  y = clamp(y * ysize - 0.5f, 0.0f, (float)ysize);
+
+  int index = min(float_to_int(y), ysize - 1);
+  int nindex = min(index + 1, ysize - 1);
+  float t = y - index;
+
+  float data0 = lookup_table_read(table + xsize * nindex, x, xsize);
+  if (t == 0.0f)
+return data0;
+
+  float data1 = lookup_table_read(table + xsize * nindex, x, xsize);
+  return mix(data0, data1, t);
+}
+
+static float microfacet_ggx_E(float mu, float rough)
+{
+  return lookup_table_read_2D(_ggx_E[0][0], mu, 1 - rough, 32, 32);
+}
+
+static float microfacet_ggx_E_avg(float rough)
+{
+  return lookup_table_read(table_ggx_E_avg, 1 - rough, 32);
+}
+
 /* From PBRT: core/montecarlo.h */
 inline float VanDerCorput(uint32_t n, uint32_t scramble)
 {
@@ -47,19 +93,16 @@ static float precompute_sheen_E(float rough, float mu, 
float u1, float u2)
   bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
   bsdf.roughness = sqr(rough);
 
-  float3 eval, omega_in, domega_in_dx, domega_in_dy;
+  float3 omega_in;
+  Spectrum eval;
   float pdf = 0.0f;
   bsdf_principled_sheen_sample((ShaderClosure *),
make_float3(0.0f, 0.0f, 1.0f),
make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
-   zero_float3(),
-   zero_float3(),
u1,
u2,
,
_in,
-   _in_dx,
-   _in_dy,
);
   if (pdf != 0.0f) {
 return clamp(average(eval) / pdf, 0.0f, 1e5f);
@@ -86,20 +129,20 @@ static float precompute_clearcoat_E(float rough, float mu, 
float u1, float u2)
   float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
   float albedo_scale = 1.0f + Fms * ((1.0f - E) / E);
 
-  float3 eval, omega_in, domega_in_dx, domega_in_dy;
-  float pdf = 0.0f;
+  float3 omega_in;
+  Spectrum eval;
+  float pdf = 0.0f, sampled_eta;
+  float2 sampled_roughness;
   bsdf_microfacet_ggx_sample((ShaderClosure *),
  make_float3(0.0f, 0.0f, 1.0f),
  make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
- zero_float3(),
- zero_float3(),
  u1,
  u2,
  ,
  _in,
- _in_dx,
- _in_dy,
- );
+ ,
+ _roughness,
+ _eta);
   if (pdf != 0.0f) {
 /* Encode relative to macrosurface Fresnel, saves resolution.
  * TODO: Worth the extra evaluation? */
@@ -120,20 +163,20 @@ static float precompute_ggx_E(float rough, float mu, 
float u1, float u2)
   bsdf.extra = nullptr;
   bsdf.T = make_float3(1.0f, 0.0f, 0.0f);
 
-  float3 eval, omega_in, domega_in_dx, domega_in_dy;
-  float pdf = 0.0f;
+  float3 omega_in;
+  Spectrum eval;
+  float pdf = 0.0f, sampled_eta;
+  float2 sampled_roughness;
   bsdf_microfacet_ggx_sample((ShaderClosure *),
  make_float3(0.0f, 0.0f, 1.0f),
  make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
- zero_float3(),
- zero_float3(),
  u1,
  u2,
  ,
   

[Bf-blender-cvs] [0fdeb3abf6a] principled-v2: Temporary workaround to stop Eevee from crashing

2022-10-29 Thread Lukas Stockner
Commit: 0fdeb3abf6a7499e4ffa3b30b3e75a30ed20fb19
Author: Lukas Stockner
Date:   Sun Oct 30 00:14:03 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB0fdeb3abf6a7499e4ffa3b30b3e75a30ed20fb19

Temporary workaround to stop Eevee from crashing

===

M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git 
a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl 
b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
index d186d61ee40..ec9ff909940 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
@@ -47,11 +47,15 @@ void node_bsdf_principled(vec4 base_color,
   float weight,
   const float do_diffuse,
   const float do_clearcoat,
-  const float do_refraction,
-  const float do_multiscatter,
+  //const float do_refraction,
+  //const float do_multiscatter,
   float do_sss,
   out Closure result)
 {
+  // TODO: Disabled because of GLSL argument limit
+  float do_multiscatter = 0.0f;
+  float do_refraction = 0.0f;
+
   /* Match cycles. */
   metallic = clamp(metallic, 0.0, 1.0);
   transmission = clamp(transmission, 0.0, 1.0) * (1.0 - metallic);
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc 
b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
index a803819826b..6282fb99fa6 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc
@@ -234,8 +234,8 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat,
 out,
 GPU_constant(_diffuse_f),
 GPU_constant(_clear_f),
-GPU_constant(_refract_f),
-GPU_constant(_multi_scatter),
+//GPU_constant(_refract_f),
+//GPU_constant(_multi_scatter),  // TODO: Disabled 
because of GLSL argument limit
 GPU_uniform(_sss));
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bc37e8d8399] principled-v2: Merge remote-tracking branch 'origin/master' into principled-v2

2022-10-29 Thread Lukas Stockner
Commit: bc37e8d8399eef686b71341aa90eced9bc117786
Author: Lukas Stockner
Date:   Sat Oct 29 23:41:21 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBbc37e8d8399eef686b71341aa90eced9bc117786

Merge remote-tracking branch 'origin/master' into principled-v2

===



===

diff --cc intern/cycles/app/cycles_precompute.cpp
index 26be3f16f3a,000..6f9d9601b1e
mode 100644,00..100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@@ -1,401 -1,0 +1,400 @@@
 +#include "util/math.h"
 +#include "util/string.h"
 +#include "util/system.h"
 +
 +#include "util/hash.h"
 +#include "util/task.h"
 +
 +#include "kernel/device/cpu/compat.h"
 +#include "kernel/device/cpu/globals.h"
 +
 +#include "kernel/sample/lcg.h"
 +#include "kernel/sample/mapping.h"
 +
 +#include "kernel/closure/bsdf_microfacet.h"
 +#include "kernel/closure/bsdf_microfacet_glass.h"
 +#include "kernel/closure/bsdf_principled_sheen.h"
 +
 +#include 
 +
 +CCL_NAMESPACE_BEGIN
 +
 +/* From PBRT: core/montecarlo.h */
 +inline float VanDerCorput(uint32_t n, uint32_t scramble)
 +{
 +  n = (n << 16) | (n >> 16);
 +  n = ((n & 0x00ff00ff) << 8) | ((n & 0xff00ff00) >> 8);
 +  n = ((n & 0x0f0f0f0f) << 4) | ((n & 0xf0f0f0f0) >> 4);
 +  n = ((n & 0x) << 2) | ((n & 0x) >> 2);
 +  n = ((n & 0x) << 1) | ((n & 0x) >> 1);
 +  n ^= scramble;
 +  return ((n >> 8) & 0xff) / float(1 << 24);
 +}
 +inline float Sobol2(uint32_t n, uint32_t scramble)
 +{
 +  for (uint32_t v = 1 << 31; n != 0; n >>= 1, v ^= v >> 1)
 +if (n & 0x1)
 +  scramble ^= v;
 +  return ((scramble >> 8) & 0xff) / float(1 << 24);
 +}
 +
 +static float precompute_sheen_E(float rough, float mu, float u1, float u2)
 +{
 +  PrincipledSheenBsdf bsdf;
 +  bsdf.weight = one_float3();
 +  bsdf.type = CLOSURE_BSDF_PRINCIPLED_SHEEN_V2_ID;
 +  bsdf.sample_weight = 1.0f;
 +  bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
 +  bsdf.roughness = sqr(rough);
 +
 +  float3 eval, omega_in, domega_in_dx, domega_in_dy;
 +  float pdf = 0.0f;
 +  bsdf_principled_sheen_sample((ShaderClosure *),
 +   make_float3(0.0f, 0.0f, 1.0f),
 +   make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
 +   zero_float3(),
 +   zero_float3(),
 +   u1,
 +   u2,
 +   ,
 +   _in,
 +   _in_dx,
 +   _in_dy,
 +   );
 +  if (pdf != 0.0f) {
 +return clamp(average(eval) / pdf, 0.0f, 1e5f);
 +  }
 +  return 0.0f;
 +}
 +
 +static float precompute_clearcoat_E(float rough, float mu, float u1, float u2)
 +{
 +  MicrofacetBsdf bsdf;
 +  bsdf.weight = one_float3();
 +  bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_V2_ID;
 +  bsdf.sample_weight = 1.0f;
 +  bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
 +  bsdf.alpha_x = bsdf.alpha_y = sqr(rough);
 +  bsdf.ior = 1.5f;
 +  bsdf.extra = nullptr;
 +  bsdf.T = make_float3(1.0f, 0.0f, 0.0f);
 +
 +  /* Account for the albedo scaling that the closure performs.
 +   * Dependency warning - this relies on the ggx_E and ggx_E_avg lookup 
tables! */
 +  float E = microfacet_ggx_E(mu, rough), E_avg = microfacet_ggx_E_avg(rough);
 +  float Fss = dielectric_fresnel_Fss(1.5f);
 +  float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
 +  float albedo_scale = 1.0f + Fms * ((1.0f - E) / E);
 +
 +  float3 eval, omega_in, domega_in_dx, domega_in_dy;
 +  float pdf = 0.0f;
 +  bsdf_microfacet_ggx_sample((ShaderClosure *),
 + make_float3(0.0f, 0.0f, 1.0f),
 + make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
 + zero_float3(),
 + zero_float3(),
 + u1,
 + u2,
 + ,
 + _in,
 + _in_dx,
 + _in_dy,
 + );
 +  if (pdf != 0.0f) {
 +/* Encode relative to macrosurface Fresnel, saves resolution.
 + * TODO: Worth the extra evaluation? */
 +return albedo_scale * (average(eval) / pdf) / fresnel_dielectric_cos(mu, 
1.5f);
 +  }
 +  return 0.0f;
 +}
 +
 +static float precompute_ggx_E(float rough, float mu, float u1, float u2)
 +{
 +  MicrofacetBsdf bsdf;
 +  bsdf.weight = one_float3();
 +  bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_ID;
 +  bsdf.sample_w

[Bf-blender-cvs] [f4b61c696b7] principled-v2: Simplify v1 Fresnel computation

2022-10-29 Thread Lukas Stockner
Commit: f4b61c696b740cf173d1ba7decc3f776955cf02b
Author: Lukas Stockner
Date:   Sun Oct 30 00:14:03 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBf4b61c696b740cf173d1ba7decc3f776955cf02b

Simplify v1 Fresnel computation

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/closure/bsdf_util.h

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 6f9d9601b1e..b55246e9e91 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -213,7 +213,7 @@ static float precompute_ggx_dielectric_E(float rough, float 
mu, float eta, float
  * is an issue since there are changes in that range at higher roughnesses.
  * Therefore, the remapping is blended with the identity function for a 
compromise.
  */
-float F0 = fresnel_dielectric_cos(1.0f, eta);
+float F0 = fresnel_dielectric_F0(eta);
 auto get_remap = [eta, F0](float x) {
   return mix(x, inverse_lerp(1.0f, F0, fresnel_dielectric_cos(x, eta)), 
0.5f);
 };
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index b531c192e03..8a0902f054b 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -106,7 +106,7 @@ ccl_device_forceinline float 
microfacet_ggx_dielectric_E(KernelGlobals kg,
kernel_data.tables.ggx_dielectric_E_offset;
 
   float macro_fresnel = fresnel_dielectric_cos(mu, ior);
-  float F0 = fresnel_dielectric_cos(1.0f, ior);
+  float F0 = fresnel_dielectric_F0(ior);
   float x = mix(mu, inverse_lerp(1.0f, F0, macro_fresnel), 0.5f);
   float y = 1 - rough;
   float z = sqrtf(0.5f * ((inv_table ? 1.0f / ior : ior) - 1.0f));
diff --git a/intern/cycles/kernel/closure/bsdf_util.h 
b/intern/cycles/kernel/closure/bsdf_util.h
index 13de4ac15b0..47a37a43c87 100644
--- a/intern/cycles/kernel/closure/bsdf_util.h
+++ b/intern/cycles/kernel/closure/bsdf_util.h
@@ -71,6 +71,13 @@ ccl_device float fresnel_dielectric_cos(float cosi, float 
eta)
   return 1.0f;  // TIR(no refracted component)
 }
 
+/* Returns F0 (perpendicular) reflectivity for given eta,
+ * equivalent to fresnel_dielectric_cos(1.0f, eta). */
+ccl_device float fresnel_dielectric_F0(float eta)
+{
+  return sqr((eta - 1.0f) / (eta + 1.0f));
+}
+
 ccl_device Spectrum fresnel_conductor(float cosi, const Spectrum eta, const 
Spectrum k)
 {
   Spectrum cosi2 = make_spectrum(sqr(cosi));
@@ -124,11 +131,9 @@ ccl_device_forceinline Spectrum 
interpolate_fresnel_color(Spectrum L,
 {
   /* Compute the real Fresnel term and remap it from real_F0...1 to F0...1.
* We could also just use actual Schlick fresnel (mix(F0, 1, (1-cosI)^5)) 
here. */
-  float real_F0 = fresnel_dielectric_cos(1.0f, ior);
-  float F0_norm = 1.0f / (1.0f - real_F0);
-  float FH = (fresnel_dielectric_cos(dot(L, H), ior) - real_F0) * F0_norm;
-
-  return mix(F0, one_spectrum(), FH);
+  float real_F0 = fresnel_dielectric_F0(ior);
+  float mixFactor = inverse_lerp(real_F0, 1.0f, fresnel_dielectric_cos(dot(L, 
H), ior));
+  return mix(F0, one_spectrum(), mixFactor);
 }
 
 ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [30774f01cdc] blender-v3.3-release: Fix T98672: Noise texture shows incorrect behaviour for large scales

2022-10-26 Thread Lukas Stockner
Commit: 30774f01cdcc0855a444715940d318984c10f27e
Author: Lukas Stockner
Date:   Sun Oct 16 01:57:44 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB30774f01cdcc0855a444715940d318984c10f27e

Fix T98672: Noise texture shows incorrect behaviour for large scales

This was a floating point precision issue - or, to be more precise,
an issue with how Cycles split floats into the integer and fractional
parts for Perlin noise.
For coordinates below -2^24, the integer could be wrong, leading to
the fractional part being outside of 0-1 range, which breaks all sorts
of other things. 2^24 sounds like a lot, but due to how the detail
octaves work, it's not that hard to reach when combined with a large
scale.

Since this code is originally based on OSL, I checked if they changed
it in the meantime, and sure enough, there's a fix for it:
https://github.com/OpenImageIO/oiio/commit/5c9dc68391e9

So, this basically just ports over that change to Cycles.

The original code mentions being faster, but as pointed out in the
linked commit, the performance impact is actually irrelevant.

I also checked in a simple scene with eight Noise textures at
detail 15 (with >90% of render time being spent on the noise), and
the render time went from 13.06sec to 13.05sec. So, yeah, no issue.

===

M   intern/cycles/util/math.h
M   intern/cycles/util/math_float3.h
M   intern/cycles/util/ssef.h

===

diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h
index f6400cb879f..b3bff9bccf2 100644
--- a/intern/cycles/util/math.h
+++ b/intern/cycles/util/math.h
@@ -417,15 +417,11 @@ ccl_device_inline int floor_to_int(float f)
   return float_to_int(floorf(f));
 }
 
-ccl_device_inline int quick_floor_to_int(float x)
-{
-  return float_to_int(x) - ((x < 0) ? 1 : 0);
-}
-
 ccl_device_inline float floorfrac(float x, ccl_private int *i)
 {
-  *i = quick_floor_to_int(x);
-  return x - *i;
+  float f = floorf(x);
+  *i = float_to_int(f);
+  return x - f;
 }
 
 ccl_device_inline int ceil_to_int(float f)
diff --git a/intern/cycles/util/math_float3.h b/intern/cycles/util/math_float3.h
index c408eadf195..eec7122b9dc 100644
--- a/intern/cycles/util/math_float3.h
+++ b/intern/cycles/util/math_float3.h
@@ -535,18 +535,6 @@ ccl_device_inline float3 pow(float3 v, float e)
   return make_float3(powf(v.x, e), powf(v.y, e), powf(v.z, e));
 }
 
-ccl_device_inline int3 quick_floor_to_int3(const float3 a)
-{
-#ifdef __KERNEL_SSE__
-  int3 b = int3(_mm_cvttps_epi32(a.m128));
-  int3 isneg = int3(_mm_castps_si128(_mm_cmplt_ps(a.m128, _mm_set_ps1(0.0f;
-  /* Unsaturated add 0x is the same as subtract -1. */
-  return b + isneg;
-#else
-  return make_int3(quick_floor_to_int(a.x), quick_floor_to_int(a.y), 
quick_floor_to_int(a.z));
-#endif
-}
-
 ccl_device_inline bool isfinite_safe(float3 v)
 {
   return isfinite_safe(v.x) && isfinite_safe(v.y) && isfinite_safe(v.z);
diff --git a/intern/cycles/util/ssef.h b/intern/cycles/util/ssef.h
index ad435e65b01..1e2bfa90354 100644
--- a/intern/cycles/util/ssef.h
+++ b/intern/cycles/util/ssef.h
@@ -5,6 +5,8 @@
 #ifndef __UTIL_SSEF_H__
 #define __UTIL_SSEF_H__
 
+#include 
+
 #include "util/ssei.h"
 
 CCL_NAMESPACE_BEGIN
@@ -534,6 +536,12 @@ __forceinline const ssef ceil(const ssef )
   return _mm_round_ps(a, _MM_FROUND_TO_POS_INF);
 #endif
 }
+#  else
+/* Non-SSE4.1 fallback, needed for floorfrac. */
+__forceinline const ssef floor(const ssef )
+{
+  return _mm_set_ps(floorf(a.f[3]), floorf(a.f[2]), floorf(a.f[1]), 
floorf(a.f[0]));
+}
 #  endif
 
 __forceinline ssei truncatei(const ssef )
@@ -541,20 +549,11 @@ __forceinline ssei truncatei(const ssef )
   return _mm_cvttps_epi32(a.m128);
 }
 
-/* This is about 25% faster than straightforward floor to integer conversion
- * due to better pipelining.
- *
- * Unsaturated add 0x (a < 0) is the same as subtract -1.
- */
-__forceinline ssei floori(const ssef )
-{
-  return truncatei(a) + cast((a < 0.0f).m128);
-}
-
 __forceinline ssef floorfrac(const ssef , ssei *i)
 {
-  *i = floori(x);
-  return x - ssef(*i);
+  ssef f = floor(x);
+  *i = truncatei(f);
+  return x - f;
 }
 
 


___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1492f566c83] blender-v3.3-release: Fix T99450: Animated Holdout not updating on frame change

2022-10-26 Thread Lukas Stockner
Commit: 1492f566c83c7c7a631ecc8b0c9113981fda75c5
Author: Lukas Stockner
Date:   Sat Oct 15 22:51:21 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB1492f566c83c7c7a631ecc8b0c9113981fda75c5

Fix T99450: Animated Holdout not updating on frame change

Problem here was that layer_collection_objects_sync wasn't called when
the holdout property is updated due to frame change, so the changed
visibility flag was never applied to ob->base_flag.

Turns out there's no real reason to handle the per-object holdout
property through the layer system. So, instead of merging both the
layer holdout and object holdout into base_flag and checking that
from the render engines, only handle the layer holdout (which can't
be animated, so no issue here) through base_flag and explicitly also
check the object holdout in the render engines.

===

M   source/blender/blenkernel/intern/layer.c
M   source/blender/draw/engines/eevee/eevee_materials.c
M   source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M   source/blender/makesrna/intern/rna_object_api.c

===

diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index 4257bccad93..0e34d08082f 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1012,7 +1012,7 @@ static void layer_collection_objects_sync(ViewLayer 
*view_layer,
 }
 
 /* Holdout and indirect only */
-if ((layer->flag & LAYER_COLLECTION_HOLDOUT) || 
(base->object->visibility_flag & OB_HOLDOUT)) {
+if ((layer->flag & LAYER_COLLECTION_HOLDOUT)) {
   base->flag_from_collection |= BASE_HOLDOUT;
 }
 if (layer->flag & LAYER_COLLECTION_INDIRECT_ONLY) {
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c 
b/source/blender/draw/engines/eevee/eevee_materials.c
index efd27c19654..39ab91861f9 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -752,7 +752,8 @@ BLI_INLINE Material *eevee_object_material_get(Object *ob, 
int slot, bool holdou
 BLI_INLINE EeveeMaterialCache eevee_material_cache_get(
 EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob, int slot, 
bool is_hair)
 {
-  const bool holdout = (ob->base_flag & BASE_HOLDOUT) != 0;
+  const bool holdout = ((ob->base_flag & BASE_HOLDOUT) != 0) ||
+   ((ob->visibility_flag & OB_HOLDOUT) != 0);
   EeveeMaterialCache matcache;
   Material *ma = eevee_object_material_get(ob, slot, holdout);
   switch (ma->blend_method) {
diff --git 
a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp 
b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index e76e74b89e4..299036a552f 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -69,7 +69,8 @@ NodeGroup *BlenderFileLoader::Load()
   break;
 }
 
-if (ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) {
+if ((ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) ||
+(ob->visibility_flag & OB_HOLDOUT)) {
   continue;
 }
 
diff --git a/source/blender/makesrna/intern/rna_object_api.c 
b/source/blender/makesrna/intern/rna_object_api.c
index 6967f78026a..5ba160c1926 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -192,7 +192,7 @@ static bool rna_Object_holdout_get(Object *ob, bContext *C, 
ViewLayer *view_laye
 return false;
   }
 
-  return ((base->flag & BASE_HOLDOUT) != 0);
+  return ((base->flag & BASE_HOLDOUT) != 0) || ((ob->visibility_flag & 
OB_HOLDOUT) != 0);
 }
 
 static bool rna_Object_indirect_only_get(Object *ob, bContext *C, ViewLayer 
*view_layer)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5ff62df238f] blender-v3.3-release: Cycles: Fix floor intrinsic for ARM Neon

2022-10-26 Thread Lukas Stockner
Commit: 5ff62df238ff5558f7c45f848749e1839d18d99a
Author: Lukas Stockner
Date:   Mon Oct 17 00:56:19 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB5ff62df238ff5558f7c45f848749e1839d18d99a

Cycles: Fix floor intrinsic for ARM Neon

===

M   intern/cycles/util/ssef.h

===

diff --git a/intern/cycles/util/ssef.h b/intern/cycles/util/ssef.h
index a2fff94303e..ad435e65b01 100644
--- a/intern/cycles/util/ssef.h
+++ b/intern/cycles/util/ssef.h
@@ -521,7 +521,7 @@ __forceinline const ssef round_zero(const ssef )
 __forceinline const ssef floor(const ssef )
 {
 #ifdef __KERNEL_NEON__
-  return vrndnq_f32(a);
+  return vrndmq_f32(a);
 #else
   return _mm_round_ps(a, _MM_FROUND_TO_NEG_INF);
 #endif

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3d7f298e9a5] blender-v3.3-release: Fix T101651: Cycles crashes when failing to initialize render device

2022-10-26 Thread Lukas Stockner
Commit: 3d7f298e9a5c8f2e95f118e571589521abc71b1a
Author: Lukas Stockner
Date:   Mon Oct 10 17:42:44 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB3d7f298e9a5c8f2e95f118e571589521abc71b1a

Fix T101651: Cycles crashes when failing to initialize render device

The issue here was that PathTraceWork was set up before checking if
any error occurred, and it didn't account for the dummy device so
it called a non-implemented function.

This fix therefore avoids creating PathTraceWork for dummy devices
and checks for device creation errors earlier in the process.

===

M   intern/cycles/integrator/path_trace.cpp
M   intern/cycles/integrator/path_trace_work.cpp
M   intern/cycles/integrator/work_balancer.cpp
M   intern/cycles/session/session.cpp

===

diff --git a/intern/cycles/integrator/path_trace.cpp 
b/intern/cycles/integrator/path_trace.cpp
index 3ec7b601d9f..ae03ee0b9a5 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -43,8 +43,11 @@ PathTrace::PathTrace(Device *device,
   /* Create path tracing work in advance, so that it can be reused by 
incremental sampling as much
* as possible. */
   device_->foreach_device([&](Device *path_trace_device) {
-path_trace_works_.emplace_back(PathTraceWork::create(
-path_trace_device, film, device_scene, _cancel_.is_requested));
+unique_ptr work = PathTraceWork::create(
+path_trace_device, film, device_scene, _cancel_.is_requested);
+if (work) {
+  path_trace_works_.emplace_back(std::move(work));
+}
   });
 
   work_balance_infos_.resize(path_trace_works_.size());
diff --git a/intern/cycles/integrator/path_trace_work.cpp 
b/intern/cycles/integrator/path_trace_work.cpp
index bb5c6e1a61a..a5f98b5475a 100644
--- a/intern/cycles/integrator/path_trace_work.cpp
+++ b/intern/cycles/integrator/path_trace_work.cpp
@@ -23,6 +23,10 @@ unique_ptr PathTraceWork::create(Device 
*device,
   if (device->info.type == DEVICE_CPU) {
 return make_unique(device, film, device_scene, 
cancel_requested_flag);
   }
+  if (device->info.type == DEVICE_DUMMY) {
+/* Dummy devices can't perform any work. */
+return nullptr;
+  }
 
   return make_unique(device, film, device_scene, 
cancel_requested_flag);
 }
diff --git a/intern/cycles/integrator/work_balancer.cpp 
b/intern/cycles/integrator/work_balancer.cpp
index 5f1c6c92b9d..0fe170b2791 100644
--- a/intern/cycles/integrator/work_balancer.cpp
+++ b/intern/cycles/integrator/work_balancer.cpp
@@ -17,6 +17,9 @@ void work_balance_do_initial(vector 
_balance_infos)
 work_balance_infos[0].weight = 1.0;
 return;
   }
+  else if (num_infos == 0) {
+return;
+  }
 
   /* There is no statistics available, so start with an equal distribution. */
   const double weight = 1.0 / num_infos;
diff --git a/intern/cycles/session/session.cpp 
b/intern/cycles/session/session.cpp
index de685a47003..15bb93b0385 100644
--- a/intern/cycles/session/session.cpp
+++ b/intern/cycles/session/session.cpp
@@ -43,6 +43,10 @@ Session::Session(const SessionParams _, const 
SceneParams _params)
 
   device = Device::create(params.device, stats, profiler);
 
+  if (device->have_error()) {
+progress.set_error(device->error_message());
+  }
+
   scene = new Scene(scene_params, device);
 
   /* Configure path tracer. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7e942b2a1e3] blender-v3.3-release: Partially fix T101702: OSL Shaders with boolean inputs crash

2022-10-26 Thread Lukas Stockner
Commit: 7e942b2a1e3d4d72ba90b498a514455452eab94c
Author: Lukas Stockner
Date:   Mon Oct 10 01:03:12 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB7e942b2a1e3d4d72ba90b498a514455452eab94c

Partially fix T101702: OSL Shaders with boolean inputs crash

OSL (like Cycles) has no internal boolean type, instead an integer
input can be flagged to be shown as a boolean in the UI.
Cycles reacts to this by creating a boolean socket on the Blender
side, but as a result incorrectly called the boolean overload of the
set function even though the internal type is an integer.

There's another unrelated crash in the GPU viewport shader code that
appears to apply to every OSL node that outputs a shader, and the file
in T101702 triggers both, so this is only a partial fix for the report.

===

M   intern/cycles/blender/shader.cpp

===

diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index 04eb1576330..c8798e23b0c 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -205,7 +205,9 @@ static void set_default_value(ShaderInput *input,
 }
 case SocketType::INT: {
   if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) {
-node->set(socket, get_boolean(b_sock.ptr, "default_value"));
+/* Make sure to call the int overload of set() since this is an 
integer socket as far as
+ * Cycles is concerned. */
+node->set(socket, get_boolean(b_sock.ptr, "default_value") ? 1 : 0);
   }
   else {
 node->set(socket, get_int(b_sock.ptr, "default_value"));

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [afec1cd3338] master: Cleanup: clang-format

2022-10-22 Thread Lukas Stockner
Commit: afec1cd33385109ac1ca41177426e7b72e174cda
Author: Lukas Stockner
Date:   Sat Oct 22 18:32:06 2022 +0200
Branches: master
https://developer.blender.org/rBafec1cd33385109ac1ca41177426e7b72e174cda

Cleanup: clang-format

===

M   source/blender/editors/transform/transform.c
M   source/blender/editors/transform/transform_mode_translate.c

===

diff --git a/source/blender/editors/transform/transform.c 
b/source/blender/editors/transform/transform.c
index 9fe8cd3df2e..5b194ae7237 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1731,7 +1731,8 @@ static void initSnapSpatial(TransInfo *t, float 
r_snap[3], float *r_snap_precisi
   if (t->spacetype == SPACE_VIEW3D) {
 if (t->region->regiondata) {
   View3D *v3d = t->area->spacedata.first;
-  r_snap[0] = r_snap[1] = r_snap[2] = ED_view3d_grid_view_scale(t->scene, 
v3d, t->region, NULL);
+  r_snap[0] = r_snap[1] = r_snap[2] = ED_view3d_grid_view_scale(
+  t->scene, v3d, t->region, NULL);
 }
   }
   else if (t->spacetype == SPACE_IMAGE) {
diff --git a/source/blender/editors/transform/transform_mode_translate.c 
b/source/blender/editors/transform/transform_mode_translate.c
index 6461182afc1..c751a68092f 100644
--- a/source/blender/editors/transform/transform_mode_translate.c
+++ b/source/blender/editors/transform/transform_mode_translate.c
@@ -370,10 +370,10 @@ static void translate_snap_target_grid_ensure(TransInfo 
*t)
 }
 
 static void translate_snap_grid_apply(TransInfo *t,
-const int max_index,
-const float grid_dist[3],
-const float loc[3],
-float r_out[3])
+  const int max_index,
+  const float grid_dist[3],
+  const float loc[3],
+  float r_out[3])
 {
   BLI_assert(max_index <= 2);
   translate_snap_target_grid_ensure(t);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [21fdb0d92b6] master: Fix T101329: EXR 'JPG Preview' doesn't use color space anymore

2022-10-22 Thread Lukas Stockner
Commit: 21fdb0d92b6697cba252a1e8080b19012efa8383
Author: Lukas Stockner
Date:   Sat Oct 22 18:15:02 2022 +0200
Branches: master
https://developer.blender.org/rB21fdb0d92b6697cba252a1e8080b19012efa8383

Fix T101329: EXR 'JPG Preview' doesn't use color space anymore

For the JPG preview, the only thing that was changed in the image
format was the format itself. However, the colorspace code now also
checks the bitdepth through BKE_image_format_is_byte, so the depth
needs to be explicitly set to 8-bit for the JPG preview output.

===

M   source/blender/blenkernel/intern/image_save.cc

===

diff --git a/source/blender/blenkernel/intern/image_save.cc 
b/source/blender/blenkernel/intern/image_save.cc
index 4e47e71fb2b..003211e6288 100644
--- a/source/blender/blenkernel/intern/image_save.cc
+++ b/source/blender/blenkernel/intern/image_save.cc
@@ -968,6 +968,7 @@ bool BKE_image_render_write(ReportList *reports,
 /* optional preview images for exr */
 if (ok && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
   image_format.imtype = R_IMF_IMTYPE_JPEG90;
+  image_format.depth = R_IMF_CHAN_DEPTH_8;
 
   if (BLI_path_extension_check(filepath, ".exr")) {
 filepath[strlen(filepath) - 4] = 0;
@@ -1025,6 +1026,7 @@ bool BKE_image_render_write(ReportList *reports,
   /* optional preview images for exr */
   if (ok && is_exr_rr && (image_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
 image_format.imtype = R_IMF_IMTYPE_JPEG90;
+image_format.depth = R_IMF_CHAN_DEPTH_8;
 
 if (BLI_path_extension_check(filepath, ".exr")) {
   filepath[strlen(filepath) - 4] = 0;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ea571ddc29e] master: Fix T101969: Crash when using large texture with nonstandard colorspace

2022-10-21 Thread Lukas Stockner
Commit: ea571ddc29e4e7be441a9b58bef50190a4a35c04
Author: Lukas Stockner
Date:   Sat Oct 22 02:51:52 2022 +0200
Branches: master
https://developer.blender.org/rBea571ddc29e4e7be441a9b58bef50190a4a35c04

Fix T101969: Crash when using large texture with nonstandard colorspace

When the image colorspace is not data, linear or sRGB, the image will
be converted to float (and colorspace-converted) during loading.

However, if it also needs to be rescaled (due to exceeding the GPU
texture size limit), the resizing assumed that it's still a byte
texture.

===

M   source/blender/imbuf/intern/util_gpu.c

===

diff --git a/source/blender/imbuf/intern/util_gpu.c 
b/source/blender/imbuf/intern/util_gpu.c
index dd509677d8d..5ed6b2b9843 100644
--- a/source/blender/imbuf/intern/util_gpu.c
+++ b/source/blender/imbuf/intern/util_gpu.c
@@ -174,6 +174,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
   /* Other colorspace, store as float texture to avoid precision loss. */
   data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
   *r_freedata = freedata = true;
+  is_float_rect = true;
 
   if (data_rect == NULL) {
 return NULL;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e2a93e9c7c5] master: Fix T94136: Cycles: No Hair Shadows with Transparent BSDF

2022-10-19 Thread Lukas Stockner
Commit: e2a93e9c7c5fece5ea7d46da949694ad2eca872e
Author: Lukas Stockner
Date:   Thu Oct 20 04:38:50 2022 +0200
Branches: master
https://developer.blender.org/rBe2a93e9c7c5fece5ea7d46da949694ad2eca872e

Fix T94136: Cycles: No Hair Shadows with Transparent BSDF

===

M   intern/cycles/kernel/bvh/shadow_all.h
M   intern/cycles/kernel/bvh/util.h
M   intern/cycles/kernel/device/cpu/bvh.h
M   intern/cycles/kernel/device/metal/kernel.metal
M   intern/cycles/kernel/device/optix/bvh.h

===

diff --git a/intern/cycles/kernel/bvh/shadow_all.h 
b/intern/cycles/kernel/bvh/shadow_all.h
index 2ffe1496c72..b31ba479e4f 100644
--- a/intern/cycles/kernel/bvh/shadow_all.h
+++ b/intern/cycles/kernel/bvh/shadow_all.h
@@ -229,7 +229,7 @@ ccl_device_inline
   /* Always use baked shadow transparency for curves. */
   if (isect.type & PRIMITIVE_CURVE) {
 *r_throughput *= intersection_curve_shadow_transparency(
-kg, isect.object, isect.prim, isect.u);
+kg, isect.object, isect.prim, isect.type, isect.u);
 
 if (*r_throughput < CURVE_SHADOW_TRANSPARENCY_CUTOFF) {
   return true;
diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h
index a57703a8b8c..9ba787550c5 100644
--- a/intern/cycles/kernel/bvh/util.h
+++ b/intern/cycles/kernel/bvh/util.h
@@ -190,10 +190,8 @@ ccl_device_inline int 
intersection_find_attribute(KernelGlobals kg,
 /* Cut-off value to stop transparent shadow tracing when practically opaque. */
 #define CURVE_SHADOW_TRANSPARENCY_CUTOFF 0.001f
 
-ccl_device_inline float intersection_curve_shadow_transparency(KernelGlobals 
kg,
-   const int 
object,
-   const int prim,
-   const float u)
+ccl_device_inline float intersection_curve_shadow_transparency(
+KernelGlobals kg, const int object, const int prim, const int type, const 
float u)
 {
   /* Find attribute. */
   const int offset = intersection_find_attribute(kg, object, 
ATTR_STD_SHADOW_TRANSPARENCY);
@@ -204,7 +202,7 @@ ccl_device_inline float 
intersection_curve_shadow_transparency(KernelGlobals kg,
 
   /* Interpolate transparency between curve keys. */
   const KernelCurve kcurve = kernel_data_fetch(curves, prim);
-  const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(kcurve.type);
+  const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(type);
   const int k1 = k0 + 1;
 
   const float f0 = kernel_data_fetch(attributes_float, offset + k0);
diff --git a/intern/cycles/kernel/device/cpu/bvh.h 
b/intern/cycles/kernel/device/cpu/bvh.h
index d9267e1cd6d..2d7d8c2d704 100644
--- a/intern/cycles/kernel/device/cpu/bvh.h
+++ b/intern/cycles/kernel/device/cpu/bvh.h
@@ -252,7 +252,7 @@ ccl_device void kernel_embree_filter_occluded_func(const 
RTCFilterFunctionNArgum
   /* Always use baked shadow transparency for curves. */
   if (current_isect.type & PRIMITIVE_CURVE) {
 ctx->throughput *= intersection_curve_shadow_transparency(
-kg, current_isect.object, current_isect.prim, current_isect.u);
+kg, current_isect.object, current_isect.prim, current_isect.type, 
current_isect.u);
 
 if (ctx->throughput < CURVE_SHADOW_TRANSPARENCY_CUTOFF) {
   ctx->opaque_hit = true;
diff --git a/intern/cycles/kernel/device/metal/kernel.metal 
b/intern/cycles/kernel/device/metal/kernel.metal
index 5646c7446db..8b69ee025cd 100644
--- a/intern/cycles/kernel/device/metal/kernel.metal
+++ b/intern/cycles/kernel/device/metal/kernel.metal
@@ -228,7 +228,7 @@ bool metalrt_shadow_all_hit(constant KernelParamsMetal 
_params_metal,
   /* Always use baked shadow transparency for curves. */
   if (type & PRIMITIVE_CURVE) {
 float throughput = payload.throughput;
-throughput *= context.intersection_curve_shadow_transparency(nullptr, 
object, prim, u);
+throughput *= context.intersection_curve_shadow_transparency(nullptr, 
object, prim, type, u);
 payload.throughput = throughput;
 payload.num_hits += 1;
 
diff --git a/intern/cycles/kernel/device/optix/bvh.h 
b/intern/cycles/kernel/device/optix/bvh.h
index fb9907709ce..6d81b44660c 100644
--- a/intern/cycles/kernel/device/optix/bvh.h
+++ b/intern/cycles/kernel/device/optix/bvh.h
@@ -202,7 +202,7 @@ extern "C" __global__ void 
__anyhit__kernel_optix_shadow_all_hit()
   /* Always use baked shadow transparency for curves. */
   if (type & PRIMITIVE_CURVE) {
 float throughput = __uint_as_float(optixGetPayload_1());
-throughput *= intersection_curve_shadow_transparency(nullptr, object, 
prim, u);
+throughput *= intersection_curve_shadow_transparency(nullptr, object

[Bf-blender-cvs] [3411a96e749] master: Fix T93382: Blender still generates subsurface render passes

2022-10-19 Thread Lukas Stockner
Commit: 3411a96e74938afe9b7ffe64e61a225da5f2eb6a
Author: Lukas Stockner
Date:   Wed Oct 19 04:02:39 2022 +0200
Branches: master
https://developer.blender.org/rB3411a96e74938afe9b7ffe64e61a225da5f2eb6a

Fix T93382: Blender still generates subsurface render passes

In T93382, the problem was that the Blender-side rendering code was
still generating the subsurface passes because the old render pass
flags were set, even though Cycles doesn't generate them anymore.

After a closer look, it turns out that the entire hardcoded pass
creation code can be removed. We already have an Engine API function
to query the list of render passes from the engine, so we might as
well just call that and create the returned passes.

Turns out that Eevee already did this anyways. On the Cycles side, it
allows to deduplicate a lot of `BlenderSync::sync_render_passes`.
Before, passes were defined in engine.py and in sync.cpp. Now, all
passes that engine.py returns are created automatically, so sync.cpp
only needs to handle a few special cases.

I'm not really concerned about affecting external renderer addons,
since they already needed to handle the old "builtin passes" in
their Engine API implementation anyways to make them show up in the
compositor. So, unless they missed that for like 10 releases, they
should not notice any difference.

Differential Revision: https://developer.blender.org/D16295

===

M   intern/cycles/blender/addon/engine.py
M   intern/cycles/blender/sync.cpp
M   source/blender/draw/intern/draw_manager.c
M   source/blender/render/intern/engine.cc
M   source/blender/render/intern/render_result.cc

===

diff --git a/intern/cycles/blender/addon/engine.py 
b/intern/cycles/blender/addon/engine.py
index 794338fe78e..e33891fa7a2 100644
--- a/intern/cycles/blender/addon/engine.py
+++ b/intern/cycles/blender/addon/engine.py
@@ -209,22 +209,25 @@ def list_render_passes(scene, srl):
 yield ("Debug Sample Count", "X", 'VALUE')
 
 # Cryptomatte passes.
-crypto_depth = (srl.pass_cryptomatte_depth + 1) // 2
+# NOTE: Name channels are lowercase RGBA so that compression rules check 
in OpenEXR DWA code
+# uses lossless compression. Reportedly this naming is the only one which 
works good from the
+# interoperability point of view. Using XYZW naming is not portable.
+crypto_depth = (min(16, srl.pass_cryptomatte_depth) + 1) // 2
 if srl.use_pass_cryptomatte_object:
 for i in range(0, crypto_depth):
-yield ("CryptoObject" + '{:02d}'.format(i), "RGBA", 'COLOR')
+yield ("CryptoObject" + '{:02d}'.format(i), "rgba", 'COLOR')
 if srl.use_pass_cryptomatte_material:
 for i in range(0, crypto_depth):
-yield ("CryptoMaterial" + '{:02d}'.format(i), "RGBA", 'COLOR')
+yield ("CryptoMaterial" + '{:02d}'.format(i), "rgba", 'COLOR')
 if srl.use_pass_cryptomatte_asset:
 for i in range(0, crypto_depth):
-yield ("CryptoAsset" + '{:02d}'.format(i), "RGBA", 'COLOR')
+yield ("CryptoAsset" + '{:02d}'.format(i), "rgba", 'COLOR')
 
 # Denoising passes.
 if scene.cycles.use_denoising and crl.use_denoising:
 yield ("Noisy Image", "RGBA", 'COLOR')
 if crl.use_pass_shadow_catcher:
-yield ("Noisy Shadow Catcher", "RGBA", 'COLOR')
+yield ("Noisy Shadow Catcher", "RGB", 'COLOR')
 if crl.denoising_store_passes:
 yield ("Denoising Normal", "XYZ", 'VECTOR')
 yield ("Denoising Albedo", "RGB", 'COLOR')
@@ -232,6 +235,8 @@ def list_render_passes(scene, srl):
 
 # Custom AOV passes.
 for aov in srl.aovs:
+if not aov.is_valid:
+continue
 if aov.type == 'VALUE':
 yield (aov.name, "X", 'VALUE')
 else:
diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp
index a69a94614d3..5251f0fee9c 100644
--- a/intern/cycles/blender/sync.cpp
+++ b/intern/cycles/blender/sync.cpp
@@ -575,68 +575,72 @@ void BlenderSync::sync_images()
 
 /* Passes */
 
-static PassType get_blender_pass_type(BL::RenderPass _pass)
+static bool get_known_pass_type(BL::RenderPass _pass, PassType , 
PassMode )
 {
   string name = b_pass.name();
-#define MAP_PASS(passname, passtype) \
+#define MAP_PASS(passname, passtype, noisy) \
   if (name == passname) { \
-return passtype; \
+type = passtype; \
+mode = (noisy) ? PassMode::NOISY : PassMode::DENOISED; \
+return true; \
   } \
   ((void)0)
 
-  /* NOTE: Keep in sync with defined names from DNA_scene_types.h */
+  /* NOTE: Keep in sync with defined names from

[Bf-blender-cvs] [3915f5300ad] master: Fix T99151: Cycles not updating on Object Type visibility change

2022-10-19 Thread Lukas Stockner
Commit: 3915f5300ad2d2a3c12a8bb67bb97f60160953e7
Author: Lukas Stockner
Date:   Sun Oct 16 00:57:09 2022 +0200
Branches: master
https://developer.blender.org/rB3915f5300ad2d2a3c12a8bb67bb97f60160953e7

Fix T99151: Cycles not updating on Object Type visibility change

Differential Revision: https://developer.blender.org/D16259

===

M   source/blender/makesrna/intern/rna_internal.h
M   source/blender/makesrna/intern/rna_space.c
M   source/blender/makesrna/intern/rna_space_api.c
M   source/blender/makesrna/intern/rna_xr.c

===

diff --git a/source/blender/makesrna/intern/rna_internal.h 
b/source/blender/makesrna/intern/rna_internal.h
index 8e652753ec0..ea829e5cd86 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -322,7 +322,9 @@ void rna_object_vcollayer_name_set(struct PointerRNA *ptr,
 PointerRNA rna_object_shapekey_index_get(struct ID *id, int value);
 int rna_object_shapekey_index_set(struct ID *id, PointerRNA value, int 
current);
 
-void rna_def_object_type_visibility_flags_common(StructRNA *srna, int 
noteflag);
+void rna_def_object_type_visibility_flags_common(StructRNA *srna,
+ int noteflag,
+ const char *update_func);
 int rna_object_type_visibility_icon_get_common(int 
object_type_exclude_viewport,
const int 
*object_type_exclude_select);
 
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 5c192b80dc1..b2663b89333 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -990,6 +990,13 @@ static PointerRNA rna_SpaceView3D_region_3d_get(PointerRNA 
*ptr)
   return rna_pointer_inherit_refine(ptr, _RegionView3D, regiondata);
 }
 
+static void rna_SpaceView3D_object_type_visibility_update(Main *UNUSED(bmain),
+  Scene *scene,
+  PointerRNA 
*UNUSED(ptr))
+{
+  DEG_id_tag_update(>id, ID_RECALC_BASE_FLAGS);
+}
+
 static void rna_SpaceView3D_region_quadviews_begin(CollectionPropertyIterator 
*iter,
PointerRNA *ptr)
 {
@@ -5086,7 +5093,8 @@ static void rna_def_space_view3d(BlenderRNA *brna)
   prop, NC_SPACE | ND_SPACE_VIEW3D, 
"rna_SpaceView3D_mirror_xr_session_update");
 
   rna_def_object_type_visibility_flags_common(srna,
-  NC_SPACE | ND_SPACE_VIEW3D | 
NS_VIEW3D_SHADING);
+  NC_SPACE | ND_SPACE_VIEW3D | 
NS_VIEW3D_SHADING,
+  
"rna_SpaceView3D_object_type_visibility_update");
 
   /* Helper for drawing the icon. */
   prop = RNA_def_property(srna, "icon_from_show_object_viewport", PROP_INT, 
PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_space_api.c 
b/source/blender/makesrna/intern/rna_space_api.c
index b3896919275..9790a85e1c8 100644
--- a/source/blender/makesrna/intern/rna_space_api.c
+++ b/source/blender/makesrna/intern/rna_space_api.c
@@ -119,7 +119,9 @@ void RNA_api_space_text(StructRNA *srna)
   RNA_def_function_output(func, parm);
 }
 
-void rna_def_object_type_visibility_flags_common(StructRNA *srna, int noteflag)
+void rna_def_object_type_visibility_flags_common(StructRNA *srna,
+ int noteflag,
+ const char *update_func)
 {
   PropertyRNA *prop;
 
@@ -173,7 +175,7 @@ void rna_def_object_type_visibility_flags_common(StructRNA 
*srna, int noteflag)
   RNA_def_property_boolean_negative_sdna(
   prop, NULL, view_mask_member[mask_index], 
info[type_index].type_mask);
   RNA_def_property_ui_text(prop, info[type_index].name, "");
-  RNA_def_property_update(prop, noteflag, NULL);
+  RNA_def_property_update(prop, noteflag, update_func);
 }
   }
 }
diff --git a/source/blender/makesrna/intern/rna_xr.c 
b/source/blender/makesrna/intern/rna_xr.c
index dcfa1bbca51..c803e5dc9a8 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -2052,7 +2052,7 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
   "Allow the VR tracking origin to be defined independently of the headset 
location");
   RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
 
-  rna_def_object_type_visibility_flags_common(srna, NC_WM | 
ND_XR_DATA_CHANGED);
+  rna_def_object_type_visibility_flags_common(srna, NC_WM | 
ND_XR_DATA_CHANGED, NULL);
 
   /* Helper for drawing the icon. */
   prop = RNA_def_property(srna, &

[Bf-blender-cvs] [72a34ab1b91] blender-v3.3-release: Fix T100330: Remove Render Slot not working for first slot

2022-10-17 Thread Lukas Stockner
Commit: 72a34ab1b91d56926aeee8677b2896d583f1cd8f
Author: Lukas Stockner
Date:   Sat Sep 17 01:46:03 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB72a34ab1b91d56926aeee8677b2896d583f1cd8f

Fix T100330: Remove Render Slot not working for first slot

This bug was caused by the weird ownership logic for render results.
Basically, the most recent render result is owned by the Render, while
all others are owned by the RenderSlots.
When a new render is started, the previous Render is handed over to its
slot, and the new slot is cleared. So far, so good.

However, when a slot is removed and happens to be the one with the most
recent render, this causes a complication.
The code handles this by making another slot the most recent one, along
with moving its result back to the Render, as if that had always been
the most recent one.

That works, unless there is no most recent render because you haven't
rendered anything yet. Unfortunately, there is no way to store "there
hasn't been a render yet", so the code still tries to perform this
handover but can't.
Previously, the code handled that case by just refusing to delete the
slot. However, this blocks users from deleting this slot.

But of course, if there hasn't been a render yet, the slots will not
contain anything yet, so this entire maneuver is pointless.
Therefore, the fix for the bug is to just skip it altogether if there
is no Render instead of failing the operation.

Technically, there is a weird corner case remaining, because Renders
are per-scene. Therefore, if a user renders images in one scene,
switches to a different scene, deletes a slot there and then switches
back, in some situations the result in the deleted slot might end up
in the next slot.
Unfortunately this is just a limitation of the weird split ownership
logic and can't just be worked around. The proper fix for this
probably would be to hand over ownership of the result from the Render
to the RenderSlot once the render is done, but this is quite complex.

Also fixes a crash when iuser->scene is NULL.

===

M   source/blender/blenkernel/intern/image.cc

===

diff --git a/source/blender/blenkernel/intern/image.cc 
b/source/blender/blenkernel/intern/image.cc
index b196bcd7207..d56e3530b7c 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -5476,15 +5476,14 @@ bool BKE_image_remove_renderslot(Image *ima, ImageUser 
*iuser, int slot)
   next_last_slot = current_slot;
 }
 
-if (!iuser) {
+if (iuser == nullptr || iuser->scene == nullptr) {
   return false;
 }
 Render *re = RE_GetSceneRender(iuser->scene);
-if (!re) {
-  return false;
+if (re != nullptr) {
+  RE_SwapResult(re, _last_slot->render);
+  RE_SwapResult(re, _last_slot->render);
 }
-RE_SwapResult(re, _last_slot->render);
-RE_SwapResult(re, _last_slot->render);
 current_last_slot = next_last_slot;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6ad04a031c0] master: Cycles: Fix floor intrinsic for ARM Neon

2022-10-16 Thread Lukas Stockner
Commit: 6ad04a031c0f4375769a9a6a47942905be544992
Author: Lukas Stockner
Date:   Mon Oct 17 00:56:19 2022 +0200
Branches: master
https://developer.blender.org/rB6ad04a031c0f4375769a9a6a47942905be544992

Cycles: Fix floor intrinsic for ARM Neon

===

M   intern/cycles/util/ssef.h

===

diff --git a/intern/cycles/util/ssef.h b/intern/cycles/util/ssef.h
index 7f9e332a997..1e2bfa90354 100644
--- a/intern/cycles/util/ssef.h
+++ b/intern/cycles/util/ssef.h
@@ -523,7 +523,7 @@ __forceinline const ssef round_zero(const ssef )
 __forceinline const ssef floor(const ssef )
 {
 #ifdef __KERNEL_NEON__
-  return vrndnq_f32(a);
+  return vrndmq_f32(a);
 #else
   return _mm_round_ps(a, _MM_FROUND_TO_NEG_INF);
 #endif

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0c50f9c4aaf] master: Fix T98672: Noise texture shows incorrect behaviour for large scales

2022-10-15 Thread Lukas Stockner
Commit: 0c50f9c4aaf90eb26240c31fbeff12af519a8ab0
Author: Lukas Stockner
Date:   Sun Oct 16 01:57:44 2022 +0200
Branches: master
https://developer.blender.org/rB0c50f9c4aaf90eb26240c31fbeff12af519a8ab0

Fix T98672: Noise texture shows incorrect behaviour for large scales

This was a floating point precision issue - or, to be more precise,
an issue with how Cycles split floats into the integer and fractional
parts for Perlin noise.
For coordinates below -2^24, the integer could be wrong, leading to
the fractional part being outside of 0-1 range, which breaks all sorts
of other things. 2^24 sounds like a lot, but due to how the detail
octaves work, it's not that hard to reach when combined with a large
scale.

Since this code is originally based on OSL, I checked if they changed
it in the meantime, and sure enough, there's a fix for it:
https://github.com/OpenImageIO/oiio/commit/5c9dc68391e9

So, this basically just ports over that change to Cycles.

The original code mentions being faster, but as pointed out in the
linked commit, the performance impact is actually irrelevant.

I also checked in a simple scene with eight Noise textures at
detail 15 (with >90% of render time being spent on the noise), and
the render time went from 13.06sec to 13.05sec. So, yeah, no issue.

===

M   intern/cycles/util/math.h
M   intern/cycles/util/math_float3.h
M   intern/cycles/util/ssef.h

===

diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h
index 0905b3ec5c9..3a2e0e074a2 100644
--- a/intern/cycles/util/math.h
+++ b/intern/cycles/util/math.h
@@ -417,15 +417,11 @@ ccl_device_inline int floor_to_int(float f)
   return float_to_int(floorf(f));
 }
 
-ccl_device_inline int quick_floor_to_int(float x)
-{
-  return float_to_int(x) - ((x < 0) ? 1 : 0);
-}
-
 ccl_device_inline float floorfrac(float x, ccl_private int *i)
 {
-  *i = quick_floor_to_int(x);
-  return x - *i;
+  float f = floorf(x);
+  *i = float_to_int(f);
+  return x - f;
 }
 
 ccl_device_inline int ceil_to_int(float f)
diff --git a/intern/cycles/util/math_float3.h b/intern/cycles/util/math_float3.h
index c408eadf195..eec7122b9dc 100644
--- a/intern/cycles/util/math_float3.h
+++ b/intern/cycles/util/math_float3.h
@@ -535,18 +535,6 @@ ccl_device_inline float3 pow(float3 v, float e)
   return make_float3(powf(v.x, e), powf(v.y, e), powf(v.z, e));
 }
 
-ccl_device_inline int3 quick_floor_to_int3(const float3 a)
-{
-#ifdef __KERNEL_SSE__
-  int3 b = int3(_mm_cvttps_epi32(a.m128));
-  int3 isneg = int3(_mm_castps_si128(_mm_cmplt_ps(a.m128, _mm_set_ps1(0.0f;
-  /* Unsaturated add 0x is the same as subtract -1. */
-  return b + isneg;
-#else
-  return make_int3(quick_floor_to_int(a.x), quick_floor_to_int(a.y), 
quick_floor_to_int(a.z));
-#endif
-}
-
 ccl_device_inline bool isfinite_safe(float3 v)
 {
   return isfinite_safe(v.x) && isfinite_safe(v.y) && isfinite_safe(v.z);
diff --git a/intern/cycles/util/ssef.h b/intern/cycles/util/ssef.h
index a2fff94303e..7f9e332a997 100644
--- a/intern/cycles/util/ssef.h
+++ b/intern/cycles/util/ssef.h
@@ -5,6 +5,8 @@
 #ifndef __UTIL_SSEF_H__
 #define __UTIL_SSEF_H__
 
+#include 
+
 #include "util/ssei.h"
 
 CCL_NAMESPACE_BEGIN
@@ -534,6 +536,12 @@ __forceinline const ssef ceil(const ssef )
   return _mm_round_ps(a, _MM_FROUND_TO_POS_INF);
 #endif
 }
+#  else
+/* Non-SSE4.1 fallback, needed for floorfrac. */
+__forceinline const ssef floor(const ssef )
+{
+  return _mm_set_ps(floorf(a.f[3]), floorf(a.f[2]), floorf(a.f[1]), 
floorf(a.f[0]));
+}
 #  endif
 
 __forceinline ssei truncatei(const ssef )
@@ -541,20 +549,11 @@ __forceinline ssei truncatei(const ssef )
   return _mm_cvttps_epi32(a.m128);
 }
 
-/* This is about 25% faster than straightforward floor to integer conversion
- * due to better pipelining.
- *
- * Unsaturated add 0x (a < 0) is the same as subtract -1.
- */
-__forceinline ssei floori(const ssef )
-{
-  return truncatei(a) + cast((a < 0.0f).m128);
-}
-
 __forceinline ssef floorfrac(const ssef , ssei *i)
 {
-  *i = floori(x);
-  return x - ssef(*i);
+  ssef f = floor(x);
+  *i = truncatei(f);
+  return x - f;
 }
 
 


___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b898330c374] master: Fix T99450: Animated Holdout not updating on frame change

2022-10-15 Thread Lukas Stockner
Commit: b898330c3744669a8c3805f1560130821422cca1
Author: Lukas Stockner
Date:   Sat Oct 15 22:51:21 2022 +0200
Branches: master
https://developer.blender.org/rBb898330c3744669a8c3805f1560130821422cca1

Fix T99450: Animated Holdout not updating on frame change

Problem here was that layer_collection_objects_sync wasn't called when
the holdout property is updated due to frame change, so the changed
visibility flag was never applied to ob->base_flag.

Turns out there's no real reason to handle the per-object holdout
property through the layer system. So, instead of merging both the
layer holdout and object holdout into base_flag and checking that
from the render engines, only handle the layer holdout (which can't
be animated, so no issue here) through base_flag and explicitly also
check the object holdout in the render engines.

===

M   source/blender/blenkernel/intern/layer.c
M   source/blender/draw/engines/eevee/eevee_materials.c
M   source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M   source/blender/makesrna/intern/rna_object_api.c

===

diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index fcb0adfde34..06d69b6ff61 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1049,7 +1049,7 @@ static void layer_collection_objects_sync(ViewLayer 
*view_layer,
 }
 
 /* Holdout and indirect only */
-if ((layer->flag & LAYER_COLLECTION_HOLDOUT) || 
(base->object->visibility_flag & OB_HOLDOUT)) {
+if ((layer->flag & LAYER_COLLECTION_HOLDOUT)) {
   base->flag_from_collection |= BASE_HOLDOUT;
 }
 if (layer->flag & LAYER_COLLECTION_INDIRECT_ONLY) {
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c 
b/source/blender/draw/engines/eevee/eevee_materials.c
index f79e4e1d568..b5f81f3a307 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -759,7 +759,8 @@ BLI_INLINE Material *eevee_object_material_get(Object *ob, 
int slot, bool holdou
 BLI_INLINE EeveeMaterialCache eevee_material_cache_get(
 EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob, int slot, 
bool is_hair)
 {
-  const bool holdout = (ob->base_flag & BASE_HOLDOUT) != 0;
+  const bool holdout = ((ob->base_flag & BASE_HOLDOUT) != 0) ||
+   ((ob->visibility_flag & OB_HOLDOUT) != 0);
   EeveeMaterialCache matcache;
   Material *ma = eevee_object_material_get(ob, slot, holdout);
   switch (ma->blend_method) {
diff --git 
a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp 
b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 19589491bc4..0d41b5a773d 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -73,7 +73,8 @@ NodeGroup *BlenderFileLoader::Load()
   break;
 }
 
-if (ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) {
+if ((ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) ||
+(ob->visibility_flag & OB_HOLDOUT)) {
   continue;
 }
 
diff --git a/source/blender/makesrna/intern/rna_object_api.c 
b/source/blender/makesrna/intern/rna_object_api.c
index c99c5fb723d..366a3597ce6 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -199,7 +199,7 @@ static bool rna_Object_holdout_get(Object *ob, bContext *C, 
PointerRNA *view_lay
 return false;
   }
 
-  return ((base->flag & BASE_HOLDOUT) != 0);
+  return ((base->flag & BASE_HOLDOUT) != 0) || ((ob->visibility_flag & 
OB_HOLDOUT) != 0);
 }
 
 static bool rna_Object_indirect_only_get(Object *ob, bContext *C, PointerRNA 
*view_layer_ptr)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [95aac5df736] master: Fix T101651: Cycles crashes when failing to initialize render device

2022-10-10 Thread Lukas Stockner
Commit: 95aac5df736e8bbf0fe55954524e42845ba7e20a
Author: Lukas Stockner
Date:   Mon Oct 10 17:42:44 2022 +0200
Branches: master
https://developer.blender.org/rB95aac5df736e8bbf0fe55954524e42845ba7e20a

Fix T101651: Cycles crashes when failing to initialize render device

The issue here was that PathTraceWork was set up before checking if
any error occurred, and it didn't account for the dummy device so
it called a non-implemented function.

This fix therefore avoids creating PathTraceWork for dummy devices
and checks for device creation errors earlier in the process.

===

M   intern/cycles/integrator/path_trace.cpp
M   intern/cycles/integrator/path_trace_work.cpp
M   intern/cycles/integrator/work_balancer.cpp
M   intern/cycles/session/session.cpp

===

diff --git a/intern/cycles/integrator/path_trace.cpp 
b/intern/cycles/integrator/path_trace.cpp
index 6b033cfd051..506d962f13d 100644
--- a/intern/cycles/integrator/path_trace.cpp
+++ b/intern/cycles/integrator/path_trace.cpp
@@ -43,8 +43,11 @@ PathTrace::PathTrace(Device *device,
   /* Create path tracing work in advance, so that it can be reused by 
incremental sampling as much
* as possible. */
   device_->foreach_device([&](Device *path_trace_device) {
-path_trace_works_.emplace_back(PathTraceWork::create(
-path_trace_device, film, device_scene, _cancel_.is_requested));
+unique_ptr work = PathTraceWork::create(
+path_trace_device, film, device_scene, _cancel_.is_requested);
+if (work) {
+  path_trace_works_.emplace_back(std::move(work));
+}
   });
 
   work_balance_infos_.resize(path_trace_works_.size());
diff --git a/intern/cycles/integrator/path_trace_work.cpp 
b/intern/cycles/integrator/path_trace_work.cpp
index bb5c6e1a61a..a5f98b5475a 100644
--- a/intern/cycles/integrator/path_trace_work.cpp
+++ b/intern/cycles/integrator/path_trace_work.cpp
@@ -23,6 +23,10 @@ unique_ptr PathTraceWork::create(Device 
*device,
   if (device->info.type == DEVICE_CPU) {
 return make_unique(device, film, device_scene, 
cancel_requested_flag);
   }
+  if (device->info.type == DEVICE_DUMMY) {
+/* Dummy devices can't perform any work. */
+return nullptr;
+  }
 
   return make_unique(device, film, device_scene, 
cancel_requested_flag);
 }
diff --git a/intern/cycles/integrator/work_balancer.cpp 
b/intern/cycles/integrator/work_balancer.cpp
index 5f1c6c92b9d..0fe170b2791 100644
--- a/intern/cycles/integrator/work_balancer.cpp
+++ b/intern/cycles/integrator/work_balancer.cpp
@@ -17,6 +17,9 @@ void work_balance_do_initial(vector 
_balance_infos)
 work_balance_infos[0].weight = 1.0;
 return;
   }
+  else if (num_infos == 0) {
+return;
+  }
 
   /* There is no statistics available, so start with an equal distribution. */
   const double weight = 1.0 / num_infos;
diff --git a/intern/cycles/session/session.cpp 
b/intern/cycles/session/session.cpp
index a0eb3196a34..acaa55f4990 100644
--- a/intern/cycles/session/session.cpp
+++ b/intern/cycles/session/session.cpp
@@ -43,6 +43,10 @@ Session::Session(const SessionParams _, const 
SceneParams _params)
 
   device = Device::create(params.device, stats, profiler);
 
+  if (device->have_error()) {
+progress.set_error(device->error_message());
+  }
+
   scene = new Scene(scene_params, device);
 
   /* Configure path tracer. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [9a8746dff13] master: Cleanup: clang-format

2022-10-10 Thread Lukas Stockner
Commit: 9a8746dff13df68f64c507097739bb71edd48881
Author: Lukas Stockner
Date:   Mon Oct 10 17:57:25 2022 +0200
Branches: master
https://developer.blender.org/rB9a8746dff13df68f64c507097739bb71edd48881

Cleanup: clang-format

===

M   source/blender/editors/space_clip/clip_ops.c

===

diff --git a/source/blender/editors/space_clip/clip_ops.c 
b/source/blender/editors/space_clip/clip_ops.c
index b10ad86504c..2b107b423e5 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -1611,7 +1611,8 @@ void CLIP_OT_mode_set(wmOperatorType *ot)
   ot->poll = ED_space_clip_poll;
 
   /* properties */
-  ot->prop = RNA_def_enum(ot->srna, "mode", rna_enum_clip_editor_mode_items, 
SC_MODE_TRACKING, "Mode", "");
+  ot->prop = RNA_def_enum(
+  ot->srna, "mode", rna_enum_clip_editor_mode_items, SC_MODE_TRACKING, 
"Mode", "");
   RNA_def_property_translation_context(ot->prop, BLT_I18NCONTEXT_ID_MOVIECLIP);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [aaa731a7823] master: Partially fix T101702: OSL Shaders with boolean inputs crash

2022-10-09 Thread Lukas Stockner
Commit: aaa731a7823a986c37745a9c48b485ce03205593
Author: Lukas Stockner
Date:   Mon Oct 10 01:03:12 2022 +0200
Branches: master
https://developer.blender.org/rBaaa731a7823a986c37745a9c48b485ce03205593

Partially fix T101702: OSL Shaders with boolean inputs crash

OSL (like Cycles) has no internal boolean type, instead an integer
input can be flagged to be shown as a boolean in the UI.
Cycles reacts to this by creating a boolean socket on the Blender
side, but as a result incorrectly called the boolean overload of the
set function even though the internal type is an integer.

There's another unrelated crash in the GPU viewport shader code that
appears to apply to every OSL node that outputs a shader, and the file
in T101702 triggers both, so this is only a partial fix for the report.

===

M   intern/cycles/blender/shader.cpp

===

diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp
index fd32e7ca1d7..dbc49df7f22 100644
--- a/intern/cycles/blender/shader.cpp
+++ b/intern/cycles/blender/shader.cpp
@@ -215,7 +215,9 @@ static void set_default_value(ShaderInput *input,
 }
 case SocketType::INT: {
   if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) {
-node->set(socket, get_boolean(b_sock.ptr, "default_value"));
+/* Make sure to call the int overload of set() since this is an 
integer socket as far as
+ * Cycles is concerned. */
+node->set(socket, get_boolean(b_sock.ptr, "default_value") ? 1 : 0);
   }
   else {
 node->set(socket, get_int(b_sock.ptr, "default_value"));

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b804f925c70] master: Fix T101185: New Mikktspace crashes on meshes without valid triangles

2022-10-04 Thread Lukas Stockner
Commit: b804f925c70cb7245038c14bede3ede11aed9a37
Author: Lukas Stockner
Date:   Wed Oct 5 02:42:43 2022 +0200
Branches: master
https://developer.blender.org/rBb804f925c70cb7245038c14bede3ede11aed9a37

Fix T101185: New Mikktspace crashes on meshes without valid triangles

The code already had a check for meshes with zero triangles, but it
didn't catch the case where all triangles are flagged as degenerate.
A simple way to reproduce this is to take a mesh and scale it to zero.

After checking the code, it turns out that in this case it's supposed
to just set all tangents to zero, so the fix simply is to detect this
case and skip the computation.

===

M   intern/mikktspace/mikktspace.hh

===

diff --git a/intern/mikktspace/mikktspace.hh b/intern/mikktspace/mikktspace.hh
index 2e5b0b065a8..e2c7084566f 100644
--- a/intern/mikktspace/mikktspace.hh
+++ b/intern/mikktspace/mikktspace.hh
@@ -178,24 +178,30 @@ template class Mikktspace {
 // put the degenerate triangles last.
 degenPrologue();
 
-// evaluate triangle level attributes and neighbor list
-initTriangle();
+if (nrTriangles == 0) {
+  // No point in building tangents if there are no non-degenerate 
triangles, so just zero them
+  tSpaces.resize(nrTSpaces);
+}
+else {
+  // evaluate triangle level attributes and neighbor list
+  initTriangle();
 
-// match up edge pairs
-buildNeighbors();
+  // match up edge pairs
+  buildNeighbors();
 
-// based on the 4 rules, identify groups based on connectivity
-build4RuleGroups();
+  // based on the 4 rules, identify groups based on connectivity
+  build4RuleGroups();
 
-// make tspaces, each group is split up into subgroups.
-// Finally a tangent space is made for every resulting subgroup
-generateTSpaces();
+  // make tspaces, each group is split up into subgroups.
+  // Finally a tangent space is made for every resulting subgroup
+  generateTSpaces();
 
-// degenerate quads with one good triangle will be fixed by copying a 
space from
-// the good triangle to the coinciding vertex.
-// all other degenerate triangles will just copy a space from any good 
triangle
-// with the same welded index in vertices[].
-degenEpilogue();
+  // degenerate quads with one good triangle will be fixed by copying a 
space from
+  // the good triangle to the coinciding vertex.
+  // all other degenerate triangles will just copy a space from any good 
triangle
+  // with the same welded index in vertices[].
+  degenEpilogue();
+}
 
 uint index = 0;
 for (uint f = 0; f < nrFaces; f++) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7f418290ba2] temp-T97352-3d-texturing-seam-bleeding-b2: Mikktspace: Fix triangle reordering predicate

2022-09-20 Thread Lukas Stockner
Commit: 7f418290ba2307dafbdb04e1930cbd5b02273b5e
Author: Lukas Stockner
Date:   Sat Sep 17 21:12:25 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB7f418290ba2307dafbdb04e1930cbd5b02273b5e

Mikktspace: Fix triangle reordering predicate

This only affected meshes containing degenerate triangles.

===

M   intern/mikktspace/mikktspace.hh

===

diff --git a/intern/mikktspace/mikktspace.hh b/intern/mikktspace/mikktspace.hh
index 4b45fa86e14..93e22658a56 100644
--- a/intern/mikktspace/mikktspace.hh
+++ b/intern/mikktspace/mikktspace.hh
@@ -401,7 +401,7 @@ template class Mikktspace {
 });
 
 std::stable_partition(triangles.begin(), triangles.end(), [](const 
Triangle ) {
-  return tri.markDegenerate;
+  return !tri.markDegenerate;
 });
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [91a29361a9a] temp-T97352-3d-texturing-seam-bleeding-b2: Fix T100330: Remove Render Slot not working for first slot

2022-09-20 Thread Lukas Stockner
Commit: 91a29361a9aff15c29b92d3e3fa2bf8b1d0c93d5
Author: Lukas Stockner
Date:   Sat Sep 17 01:46:03 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB91a29361a9aff15c29b92d3e3fa2bf8b1d0c93d5

Fix T100330: Remove Render Slot not working for first slot

This bug was caused by the weird ownership logic for render results.
Basically, the most recent render result is owned by the Render, while
all others are owned by the RenderSlots.
When a new render is started, the previous Render is handed over to its
slot, and the new slot is cleared. So far, so good.

However, when a slot is removed and happens to be the one with the most
recent render, this causes a complication.
The code handles this by making another slot the most recent one, along
with moving its result back to the Render, as if that had always been
the most recent one.

That works, unless there is no most recent render because you haven't
rendered anything yet. Unfortunately, there is no way to store "there
hasn't been a render yet", so the code still tries to perform this
handover but can't.
Previously, the code handled that case by just refusing to delete the
slot. However, this blocks users from deleting this slot.

But of course, if there hasn't been a render yet, the slots will not
contain anything yet, so this entire maneuver is pointless.
Therefore, the fix for the bug is to just skip it altogether if there
is no Render instead of failing the operation.

Technically, there is a weird corner case remaining, because Renders
are per-scene. Therefore, if a user renders images in one scene,
switches to a different scene, deletes a slot there and then switches
back, in some situations the result in the deleted slot might end up
in the next slot.
Unfortunately this is just a limitation of the weird split ownership
logic and can't just be worked around. The proper fix for this
probably would be to hand over ownership of the result from the Render
to the RenderSlot once the render is done, but this is quite complex.

Also fixes a crash when iuser->scene is NULL.

===

M   source/blender/blenkernel/intern/image.cc

===

diff --git a/source/blender/blenkernel/intern/image.cc 
b/source/blender/blenkernel/intern/image.cc
index 44e0e7be97b..000e51c0150 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -5567,15 +5567,14 @@ bool BKE_image_remove_renderslot(Image *ima, ImageUser 
*iuser, int slot)
   next_last_slot = current_slot;
 }
 
-if (!iuser) {
+if (iuser == nullptr || iuser->scene == nullptr) {
   return false;
 }
 Render *re = RE_GetSceneRender(iuser->scene);
-if (!re) {
-  return false;
+if (re != nullptr) {
+  RE_SwapResult(re, _last_slot->render);
+  RE_SwapResult(re, _last_slot->render);
 }
-RE_SwapResult(re, _last_slot->render);
-RE_SwapResult(re, _last_slot->render);
 current_last_slot = next_last_slot;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6069cab4420] master: Mikktspace: Fix triangle reordering predicate

2022-09-17 Thread Lukas Stockner
Commit: 6069cab442045775262691929e85b9c1fb3874dc
Author: Lukas Stockner
Date:   Sat Sep 17 21:12:25 2022 +0200
Branches: master
https://developer.blender.org/rB6069cab442045775262691929e85b9c1fb3874dc

Mikktspace: Fix triangle reordering predicate

This only affected meshes containing degenerate triangles.

===

M   intern/mikktspace/mikktspace.hh

===

diff --git a/intern/mikktspace/mikktspace.hh b/intern/mikktspace/mikktspace.hh
index 4b45fa86e14..93e22658a56 100644
--- a/intern/mikktspace/mikktspace.hh
+++ b/intern/mikktspace/mikktspace.hh
@@ -401,7 +401,7 @@ template class Mikktspace {
 });
 
 std::stable_partition(triangles.begin(), triangles.end(), [](const 
Triangle ) {
-  return tri.markDegenerate;
+  return !tri.markDegenerate;
 });
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f8a3ec48e4b] master: Fix T100330: Remove Render Slot not working for first slot

2022-09-17 Thread Lukas Stockner
Commit: f8a3ec48e4babf4a907b0350c5f7bd050343466f
Author: Lukas Stockner
Date:   Sat Sep 17 01:46:03 2022 +0200
Branches: master
https://developer.blender.org/rBf8a3ec48e4babf4a907b0350c5f7bd050343466f

Fix T100330: Remove Render Slot not working for first slot

This bug was caused by the weird ownership logic for render results.
Basically, the most recent render result is owned by the Render, while
all others are owned by the RenderSlots.
When a new render is started, the previous Render is handed over to its
slot, and the new slot is cleared. So far, so good.

However, when a slot is removed and happens to be the one with the most
recent render, this causes a complication.
The code handles this by making another slot the most recent one, along
with moving its result back to the Render, as if that had always been
the most recent one.

That works, unless there is no most recent render because you haven't
rendered anything yet. Unfortunately, there is no way to store "there
hasn't been a render yet", so the code still tries to perform this
handover but can't.
Previously, the code handled that case by just refusing to delete the
slot. However, this blocks users from deleting this slot.

But of course, if there hasn't been a render yet, the slots will not
contain anything yet, so this entire maneuver is pointless.
Therefore, the fix for the bug is to just skip it altogether if there
is no Render instead of failing the operation.

Technically, there is a weird corner case remaining, because Renders
are per-scene. Therefore, if a user renders images in one scene,
switches to a different scene, deletes a slot there and then switches
back, in some situations the result in the deleted slot might end up
in the next slot.
Unfortunately this is just a limitation of the weird split ownership
logic and can't just be worked around. The proper fix for this
probably would be to hand over ownership of the result from the Render
to the RenderSlot once the render is done, but this is quite complex.

Also fixes a crash when iuser->scene is NULL.

===

M   source/blender/blenkernel/intern/image.cc

===

diff --git a/source/blender/blenkernel/intern/image.cc 
b/source/blender/blenkernel/intern/image.cc
index 44e0e7be97b..000e51c0150 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -5567,15 +5567,14 @@ bool BKE_image_remove_renderslot(Image *ima, ImageUser 
*iuser, int slot)
   next_last_slot = current_slot;
 }
 
-if (!iuser) {
+if (iuser == nullptr || iuser->scene == nullptr) {
   return false;
 }
 Render *re = RE_GetSceneRender(iuser->scene);
-if (!re) {
-  return false;
+if (re != nullptr) {
+  RE_SwapResult(re, _last_slot->render);
+  RE_SwapResult(re, _last_slot->render);
 }
-RE_SwapResult(re, _last_slot->render);
-RE_SwapResult(re, _last_slot->render);
 current_last_slot = next_last_slot;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [44aaa9893ba] master: Eevee: Add support for Nishita sky texture

2022-09-16 Thread Lukas Stockner
Commit: 44aaa9893ba876d23c7b9e93c2ed83c55f96afd9
Author: Lukas Stockner
Date:   Fri Sep 16 15:04:47 2022 +0200
Branches: master
https://developer.blender.org/rB44aaa9893ba876d23c7b9e93c2ed83c55f96afd9

Eevee: Add support for Nishita sky texture

Sun Disc is currently not supported because it'll need special handling - on 
the one hand, I'm not sure if Eevee would handle a 1e6 coming out of a 
background shader without issues, and on the other hand it won't actually cast 
sharp shadows anyways.
I guess we'd want to internally add a sun to the lamps if Sun Disc is enabled, 
but getting that right is tricky since the user could e.g. swap RGB channels in 
the node tree and the lamp wouldn't match that.
Anyways, that can be handled later, the sky itself is already a start.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D13522

===

M   source/blender/draw/intern/draw_manager_data.c
M   source/blender/gpu/GPU_material.h
M   source/blender/gpu/intern/gpu_codegen.cc
M   source/blender/gpu/intern/gpu_material.c
M   source/blender/gpu/intern/gpu_node_graph.c
M   source/blender/gpu/intern/gpu_node_graph.h
M   source/blender/gpu/shaders/material/gpu_shader_material_tex_sky.glsl
M   source/blender/makesdna/DNA_color_types.h
M   source/blender/nodes/shader/CMakeLists.txt
M   source/blender/nodes/shader/nodes/node_shader_tex_sky.cc

===

diff --git a/source/blender/draw/intern/draw_manager_data.c 
b/source/blender/draw/intern/draw_manager_data.c
index c75049508f9..820242720c8 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1631,6 +1631,10 @@ void DRW_shgroup_add_material_resources(DRWShadingGroup 
*grp, struct GPUMaterial
   /* Color Ramp */
   DRW_shgroup_uniform_texture(grp, tex->sampler_name, *tex->colorband);
 }
+else if (tex->sky) {
+  /* Sky */
+  DRW_shgroup_uniform_texture_ex(grp, tex->sampler_name, *tex->sky, 
tex->sampler_state);
+}
   }
 
   GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material);
diff --git a/source/blender/gpu/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index 023221543ec..922988bf95a 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -162,6 +162,12 @@ GPUNodeLink *GPU_image_tiled(GPUMaterial *mat,
  struct ImageUser *iuser,
  eGPUSamplerState sampler_state);
 GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, 
struct ImageUser *iuser);
+GPUNodeLink *GPU_image_sky(GPUMaterial *mat,
+   int width,
+   int height,
+   const float *pixels,
+   float *layer,
+   eGPUSamplerState sampler_state);
 GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float 
*row);
 
 /**
@@ -297,6 +303,7 @@ typedef struct GPUMaterialTexture {
   struct ImageUser iuser;
   bool iuser_available;
   struct GPUTexture **colorband;
+  struct GPUTexture **sky;
   char sampler_name[32];   /* Name of sampler in GLSL. */
   char tiled_mapping_name[32]; /* Name of tile mapping sampler in GLSL. */
   int users;
diff --git a/source/blender/gpu/intern/gpu_codegen.cc 
b/source/blender/gpu/intern/gpu_codegen.cc
index 75e148e0a8f..2241bcf9f9b 100644
--- a/source/blender/gpu/intern/gpu_codegen.cc
+++ b/source/blender/gpu/intern/gpu_codegen.cc
@@ -386,6 +386,10 @@ void GPUCodegen::generate_resources()
   const char *name = 
info.name_buffer.append_sampler_name(tex->sampler_name);
   info.sampler(slot++, ImageType::FLOAT_1D_ARRAY, name, Frequency::BATCH);
 }
+else if (tex->sky) {
+  const char *name = 
info.name_buffer.append_sampler_name(tex->sampler_name);
+  info.sampler(0, ImageType::FLOAT_2D_ARRAY, name, Frequency::BATCH);
+}
 else if (tex->tiled_mapping_name[0] != '\0') {
   const char *name = 
info.name_buffer.append_sampler_name(tex->sampler_name);
   info.sampler(slot++, ImageType::FLOAT_2D_ARRAY, name, Frequency::BATCH);
diff --git a/source/blender/gpu/intern/gpu_material.c 
b/source/blender/gpu/intern/gpu_material.c
index 75066b21e7b..96809db1587 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -41,12 +41,18 @@
 
 /* Structs */
 #define MAX_COLOR_BAND 128
+#define MAX_GPU_SKIES 8
 
 typedef struct GPUColorBandBuilder {
   float pixels[MAX_COLOR_BAND][CM_TABLE + 1][4];
   int current_layer;
 } GPUColorBandBuilder;
 
+typedef struct GPUSkyBuilder {
+  float pixels[MAX_GPU_SKIES][GPU_SKY_WIDTH * GPU_SKY_HEIGHT][4];
+  int current_layer;
+} GPUSkyBuilder;
+
 struct GPUMaterial {
   /* Contains GPUShader and source code for deferred compila

[Bf-blender-cvs] [6951e8890ae] master: Mikktspace: Optimized port to C++

2022-09-06 Thread Lukas Stockner
Commit: 6951e8890ae3d0923e377cff6023d78202d81a03
Author: Lukas Stockner
Date:   Sat Sep 3 17:21:44 2022 +0200
Branches: master
https://developer.blender.org/rB6951e8890ae3d0923e377cff6023d78202d81a03

Mikktspace: Optimized port to C++

This commit is a big overhaul to the Mikktspace module, which is used
to compute tangents. I'm not calling it a rewrite since it's the
result of a lot of iterations on the original code, but pretty much
everything is reworked somehow.

Overall goal was to a) make it faster and b) make it maintainable.

Notable changes:
- Since the callbacks for requesting geometry data were a big
  bottleneck before, I've ported it to C++ and made it header-only,
  templating on the data source. That way, the compiler generates code
  specific to the caller, which allows it to inline the data source and
  specialize for some cases (e.g. subd vs. non-subd in Cycles).
- The one input parameter, an optional angle threshold, was not used
  anywhere. Turns out that removing it allows for considerable
  algorithmic simplification, removing a lot of the complexity in the
  later stages. Therefore, I've just removed the option in the new code.
- The code computes several outputs, but only one (the tangent itself)
  is ever used in Blender. Therefore, I've removed the others to
  simplify the code. They could easily be brought back if needed, none
  of the algorithmic simplifications are conflicting with them.
- The original code had fallback paths for many steps in case temporary
  memory allocation fails, but that never actually gets used anyways
  since malloc() doesn't really ever return NULL in practise, so I
  removed them.
- In general, I've restructured A LOT of the code to make the
  algorithms clearer and make use of some C++ features (vectors,
  std::array, booleans, classes), though there's still some of cleanup
  that could be done.
- Parallelized duplicate detection, neighbor detection, triangle
  tangent computation, degenerate triangle handling and tangent space
  accumulation.
- Replaced several algorithms with faster equivalents: Duplicate
  detection uses a (concurrent) hash set now, neighbor detection uses
  Radixsort and splits vertices by index pairs etc.

As for results, the exact speedup depends on the scene of course, but
let's consider the file from T97378:
- Blender 3.1 (before D14675): 6.07sec
- Blender 3.2 (with D14675): 4.62sec
- rBf0a36599007d (last nightly build): 4.42sec
- With this commit: 0.90sec

This speedup will mostly be noticed at the start of Cycles renders and,
even more importantly, in Eevee when doing something that changes the
geometry (e.g. animating) on a model using normal maps.

Differential Revision: https://developer.blender.org/D15589

===

M   intern/cycles/blender/CMakeLists.txt
M   intern/cycles/blender/mesh.cpp
M   intern/cycles/util/math.h
M   intern/mikktspace/CMakeLists.txt
A   intern/mikktspace/mikk_atomic_hash_set.hh
A   intern/mikktspace/mikk_float3.hh
A   intern/mikktspace/mikk_util.hh
D   intern/mikktspace/mikktspace.c
D   intern/mikktspace/mikktspace.h
A   intern/mikktspace/mikktspace.hh
M   source/blender/blenkernel/intern/editmesh_tangent.cc
M   source/blender/blenkernel/intern/mesh_tangent.cc

===

diff --git a/intern/cycles/blender/CMakeLists.txt 
b/intern/cycles/blender/CMakeLists.txt
index 24bc165c708..666b0077a72 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -65,6 +65,8 @@ set(LIB
   cycles_subd
   cycles_util
 
+  bf_intern_mikktspace
+
   ${Epoxy_LIBRARIES}
   ${PYTHON_LINKFLAGS}
   ${PYTHON_LIBRARIES}
@@ -101,6 +103,10 @@ if(WITH_MOD_FLUID)
   add_definitions(-DWITH_FLUID)
 endif()
 
+if(WITH_TBB)
+  add_definitions(-DWITH_TBB)
+endif()
+
 if(WITH_OPENVDB)
   add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS})
   list(APPEND INC_SYS
diff --git a/intern/cycles/blender/mesh.cpp b/intern/cycles/blender/mesh.cpp
index 47c3ff65aae..1d1eadebc39 100644
--- a/intern/cycles/blender/mesh.cpp
+++ b/intern/cycles/blender/mesh.cpp
@@ -24,7 +24,7 @@
 #include "util/log.h"
 #include "util/math.h"
 
-#include "mikktspace.h"
+#include "mikktspace.hh"
 
 #include "DNA_meshdata_types.h"
 
@@ -32,16 +32,15 @@ CCL_NAMESPACE_BEGIN
 
 /* Tangent Space */
 
-struct MikkUserData {
-  MikkUserData(const BL::Mesh _mesh,
-   const char *layer_name,
-   const Mesh *mesh,
-   float3 *tangent,
-   float *tangent_sign)
+template struct MikkMeshWrapper {
+  MikkMeshWrapper(const BL::Mesh _mesh,
+  const char *layer_name,
+  const Mesh *mesh,
+  float3 *tangent,
+  float *tangent_sign)
   : mesh(mesh), texface(NULL), orco(NULL), tangent(tangent), 
tangent_sign(t

[Bf-blender-cvs] [6b6428fcbcc] master: Cleanup: Move (edit)mesh_tangent.c to C++

2022-09-06 Thread Lukas Stockner
Commit: 6b6428fcbcc7b210e6d3dcf51df9c6de3070a9db
Author: Lukas Stockner
Date:   Sat Sep 3 16:35:24 2022 +0200
Branches: master
https://developer.blender.org/rB6b6428fcbcc7b210e6d3dcf51df9c6de3070a9db

Cleanup: Move (edit)mesh_tangent.c to C++

This changes the two tangent-related files in BKE to C++ in preparation for the 
C++ Mikktspace port in D15589.
For now, they still use the original Mikktspace.

Differential Revision: https://developer.blender.org/D15636

===

M   source/blender/blenkernel/CMakeLists.txt
R089source/blender/blenkernel/intern/editmesh_tangent.c 
source/blender/blenkernel/intern/editmesh_tangent.cc
R087source/blender/blenkernel/intern/mesh_tangent.c 
source/blender/blenkernel/intern/mesh_tangent.cc

===

diff --git a/source/blender/blenkernel/CMakeLists.txt 
b/source/blender/blenkernel/CMakeLists.txt
index 61549a66e1f..9521da8417e 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -128,7 +128,7 @@ set(SRC
   intern/editmesh.c
   intern/editmesh_bvh.c
   intern/editmesh_cache.cc
-  intern/editmesh_tangent.c
+  intern/editmesh_tangent.cc
   intern/effect.c
   intern/fcurve.c
   intern/fcurve_cache.c
@@ -211,7 +211,7 @@ set(SRC
   intern/mesh_remesh_voxel.cc
   intern/mesh_runtime.cc
   intern/mesh_sample.cc
-  intern/mesh_tangent.c
+  intern/mesh_tangent.cc
   intern/mesh_tessellate.cc
   intern/mesh_validate.cc
   intern/mesh_wrapper.cc
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c 
b/source/blender/blenkernel/intern/editmesh_tangent.cc
similarity index 89%
rename from source/blender/blenkernel/intern/editmesh_tangent.c
rename to source/blender/blenkernel/intern/editmesh_tangent.cc
index ec608f79e66..5a01f64826d 100644
--- a/source/blender/blenkernel/intern/editmesh_tangent.c
+++ b/source/blender/blenkernel/intern/editmesh_tangent.cc
@@ -29,7 +29,7 @@
 /* Necessary complexity to handle looptri's as quads for correct tangents */
 #define USE_LOOPTRI_DETECT_QUADS
 
-typedef struct {
+struct SGLSLEditMeshToTangent {
   const float (*precomputedFaceNormals)[3];
   const float (*precomputedLoopNormals)[3];
   const BMLoop *(*looptris)[3];
@@ -44,8 +44,7 @@ typedef struct {
   const int *face_as_quad_map;
   int num_face_as_quad_map;
 #endif
-
-} SGLSLEditMeshToTangent;
+};
 
 #ifdef USE_LOOPTRI_DETECT_QUADS
 /* seems weak but only used on quads */
@@ -61,7 +60,7 @@ static const BMLoop *bm_loop_at_face_index(const BMFace *f, 
int vert_index)
 
 static int emdm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
 {
-  SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+  SGLSLEditMeshToTangent *pMesh = static_cast(pContext->m_pUserData);
 
 #ifdef USE_LOOPTRI_DETECT_QUADS
   return pMesh->num_face_as_quad_map;
@@ -73,7 +72,7 @@ static int emdm_ts_GetNumFaces(const SMikkTSpaceContext 
*pContext)
 static int emdm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const 
int face_num)
 {
 #ifdef USE_LOOPTRI_DETECT_QUADS
-  SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+  SGLSLEditMeshToTangent *pMesh = static_cast(pContext->m_pUserData);
   if (pMesh->face_as_quad_map) {
 const BMLoop **lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
 if (lt[0]->f->len == 4) {
@@ -93,7 +92,7 @@ static void emdm_ts_GetPosition(const SMikkTSpaceContext 
*pContext,
 const int vert_index)
 {
   // BLI_assert(vert_index >= 0 && vert_index < 4);
-  SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+  SGLSLEditMeshToTangent *pMesh = static_cast(pContext->m_pUserData);
   const BMLoop **lt;
   const BMLoop *l;
 
@@ -127,7 +126,7 @@ static void emdm_ts_GetTextureCoordinate(const 
SMikkTSpaceContext *pContext,
  const int vert_index)
 {
   // BLI_assert(vert_index >= 0 && vert_index < 4);
-  SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+  SGLSLEditMeshToTangent *pMesh = static_cast(pContext->m_pUserData);
   const BMLoop **lt;
   const BMLoop *l;
 
@@ -150,7 +149,7 @@ static void emdm_ts_GetTextureCoordinate(const 
SMikkTSpaceContext *pContext,
 
 finally:
   if (pMesh->cd_loop_uv_offset != -1) {
-const float *uv = BM_ELEM_CD_GET_VOID_P(l, pMesh->cd_loop_uv_offset);
+const float *uv = BM_ELEM_CD_GET_FLOAT_P(l, pMesh->cd_loop_uv_offset);
 copy_v2_v2(r_uv, uv);
   }
   else {
@@ -165,7 +164,7 @@ static void emdm_ts_GetNormal(const SMikkTSpaceContext 
*pContext,
   const int vert_index)
 {
   // BLI_assert(vert_index >= 0 && vert_index < 4);
-  SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+  SGLSLEditMeshToTangent *pMesh = static_cast(pContext->m_pUserData);
   const BMLoop **lt;
   const BMLoop *l;
 
@@ -210,7 +209,7 @@ static void emdm_ts

[Bf-blender-cvs] [83d412a504b] blender-v3.2-release: Fix T98367: Light group passes do not work when shadow catcher is used

2022-07-26 Thread Lukas Stockner
Commit: 83d412a504bf5e1399f61b34154ef8927049ac65
Author: Lukas Stockner
Date:   Sun Jul 24 20:32:19 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB83d412a504bf5e1399f61b34154ef8927049ac65

Fix T98367: Light group passes do not work when shadow catcher is used

===

M   intern/cycles/session/buffers.cpp

===

diff --git a/intern/cycles/session/buffers.cpp 
b/intern/cycles/session/buffers.cpp
index b74074765fe..e060e0c6829 100644
--- a/intern/cycles/session/buffers.cpp
+++ b/intern/cycles/session/buffers.cpp
@@ -209,7 +209,7 @@ const BufferPass 
*BufferParams::get_actual_display_pass(const BufferPass *pass)
 return nullptr;
   }
 
-  if (pass->type == PASS_COMBINED) {
+  if (pass->type == PASS_COMBINED && pass->lightgroup.empty()) {
 const BufferPass *shadow_catcher_matte_pass = 
find_pass(PASS_SHADOW_CATCHER_MATTE, pass->mode);
 if (shadow_catcher_matte_pass) {
   pass = shadow_catcher_matte_pass;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6db059e3d7c] master: Render: Update lightgroup membership in objects and world if lightgroup is renamed

2022-07-24 Thread Lukas Stockner
Commit: 6db059e3d7c3156943e3f0646612eb1d74409215
Author: Lukas Stockner
Date:   Mon May 16 10:52:49 2022 +0200
Branches: master
https://developer.blender.org/rB6db059e3d7c3156943e3f0646612eb1d74409215

Render: Update lightgroup membership in objects and world if lightgroup is 
renamed

As discussed, this only updates objects in and the world of the scene to which 
the view layer belongs, which also avoids the problem of not having a BMain 
available.

Differential Revision: https://developer.blender.org/D14740

===

M   source/blender/blenkernel/BKE_layer.h
M   source/blender/blenkernel/intern/layer.c
M   source/blender/makesrna/intern/rna_scene.c

===

diff --git a/source/blender/blenkernel/BKE_layer.h 
b/source/blender/blenkernel/BKE_layer.h
index 3e4f2fe154e..9a6c3cf2b5f 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -590,7 +590,8 @@ void BKE_view_layer_set_active_lightgroup(struct ViewLayer 
*view_layer,
   struct ViewLayerLightgroup 
*lightgroup);
 struct ViewLayer *BKE_view_layer_find_with_lightgroup(
 struct Scene *scene, struct ViewLayerLightgroup *view_layer_lightgroup);
-void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer,
+void BKE_view_layer_rename_lightgroup(struct Scene *scene,
+  ViewLayer *view_layer,
   ViewLayerLightgroup *lightgroup,
   const char *name);
 
diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index ac582ff69ca..dabc76f29ca 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -39,6 +39,7 @@
 #include "DNA_view3d_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_workspace_types.h"
+#include "DNA_world_types.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_debug.h"
@@ -2588,12 +2589,36 @@ ViewLayer *BKE_view_layer_find_with_lightgroup(struct 
Scene *scene,
   return NULL;
 }
 
-void BKE_view_layer_rename_lightgroup(ViewLayer *view_layer,
+void BKE_view_layer_rename_lightgroup(Scene *scene,
+  ViewLayer *view_layer,
   ViewLayerLightgroup *lightgroup,
   const char *name)
 {
+  char old_name[64];
+  BLI_strncpy_utf8(old_name, lightgroup->name, sizeof(old_name));
   BLI_strncpy_utf8(lightgroup->name, name, sizeof(lightgroup->name));
   viewlayer_lightgroup_make_name_unique(view_layer, lightgroup);
+
+  if (scene != NULL) {
+/* Update objects in the scene to refer to the new name instead. */
+FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
+  if (!ID_IS_LINKED(ob) && ob->lightgroup != NULL) {
+LightgroupMembership *lgm = ob->lightgroup;
+if (STREQ(lgm->name, old_name)) {
+  BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
+}
+  }
+}
+FOREACH_SCENE_OBJECT_END;
+
+/* Update the scene's world to refer to the new name instead. */
+if (scene->world != NULL && !ID_IS_LINKED(scene->world) && 
scene->world->lightgroup != NULL) {
+  LightgroupMembership *lgm = scene->world->lightgroup;
+  if (STREQ(lgm->name, old_name)) {
+BLI_strncpy_utf8(lgm->name, lightgroup->name, sizeof(lgm->name));
+  }
+}
+  }
 }
 
 void BKE_lightgroup_membership_get(struct LightgroupMembership *lgm, char 
*name)
diff --git a/source/blender/makesrna/intern/rna_scene.c 
b/source/blender/makesrna/intern/rna_scene.c
index daf4c99845d..f24aec3447b 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2501,7 +2501,7 @@ static void rna_ViewLayerLightgroup_name_set(PointerRNA 
*ptr, const char *value)
   Scene *scene = (Scene *)ptr->owner_id;
   ViewLayer *view_layer = BKE_view_layer_find_with_lightgroup(scene, 
lightgroup);
 
-  BKE_view_layer_rename_lightgroup(view_layer, lightgroup, value);
+  BKE_view_layer_rename_lightgroup(scene, view_layer, lightgroup, value);
 }
 
 /* Fake value, used internally (not saved to DNA). */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d26c29d8e46] master: Fix T98367: Light group passes do not work when shadow catcher is used

2022-07-24 Thread Lukas Stockner
Commit: d26c29d8e46c284b27cc6d3bcde8fde7ff678ae4
Author: Lukas Stockner
Date:   Sun Jul 24 20:32:19 2022 +0200
Branches: master
https://developer.blender.org/rBd26c29d8e46c284b27cc6d3bcde8fde7ff678ae4

Fix T98367: Light group passes do not work when shadow catcher is used

===

M   intern/cycles/session/buffers.cpp

===

diff --git a/intern/cycles/session/buffers.cpp 
b/intern/cycles/session/buffers.cpp
index b74074765fe..e060e0c6829 100644
--- a/intern/cycles/session/buffers.cpp
+++ b/intern/cycles/session/buffers.cpp
@@ -209,7 +209,7 @@ const BufferPass 
*BufferParams::get_actual_display_pass(const BufferPass *pass)
 return nullptr;
   }
 
-  if (pass->type == PASS_COMBINED) {
+  if (pass->type == PASS_COMBINED && pass->lightgroup.empty()) {
 const BufferPass *shadow_catcher_matte_pass = 
find_pass(PASS_SHADOW_CATCHER_MATTE, pass->mode);
 if (shadow_catcher_matte_pass) {
   pass = shadow_catcher_matte_pass;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [552abb838c7] principled-v2: Replace metallic Fresnel with F82 model

2022-07-23 Thread Lukas Stockner
Commit: 552abb838c76d44a0d7d1226b59a1ab381e88386
Author: Lukas Stockner
Date:   Sun Jul 24 03:40:57 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB552abb838c76d44a0d7d1226b59a1ab381e88386

Replace metallic Fresnel with F82 model

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/closure/bsdf_util.h
M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/scene/shader_nodes.cpp
M   intern/cycles/scene/shader_nodes.h
M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
M   source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 4ce62d2298a..26be3f16f3a 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -242,8 +242,7 @@ static float precompute_ggx_dielectric_E(float rough, float 
mu, float eta, float
   bsdf.ior = eta;
   bsdf.extra = (MicrofacetExtra *)
   bsdf.T = make_float3(1.0f, 0.0f, 0.0f);
-  extra.metal_base = extra.metal_edge = zero_float3();
-  extra.metal_falloff = 0.0f;
+  extra.metallic = extra.metal_base = extra.metal_edge_factor = zero_float3();
 
   /* Dependency warning - this relies on the ggx_E and ggx_E_avg lookup 
tables! */
   float E = microfacet_ggx_E(mu, rough), E_avg = microfacet_ggx_E_avg(rough);
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 5c7e70181d7..4fe36b5f235 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -19,8 +19,8 @@ typedef struct MicrofacetExtra {
 
 typedef struct MicrofacetExtrav2 {
   /* Metallic fresnel control */
-  float3 metal_base, metal_edge;
-  float metal_falloff;
+  float3 metal_base, metal_edge_factor;
+  float3 metallic;
   float dielectric;
 } MicrofacetExtrav2;
 
@@ -66,8 +66,8 @@ ccl_device_forceinline float3 reflection_color(ccl_private 
const MicrofacetBsdf
 /* Metallic Fresnel: Kinda Schlick-Fresnel-like with configurable F0 and 
F90
  * as well as falloff control. F90=white and falloff=0.2 gives classic 
Schlick Fresnel.
  * Metallic factor and albedo scaling is baked into the F0 and F90 
parameters. */
-float metallicBlend = powf(1.0f - cosHL, extra->metal_falloff);
-float3 metallic = mix(extra->metal_base, extra->metal_edge, metallicBlend);
+float3 metallic = extra->metallic *
+  fresnel_metallic(extra->metal_base, 
extra->metal_edge_factor, cosHL);
 /* Dielectric Fresnel, just basic IOR control. */
 float dielectric = extra->dielectric * fresnel_dielectric_cos(cosHL, 
bsdf->ior);
 
@@ -187,18 +187,13 @@ ccl_device int 
bsdf_microfacet_ggx_fresnel_v2_setup(KernelGlobals kg,
   MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
 
   if (metallic > 0.0f) {
-extra->metal_base = saturate(extra->metal_base);
-extra->metal_edge = saturate(extra->metal_edge);
-extra->metal_falloff = 1.0f / clamp(extra->metal_falloff, 1e-3f, 1.0f);
-float3 metal_Fss = metallic_Fss(extra->metal_base, extra->metal_edge, 
extra->metal_falloff);
-float3 metal_scale = microfacet_ggx_albedo_scaling(kg, bsdf, sd, 
metal_Fss);
-extra->metal_base *= metallic * metal_scale;
-extra->metal_edge *= metallic * metal_scale;
+float3 metal_Fss = fresnel_metallic_Fss(extra->metal_base, 
extra->metal_edge_factor);
+extra->metallic = metallic * microfacet_ggx_albedo_scaling(kg, bsdf, sd, 
metal_Fss);
   }
   else {
-extra->metal_falloff = 0.0f;
+extra->metallic = zero_float3();
 extra->metal_base = zero_float3();
-extra->metal_edge = zero_float3();
+extra->metal_edge_factor = zero_float3();
   }
 
   if (dielectric > 0.0f) {
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index a1399bff5fe..a5c77763133 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -131,16 +131,14 @@ ccl_device_forceinline float clearcoat_E(KernelGlobals 
kg, float mu, float rough
   return table * fresnel_dielectric_cos(mu, 1.5f);
 }
 
-ccl_device_inline float3 metallic_Fss(float3 F0, float3 F90, float falloff)
+ccl_device_inline float3 fresnel_metallic_Fss(float3 F0, float3 B)
 {
-  /* Fss for mix(F0, F90, (1-cosNI)^falloff) */
-  return mix(F0, F90, 2.0f / (sqr(falloff) + 3 * falloff + 2));
+  return saturate(mix(F0, one_float3(), 1.0f / 21.0f) - B * (1.0f / 126.0f));
 }
 
 ccl_device_inline float3 schlick_fresnel_Fs

[Bf-blender-cvs] [86b8823b177] principled-v2: Fix precomputation lookup for IOR<1

2022-07-23 Thread Lukas Stockner
Commit: 86b8823b177181d51c2abef8b11bfa78033ef7fb
Author: Lukas Stockner
Date:   Sat Jul 23 19:59:17 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB86b8823b177181d51c2abef8b11bfa78033ef7fb

Fix precomputation lookup for IOR<1

===

M   intern/cycles/kernel/closure/bsdf_microfacet_util.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index e6688e8a82b..a1399bff5fe 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -88,13 +88,11 @@ ccl_device_forceinline float 
microfacet_ggx_glass_E(KernelGlobals kg,
 float ior)
 {
   bool inv_table = (ior < 1.0f);
-  if (inv_table) {
-ior = 1.0f / ior;
-  }
   int offset = inv_table ? kernel_data.tables.ggx_glass_inv_E_offset :
kernel_data.tables.ggx_glass_E_offset;
 
-  float x = mu, y = 1 - rough, z = sqrtf(0.5f * (ior - 1.0f));
+  float x = mu, y = 1 - rough;
+  float z = sqrtf(0.5f * ((inv_table? 1.0f / ior : ior) - 1.0f));
   return lookup_table_read_3D(kg, x, y, z, offset, 16, 16, 16);
 }
 
@@ -104,9 +102,6 @@ ccl_device_forceinline float 
microfacet_ggx_dielectric_E(KernelGlobals kg,
  float ior)
 {
   bool inv_table = (ior < 1.0f);
-  if (inv_table) {
-ior = 1.0f / ior;
-  }
   int offset = inv_table ? kernel_data.tables.ggx_dielectric_inv_E_offset :
kernel_data.tables.ggx_dielectric_E_offset;
 
@@ -114,7 +109,7 @@ ccl_device_forceinline float 
microfacet_ggx_dielectric_E(KernelGlobals kg,
   float F0 = fresnel_dielectric_cos(1.0f, ior);
   float x = mix(mu, inverse_lerp(1.0f, F0, macro_fresnel), 0.5f);
   float y = 1 - rough;
-  float z = sqrtf(0.5f * (ior - 1.0f));
+  float z = sqrtf(0.5f * ((inv_table? 1.0f / ior : ior) - 1.0f));
 
   return lookup_table_read_3D(kg, x, y, z, offset, 16, 16, 16);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a434e780959] principled-v2: Make clearcoat tint independent of clearcoat strength and caustics setting

2022-07-23 Thread Lukas Stockner
Commit: a434e7809599348b2d5c9b5a89c1cddea88b7064
Author: Lukas Stockner
Date:   Sat Jul 23 00:28:38 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBa434e7809599348b2d5c9b5a89c1cddea88b7064

Make clearcoat tint independent of clearcoat strength and caustics setting

===

M   intern/cycles/kernel/svm/closure_principled.h

===

diff --git a/intern/cycles/kernel/svm/closure_principled.h 
b/intern/cycles/kernel/svm/closure_principled.h
index 8e6d0b141e2..d352cac2fcc 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -493,27 +493,11 @@ ccl_device_inline float3 
principled_v2_clearcoat(KernelGlobals kg,
  int path_flag,
  uint data)
 {
-#ifdef __CAUSTICS_TRICKS__
-  if (!kernel_data.integrator.caustics_reflective && (path_flag & 
PATH_RAY_DIFFUSE)) {
-return one_float3();
-  }
-#endif
-
   uint clearcoat_offset, roughness_offset, tint_offset, normal_offset;
   svm_unpack_node_uchar4(data, _offset, _offset, 
_offset, _offset);
-  float clearcoat = saturatef(stack_load_float(stack, clearcoat_offset));
-
-  if (clearcoat <= CLOSURE_WEIGHT_CUTOFF) {
-return one_float3();
-  }
 
-  float roughness = saturatef(stack_load_float(stack, roughness_offset));
   float3 N = stack_valid(normal_offset) ? stack_load_float3(stack, 
normal_offset) : sd->N;
-  if (!(sd->type & PRIMITIVE_CURVE)) {
-N = ensure_valid_reflection(sd->Ng, sd->I, N);
-  }
   float3 tint = saturate(stack_load_float3(stack, tint_offset));
-
   if (tint != one_float3()) {
 /* Tint is normalized to perpendicular incidence.
  * Therefore, if we define the coating thickness as length 1, the length 
along the ray is
@@ -521,8 +505,6 @@ ccl_device_inline float3 
principled_v2_clearcoat(KernelGlobals kg,
  * From Beer's law, we have T = exp(-sigma_e * t).
  * Therefore, tint = exp(-sigma_e * 1) (per def.), so -sigma_e = log(tint).
  * From this, T = exp(log(tint) * t) = exp(log(tint)) ^ t = tint ^ t;
- * Additionally, the strength input controls the optical depth for a 
smooth fade
- * from maximum to zero impact.
  *
  * Note that this is only an approximation - in particular, the exit path 
of the
  * light that bounces off the main layer is not accounted for.
@@ -541,14 +523,30 @@ ccl_device_inline float3 
principled_v2_clearcoat(KernelGlobals kg,
  * TIR is no concern here since we're always coming from the outside. */
 float cosNT = sqrtf(1.0f - sqr(1.0f / 1.5f) * (1 - sqr(cosNI)));
 float optical_depth = 1.0f / cosNT;
-tint = pow(tint, optical_depth * clearcoat);
+tint = pow(tint, optical_depth);
+  }
+
+  float clearcoat = saturatef(stack_load_float(stack, clearcoat_offset));
+  if (clearcoat <= CLOSURE_WEIGHT_CUTOFF) {
+return tint;
+  }
+
+#ifdef __CAUSTICS_TRICKS__
+  if (!kernel_data.integrator.caustics_reflective && (path_flag & 
PATH_RAY_DIFFUSE)) {
+return tint;
+  }
+#endif
+
+  float roughness = saturatef(stack_load_float(stack, roughness_offset));
+  if (!(sd->type & PRIMITIVE_CURVE)) {
+N = ensure_valid_reflection(sd->Ng, sd->I, N);
   }
 
   ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
   sd, sizeof(MicrofacetBsdf), clearcoat * weight);
 
   if (bsdf == NULL) {
-return one_float3();
+return tint;
   }
 
   bsdf->N = N;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6f71036b28e] principled-v2: Merge remote-tracking branch 'origin/master' into principled-v2

2022-07-23 Thread Lukas Stockner
Commit: 6f71036b28e9bfdf6dc71a15b76010e44e1b0e57
Author: Lukas Stockner
Date:   Sat Jul 23 00:28:29 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB6f71036b28e9bfdf6dc71a15b76010e44e1b0e57

Merge remote-tracking branch 'origin/master' into principled-v2

===



===

diff --cc intern/cycles/kernel/types.h
index 80e09805d08,4f4b811a8e7..9cb610503b7
--- a/intern/cycles/kernel/types.h
+++ b/intern/cycles/kernel/types.h
@@@ -1349,15 -1148,8 +1148,16 @@@ typedef enum KernelBVHLayout 
  
  typedef struct KernelTables {
int beckmann_offset;
+   int filter_table_offset;
 +  int ggx_E_offset;
 +  int ggx_E_avg_offset;
 +  int ggx_clearcoat_E_offset;
 +  int ggx_glass_E_offset;
 +  int ggx_glass_inv_E_offset;
 +  int ggx_dielectric_E_offset;
 +  int ggx_dielectric_inv_E_offset;
 +  int sheen_E_offset;
-   int pad1, pad2, pad3;
+   int pad1, pad2;
  } KernelTables;
  static_assert_align(KernelTables, 16);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b4c5db0a1a5] principled-v2: Add special handling for specular case in Glass closure

2022-07-05 Thread Lukas Stockner
Commit: b4c5db0a1a55ead78ec4188f5e496c6b0f8590e4
Author: Lukas Stockner
Date:   Tue Jul 5 22:09:24 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBb4c5db0a1a55ead78ec4188f5e496c6b0f8590e4

Add special handling for specular case in Glass closure

===

M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 942812aaa71..121b9a2dd50 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -74,7 +74,13 @@ ccl_device float3 
bsdf_microfacet_ggx_glass_eval_reflect(ccl_private const Shade
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf 
*)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
+  float alpha2 = alpha_x * alpha_y;
+
+  if (alpha2 <= 1e-7f) {
+*pdf = 0.0f;
+return zero_float3();
+  }
+
   float3 N = bsdf->N;
 
   float cosNO = dot(N, I);
@@ -85,7 +91,6 @@ ccl_device float3 
bsdf_microfacet_ggx_glass_eval_reflect(ccl_private const Shade
   }
 
   float3 m = normalize(omega_in + I);
-  float alpha2 = alpha_x * alpha_y;
   float D = microfacet_ggx_D(dot(N, m), alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
   float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
@@ -111,10 +116,15 @@ ccl_device float3 
bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Shad
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf 
*)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
+  float alpha2 = alpha_x * alpha_y;
   float eta = bsdf->ior;
   float3 N = bsdf->N;
 
+  if (alpha2 <= 1e-7f) {
+*pdf = 0.0f;
+return zero_float3();
+  }
+
   float cosNO = dot(N, I);
   float cosNI = dot(N, omega_in);
   if (cosNO <= 0 || cosNI >= 0) {
@@ -134,7 +144,6 @@ ccl_device float3 
bsdf_microfacet_ggx_glass_eval_transmit(ccl_private const Shad
 return zero_float3();
   }
 
-  float alpha2 = alpha_x * alpha_y;
   float D = microfacet_ggx_D(dot(N, m), alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
   float lambdaI = microfacet_ggx_lambda(cosNI, alpha2);
@@ -168,7 +177,6 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private 
const ShaderClosure
   ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf 
*)sc;
   float alpha_x = bsdf->alpha_x;
   float alpha_y = bsdf->alpha_y;
-  kernel_assert(alpha_x * alpha_y > 1e-7f);
   float eta = bsdf->ior;
   float3 N = bsdf->N;
   int label;
@@ -220,8 +228,26 @@ ccl_device int 
bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
   float randw = hash_float2_to_float(make_float2(randu, randv));
   bool do_reflect = randw < fresnel;
 
-  /* Common microfacet model terms. */
   float alpha2 = alpha_x * alpha_y;
+  if (alpha2 <= 1e-7f) {
+/* Specular case, just return some high number for MIS */
+*pdf = 1e6f;
+*eval = make_float3(1e6f, 1e6f, 1e6f);
+
+*omega_in = do_reflect ? R : T;
+#ifdef __RAY_DIFFERENTIALS__
+*domega_in_dx = do_reflect ? dRdx : dTdx;
+*domega_in_dy = do_reflect ? dRdy : dTdy;
+#endif
+
+if (bsdf->type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID) {
+  *eval *= do_reflect ? reflection_color(bsdf, *omega_in, m) : 
bsdf->extra->color;
+}
+
+return LABEL_SINGULAR | (do_reflect ? LABEL_REFLECT : LABEL_TRANSMIT);
+  }
+
+  /* Common microfacet model terms. */
   float D = microfacet_ggx_D(cosThetaM, alpha2);
   float lambdaO = microfacet_ggx_lambda(cosNO, alpha2);
 
@@ -269,7 +295,7 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private 
const ShaderClosure
   *eval = make_float3(out, out, out);
 
   if (bsdf->type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID) {
-*eval *= (label & LABEL_REFLECT) ? reflection_color(bsdf, *omega_in, m) : 
bsdf->extra->color;
+*eval *= do_reflect ? reflection_color(bsdf, *omega_in, m) : 
bsdf->extra->color;
   }
   return label;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c68542de707] principled-v2: Remove LCG from Glass closure by hashing 2d random input to get third variable instead

2022-07-05 Thread Lukas Stockner
Commit: c68542de70722a1ed5964bb8512af1c3f3658ba5
Author: Lukas Stockner
Date:   Tue Jul 5 18:10:27 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBc68542de70722a1ed5964bb8512af1c3f3658ba5

Remove LCG from Glass closure by hashing 2d random input to get third variable 
instead

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf.h
M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 7c6d5d72241..4ce62d2298a 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -173,7 +173,7 @@ static float precompute_ggx_refract_E(float rough, float 
mu, float eta, float u1
 }
 
 static float precompute_ggx_glass_E(
-float rough, float mu, float eta, float u1, float u2, uint *rng)
+float rough, float mu, float eta, float u1, float u2)
 {
   MicrofacetBsdf bsdf;
   bsdf.weight = one_float3();
@@ -198,8 +198,7 @@ static float precompute_ggx_glass_E(
_in,
_in_dx,
_in_dy,
-   ,
-   rng);
+   );
   if (pdf != 0.0f) {
 return average(eval) / pdf;
   }
@@ -274,7 +273,7 @@ static float precompute_ggx_dielectric_E(float rough, float 
mu, float eta, float
 
 struct PrecomputeTerm {
   int dim, samples, res;
-  std::function evaluation;
+  std::function evaluation;
 };
 
 bool cycles_precompute(std::string name);
@@ -282,44 +281,44 @@ bool cycles_precompute(std::string name)
 {
   std::map precompute_terms;
   precompute_terms["sheen_E"] = {
-  2, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  2, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_sheen_E(rough, mu, u1, u2);
   }};
   precompute_terms["clearcoat_E"] = {
-  2, 1 << 23, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  2, 1 << 23, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_clearcoat_E(rough, mu, u1, u2);
   }};
   precompute_terms["ggx_E"] = {
-  2, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  2, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_ggx_E(rough, mu, u1, u2);
   }};
   precompute_terms["ggx_E_avg"] = {
-  1, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  1, 1 << 23, 32, [](float rough, float mu, float ior, float u1, float u2) 
{
 return 2.0f * mu * precompute_ggx_E(rough, mu, u1, u2);
   }};
   precompute_terms["ggx_glass_E"] = {
-  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
-return precompute_ggx_glass_E(rough, mu, ior, u1, u2, rng);
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
+return precompute_ggx_glass_E(rough, mu, ior, u1, u2);
   }};
   precompute_terms["ggx_glass_inv_E"] = {
-  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
-return precompute_ggx_glass_E(rough, mu, 1.0f / ior, u1, u2, rng);
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
+return precompute_ggx_glass_E(rough, mu, 1.0f / ior, u1, u2);
   }};
   precompute_terms["ggx_refract_E"] = {
-  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_ggx_refract_E(rough, mu, ior, u1, u2);
   }};
   precompute_terms["ggx_refract_inv_E"] = {
-  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_ggx_refract_E(rough, mu, 1.0f / ior, u1, u2);
   }};
   precompute_terms["ggx_dielectric_E"] = {
-  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2) 
{
 return precompute_ggx_dielectric_E(rough, mu, ior, u1, u2);
   }};
   // TODO: Consider more X resolution for this table.
   precompute_terms["ggx_dielectric_inv_E"] = {
-  3, 1 << 20, 16, [](float roug

[Bf-blender-cvs] [fe3d875dabc] principled-v2: Disable HIP directly in CMake to prevent the buildbot command line from overriding it

2022-07-05 Thread Lukas Stockner
Commit: fe3d875dabcf6388316f68de16357b88e68ccf33
Author: Lukas Stockner
Date:   Tue Jul 5 22:14:02 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBfe3d875dabcf6388316f68de16357b88e68ccf33

Disable HIP directly in CMake to prevent the buildbot command line from 
overriding it

===

M   build_files/cmake/config/blender_release.cmake
M   intern/cycles/kernel/CMakeLists.txt

===

diff --git a/build_files/cmake/config/blender_release.cmake 
b/build_files/cmake/config/blender_release.cmake
index 0b8ac269231..42759fec7cc 100644
--- a/build_files/cmake/config/blender_release.cmake
+++ b/build_files/cmake/config/blender_release.cmake
@@ -91,7 +91,7 @@ if(NOT APPLE)
   set(WITH_CYCLES_DEVICE_OPTIXON  CACHE BOOL "" FORCE)
   set(WITH_CYCLES_CUDA_BINARIES   ON  CACHE BOOL "" FORCE)
   set(WITH_CYCLES_CUBIN_COMPILER  OFF CACHE BOOL "" FORCE)
-  set(WITH_CYCLES_HIP_BINARIESOFF CACHE BOOL "" FORCE)
+  set(WITH_CYCLES_HIP_BINARIESON  CACHE BOOL "" FORCE)
 
   # Disable AoT kernels compilations until buildbot can deliver them in a 
reasonabel time.
   set(WITH_CYCLES_ONEAPI_BINARIES OFF CACHE BOOL "" FORCE)
diff --git a/intern/cycles/kernel/CMakeLists.txt 
b/intern/cycles/kernel/CMakeLists.txt
index 4eaae9fdb00..4c8e71e3ca7 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -540,7 +540,8 @@ endif()
 
 # HIP module
 
-if(WITH_CYCLES_HIP_BINARIES AND WITH_CYCLES_DEVICE_HIP)
+# TODO: Re-enable HIP and figure out compiler crash
+if(WITH_CYCLES_HIP_BINARIES AND WITH_CYCLES_DEVICE_HIP AND FALSE)
   # build for each arch
   set(hip_sources device/hip/kernel.cpp
 ${SRC_KERNEL_HEADERS}

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8d9d8075516] principled-v2: Skip specular closure if it will have weight zero

2022-07-05 Thread Lukas Stockner
Commit: 8d9d80755169599472ddd0a0f9277813d797e40e
Author: Lukas Stockner
Date:   Tue Jul 5 22:08:50 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB8d9d80755169599472ddd0a0f9277813d797e40e

Skip specular closure if it will have weight zero

===

M   intern/cycles/kernel/svm/closure_principled.h

===

diff --git a/intern/cycles/kernel/svm/closure_principled.h 
b/intern/cycles/kernel/svm/closure_principled.h
index d915f0707bb..8e6d0b141e2 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -611,6 +611,10 @@ ccl_device_inline float 
principled_v2_specular(KernelGlobals kg,
 {
   // TODO Handle caustics flag
 
+  if (metallic + (1.0f - transmission) <= CLOSURE_WEIGHT_CUTOFF) {
+return 0.0f;
+  }
+
   uint falloff_offset, edge_offset, dummy;
   uint aniso_offset, rotation_offset, tangent_offset;
   svm_unpack_node_uchar4(data1, _offset, _offset, , );

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [92725760c70] principled-v2: Disable HIP for now to make the buildbot not crash

2022-07-05 Thread Lukas Stockner
Commit: 92725760c7059f3296fec66c2ad65e78645fe314
Author: Lukas Stockner
Date:   Tue Jul 5 12:05:36 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB92725760c7059f3296fec66c2ad65e78645fe314

Disable HIP for now to make the buildbot not crash

===

M   build_files/cmake/config/blender_release.cmake

===

diff --git a/build_files/cmake/config/blender_release.cmake 
b/build_files/cmake/config/blender_release.cmake
index 42759fec7cc..0b8ac269231 100644
--- a/build_files/cmake/config/blender_release.cmake
+++ b/build_files/cmake/config/blender_release.cmake
@@ -91,7 +91,7 @@ if(NOT APPLE)
   set(WITH_CYCLES_DEVICE_OPTIXON  CACHE BOOL "" FORCE)
   set(WITH_CYCLES_CUDA_BINARIES   ON  CACHE BOOL "" FORCE)
   set(WITH_CYCLES_CUBIN_COMPILER  OFF CACHE BOOL "" FORCE)
-  set(WITH_CYCLES_HIP_BINARIESON  CACHE BOOL "" FORCE)
+  set(WITH_CYCLES_HIP_BINARIESOFF CACHE BOOL "" FORCE)
 
   # Disable AoT kernels compilations until buildbot can deliver them in a 
reasonabel time.
   set(WITH_CYCLES_ONEAPI_BINARIES OFF CACHE BOOL "" FORCE)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b2432861fa3] principled-v2: Prevent Eevee from crashing with Principled v2

2022-07-04 Thread Lukas Stockner
Commit: b2432861fa32574a0c53218997aa79d38a584206
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBb2432861fa32574a0c53218997aa79d38a584206

Prevent Eevee from crashing with Principled v2

===

M   source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl

===

diff --git 
a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl 
b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
index 2e695fa3e14..8b4936b6fb3 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl
@@ -15,11 +15,14 @@ float principled_sheen(float NV)
 
 void node_bsdf_principled(vec4 base_color,
   float subsurface,
+  float subsurface_scale, //todo
   vec3 subsurface_radius,
   vec4 subsurface_color,
   float subsurface_ior,
   float subsurface_anisotropy,
   float metallic,
+  vec4 metallic_edge, //todo
+  float metallic_falloff, //todo
   float specular,
   float specular_tint,
   float roughness,
@@ -27,8 +30,10 @@ void node_bsdf_principled(vec4 base_color,
   float anisotropic_rotation,
   float sheen,
   float sheen_tint,
+  float sheen_roughness, //todo
   float clearcoat,
   float clearcoat_roughness,
+  vec4 clearcoat_tint, //todo
   float ior,
   float transmission,
   float transmission_roughness,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cc8dce80ae2] principled-v2: Use refracted angle for clearcoat tint calculation to fix extreme saturation

2022-07-04 Thread Lukas Stockner
Commit: cc8dce80ae2bf3cf651f4b887a3c52e904b48196
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBcc8dce80ae2bf3cf651f4b887a3c52e904b48196

Use refracted angle for clearcoat tint calculation to fix extreme saturation

===

M   intern/cycles/kernel/svm/closure_principled.h

===

diff --git a/intern/cycles/kernel/svm/closure_principled.h 
b/intern/cycles/kernel/svm/closure_principled.h
index 1966b06fe0c..7260ed416b7 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -501,7 +501,10 @@ ccl_device_inline float3 
principled_v2_clearcoat(KernelGlobals kg,
  * That way, mirrors preserve their look, but diffuse-ish objects have a 
more natural behavior.
  */
 float cosNI = dot(sd->I, N);
-float optical_depth = 1.0f / cosNI;
+/* Refract incoming direction into clearcoat material, which has a fixed 
IOR of 1.5.
+ * TIR is no concern here since we're always coming from the outside. */
+float cosNT = sqrtf(1.0f - sqr(1.0f / 1.5f) * (1 - sqr(cosNI)));
+float optical_depth = 1.0f / cosNT;
 tint = pow(tint, optical_depth * clearcoat);
   }
 
@@ -659,7 +662,8 @@ ccl_device void 
svm_node_closure_principled_v2(KernelGlobals kg,
   uint base_color_offset, normal_offset, dummy;
   uint roughness_offset, metallic_offset, ior_offset, transmission_offset;
   svm_unpack_node_uchar4(node_1.y, , _color_offset, _offset, 
);
-  svm_unpack_node_uchar4(node_1.z, _offset, _offset, 
_offset, _offset);
+  svm_unpack_node_uchar4(
+  node_1.z, _offset, _offset, _offset, 
_offset);
 
   float3 base_color = stack_load_float3(stack, base_color_offset);
   float3 N = stack_valid(normal_offset) ? stack_load_float3(stack, 
normal_offset) : sd->N;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bddec1bfca5] principled-v2: Refactor lookup tables to use existing LUT code

2022-07-04 Thread Lukas Stockner
Commit: bddec1bfca5d0d89f6f058f8098149032b1a3600
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBbddec1bfca5d0d89f6f058f8098149032b1a3600

Refactor lookup tables to use existing LUT code

===

M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/closure/bsdf_principled_sheen.h
M   intern/cycles/kernel/svm/closure.h
M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/kernel/tables.h
M   intern/cycles/kernel/types.h
M   intern/cycles/kernel/util/lookup_table.h
M   intern/cycles/scene/shader.cpp
M   intern/cycles/scene/shader.h
A   intern/cycles/scene/shader.tables

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 7d2fb0eaca6..5c7e70181d7 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -89,15 +89,16 @@ ccl_device_forceinline void 
bsdf_microfacet_fresnel_color(ccl_private const Shad
   }
 }
 
-ccl_device_inline float3 microfacet_ggx_albedo_scaling(ccl_private const 
MicrofacetBsdf *bsdf,
+ccl_device_inline float3 microfacet_ggx_albedo_scaling(KernelGlobals kg,
+   ccl_private const 
MicrofacetBsdf *bsdf,
ccl_private const 
ShaderData *sd,
const float3 Fss)
 {
   float mu = dot(sd->I, bsdf->N);
   float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
-  float E = microfacet_ggx_E(mu, rough);
+  float E = microfacet_ggx_E(kg, mu, rough);
 
-  float E_avg = microfacet_ggx_E_avg(rough);
+  float E_avg = microfacet_ggx_E_avg(kg, rough);
   /* Fms here is based on the appendix of
* 
https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf,
* with one Fss cancelled out since this is just a multiplier on top of
@@ -108,14 +109,15 @@ ccl_device_inline float3 
microfacet_ggx_albedo_scaling(ccl_private const Microfa
   /* TODO: Ensure that increase in weight does not mess up glossy color, 
albedo etc. passes */
 }
 
-ccl_device_inline float microfacet_ggx_albedo_scaling_float(ccl_private const 
MicrofacetBsdf *bsdf,
+ccl_device_inline float microfacet_ggx_albedo_scaling_float(KernelGlobals kg,
+ccl_private const 
MicrofacetBsdf *bsdf,
 ccl_private const 
ShaderData *sd,
 const float Fss)
 {
   // TOOD: Deduplicate somehow?
   float mu = dot(sd->I, bsdf->N);
   float rough = sqrtf(sqrtf(bsdf->alpha_x * bsdf->alpha_y));
-  float E = microfacet_ggx_E(mu, rough), E_avg = microfacet_ggx_E_avg(rough);
+  float E = microfacet_ggx_E(kg, mu, rough), E_avg = microfacet_ggx_E_avg(kg, 
rough);
   float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
   return 1.0f + Fms * ((1.0f - E) / E);
 }
@@ -140,11 +142,12 @@ ccl_device int 
bsdf_microfacet_ggx_isotropic_setup(ccl_private MicrofacetBsdf *b
   return bsdf_microfacet_ggx_setup(bsdf);
 }
 
-ccl_device int bsdf_microfacet_multi_ggx_setup(ccl_private MicrofacetBsdf 
*bsdf,
+ccl_device int bsdf_microfacet_multi_ggx_setup(KernelGlobals kg,
+   ccl_private MicrofacetBsdf 
*bsdf,
ccl_private const ShaderData 
*sd,
const float3 color)
 {
-  bsdf->weight *= microfacet_ggx_albedo_scaling(bsdf, sd, saturate(color));
+  bsdf->weight *= microfacet_ggx_albedo_scaling(kg, bsdf, sd, saturate(color));
   return bsdf_microfacet_ggx_setup(bsdf);
 }
 
@@ -163,15 +166,17 @@ ccl_device int 
bsdf_microfacet_ggx_fresnel_setup(ccl_private MicrofacetBsdf *bsd
   return SD_BSDF | SD_BSDF_HAS_EVAL;
 }
 
-ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(ccl_private 
MicrofacetBsdf *bsdf,
+ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(KernelGlobals kg,
+   ccl_private 
MicrofacetBsdf *bsdf,
ccl_private const 
ShaderData *sd)
 {
   float3 Fss = schlick_fresnel_Fss(bsdf->extra->cspec0);
-  bsdf->weight *= microfacet_ggx_albedo_scaling(bsdf, sd, Fss);
+  bsdf->weight *= microfacet_ggx_albedo_scaling(kg, bsdf, sd, Fss);
   return bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
 }
 
-ccl_device int bsdf_microfacet_ggx_fresnel_v2_setup(ccl_private MicrofacetBsdf 
*bsdf,
+ccl_devic

[Bf-blender-cvs] [498818ae668] principled-v2: Cleanup: Formatting

2022-07-04 Thread Lukas Stockner
Commit: 498818ae66849d8ec68db7f5691f644656ab6745
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rB498818ae66849d8ec68db7f5691f644656ab6745

Cleanup: Formatting

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf_microfacet.h
M   intern/cycles/kernel/closure/bsdf_util.h
M   intern/cycles/kernel/svm/types.h

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index c0f3d732c22..7c6d5d72241 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -348,8 +348,8 @@ bool cycles_precompute(std::string name)
   float rough = 1.0f - (float(y) + lcg_step_float()) / float(ny);
   float mu = (float(x) + lcg_step_float()) / float(nx);
   float ior = (float(z) + lcg_step_float()) / float(nz);
-  /* Encode IOR remapped as sqrt(0.5*(IOR-1)) for more resolution at 
the start, where most of the
-   * changes happen (also places the most common range around 1.5 in 
the center) */
+  /* Encode IOR remapped as sqrt(0.5*(IOR-1)) for more resolution at 
the start, where most
+   * of the changes happen (also places the most common range around 
1.5 in the center) */
   ior = 1.0f + 2.0f * sqr(ior);
   float u1 = VanDerCorput(i, scramble1);
   float u2 = Sobol2(i, scramble2);
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h 
b/intern/cycles/kernel/closure/bsdf_microfacet.h
index e31b0d6ea89..7d2fb0eaca6 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -61,7 +61,7 @@ ccl_device_forceinline float3 reflection_color(ccl_private 
const MicrofacetBsdf
 return make_float3(f, f, f);
   }
   else if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID) {
-MicrofacetExtrav2 *extra = (MicrofacetExtrav2*) bsdf->extra;
+MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
 float cosHL = dot(H, L);
 /* Metallic Fresnel: Kinda Schlick-Fresnel-like with configurable F0 and 
F90
  * as well as falloff control. F90=white and falloff=0.2 gives classic 
Schlick Fresnel.
@@ -179,7 +179,7 @@ ccl_device int 
bsdf_microfacet_ggx_fresnel_v2_setup(ccl_private MicrofacetBsdf *
   bsdf->alpha_x = saturatef(bsdf->alpha_x);
   bsdf->alpha_y = saturatef(bsdf->alpha_y);
 
-  MicrofacetExtrav2 *extra = (MicrofacetExtrav2*) bsdf->extra;
+  MicrofacetExtrav2 *extra = (MicrofacetExtrav2 *)bsdf->extra;
 
   if (metallic > 0.0f) {
 extra->metal_base = saturate(extra->metal_base);
diff --git a/intern/cycles/kernel/closure/bsdf_util.h 
b/intern/cycles/kernel/closure/bsdf_util.h
index 6468f5cd78c..47ace534440 100644
--- a/intern/cycles/kernel/closure/bsdf_util.h
+++ b/intern/cycles/kernel/closure/bsdf_util.h
@@ -110,8 +110,7 @@ ccl_device float schlick_fresnel(float u)
 }
 
 /* Calculate the fresnel color which is a blend between white and the F0 color 
*/
-ccl_device_forceinline float3
-interpolate_fresnel_color(float3 L, float3 H, float ior, float3 F0)
+ccl_device_forceinline float3 interpolate_fresnel_color(float3 L, float3 H, 
float ior, float3 F0)
 {
   /* Compute the real Fresnel term and remap it from real_F0...1 to F0...1.
* We could also just use actual Schlick fresnel (mix(F0, 1, (1-cosI)^5)) 
here. */
diff --git a/intern/cycles/kernel/svm/types.h b/intern/cycles/kernel/svm/types.h
index 755f36f8ffd..873c470df7a 100644
--- a/intern/cycles/kernel/svm/types.h
+++ b/intern/cycles/kernel/svm/types.h
@@ -591,7 +591,7 @@ typedef enum ClosureType {
 #define CLOSURE_IS_BSDF_MICROFACET_FRESNEL(type) \
   (type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID || \
type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID)
-   // TODO Fresnel v2
+// TODO Fresnel v2
 #define CLOSURE_IS_BSDF_SHEEN(type) \
   (type == CLOSURE_BSDF_PRINCIPLED_SHEEN_ID || type == 
CLOSURE_BSDF_PRINCIPLED_SHEEN_V2_ID)
 #define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= 
CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [dbdd2bb4545] principled-v2: Add energy compensation for specular component

2022-07-04 Thread Lukas Stockner
Commit: dbdd2bb454559a757b007cfddfa773326751fc2d
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBdbdd2bb454559a757b007cfddfa773326751fc2d

Add energy compensation for specular component

===

M   intern/cycles/app/cycles_precompute.cpp
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/kernel/tables.h

===

diff --git a/intern/cycles/app/cycles_precompute.cpp 
b/intern/cycles/app/cycles_precompute.cpp
index 5ca0ac0953e..1b399df3d01 100644
--- a/intern/cycles/app/cycles_precompute.cpp
+++ b/intern/cycles/app/cycles_precompute.cpp
@@ -165,6 +165,49 @@ static float precompute_ggx_glass_E(
   return 0.0f;
 }
 
+static float precompute_ggx_dielectric_E(float rough, float mu, float eta, 
float u1, float u2)
+{
+  // TODO: Reparametrize based on fresnel_dielectric_cos(mu, eta) instead of 
mu to get more resolution?
+  // Probably need lerp(mu, fresnel_dielectric_cos(mu, eta), 0.9) or so 
because of flat IOR region.
+  MicrofacetExtrav2 extra;
+  MicrofacetBsdf bsdf;
+  bsdf.weight = one_float3();
+  bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_V2_ID;
+  bsdf.sample_weight = 1.0f;
+  bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
+  bsdf.alpha_x = bsdf.alpha_y = sqr(rough);
+  bsdf.ior = eta;
+  bsdf.extra = (MicrofacetExtra *)
+  bsdf.T = make_float3(1.0f, 0.0f, 0.0f);
+  extra.metal_base = extra.metal_edge = zero_float3();
+  extra.metal_falloff = 0.0f;
+
+  /* Dependency warning - this relies on the ggx_E and ggx_E_avg lookup 
tables! */
+  float E = microfacet_ggx_E(mu, rough), E_avg = microfacet_ggx_E_avg(rough);
+  float Fss = dielectric_fresnel_Fss(eta);
+  float Fms = Fss * E_avg / (1.0f - Fss * (1.0f - E_avg));
+  extra.dielectric = 1.0f + Fms * ((1.0f - E) / E);
+
+  float3 eval, omega_in, domega_in_dx, domega_in_dy;
+  float pdf = 0.0f;
+  bsdf_microfacet_ggx_sample((ShaderClosure *),
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ ,
+ _in,
+ _in_dx,
+ _in_dy,
+ );
+  if (pdf != 0.0f) {
+return average(eval) / pdf;
+  }
+  return 0.0f;
+}
+
 struct PrecomputeTerm {
   int dim, samples, res;
   std::function evaluation;
@@ -202,6 +245,15 @@ bool cycles_precompute(std::string name)
   3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
 return precompute_ggx_refract_E(rough, mu, 1.0f / ior, u1, u2);
   }};
+  precompute_terms["ggx_dielectric_E"] = {
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+return precompute_ggx_dielectric_E(rough, mu, ior, u1, u2);
+  }};
+  // TODO: Consider more X resolution for this table.
+  precompute_terms["ggx_dielectric_inv_E"] = {
+  3, 1 << 20, 16, [](float rough, float mu, float ior, float u1, float u2, 
uint *rng) {
+return precompute_ggx_dielectric_E(rough, mu, 1.0f / ior, u1, u2);
+  }};
 
   if (precompute_terms.count(name) == 0) {
 return false;
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index d8a7b5f9a87..509cd6708ec 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -110,6 +110,37 @@ ccl_device_forceinline float microfacet_ggx_glass_E(float 
mu, float rough, float
   return lerp(lerp(a, b, rough), lerp(c, d, rough), ior);
 }
 
+ccl_device_forceinline float microfacet_ggx_dielectric_E(float mu, float 
rough, float ior)
+{
+  bool inv_table = (ior < 1.0f);
+  if (inv_table) {
+ior = 1.0f / ior;
+  }
+
+  rough = saturatef(1 - rough) * 16.0f;
+  mu = saturatef(mu) * 16.0f;
+  ior = saturatef(sqrtf(0.5f * (ior - 1.0f))) * 16.0f;
+
+  int rough_i = min(15, (int)rough);
+  int rough_i1 = min(15, rough_i + 1);
+  int mu_i = min(15, (int)mu);
+  int mu_i1 = min(15, mu_i + 1);
+  int ior_i = min(15, (int)ior);
+  int ior_i1 = min(15, ior_i + 1);
+
+  rough -= rough_i;
+  mu -= mu_i;
+  ior -= ior_i;
+
+  auto  = inv_table ? table_ggx_dielectric_inv_E : 
table_ggx_dielectric_E;
+  float a = lerp(table[ior_i][rough_i][mu_i], table[ior_i][rough_i][mu_i1], 
mu);
+  float b = lerp(table[ior_i][rough_i1][mu_i], table[ior_i][rough_i1][mu_i1], 
mu);
+  float c = lerp(table[ior_i1][rough_i][mu_i], table[ior_i1][rough_i][mu_i1], 
mu);
+  float d = lerp(table[ior_i1][rough_i1][mu_i], 
table[ior_i1

[Bf-blender-cvs] [f4b35fd4c01] principled-v2: Add subsurface support to Principled v2

2022-07-04 Thread Lukas Stockner
Commit: f4b35fd4c01a10b7a1c498cf6e903457d6412553
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBf4b35fd4c01a10b7a1c498cf6e903457d6412553

Add subsurface support to Principled v2

===

M   intern/cycles/kernel/svm/closure_principled.h
M   intern/cycles/scene/shader_nodes.cpp

===

diff --git a/intern/cycles/kernel/svm/closure_principled.h 
b/intern/cycles/kernel/svm/closure_principled.h
index 7260ed416b7..d3bba688ed4 100644
--- a/intern/cycles/kernel/svm/closure_principled.h
+++ b/intern/cycles/kernel/svm/closure_principled.h
@@ -430,15 +430,51 @@ ccl_device_inline void 
principled_v1_clearcoat(KernelGlobals kg,
 
 /* Principled v2 components */
 
-ccl_device_inline void principled_v2_diffuse(
-ccl_private ShaderData *sd, float3 weight, float3 base_color, float 
diffuse_weight, float3 N)
+ccl_device_inline void principled_v2_diffuse_sss(ccl_private ShaderData *sd,
+ ccl_private float *stack,
+ float3 weight,
+ int path_flag,
+ uint data,
+ float3 base_color,
+ float ior,
+ float3 N)
 {
-  if (diffuse_weight <= CLOSURE_WEIGHT_CUTOFF) {
+  if (reduce_max(weight * base_color) <= CLOSURE_WEIGHT_CUTOFF) {
 return;
   }
 
+#ifdef __SUBSURFACE__
+  uint method, scale_offset, aniso_offset, radius_offset;
+  svm_unpack_node_uchar4(data, _offset, _offset, _offset, 
);
+
+  float aniso = stack_load_float(stack, aniso_offset);
+  float3 radius = stack_load_float3(stack, radius_offset) * 
stack_load_float(stack, scale_offset);
+
+  /* Fall back to diffuse if there has been a diffuse bounce before or the 
radius is too small. */
+  if ((path_flag & PATH_RAY_DIFFUSE_ANCESTOR) == 0 && reduce_max(radius) > 
1e-7f) {
+ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, base_color * weight);
+
+if (bssrdf == NULL) {
+  return;
+}
+
+bssrdf->radius = radius;
+bssrdf->albedo = base_color;
+bssrdf->N = N;
+bssrdf->roughness = FLT_MAX;
+
+/* Clamps protecting against bad/extreme and non physical values. */
+bssrdf->anisotropy = clamp(aniso, 0.0f, 0.9f);
+
+/* setup bsdf */
+sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)method, clamp(ior, 
1.01f, 3.8f));
+
+return;
+  }
+#endif
+
   ccl_private DiffuseBsdf *bsdf = (ccl_private DiffuseBsdf *)bsdf_alloc(
-  sd, sizeof(DiffuseBsdf), diffuse_weight * base_color * weight);
+  sd, sizeof(DiffuseBsdf), base_color * weight);
 
   if (bsdf == NULL) {
 return;
@@ -695,7 +731,7 @@ ccl_device void 
svm_node_closure_principled_v2(KernelGlobals kg,
 
   weight *= (1.0f - transmission) * (1.0f - dielectric_albedo);
 
-  principled_v2_diffuse(sd, weight, base_color, 1.0f, N);
+  principled_v2_diffuse_sss(sd, stack, weight, path_flag, node_1.w, 
base_color, ior, N);
 }
 
 ccl_device void svm_node_closure_principled(KernelGlobals kg,
diff --git a/intern/cycles/scene/shader_nodes.cpp 
b/intern/cycles/scene/shader_nodes.cpp
index 930532fd92f..c900b7fc309 100644
--- a/intern/cycles/scene/shader_nodes.cpp
+++ b/intern/cycles/scene/shader_nodes.cpp
@@ -2929,7 +2929,7 @@ void PrincipledBsdfNode::compile_v2(SVMCompiler )
   uint sss = compiler.encode_uchar4(compiler.stack_assign(input("Subsurface 
Scale")),
 compiler.stack_assign(input("Subsurface 
Anisotropy")),
 compiler.stack_assign(input("Subsurface 
Radius")),
-SVM_STACK_INVALID);
+subsurface_method);
   uint metallic = compiler.encode_uchar4(compiler.stack_assign(input("Metallic 
Falloff")),
  compiler.stack_assign(input("Metallic 
Edge")),
  SVM_STACK_INVALID,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f353f129ec3] principled-v2: Fix compilation with OSL, support for v2 is still missing

2022-07-04 Thread Lukas Stockner
Commit: f353f129ec3775dd744561889f70fd1503698b0b
Author: Lukas Stockner
Date:   Mon Jul 4 23:31:48 2022 +0200
Branches: principled-v2
https://developer.blender.org/rBf353f129ec3775dd744561889f70fd1503698b0b

Fix compilation with OSL, support for v2 is still missing

===

M   intern/cycles/kernel/closure/bsdf_microfacet_glass.h
M   intern/cycles/kernel/closure/bsdf_microfacet_util.h
M   intern/cycles/kernel/osl/closures.cpp

===

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 1fd65f676a6..8001cd8fb17 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -3,6 +3,8 @@
 
 #pragma once
 
+#include "kernel/sample/lcg.h"
+
 CCL_NAMESPACE_BEGIN
 
 ccl_device_inline float3
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_util.h 
b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
index 8a412601903..e6688e8a82b 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_util.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_util.h
@@ -5,6 +5,8 @@
 
 #include "kernel/closure/bsdf_util.h"
 
+#include "kernel/util/lookup_table.h"
+
 CCL_NAMESPACE_BEGIN
 
 /* GGX microfacet with Smith shadow-masking from:
diff --git a/intern/cycles/kernel/osl/closures.cpp 
b/intern/cycles/kernel/osl/closures.cpp
index 39157f0b796..e80b7aa1fd5 100644
--- a/intern/cycles/kernel/osl/closures.cpp
+++ b/intern/cycles/kernel/osl/closures.cpp
@@ -27,7 +27,7 @@
 #include "kernel/closure/bsdf_diffuse.h"
 #include "kernel/closure/bsdf_microfacet.h"
 #include "kernel/closure/bsdf_microfacet_beckmann.h"
-#include "kernel/closure/bsdf_microfacet_multi.h"
+#include "kernel/closure/bsdf_microfacet_glass.h"
 #include "kernel/closure/bsdf_oren_nayar.h"
 #include "kernel/closure/bsdf_reflection.h"
 #include "kernel/closure/bsdf_refraction.h"
@@ -681,14 +681,7 @@ class MicrofacetMultiClosure : public CBSDFClosure {
   return NULL;
 }
 
-MicrofacetExtra *extra = (MicrofacetExtra *)closure_alloc_extra(sd, 
sizeof(MicrofacetExtra));
-if (!extra) {
-  return NULL;
-}
-
-bsdf->extra = extra;
-bsdf->extra->color = color;
-bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
+bsdf->extra = NULL;
 return bsdf;
   }
 };
@@ -704,10 +697,12 @@ class MicrofacetMultiGGXClosure : public 
MicrofacetMultiClosure {
   return;
 }
 
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
 bsdf->ior = 0.0f;
 bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
 bsdf->alpha_y = bsdf->alpha_x;
-sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
+sd->flag |= bsdf_microfacet_multi_ggx_setup(kg, bsdf, sd, color);
   }
 };
 
@@ -734,8 +729,10 @@ class MicrofacetMultiGGXAnisoClosure : public 
MicrofacetMultiClosure {
   return;
 }
 
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
 bsdf->ior = 0.0f;
-sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
+sd->flag |= bsdf_microfacet_multi_ggx_setup(kg, bsdf, sd, color);
   }
 };
 
@@ -768,9 +765,11 @@ class MicrofacetMultiGGXGlassClosure : public 
MicrofacetMultiClosure {
   return;
 }
 
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
 bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
 bsdf->alpha_y = bsdf->alpha_x;
-sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
+sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(kg, bsdf, sd, color);
   }
 };
 
@@ -833,9 +832,11 @@ class MicrofacetMultiGGXFresnelClosure : public 
MicrofacetMultiFresnelClosure {
   return;
 }
 
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
 bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
 bsdf->alpha_y = bsdf->alpha_x;
-sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd);
+sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(kg, bsdf, sd);
   }
 };
 
@@ -865,7 +866,9 @@ class MicrofacetMultiGGXAnisoFresnelClosure : public 
MicrofacetMultiFresnelClosu
   return;
 }
 
-sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd);
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
+sd->flag |= bsdf_microfacet_multi_ggx_fresnel_setup(kg, bsdf, sd);
   }
 };
 
@@ -901,9 +904,11 @@ class MicrofacetMultiGGXGlassFresnelClosure : public 
MicrofacetMultiFresnelClosu
   return;
 }
 
+const KernelGlobalsCPU *kg = sd->osl_globals;
+
 bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
 bsdf->alpha_y = bsdf->alpha_x;
-sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
+sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(kg, bsdf, sd);
   }
 };

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


  1   2   3   4   5   6   7   8   9   10   >