diff options
Diffstat (limited to 'intern/cycles/kernel/util/differential.h')
-rw-r--r-- | intern/cycles/kernel/util/differential.h | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/intern/cycles/kernel/util/differential.h b/intern/cycles/kernel/util/differential.h index 3682e91ea66..aad9bb6bb22 100644 --- a/intern/cycles/kernel/util/differential.h +++ b/intern/cycles/kernel/util/differential.h @@ -101,53 +101,59 @@ ccl_device differential3 differential3_zero() return d; } -/* Compact ray differentials that are just a scale to reduce memory usage and - * access cost in GPU. +/* Compact ray differentials that are just a radius to reduce memory usage and access cost + * on GPUs, basically cone tracing. * - * See above for more accurate reference implementations. - * - * TODO: also store the more compact version in ShaderData and recompute where - * needed? */ + * See above for more accurate reference implementations of ray differentials. */ ccl_device_forceinline float differential_zero_compact() { return 0.0f; } -ccl_device_forceinline float differential_make_compact(const differential3 D) +ccl_device_forceinline float differential_make_compact(const float dD) { - return 0.5f * (len(D.dx) + len(D.dy)); + return dD; } -ccl_device_forceinline void differential_transfer_compact(ccl_private differential3 *surface_dP, - const float ray_dP, - const float3 /* ray_D */, - const float ray_dD, - const float3 surface_Ng, - const float ray_t) +ccl_device_forceinline float differential_make_compact(const differential3 dD) { - /* ray differential transfer through homogeneous medium, to - * compute dPdx/dy at a shading point from the incoming ray */ - float scale = ray_dP + ray_t * ray_dD; + return 0.5f * (len(dD.dx) + len(dD.dy)); +} - float3 dx, dy; - make_orthonormals(surface_Ng, &dx, &dy); - surface_dP->dx = dx * scale; - surface_dP->dy = dy * scale; +ccl_device_forceinline float differential_incoming_compact(const float dD) +{ + return dD; } -ccl_device_forceinline void differential_incoming_compact(ccl_private differential3 *dI, - const float3 D, - const float dD) +ccl_device_forceinline float differential_transfer_compact(const float ray_dP, + const float3 /* ray_D */, + const float ray_dD, + const float ray_t) { - /* compute dIdx/dy at a shading point, we just need to negate the - * differential of the ray direction */ + return ray_dP + ray_t * ray_dD; +} +ccl_device_forceinline differential3 differential_from_compact(const float3 D, const float dD) +{ float3 dx, dy; make_orthonormals(D, &dx, &dy); - dI->dx = dD * dx; - dI->dy = dD * dy; + differential3 d; + d.dx = dD * dx; + d.dy = dD * dy; + return d; +} + +ccl_device void differential_dudv_compact(ccl_private differential *du, + ccl_private differential *dv, + float3 dPdu, + float3 dPdv, + float dP, + float3 Ng) +{ + /* TODO: can we speed this up? */ + differential_dudv(du, dv, dPdu, dPdv, differential_from_compact(Ng, dP), Ng); } CCL_NAMESPACE_END |