13#ifdef __DENOISING_FEATURES__
18 const bool follow_reflections)
22 if (follow_reflections) {
28 const float3 prev_P = sd->P + sd->wi * d;
31 depth = new_depth - prev_depth;
59 const uint32_t path_flag,
74 const bool use_albedo_roughness_weighting = (
kernel_data.film.denoising_pass_options_flag &
83 float specular_roughness = 0.0f;
84 float sum_weight = 0.0f;
85 float sum_nonspecular_weight = 0.0f;
87 for (
int i = 0; i < sd->num_closure; i++) {
88 const ccl_private ShaderClosure *sc = &sd->closure[i];
96 transparent_albedo += sc->weight;
101 const float closure_weight =
average(albedo);
117 if (use_albedo_roughness_weighting) {
118 diffuse_albedo += albedo * diffuse_weight;
119 specular_albedo += albedo * (1.0f - diffuse_weight);
122 diffuse_albedo += albedo;
125 specular_albedo += albedo;
128 specular_roughness +=
sqrtf(roughness) * closure_weight;
130 sum_weight += closure_weight;
131 sum_nonspecular_weight += closure_weight * diffuse_weight;
135 const float transparent_weight =
average(transparent_albedo);
136 const float total_weight = sum_weight + transparent_weight;
141 float feature_weight = 0.0f;
142 if (sum_weight > 0.0f) {
143 normal /= sum_weight;
144 specular_roughness /= sum_weight;
146 feature_weight =
smoothstep(0.0f, 0.5f, sum_nonspecular_weight / sum_weight);
149 float deferred_feature_weight = 1.0f - feature_weight;
152 const bool follow_reflections = (
kernel_data.film.denoising_pass_options_flag &
154 if (!follow_reflections) {
155 feature_weight = 1.0f;
163 if (is_first_bounce || follow_reflections) {
165 const float denoising_depth = denoising_depth_compute(
174 const float opaque_fraction = (total_weight > 0.0f) ? (sum_weight / total_weight) : 1.0f;
176 denoising_normal =
ensure_finite(denoising_normal * opaque_fraction * feature_weight *
188 if (is_first_bounce) {
190 const float denoising_roughness =
ensure_finite(specular_roughness *
193 denoising_roughness);
200 denoising_specular_albedo);
222 kg, reflector_P, reflector_N, sd);
224 denoising_specular_motion.
x);
226 denoising_specular_motion.
y);
232 Spectrum deferred_albedo = specular_albedo * deferred_feature_weight + transparent_albedo;
237 deferred_albedo = transparent_albedo;
240 if (!follow_reflections) {
241 deferred_albedo = transparent_albedo;
260 const bool follow_reflections = (
kernel_data.film.denoising_pass_options_flag &
267 if (is_first_bounce || follow_reflections) {
269 const float denoising_depth = denoising_depth_compute(
306 const uint32_t path_flag,
357 if (wrote_first_segment) {
363 const bool follow_reflections = (
kernel_data.film.denoising_pass_options_flag &
368 farclip_depth = farclip_depth /
dot(ray_D, camD);
CCL_NAMESPACE_BEGIN ccl_device_inline float bsdf_get_specular_roughness_squared(const ccl_private ShaderClosure *sc)
ccl_device_inline Spectrum closure_albedo(KernelGlobals kg, const ccl_private ShaderData *sd, const ccl_private ShaderClosure *sc, const bool reflection, const bool transmission)
#define CLOSURE_IS_GLASS(type)
#define ccl_device_forceinline
#define CLOSURE_IS_BSDF_TRANSPARENT(type)
#define CLOSURE_IS_BSDF_GLOSSY(type)
#define CLOSURE_IS_BSDF_DIFFUSE(type)
#define CLOSURE_IS_BSDF_OR_BSSRDF(type)
#define CLOSURE_IS_BSSRDF(type)
#define CCL_NAMESPACE_END
T smoothstep(T, T, T) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
float reduce_max(float2 a)
VecT safe_normalize(VecT vector)
ccl_device_forceinline float4 camera_motion_vector_direction(KernelGlobals kg, const float3 P, const float3 D)
ccl_device_inline float camera_z_depth(KernelGlobals kg, const float3 P)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int ccl_global float * render_buffer
@ CLOSURE_BSDF_HAIR_HUANG_ID
@ PATH_RAY_SHADOW_CATCHER_PASS
@ PATH_RAY_SINGLE_PASS_DONE
@ PATH_RAY_DENOISING_FEATURES
@ DENOISING_PASS_FOLLOW_REFLECTIONS
@ DENOISING_PASS_USE_ALBEDO_ROUGHNESS_WEIGHTING
ccl_device_inline float ensure_finite(const float v)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
closure color scatter(string phase, float Anisotropy, float IOR, float Backscatter, float Alpha, float Diameter)
ccl_device_forceinline float3 primitive_motion_vector_backward_depth_delta(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_forceinline float4 primitive_motion_vector_reflection(KernelGlobals kg, const float3 reflector_P, const float3 reflector_N, const ccl_private ShaderData *sd)
#define INTEGRATOR_STATE_WRITE(state, nested_struct, member)
#define INTEGRATOR_STATE(state, nested_struct, member)
IntegratorStateCPU * IntegratorState
KERNEL_FEATURE_LIGHT_PASSES denoising_feature_throughput
ccl_device Spectrum surface_shader_alpha(const ccl_private ShaderData *sd)
ccl_device_inline void film_write_pass_float3(ccl_global float *ccl_restrict buffer, const float3 value)
ccl_device_inline void film_write_pass_spectrum(ccl_global float *ccl_restrict buffer, Spectrum value)
ccl_device_inline void film_write_pass_float(ccl_global float *ccl_restrict buffer, const float value)
CCL_NAMESPACE_BEGIN ccl_device_forceinline ccl_global float * film_pass_pixel_render_buffer(KernelGlobals kg, ConstIntegratorState state, ccl_global float *ccl_restrict render_buffer)
ccl_device_inline void film_overwrite_pass_float(ccl_global float *ccl_restrict buffer, const float value)