[Bf-blender-cvs] [bc37e8d8399] principled-v2: Merge remote-tracking branch 'origin/master' into principled-v2
Lukas Stockner
noreply at git.blender.org
Sun Oct 30 00:17:16 CEST 2022
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,00000000000..6f9d9601b1e
mode 100644,000000..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 <iostream>
+
+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 & 0x33333333) << 2) | ((n & 0xcccccccc) >> 2);
+ n = ((n & 0x55555555) << 1) | ((n & 0xaaaaaaaa) >> 1);
+ n ^= scramble;
+ return ((n >> 8) & 0xffffff) / 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) & 0xffffff) / 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 *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &domega_in_dy,
+ &pdf);
+ 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 *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &domega_in_dy,
+ &pdf);
+ 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_weight = 1.0f;
+ bsdf.N = make_float3(0.0f, 0.0f, 1.0f);
+ bsdf.alpha_x = bsdf.alpha_y = sqr(rough);
+ bsdf.ior = 1.0f;
+ 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;
+ bsdf_microfacet_ggx_sample((ShaderClosure *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &domega_in_dy,
+ &pdf);
+ if (pdf != 0.0f) {
+ return average(eval) / pdf;
+ }
+ return 0.0f;
+}
+
+static float precompute_ggx_refract_E(float rough, float mu, float eta, float u1, float u2)
+{
+ MicrofacetBsdf bsdf;
+ bsdf.weight = one_float3();
+ bsdf.type = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_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 = 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;
+ bsdf_microfacet_ggx_sample((ShaderClosure *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &domega_in_dy,
+ &pdf);
+ if (pdf != 0.0f) {
+ return average(eval) / pdf;
+ }
+ return 0.0f;
+}
+
- static float precompute_ggx_glass_E(
- float rough, float mu, float eta, float u1, float u2)
++static float precompute_ggx_glass_E(float rough, float mu, float eta, float u1, float u2)
+{
+ MicrofacetBsdf bsdf;
+ bsdf.weight = one_float3();
+ bsdf.type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_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 = 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;
+ bsdf_microfacet_ggx_glass_sample((ShaderClosure *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &domega_in_dy,
+ &pdf);
+ if (pdf != 0.0f) {
+ return average(eval) / pdf;
+ }
+ return 0.0f;
+}
+
+static float precompute_ggx_dielectric_E(float rough, float mu, float eta, float u1, float u2)
+{
+ {
+ /* Reparametrize based on macrosurface fresnel to get more resolution into areas where
+ * the Fresnel curve is rapidly changing. Particularly important for eta<1 due to the TIR edge.
+ * However, in the eta<1 case, the entire TIR area would be compressed down to a point, which
+ * 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);
+ auto get_remap = [eta, F0](float x) {
+ return mix(x, inverse_lerp(1.0f, F0, fresnel_dielectric_cos(x, eta)), 0.5f);
+ };
+
+ float remap_target = mu;
+ float start = 0.0f, end = 1.0f;
+ while (end - start > 1e-7f) {
+ mu = (end + start) * 0.5f;
+ if (get_remap(mu) > remap_target) {
+ end = mu;
+ }
+ else {
+ start = mu;
+ }
+ }
+ }
+
+ 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 *)&extra;
+ bsdf.T = make_float3(1.0f, 0.0f, 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);
+ 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 *)&bsdf,
+ make_float3(0.0f, 0.0f, 1.0f),
+ make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
+ zero_float3(),
+ zero_float3(),
+ u1,
+ u2,
+ &eval,
+ &omega_in,
+ &domega_in_dx,
+ &dom
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list