Fix T52470: cycles OpenCL hair rendering not working after recent changes.
[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(state->bounce > kernel_data.integrator.ao_bounces) {
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         ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
54         PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
55         ccl_global Ray *ray = &kernel_split_state.ray[ray_index];
56         ccl_global float3 *throughput = &kernel_split_state.throughput[ray_index];
57
58         if(IS_STATE(ray_state, ray_index, RAY_HIT_BACKGROUND)) {
59                 /* eval background shader if nothing hit */
60                 if(kernel_data.background.transparent && (state->flag & PATH_RAY_CAMERA)) {
61                         L->transparent += average((*throughput));
62 #ifdef __PASSES__
63                         if(!(kernel_data.film.pass_flag & PASS_BACKGROUND))
64 #endif
65                                 kernel_split_path_end(kg, ray_index);
66                 }
67
68                 if(IS_STATE(ray_state, ray_index, RAY_HIT_BACKGROUND)) {
69 #ifdef __BACKGROUND__
70                         /* sample background shader */
71                         float3 L_background = indirect_background(kg, &kernel_split_state.sd_DL_shadow[ray_index], state, ray);
72                         path_radiance_accum_background(L, state, (*throughput), L_background);
73 #endif
74                         kernel_split_path_end(kg, ray_index);
75                 }
76         }
77
78
79 }
80
81 CCL_NAMESPACE_END