kernel_scene_intersect.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /* This kernel takes care of scene_intersect function.
  18. *
  19. * This kernel changes the ray_state of RAY_REGENERATED rays to RAY_ACTIVE.
  20. * This kernel processes rays of ray state RAY_ACTIVE
  21. * This kernel determines the rays that have hit the background and changes
  22. * their ray state to RAY_HIT_BACKGROUND.
  23. */
  24. ccl_device void kernel_scene_intersect(KernelGlobals *kg)
  25. {
  26. /* Fetch use_queues_flag */
  27. char local_use_queues_flag = *kernel_split_params.use_queues_flag;
  28. ccl_barrier(CCL_LOCAL_MEM_FENCE);
  29. int ray_index = ccl_global_id(1) * ccl_global_size(0) + ccl_global_id(0);
  30. if (local_use_queues_flag) {
  31. ray_index = get_ray_index(kg,
  32. ray_index,
  33. QUEUE_ACTIVE_AND_REGENERATED_RAYS,
  34. kernel_split_state.queue_data,
  35. kernel_split_params.queue_size,
  36. 0);
  37. if (ray_index == QUEUE_EMPTY_SLOT) {
  38. return;
  39. }
  40. }
  41. /* All regenerated rays become active here */
  42. if (IS_STATE(kernel_split_state.ray_state, ray_index, RAY_REGENERATED)) {
  43. #ifdef __BRANCHED_PATH__
  44. if (kernel_split_state.branched_state[ray_index].waiting_on_shared_samples) {
  45. kernel_split_path_end(kg, ray_index);
  46. }
  47. else
  48. #endif /* __BRANCHED_PATH__ */
  49. {
  50. ASSIGN_RAY_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE);
  51. }
  52. }
  53. if (!IS_STATE(kernel_split_state.ray_state, ray_index, RAY_ACTIVE)) {
  54. return;
  55. }
  56. ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
  57. Ray ray = kernel_split_state.ray[ray_index];
  58. PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
  59. Intersection isect;
  60. bool hit = kernel_path_scene_intersect(kg, state, &ray, &isect, L);
  61. kernel_split_state.isect[ray_index] = isect;
  62. if (!hit) {
  63. /* Change the state of rays that hit the background;
  64. * These rays undergo special processing in the
  65. * background_bufferUpdate kernel.
  66. */
  67. ASSIGN_RAY_STATE(kernel_split_state.ray_state, ray_index, RAY_HIT_BACKGROUND);
  68. }
  69. }
  70. CCL_NAMESPACE_END