Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/light/distribution.h
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| template<bool in_volume_segment> | template<bool in_volume_segment> | ||||
| ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, | ccl_device_noinline bool light_distribution_sample(KernelGlobals kg, | ||||
| float randu, | float randu, | ||||
| const float randv, | const float randv, | ||||
| const float time, | const float time, | ||||
| const float3 P, | const float3 P, | ||||
| const int bounce, | const int bounce, | ||||
| const uint32_t path_flag, | const uint32_t path_flag, | ||||
| ccl_private LightSample *ls) | ccl_private int *emitter_object, | ||||
| ccl_private int *emitter_prim, | |||||
| ccl_private int *emitter_shader_flag, | |||||
| ccl_private float *emitter_pdf_selection) | |||||
| { | { | ||||
| /* Sample light index from distribution. */ | /* Sample light index from distribution. */ | ||||
| const int index = light_distribution_sample(kg, &randu); | const int index = light_distribution_sample(kg, &randu); | ||||
| ccl_global const KernelLightDistribution *kdistribution = &kernel_data_fetch(light_distribution, | ccl_global const KernelLightDistribution *kdistribution = &kernel_data_fetch(light_distribution, | ||||
| index); | index); | ||||
| const int prim = kdistribution->prim; | |||||
| if (prim >= 0) { | *emitter_prim = kdistribution->prim; | ||||
| /* Mesh light. */ | *emitter_object = kdistribution->mesh_light.object_id; | ||||
| const int object = kdistribution->mesh_light.object_id; | *emitter_shader_flag = kdistribution->mesh_light.shader_flag; | ||||
| *emitter_pdf_selection = kernel_data.integrator.distribution_pdf_lights; | |||||
| /* Exclude synthetic meshes from shadow catcher pass. */ | |||||
| if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) && | |||||
| !(kernel_data_fetch(object_flag, object) & SD_OBJECT_SHADOW_CATCHER)) { | |||||
| return false; | |||||
| } | |||||
| const int shader_flag = kdistribution->mesh_light.shader_flag; | |||||
| triangle_light_sample<in_volume_segment>(kg, prim, object, randu, randv, time, ls, P); | |||||
| ls->shader |= shader_flag; | |||||
| return (ls->pdf > 0.0f); | |||||
| } | |||||
| const int lamp = -prim - 1; | |||||
| if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) { | |||||
| return false; | |||||
| } | |||||
| if (!light_sample<in_volume_segment>(kg, lamp, randu, randv, P, path_flag, ls)) { | |||||
| return false; | |||||
| } | |||||
| ls->pdf_selection = kernel_data.integrator.distribution_pdf_lights; | |||||
| ls->pdf *= ls->pdf_selection; | |||||
| return true; | return true; | ||||
| } | } | ||||
| ccl_device_inline float light_distribution_pdf_lamp(KernelGlobals kg) | ccl_device_inline float light_distribution_pdf_lamp(KernelGlobals kg) | ||||
| { | { | ||||
| return kernel_data.integrator.distribution_pdf_lights; | return kernel_data.integrator.distribution_pdf_lights; | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||