[Bf-blender-cvs] [c68542de707] principled-v2: Remove LCG from Glass closure by hashing 2d random input to get third variable instead
Lukas Stockner
noreply at git.blender.org
Tue Jul 5 22:17:38 CEST 2022
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(
&omega_in,
&domega_in_dx,
&domega_in_dy,
- &pdf,
- rng);
+ &pdf);
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<float(float, float, float, float, float, uint *)> evaluation;
+ std::function<float(float, float, float, float, float)> evaluation;
};
bool cycles_precompute(std::string name);
@@ -282,44 +281,44 @@ bool cycles_precompute(std::string name)
{
std::map<string, PrecomputeTerm> 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 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, 1.0f / ior, u1, u2);
}};
@@ -354,7 +353,7 @@ bool cycles_precompute(std::string name)
float u1 = VanDerCorput(i, scramble1);
float u2 = Sobol2(i, scramble2);
- float value = term.evaluation(rough, mu, ior, u1, u2, &rng);
+ float value = term.evaluation(rough, mu, ior, u1, u2);
if (isnan(value)) {
value = 0.0f;
}
diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h
index 88196fc4192..246cc8290d5 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -262,8 +262,7 @@ ccl_device_inline int bsdf_sample(KernelGlobals kg,
omega_in,
&domega_in->dx,
&domega_in->dy,
- pdf,
- &sd->lcg_state);
+ pdf);
break;
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
index 8001cd8fb17..942812aaa71 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_glass.h
@@ -5,6 +5,8 @@
#include "kernel/sample/lcg.h"
+#include "util/hash.h"
+
CCL_NAMESPACE_BEGIN
ccl_device_inline float3
@@ -42,7 +44,7 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_setup(KernelGlobals kg,
bsdf->weight *= microfacet_ggx_glass_albedo_scaling(kg, sd, bsdf, saturate(color));
- return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_NEEDS_LCG;
+ return SD_BSDF | SD_BSDF_HAS_EVAL;
}
ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(KernelGlobals kg,
@@ -61,7 +63,7 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(KernelGlobals kg,
float3 Fss = schlick_fresnel_Fss(bsdf->extra->cspec0);
bsdf->weight *= microfacet_ggx_glass_albedo_scaling(kg, sd, bsdf, Fss);
- return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_NEEDS_LCG;
+ return SD_BSDF | SD_BSDF_HAS_EVAL;
}
ccl_device float3 bsdf_microfacet_ggx_glass_eval_reflect(ccl_private const ShaderClosure *sc,
@@ -161,8 +163,7 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
ccl_private float3 *omega_in,
ccl_private float3 *domega_in_dx,
ccl_private float3 *domega_in_dy,
- ccl_private float *pdf,
- ccl_private uint *lcg_state)
+ ccl_private float *pdf)
{
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
float alpha_x = bsdf->alpha_x;
@@ -215,7 +216,8 @@ ccl_device int bsdf_microfacet_ggx_glass_sample(ccl_private const ShaderClosure
#endif
&inside);
- float randw = lcg_step_float(lcg_state);
+ // TODO: Somehow get a properly stratified value here, this causes considerable noise
+ float randw = hash_float2_to_float(make_float2(randu, randv));
bool do_reflect = randw < fresnel;
/* Common microfacet model terms. */
More information about the Bf-blender-cvs
mailing list