svm_light_path.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2011-2013 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. /* Light Path Node */
  18. ccl_device void svm_node_light_path(ShaderData *sd,
  19. ccl_addr_space PathState *state,
  20. float *stack,
  21. uint type,
  22. uint out_offset,
  23. int path_flag)
  24. {
  25. float info = 0.0f;
  26. switch (type) {
  27. case NODE_LP_camera:
  28. info = (path_flag & PATH_RAY_CAMERA) ? 1.0f : 0.0f;
  29. break;
  30. case NODE_LP_shadow:
  31. info = (path_flag & PATH_RAY_SHADOW) ? 1.0f : 0.0f;
  32. break;
  33. case NODE_LP_diffuse:
  34. info = (path_flag & PATH_RAY_DIFFUSE) ? 1.0f : 0.0f;
  35. break;
  36. case NODE_LP_glossy:
  37. info = (path_flag & PATH_RAY_GLOSSY) ? 1.0f : 0.0f;
  38. break;
  39. case NODE_LP_singular:
  40. info = (path_flag & PATH_RAY_SINGULAR) ? 1.0f : 0.0f;
  41. break;
  42. case NODE_LP_reflection:
  43. info = (path_flag & PATH_RAY_REFLECT) ? 1.0f : 0.0f;
  44. break;
  45. case NODE_LP_transmission:
  46. info = (path_flag & PATH_RAY_TRANSMIT) ? 1.0f : 0.0f;
  47. break;
  48. case NODE_LP_volume_scatter:
  49. info = (path_flag & PATH_RAY_VOLUME_SCATTER) ? 1.0f : 0.0f;
  50. break;
  51. case NODE_LP_backfacing:
  52. info = (sd->flag & SD_BACKFACING) ? 1.0f : 0.0f;
  53. break;
  54. case NODE_LP_ray_length:
  55. info = sd->ray_length;
  56. break;
  57. case NODE_LP_ray_depth:
  58. info = (float)state->bounce;
  59. break;
  60. case NODE_LP_ray_diffuse:
  61. info = (float)state->diffuse_bounce;
  62. break;
  63. case NODE_LP_ray_glossy:
  64. info = (float)state->glossy_bounce;
  65. break;
  66. case NODE_LP_ray_transparent:
  67. info = (float)state->transparent_bounce;
  68. break;
  69. case NODE_LP_ray_transmission:
  70. info = (float)state->transmission_bounce;
  71. break;
  72. }
  73. stack_store_float(stack, out_offset, info);
  74. }
  75. /* Light Falloff Node */
  76. ccl_device void svm_node_light_falloff(ShaderData *sd, float *stack, uint4 node)
  77. {
  78. uint strength_offset, out_offset, smooth_offset;
  79. decode_node_uchar4(node.z, &strength_offset, &smooth_offset, &out_offset, NULL);
  80. float strength = stack_load_float(stack, strength_offset);
  81. uint type = node.y;
  82. switch (type) {
  83. case NODE_LIGHT_FALLOFF_QUADRATIC:
  84. break;
  85. case NODE_LIGHT_FALLOFF_LINEAR:
  86. strength *= sd->ray_length;
  87. break;
  88. case NODE_LIGHT_FALLOFF_CONSTANT:
  89. strength *= sd->ray_length * sd->ray_length;
  90. break;
  91. }
  92. float smooth = stack_load_float(stack, smooth_offset);
  93. if (smooth > 0.0f) {
  94. float squared = sd->ray_length * sd->ray_length;
  95. /* Distant lamps set the ray length to FLT_MAX, which causes squared to overflow. */
  96. if (isfinite(squared)) {
  97. strength *= squared / (smooth + squared);
  98. }
  99. }
  100. stack_store_float(stack, out_offset, strength);
  101. }
  102. CCL_NAMESPACE_END