Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_accumulate.h
| Show First 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | #endif | ||||
| L->emission = make_float3(0.0f, 0.0f, 0.0f); | L->emission = make_float3(0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| L->path_total = make_float3(0.0f, 0.0f, 0.0f); | L->path_total = make_float3(0.0f, 0.0f, 0.0f); | ||||
| L->path_total_shaded = make_float3(0.0f, 0.0f, 0.0f); | L->path_total_shaded = make_float3(0.0f, 0.0f, 0.0f); | ||||
| L->shadow_color = make_float3(0.0f, 0.0f, 0.0f); | L->shadow_color = make_float3(0.0f, 0.0f, 0.0f); | ||||
| #endif | #endif | ||||
| #ifdef __DENOISING_FEATURES__ | |||||
| L->denoising_normal = make_float3(0.0f, 0.0f, 0.0f); | |||||
| L->denoising_albedo = make_float3(0.0f, 0.0f, 0.0f); | |||||
| L->denoising_depth = 0.0f; | |||||
| #endif /* __DENOISING_FEATURES__ */ | |||||
| } | } | ||||
| ccl_device_inline void path_radiance_bsdf_bounce(PathRadiance *L, ccl_addr_space float3 *throughput, | ccl_device_inline void path_radiance_bsdf_bounce(PathRadiance *L, ccl_addr_space float3 *throughput, | ||||
| BsdfEval *bsdf_eval, float bsdf_pdf, int bounce, int bsdf_label) | BsdfEval *bsdf_eval, float bsdf_pdf, int bounce, int bsdf_label) | ||||
| { | { | ||||
| float inverse_pdf = 1.0f/bsdf_pdf; | float inverse_pdf = 1.0f/bsdf_pdf; | ||||
| #ifdef __PASSES__ | #ifdef __PASSES__ | ||||
| Show All 39 Lines | #ifdef __PASSES__ | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| L->emission += throughput*value; | L->emission += throughput*value; | ||||
| } | } | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_accum_ao(PathRadiance *L, | ccl_device_inline void path_radiance_accum_ao(PathRadiance *L, | ||||
| ccl_addr_space PathState *state, | |||||
| float3 throughput, | float3 throughput, | ||||
| float3 alpha, | float3 alpha, | ||||
| float3 bsdf, | float3 bsdf, | ||||
| float3 ao, | float3 ao) | ||||
| int bounce) | |||||
| { | { | ||||
| #ifdef __PASSES__ | #ifdef __PASSES__ | ||||
| if(L->use_light_pass) { | if(L->use_light_pass) { | ||||
| if(bounce == 0) { | if(state->bounce == 0) { | ||||
| /* directly visible lighting */ | /* directly visible lighting */ | ||||
| L->direct_diffuse += throughput*bsdf*ao; | L->direct_diffuse += throughput*bsdf*ao; | ||||
| L->ao += alpha*throughput*ao; | L->ao += alpha*throughput*ao; | ||||
| } | } | ||||
| else { | else { | ||||
| /* indirectly visible lighting after BSDF bounce */ | /* indirectly visible lighting after BSDF bounce */ | ||||
| L->indirect += throughput*bsdf*ao; | L->indirect += throughput*bsdf*ao; | ||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| L->emission += throughput*bsdf*ao; | L->emission += throughput*bsdf*ao; | ||||
| } | } | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| if(state->flag & PATH_RAY_STORE_SHADOW_INFO) { | |||||
| float3 light = throughput * bsdf; | float3 light = throughput * bsdf; | ||||
| L->path_total += light; | L->path_total += light; | ||||
| L->path_total_shaded += ao * light; | L->path_total_shaded += ao * light; | ||||
| } | |||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_accum_total_ao( | ccl_device_inline void path_radiance_accum_total_ao( | ||||
| PathRadiance *L, | PathRadiance *L, | ||||
| ccl_addr_space PathState *state, | |||||
| float3 throughput, | float3 throughput, | ||||
| float3 bsdf) | float3 bsdf) | ||||
| { | { | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| if(state->flag & PATH_RAY_STORE_SHADOW_INFO) { | |||||
| L->path_total += throughput * bsdf; | L->path_total += throughput * bsdf; | ||||
| } | |||||
| #else | #else | ||||
| (void) L; | (void) L; | ||||
| (void) state; | |||||
| (void) throughput; | (void) throughput; | ||||
| (void) bsdf; | (void) bsdf; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_accum_light(PathRadiance *L, float3 throughput, BsdfEval *bsdf_eval, float3 shadow, float shadow_fac, int bounce, bool is_lamp) | ccl_device_inline void path_radiance_accum_light(PathRadiance *L, | ||||
| ccl_addr_space PathState *state, | |||||
| float3 throughput, | |||||
| BsdfEval *bsdf_eval, | |||||
| float3 shadow, | |||||
| float shadow_fac, | |||||
| bool is_lamp) | |||||
| { | { | ||||
| #ifdef __PASSES__ | #ifdef __PASSES__ | ||||
| if(L->use_light_pass) { | if(L->use_light_pass) { | ||||
| if(bounce == 0) { | if(state->bounce == 0) { | ||||
| /* directly visible lighting */ | /* directly visible lighting */ | ||||
| L->direct_diffuse += throughput*bsdf_eval->diffuse*shadow; | L->direct_diffuse += throughput*bsdf_eval->diffuse*shadow; | ||||
| L->direct_glossy += throughput*bsdf_eval->glossy*shadow; | L->direct_glossy += throughput*bsdf_eval->glossy*shadow; | ||||
| L->direct_transmission += throughput*bsdf_eval->transmission*shadow; | L->direct_transmission += throughput*bsdf_eval->transmission*shadow; | ||||
| L->direct_subsurface += throughput*bsdf_eval->subsurface*shadow; | L->direct_subsurface += throughput*bsdf_eval->subsurface*shadow; | ||||
| L->direct_scatter += throughput*bsdf_eval->scatter*shadow; | L->direct_scatter += throughput*bsdf_eval->scatter*shadow; | ||||
| if(is_lamp) { | if(is_lamp) { | ||||
| Show All 9 Lines | #ifdef __PASSES__ | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| L->emission += throughput*bsdf_eval->diffuse*shadow; | L->emission += throughput*bsdf_eval->diffuse*shadow; | ||||
| } | } | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| if(state->flag & PATH_RAY_STORE_SHADOW_INFO) { | |||||
| float3 light = throughput * bsdf_eval->sum_no_mis; | float3 light = throughput * bsdf_eval->sum_no_mis; | ||||
| L->path_total += light; | L->path_total += light; | ||||
| L->path_total_shaded += shadow * light; | L->path_total_shaded += shadow * light; | ||||
| } | |||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_accum_total_light( | ccl_device_inline void path_radiance_accum_total_light( | ||||
| PathRadiance *L, | PathRadiance *L, | ||||
| ccl_addr_space PathState *state, | |||||
| float3 throughput, | float3 throughput, | ||||
| const BsdfEval *bsdf_eval) | const BsdfEval *bsdf_eval) | ||||
| { | { | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| if(state->flag & PATH_RAY_STORE_SHADOW_INFO) { | |||||
| L->path_total += throughput * bsdf_eval->sum_no_mis; | L->path_total += throughput * bsdf_eval->sum_no_mis; | ||||
| } | |||||
| #else | #else | ||||
| (void) L; | (void) L; | ||||
| (void) state; | |||||
| (void) throughput; | (void) throughput; | ||||
| (void) bsdf_eval; | (void) bsdf_eval; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_accum_background(PathRadiance *L, | ccl_device_inline void path_radiance_accum_background(PathRadiance *L, | ||||
| ccl_addr_space PathState *state, | ccl_addr_space PathState *state, | ||||
| float3 throughput, | float3 throughput, | ||||
| Show All 10 Lines | #ifdef __PASSES__ | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| L->emission += throughput*value; | L->emission += throughput*value; | ||||
| } | } | ||||
| #ifdef __SHADOW_TRICKS__ | #ifdef __SHADOW_TRICKS__ | ||||
| if(state->flag & PATH_RAY_STORE_SHADOW_INFO) { | |||||
| L->path_total += throughput * value; | L->path_total += throughput * value; | ||||
| if(state->flag & PATH_RAY_SHADOW_CATCHER_ONLY) { | if(state->flag & PATH_RAY_SHADOW_CATCHER_ONLY) { | ||||
| L->path_total_shaded += throughput * value; | L->path_total_shaded += throughput * value; | ||||
| } | } | ||||
| } | |||||
| #endif | #endif | ||||
| #ifdef __DENOISING_FEATURES__ | |||||
| L->denoising_albedo += state->denoising_feature_weight * value; | |||||
| #endif /* __DENOISING_FEATURES__ */ | |||||
| } | } | ||||
| ccl_device_inline void path_radiance_sum_indirect(PathRadiance *L) | ccl_device_inline void path_radiance_sum_indirect(PathRadiance *L) | ||||
| { | { | ||||
| #ifdef __PASSES__ | #ifdef __PASSES__ | ||||
| /* this division is a bit ugly, but means we only have to keep track of | /* this division is a bit ugly, but means we only have to keep track of | ||||
| * only a single throughput further along the path, here we recover just | * only a single throughput further along the path, here we recover just | ||||
| * the indirect path that is not influenced by any particular BSDF type */ | * the indirect path that is not influenced by any particular BSDF type */ | ||||
| ▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | #endif | ||||
| if(!isfinite_safe(sum)) { | if(!isfinite_safe(sum)) { | ||||
| kernel_assert(!"Non-finite final sum in path_radiance_clamp_and_sum!"); | kernel_assert(!"Non-finite final sum in path_radiance_clamp_and_sum!"); | ||||
| L_sum = make_float3(0.0f, 0.0f, 0.0f); | L_sum = make_float3(0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| return L_sum; | return L_sum; | ||||
| } | } | ||||
| ccl_device_inline void path_radiance_split_denoising(KernelGlobals *kg, PathRadiance *L, float3 *noisy, float3 *clean) | |||||
| { | |||||
| #ifdef __PASSES__ | |||||
| kernel_assert(L->use_light_pass); | |||||
| *clean = L->emission + L->background; | |||||
| *noisy = L->direct_scatter + L->indirect_scatter; | |||||
| # define ADD_COMPONENT(flag, component) \ | |||||
| if(kernel_data.film.denoising_flags & flag) \ | |||||
| *clean += component; \ | |||||
| else \ | |||||
| *noisy += component; | |||||
| ADD_COMPONENT(DENOISING_CLEAN_DIFFUSE_DIR, L->direct_diffuse); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_DIFFUSE_IND, L->indirect_diffuse); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_GLOSSY_DIR, L->direct_glossy); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_GLOSSY_IND, L->indirect_glossy); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_TRANSMISSION_DIR, L->direct_transmission); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_TRANSMISSION_IND, L->indirect_transmission); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_SUBSURFACE_DIR, L->direct_subsurface); | |||||
| ADD_COMPONENT(DENOISING_CLEAN_SUBSURFACE_IND, L->indirect_subsurface); | |||||
| # undef ADD_COMPONENT | |||||
| #else | |||||
| *noisy = L->emission; | |||||
| *clean = make_float3(0.0f, 0.0f, 0.0f); | |||||
| #endif | |||||
| *noisy = ensure_finite3(*noisy); | |||||
| *clean = ensure_finite3(*clean); | |||||
| } | |||||
| ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance *L_sample, int num_samples) | ccl_device_inline void path_radiance_accum_sample(PathRadiance *L, PathRadiance *L_sample, int num_samples) | ||||
| { | { | ||||
| float fac = 1.0f/num_samples; | float fac = 1.0f/num_samples; | ||||
| #ifdef __PASSES__ | #ifdef __PASSES__ | ||||
| L->direct_diffuse += L_sample->direct_diffuse*fac; | L->direct_diffuse += L_sample->direct_diffuse*fac; | ||||
| L->direct_glossy += L_sample->direct_glossy*fac; | L->direct_glossy += L_sample->direct_glossy*fac; | ||||
| L->direct_transmission += L_sample->direct_transmission*fac; | L->direct_transmission += L_sample->direct_transmission*fac; | ||||
| Show All 24 Lines | if(path_total != 0.0f) { | ||||
| return path_total_shaded / path_total; | return path_total_shaded / path_total; | ||||
| } | } | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| /* Calculate final light sum and transparency for shadow catcher object. */ | /* Calculate final light sum and transparency for shadow catcher object. */ | ||||
| ccl_device_inline float3 path_radiance_sum_shadowcatcher(KernelGlobals *kg, | ccl_device_inline float3 path_radiance_sum_shadowcatcher(KernelGlobals *kg, | ||||
| const PathRadiance *L, | const PathRadiance *L, | ||||
| ccl_addr_space float* L_transparent) | float* alpha) | ||||
| { | { | ||||
| const float shadow = path_radiance_sum_shadow(L); | const float shadow = path_radiance_sum_shadow(L); | ||||
| float3 L_sum; | float3 L_sum; | ||||
| if(kernel_data.background.transparent) { | if(kernel_data.background.transparent) { | ||||
| *L_transparent = shadow; | *alpha = 1.0f-shadow; | ||||
| L_sum = make_float3(0.0f, 0.0f, 0.0f); | L_sum = make_float3(0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| L_sum = L->shadow_color * shadow; | L_sum = L->shadow_color * shadow; | ||||
| } | } | ||||
| return L_sum; | return L_sum; | ||||
| } | } | ||||
| #endif | #endif | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||