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_direct_lighting kernel.
20 * This is the eighth kernel in the ray tracing logic. This is the seventh
21 * of the path iteration kernels. This kernel takes care of direct lighting
22 * logic. However, the "shadow ray cast" part of direct lighting is handled
25 * This kernels determines the rays for which a shadow_blocked() function associated with direct lighting should be executed.
26 * Those rays for which a shadow_blocked() function for direct-lighting must be executed, are marked with flag RAY_SHADOW_RAY_CAST_DL and
27 * enqueued into the queue QUEUE_SHADOW_RAY_CAST_DL_RAYS
29 * The input and output are as follows,
31 * rng_coop -----------------------------------------|--- kernel_direct_lighting --|--- BSDFEval_coop
32 * PathState_coop -----------------------------------| |--- ISLamp_coop
33 * sd -----------------------------------------------| |--- LightRay_coop
34 * ray_state ----------------------------------------| |--- ray_state
35 * Queue_data (QUEUE_ACTIVE_AND_REGENERATED_RAYS) ---| |
36 * kg (globals) -------------------------------------| |
37 * queuesize ----------------------------------------| |
39 * note on sd_DL : sd_DL is neither input nor output to this kernel; sd_DL is filled and consumed in this kernel itself.
41 * This kernel only reads from the QUEUE_ACTIVE_AND_REGENERATED_RAYS queue and processes
42 * only the rays of state RAY_ACTIVE; If a ray needs to execute the corresponding shadow_blocked
43 * part, after direct lighting, the ray is marked with RAY_SHADOW_RAY_CAST_DL flag.
45 * State of queues when this kernel is called :
46 * state of queues QUEUE_ACTIVE_AND_REGENERATED_RAYS and QUEUE_HITBG_BUFF_UPDATE_TOREGEN_RAYS will be same
47 * before and after this kernel call.
48 * QUEUE_SHADOW_RAY_CAST_DL_RAYS queue will be filled with rays for which a shadow_blocked function must be executed, after this
49 * kernel call. Before this kernel call the QUEUE_SHADOW_RAY_CAST_DL_RAYS will be empty.
51 ccl_device char kernel_direct_lighting(
53 ShaderData *sd, /* Required for direct lighting */
54 ShaderData *sd_DL, /* Required for direct lighting */
55 ccl_global uint *rng_coop, /* Required for direct lighting */
56 ccl_global PathState *PathState_coop, /* Required for direct lighting */
57 ccl_global int *ISLamp_coop, /* Required for direct lighting */
58 ccl_global Ray *LightRay_coop, /* Required for direct lighting */
59 ccl_global BsdfEval *BSDFEval_coop, /* Required for direct lighting */
60 ccl_global char *ray_state, /* Denotes the state of each ray */
63 char enqueue_flag = 0;
64 if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) {
65 ccl_global PathState *state = &PathState_coop[ray_index];
69 if((kernel_data.integrator.use_direct_light &&
70 (ccl_fetch(sd, flag) & SD_BSDF_HAS_EVAL)))
72 /* Sample illumination from lights to find path contribution. */
73 ccl_global RNG* rng = &rng_coop[ray_index];
74 float light_t = path_state_rng_1D(kg, rng, state, PRNG_LIGHT);
75 float light_u, light_v;
76 path_state_rng_2D(kg, rng, state, PRNG_LIGHT_U, &light_u, &light_v);
80 light_t, light_u, light_v,
87 #ifdef __OBJECT_MOTION__
88 light_ray.time = ccl_fetch(sd, time);
93 if(direct_emission(kg, sd, &ls, state, &light_ray, &L_light, &is_lamp,
96 /* Write intermediate data to global memory to access from
99 LightRay_coop[ray_index] = light_ray;
100 BSDFEval_coop[ray_index] = L_light;
101 ISLamp_coop[ray_index] = is_lamp;
102 /* Mark ray state for next shadow kernel. */
103 ADD_RAY_FLAG(ray_state, ray_index, RAY_SHADOW_RAY_CAST_DL);
107 #endif /* __EMISSION__ */