Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/light/sample.h
| Show First 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | ccl_device_inline bool light_sample_from_volume_segment(KernelGlobals kg, | ||||
| const float time, | const float time, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 D, | const float3 D, | ||||
| const float t, | const float t, | ||||
| const int bounce, | const int bounce, | ||||
| const uint32_t path_flag, | const uint32_t path_flag, | ||||
| ccl_private LightSample *ls) | ccl_private LightSample *ls) | ||||
| { | { | ||||
| /* Select an emitter. */ | |||||
| int emitter_object = 0; | |||||
| int emitter_prim = 0; | |||||
| int emitter_shader_flag = 0; | |||||
| float emitter_pdf_selection = 0.0f; | |||||
| if (kernel_data.integrator.use_light_tree) { | if (kernel_data.integrator.use_light_tree) { | ||||
| return light_tree_sample<true>( | if (!light_tree_sample<true>(kg, | ||||
| kg, randu, randv, time, P, D, t, SD_BSDF_HAS_TRANSMISSION, bounce, path_flag, ls); | randu, | ||||
| randv, | |||||
| time, | |||||
| P, | |||||
| D, | |||||
| t, | |||||
| SD_BSDF_HAS_TRANSMISSION, | |||||
| bounce, | |||||
| path_flag, | |||||
| &emitter_object, | |||||
| &emitter_prim, | |||||
| &emitter_shader_flag, | |||||
| &emitter_pdf_selection)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (!light_distribution_sample<true>(kg, | |||||
| randu, | |||||
| randv, | |||||
| time, | |||||
| P, | |||||
| bounce, | |||||
| path_flag, | |||||
| &emitter_object, | |||||
| &emitter_prim, | |||||
| &emitter_shader_flag, | |||||
| &emitter_pdf_selection)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* Sample a point on the chosen emitter. */ | |||||
| if (emitter_prim >= 0) { | |||||
| /* Mesh light. */ | |||||
| /* Exclude synthetic meshes from shadow catcher pass. */ | |||||
| if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) && | |||||
| !(kernel_data_fetch(object_flag, emitter_object) & SD_OBJECT_SHADOW_CATCHER)) { | |||||
| return false; | |||||
| } | |||||
| if (!triangle_light_sample<true>( | |||||
| kg, emitter_prim, emitter_object, randu, randv, time, ls, P)) { | |||||
| return false; | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| return light_distribution_sample<true>(kg, randu, randv, time, P, bounce, path_flag, ls); | /* Light object. */ | ||||
| const int lamp = ~emitter_prim; | |||||
| if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) { | |||||
| return false; | |||||
| } | } | ||||
| if (!light_sample<true>(kg, lamp, randu, randv, P, path_flag, ls)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* Exception for triangle light with flat distribution that already sets pdf_selection. */ | |||||
| if (kernel_data.integrator.use_light_tree || emitter_prim < 0) { | |||||
| ls->pdf_selection = emitter_pdf_selection; | |||||
| } | |||||
| ls->pdf *= ls->pdf_selection; | |||||
| ls->shader |= emitter_shader_flag; | |||||
| return (ls->pdf > 0); | |||||
| } | } | ||||
| ccl_device bool light_sample_from_position(KernelGlobals kg, | ccl_device bool light_sample_from_position(KernelGlobals kg, | ||||
| ccl_private const RNGState *rng_state, | ccl_private const RNGState *rng_state, | ||||
| const float randu, | const float randu, | ||||
| const float randv, | const float randv, | ||||
| const float time, | const float time, | ||||
| const float3 P, | const float3 P, | ||||
| const float3 N, | const float3 N, | ||||
| const int shader_flags, | const int shader_flags, | ||||
| const int bounce, | const int bounce, | ||||
| const uint32_t path_flag, | const uint32_t path_flag, | ||||
| ccl_private LightSample *ls) | ccl_private LightSample *ls) | ||||
| { | { | ||||
| /* Select an emitter. */ | |||||
| int emitter_object = 0; | |||||
| int emitter_prim = 0; | |||||
| int emitter_shader_flag = 0; | |||||
| float emitter_pdf_selection = 0.0f; | |||||
| if (kernel_data.integrator.use_light_tree) { | if (kernel_data.integrator.use_light_tree) { | ||||
| return light_tree_sample<false>( | if (!light_tree_sample<false>(kg, | ||||
| kg, randu, randv, time, P, N, 0, shader_flags, bounce, path_flag, ls); | randu, | ||||
| randv, | |||||
| time, | |||||
| P, | |||||
| N, | |||||
| 0, | |||||
| shader_flags, | |||||
| bounce, | |||||
| path_flag, | |||||
| &emitter_object, | |||||
| &emitter_prim, | |||||
| &emitter_shader_flag, | |||||
| &emitter_pdf_selection)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (!light_distribution_sample<false>(kg, | |||||
| randu, | |||||
| randv, | |||||
| time, | |||||
| P, | |||||
| bounce, | |||||
| path_flag, | |||||
| &emitter_object, | |||||
| &emitter_prim, | |||||
| &emitter_shader_flag, | |||||
| &emitter_pdf_selection)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* Sample a point on the chosen emitter. | |||||
| * TODO: deduplicate code with light_sample_from_volume_segment? */ | |||||
| if (emitter_prim >= 0) { | |||||
| /* Mesh light. */ | |||||
| /* Exclude synthetic meshes from shadow catcher pass. */ | |||||
| if ((path_flag & PATH_RAY_SHADOW_CATCHER_PASS) && | |||||
| !(kernel_data_fetch(object_flag, emitter_object) & SD_OBJECT_SHADOW_CATCHER)) { | |||||
| return false; | |||||
| } | |||||
| if (!triangle_light_sample<false>( | |||||
| kg, emitter_prim, emitter_object, randu, randv, time, ls, P)) { | |||||
| return false; | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| return light_distribution_sample<false>(kg, randu, randv, time, P, bounce, path_flag, ls); | /* Light object. */ | ||||
| const int lamp = ~emitter_prim; | |||||
| if (UNLIKELY(light_select_reached_max_bounces(kg, lamp, bounce))) { | |||||
| return false; | |||||
| } | } | ||||
| if (!light_sample<false>(kg, lamp, randu, randv, P, path_flag, ls)) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| /* Exception for triangle light with flat distribution that already sets pdf_selection. */ | |||||
| if (kernel_data.integrator.use_light_tree || emitter_prim < 0) { | |||||
| ls->pdf_selection = emitter_pdf_selection; | |||||
| } | |||||
| ls->pdf *= ls->pdf_selection; | |||||
| ls->shader |= emitter_shader_flag; | |||||
| return (ls->pdf > 0); | |||||
| } | } | ||||
| ccl_device_inline bool light_sample_new_position(KernelGlobals kg, | ccl_device_inline bool light_sample_new_position(KernelGlobals kg, | ||||
| const float randu, | const float randu, | ||||
| const float randv, | const float randv, | ||||
| const float time, | const float time, | ||||
| const float3 P, | const float3 P, | ||||
| ccl_private LightSample *ls) | ccl_private LightSample *ls) | ||||
| ▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines | |||||