Cycles: Widen ray differentials based on BSDF roughness

This reduces texture cache memory usage, with practically identical
renders. Where it does show some differences is with strong bump maps
and refaction.

Pull Request: https://projects.blender.org/blender/blender/pulls/157244
This commit is contained in:
Brecht Van Lommel 2026-04-11 23:17:47 +02:00
parent 9c736864af
commit 4132006bf0
11 changed files with 35 additions and 14 deletions

View file

@ -57,6 +57,15 @@ ccl_device_inline float bsdf_get_roughness_pass_squared(const ccl_private Shader
return bsdf_get_specular_roughness_squared(sc);
}
/* Widen the compact ray differential dD after a non-specular bounce so that
* texture mip selection on subsequent hits reflects the BSDF lobe's angular
* spread. This significantly save memory, and is needed to make image cache
* memory usage scale with render tile size rather than overall resolution. */
ccl_device_forceinline float bsdf_widen_dD(const float prev_dD, const float2 sampled_roughness)
{
return max(prev_dD, min(sampled_roughness.x, sampled_roughness.y));
}
/* An additional term to smooth illumination on grazing angles when using bump mapping
* based on "A Microfacet-Based Shadowing Function to Solve the Bump Terminator Problem"
* by Alejandro Conty Estevez, Pascal Lecocq, and Clifford Stein. It preserves detail

View file

@ -72,6 +72,14 @@ ccl_device int volume_phase_sample(const ccl_private ShaderData *sd,
}
}
/* Widen the compact ray differential dD after a phase function scatter to
* match the lobe's angular spread. See bsdf_widen_dD for details. */
ccl_device_forceinline float volume_phase_widen_dD(const float prev_dD,
const float sampled_roughness)
{
return max(prev_dD, sampled_roughness);
}
ccl_device bool volume_phase_equal(const ccl_private ShaderClosure *c1,
const ccl_private ShaderClosure *c2)
{

View file

@ -563,6 +563,8 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
INTEGRATOR_STATE_WRITE(state, ray, tmax) = FLT_MAX;
#ifdef __RAY_DIFFERENTIALS__
INTEGRATOR_STATE_WRITE(state, ray, dP) = differential_make_compact(sd->dP);
INTEGRATOR_STATE_WRITE(state, ray, dD) = bsdf_widen_dD(INTEGRATOR_STATE(state, ray, dD),
bsdf_sampled_roughness);
#endif
}

View file

@ -2606,6 +2606,8 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(
INTEGRATOR_STATE_WRITE(state, ray, tmax) = FLT_MAX;
# ifdef __RAY_DIFFERENTIALS__
INTEGRATOR_STATE_WRITE(state, ray, dP) = differential_make_compact(sd->dP);
INTEGRATOR_STATE_WRITE(state, ray, dD) = volume_phase_widen_dD(INTEGRATOR_STATE(state, ray, dD),
sampled_roughness);
# endif
// Save memory by storing last hit prim and object in isect
INTEGRATOR_STATE_WRITE(state, isect, prim) = sd->prim;

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:58d5224117934d022de599d7c9deaa012681e544227e6ec1e8dfca2aede8678f
size 19849
oid sha256:c21764286b307709d8fa377ce838b78c783b8533b1723149dac0196ca46e8d8e
size 19943

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:397b1d349142e56bfee49ae4771c1aed363e399653968c85240dcaab655db21b
size 21404
oid sha256:c6b0fa33342e16eaf00bccec22751c93e8e8e445032126ba7c07bee92910219a
size 21345

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:db70ec4b7ba72c629723b49c9769e17f4b4fa9e04420687d081f879750caf4c7
size 19189
oid sha256:ddc755a1855ffeb1a3331b124f77bfdbe8eef288dd1f00059857e3c8cea66ced
size 19280

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d282b2997436b8f33e03cd425eae64720817785aeb0a747e36761ab59ebcb961
size 44580
oid sha256:d7c7ca021cd3f3d35324aa7f2eeb77190ecd2be2780a14136d6ec9c8c176bcc5
size 44582

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a736b7f0bc832bf88e7ef761396542c4e295f5ca933fe4aebb532af4d6d22ca9
size 32403
oid sha256:ece45f07116794f4cb145c053b5f06917063bcac891545466774b3a2c1f6987a
size 31931

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f5e5b2b5bdfe8dc03f6126a59ff9dfd410328f28b666158e9d66d374ea9de7bf
size 31414
oid sha256:426e23bdfa0a8eda5cd9c8d96942e39165028b231af692de824a8562925f85ac
size 31512

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:750151edb54a92484cd041e2edf7a330d9584adeaf80b1c9a3f022329829b11a
size 45080
oid sha256:6aac6025cf7ef8fdaf3eda9ae30a6834c798e233d35b11ab0499f58eabb82310
size 45173