2 * Copyright 2011-2015 Blender Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "kernel_split_common.h"
19 /* Note on kernel_shadow_blocked kernel.
20 * This is the ninth kernel in the ray tracing logic. This is the eighth
21 * of the path iteration kernels. This kernel takes care of "shadow ray cast"
22 * logic of the direct lighting and AO part of ray tracing.
24 * The input and output are as follows,
26 * PathState_coop ----------------------------------|--- kernel_shadow_blocked --|
27 * LightRay_dl_coop --------------------------------| |--- LightRay_dl_coop
28 * LightRay_ao_coop --------------------------------| |--- LightRay_ao_coop
29 * ray_state ---------------------------------------| |--- ray_state
30 * Queue_data(QUEUE_SHADOW_RAY_CAST_AO_RAYS & | |--- Queue_data (QUEUE_SHADOW_RAY_CAST_AO_RAYS & QUEUE_SHADOW_RAY_CAST_AO_RAYS)
31 QUEUE_SHADOW_RAY_CAST_DL_RAYS) -------| |
32 * Queue_index(QUEUE_SHADOW_RAY_CAST_AO_RAYS&
33 QUEUE_SHADOW_RAY_CAST_DL_RAYS) -------| |
34 * kg (globals) ------------------------------------| |
35 * queuesize ---------------------------------------| |
37 * Note on sd_shadow : sd_shadow is neither input nor output to this kernel. sd_shadow is filled and consumed in this kernel itself.
39 * The kernel fetches from QUEUE_SHADOW_RAY_CAST_AO_RAYS and QUEUE_SHADOW_RAY_CAST_DL_RAYS queues. We will empty
40 * these queues this kernel.
41 * State of queues when this kernel is called :
42 * state of queues QUEUE_ACTIVE_AND_REGENERATED_RAYS and QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will be same
43 * before and after this kernel call.
44 * QUEUE_SHADOW_RAY_CAST_AO_RAYS & QUEUE_SHADOW_RAY_CAST_DL_RAYS will be filled with rays marked with flags RAY_SHADOW_RAY_CAST_AO
45 * and RAY_SHADOW_RAY_CAST_DL respectively, during kernel entry.
46 * QUEUE_SHADOW_RAY_CAST_AO_RAYS and QUEUE_SHADOW_RAY_CAST_DL_RAYS will be empty at kernel exit.
48 ccl_device void kernel_shadow_blocked(
50 ShaderData *sd_shadow, /* Required for shadow blocked */
51 ccl_global PathState *PathState_coop, /* Required for shadow blocked */
52 ccl_global Ray *LightRay_dl_coop, /* Required for direct lighting's shadow blocked */
53 ccl_global Ray *LightRay_ao_coop, /* Required for AO's shadow blocked */
54 ccl_global char *ray_state,
56 char shadow_blocked_type,
59 /* Flag determining if we need to update L. */
60 char update_path_radiance = 0;
62 if(IS_FLAG(ray_state, ray_index, RAY_SHADOW_RAY_CAST_DL) ||
63 IS_FLAG(ray_state, ray_index, RAY_SHADOW_RAY_CAST_AO))
65 ccl_global PathState *state = &PathState_coop[ray_index];
66 ccl_global Ray *light_ray_dl_global = &LightRay_dl_coop[ray_index];
67 ccl_global Ray *light_ray_ao_global = &LightRay_ao_coop[ray_index];
69 ccl_global Ray *light_ray_global =
70 shadow_blocked_type == RAY_SHADOW_RAY_CAST_AO
72 : light_ray_dl_global;
75 update_path_radiance = !(shadow_blocked(kg,
80 /* We use light_ray_global's P and t to store shadow and
81 * update_path_radiance.
83 light_ray_global->P = shadow;
84 light_ray_global->t = update_path_radiance;