kernel_path_init.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. CCL_NAMESPACE_BEGIN
  17. /* This kernel initializes structures needed in path-iteration kernels.
  18. * This is the first kernel in ray-tracing logic.
  19. *
  20. * Ray state of rays outside the tile-boundary will be marked RAY_INACTIVE
  21. */
  22. ccl_device void kernel_path_init(KernelGlobals *kg)
  23. {
  24. int ray_index = ccl_global_id(0) + ccl_global_id(1) * ccl_global_size(0);
  25. /* This is the first assignment to ray_state;
  26. * So we dont use ASSIGN_RAY_STATE macro.
  27. */
  28. kernel_split_state.ray_state[ray_index] = RAY_ACTIVE;
  29. /* Get work. */
  30. ccl_global uint *work_pools = kernel_split_params.work_pools;
  31. uint total_work_size = kernel_split_params.total_work_size;
  32. uint work_index;
  33. if (!get_next_work(kg, work_pools, total_work_size, ray_index, &work_index)) {
  34. /* No more work, mark ray as inactive */
  35. kernel_split_state.ray_state[ray_index] = RAY_INACTIVE;
  36. return;
  37. }
  38. ccl_global WorkTile *tile = &kernel_split_params.tile;
  39. uint x, y, sample;
  40. get_work_pixel(tile, work_index, &x, &y, &sample);
  41. /* Store buffer offset for writing to passes. */
  42. uint buffer_offset = (tile->offset + x + y * tile->stride) * kernel_data.film.pass_stride;
  43. kernel_split_state.buffer_offset[ray_index] = buffer_offset;
  44. /* Initialize random numbers and ray. */
  45. uint rng_hash;
  46. kernel_path_trace_setup(kg, sample, x, y, &rng_hash, &kernel_split_state.ray[ray_index]);
  47. if (kernel_split_state.ray[ray_index].t != 0.0f) {
  48. /* Initialize throughput, path radiance, Ray, PathState;
  49. * These rays proceed with path-iteration.
  50. */
  51. kernel_split_state.throughput[ray_index] = make_float3(1.0f, 1.0f, 1.0f);
  52. path_radiance_init(&kernel_split_state.path_radiance[ray_index],
  53. kernel_data.film.use_light_pass);
  54. path_state_init(kg,
  55. AS_SHADER_DATA(&kernel_split_state.sd_DL_shadow[ray_index]),
  56. &kernel_split_state.path_state[ray_index],
  57. rng_hash,
  58. sample,
  59. &kernel_split_state.ray[ray_index]);
  60. #ifdef __SUBSURFACE__
  61. kernel_path_subsurface_init_indirect(&kernel_split_state.ss_rays[ray_index]);
  62. #endif
  63. }
  64. else {
  65. ASSIGN_RAY_STATE(kernel_split_state.ray_state, ray_index, RAY_TO_REGENERATE);
  66. }
  67. }
  68. CCL_NAMESPACE_END