1 /*
2 * Copyright 2011-2015 Blender Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 CCL_NAMESPACE_BEGIN
18
19 /* Shadow ray cast for direct visible light. */
kernel_shadow_blocked_dl(KernelGlobals * kg)20 ccl_device void kernel_shadow_blocked_dl(KernelGlobals *kg)
21 {
22 unsigned int dl_queue_length = kernel_split_params.queue_index[QUEUE_SHADOW_RAY_CAST_DL_RAYS];
23 ccl_barrier(CCL_LOCAL_MEM_FENCE);
24
25 int ray_index = QUEUE_EMPTY_SLOT;
26 int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
27 if (thread_index < dl_queue_length) {
28 ray_index = get_ray_index(kg,
29 thread_index,
30 QUEUE_SHADOW_RAY_CAST_DL_RAYS,
31 kernel_split_state.queue_data,
32 kernel_split_params.queue_size,
33 1);
34 }
35
36 #ifdef __BRANCHED_PATH__
37 /* TODO(mai): move this somewhere else? */
38 if (thread_index == 0) {
39 /* Clear QUEUE_INACTIVE_RAYS before next kernel. */
40 kernel_split_params.queue_index[QUEUE_INACTIVE_RAYS] = 0;
41 }
42 #endif /* __BRANCHED_PATH__ */
43
44 if (ray_index == QUEUE_EMPTY_SLOT)
45 return;
46
47 ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
48 Ray ray = kernel_split_state.light_ray[ray_index];
49 PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
50 ShaderData *sd = kernel_split_sd(sd, ray_index);
51 float3 throughput = kernel_split_state.throughput[ray_index];
52
53 BsdfEval L_light = kernel_split_state.bsdf_eval[ray_index];
54 ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]);
55 bool is_lamp = kernel_split_state.is_lamp[ray_index];
56
57 #if defined(__BRANCHED_PATH__) || defined(__SHADOW_TRICKS__)
58 bool use_branched = false;
59 int all = 0;
60
61 if (state->flag & PATH_RAY_SHADOW_CATCHER) {
62 use_branched = true;
63 all = 1;
64 }
65 # if defined(__BRANCHED_PATH__)
66 else if (kernel_data.integrator.branched) {
67 use_branched = true;
68
69 if (IS_FLAG(kernel_split_state.ray_state, ray_index, RAY_BRANCHED_INDIRECT)) {
70 all = (kernel_data.integrator.sample_all_lights_indirect);
71 }
72 else {
73 all = (kernel_data.integrator.sample_all_lights_direct);
74 }
75 }
76 # endif /* __BRANCHED_PATH__ */
77
78 if (use_branched) {
79 kernel_branched_path_surface_connect_light(
80 kg, sd, emission_sd, state, throughput, 1.0f, L, all);
81 }
82 else
83 #endif /* defined(__BRANCHED_PATH__) || defined(__SHADOW_TRICKS__)*/
84 {
85 /* trace shadow ray */
86 float3 shadow;
87
88 if (!shadow_blocked(kg, sd, emission_sd, state, &ray, &shadow)) {
89 /* accumulate */
90 path_radiance_accum_light(kg, L, state, throughput, &L_light, shadow, 1.0f, is_lamp);
91 }
92 else {
93 path_radiance_accum_total_light(L, state, throughput, &L_light);
94 }
95 }
96 }
97
98 CCL_NAMESPACE_END
99