b50de615fc8bbcb026d233f7e738099e86fb978c
[blender.git] / intern / cycles / kernel / split / kernel_shadow_blocked_ao.h
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 AO. */
20 ccl_device void kernel_shadow_blocked_ao(KernelGlobals *kg)
21 {
22         unsigned int ao_queue_length = kernel_split_params.queue_index[QUEUE_SHADOW_RAY_CAST_AO_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 < ao_queue_length) {
28                 ray_index = get_ray_index(kg, thread_index, QUEUE_SHADOW_RAY_CAST_AO_RAYS,
29                                           kernel_split_state.queue_data, kernel_split_params.queue_size, 1);
30         }
31
32         if(ray_index == QUEUE_EMPTY_SLOT) {
33                 return;
34         }
35
36         ShaderData *sd = &kernel_split_state.sd[ray_index];
37         ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]);
38         PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
39         ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
40         float3 throughput = kernel_split_state.throughput[ray_index];
41
42 #ifdef __BRANCHED_PATH__
43         if(!kernel_data.integrator.branched || IS_FLAG(kernel_split_state.ray_state, ray_index, RAY_BRANCHED_INDIRECT)) {
44 #endif
45                 kernel_path_ao(kg, sd, emission_sd, L, state, throughput, shader_bsdf_alpha(kg, sd));
46 #ifdef __BRANCHED_PATH__
47         }
48         else {
49                 kernel_branched_path_ao(kg, sd, emission_sd, L, state, throughput);
50         }
51 #endif
52 }
53
54 CCL_NAMESPACE_END
55