kernel_shadow_blocked_dl.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. CCL_NAMESPACE_BEGIN
  17. /* Shadow ray cast for direct visible light. */
  18. ccl_device void kernel_shadow_blocked_dl(KernelGlobals *kg)
  19. {
  20. unsigned int dl_queue_length = kernel_split_params.queue_index[QUEUE_SHADOW_RAY_CAST_DL_RAYS];
  21. ccl_barrier(CCL_LOCAL_MEM_FENCE);
  22. int ray_index = QUEUE_EMPTY_SLOT;
  23. int thread_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
  24. if (thread_index < dl_queue_length) {
  25. ray_index = get_ray_index(kg,
  26. thread_index,
  27. QUEUE_SHADOW_RAY_CAST_DL_RAYS,
  28. kernel_split_state.queue_data,
  29. kernel_split_params.queue_size,
  30. 1);
  31. }
  32. #ifdef __BRANCHED_PATH__
  33. /* TODO(mai): move this somewhere else? */
  34. if (thread_index == 0) {
  35. /* Clear QUEUE_INACTIVE_RAYS before next kernel. */
  36. kernel_split_params.queue_index[QUEUE_INACTIVE_RAYS] = 0;
  37. }
  38. #endif /* __BRANCHED_PATH__ */
  39. if (ray_index == QUEUE_EMPTY_SLOT)
  40. return;
  41. ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
  42. Ray ray = kernel_split_state.light_ray[ray_index];
  43. PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
  44. ShaderData *sd = kernel_split_sd(sd, ray_index);
  45. float3 throughput = kernel_split_state.throughput[ray_index];
  46. BsdfEval L_light = kernel_split_state.bsdf_eval[ray_index];
  47. ShaderData *emission_sd = AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]);
  48. bool is_lamp = kernel_split_state.is_lamp[ray_index];
  49. #if defined(__BRANCHED_PATH__) || defined(__SHADOW_TRICKS__)
  50. bool use_branched = false;
  51. int all = 0;
  52. if (state->flag & PATH_RAY_SHADOW_CATCHER) {
  53. use_branched = true;
  54. all = 1;
  55. }
  56. # if defined(__BRANCHED_PATH__)
  57. else if (kernel_data.integrator.branched) {
  58. use_branched = true;
  59. if (IS_FLAG(kernel_split_state.ray_state, ray_index, RAY_BRANCHED_INDIRECT)) {
  60. all = (kernel_data.integrator.sample_all_lights_indirect);
  61. }
  62. else {
  63. all = (kernel_data.integrator.sample_all_lights_direct);
  64. }
  65. }
  66. # endif /* __BRANCHED_PATH__ */
  67. if (use_branched) {
  68. kernel_branched_path_surface_connect_light(
  69. kg, sd, emission_sd, state, throughput, 1.0f, L, all);
  70. }
  71. else
  72. #endif /* defined(__BRANCHED_PATH__) || defined(__SHADOW_TRICKS__)*/
  73. {
  74. /* trace shadow ray */
  75. float3 shadow;
  76. if (!shadow_blocked(kg, sd, emission_sd, state, &ray, &shadow)) {
  77. /* accumulate */
  78. path_radiance_accum_light(L, state, throughput, &L_light, shadow, 1.0f, is_lamp);
  79. }
  80. else {
  81. path_radiance_accum_total_light(L, state, throughput, &L_light);
  82. }
  83. }
  84. }
  85. CCL_NAMESPACE_END