0c894bd3d71486b889abca996e0198d97cd6e25d
[blender.git] / intern / cycles / kernel / split / kernel_indirect_background.h
1 /*
2  * Copyright 2011-2017 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 ccl_device void kernel_indirect_background(KernelGlobals *kg)
20 {
21         ccl_global char *ray_state = kernel_split_state.ray_state;
22
23         int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
24         int ray_index;
25
26         if(kernel_data.integrator.ao_bounces != INT_MAX) {
27                 ray_index = get_ray_index(kg, thread_index,
28                                           QUEUE_ACTIVE_AND_REGENERATED_RAYS,
29                                           kernel_split_state.queue_data,
30                                           kernel_split_params.queue_size,
31                                           0);
32
33                 if(ray_index != QUEUE_EMPTY_SLOT) {
34                         if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) {
35                                 ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
36                                 if(path_state_ao_bounce(kg, state)) {
37                                         kernel_split_path_end(kg, ray_index);
38                                 }
39                         }
40                 }
41         }
42
43         ray_index = get_ray_index(kg, thread_index,
44                                   QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS,
45                                   kernel_split_state.queue_data,
46                                   kernel_split_params.queue_size,
47                                   0);
48
49         if(ray_index == QUEUE_EMPTY_SLOT) {
50                 return;
51         }
52
53         if(IS_STATE(ray_state, ray_index, RAY_HIT_BACKGROUND)) {
54                 ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
55                 PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
56                 ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
57                 float3 throughput = kernel_split_state.throughput[ray_index];
58                 ShaderData *sd = &kernel_split_state.sd[ray_index];
59
60                 kernel_path_background(kg, state, ray, throughput, sd, L);
61                 kernel_split_path_end(kg, ray_index);
62         }
63 }
64
65 CCL_NAMESPACE_END