svm_geometry.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. /* Geometry Node */
  18. ccl_device_inline void svm_node_geometry(
  19. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  20. {
  21. float3 data;
  22. switch (type) {
  23. case NODE_GEOM_P:
  24. data = sd->P;
  25. break;
  26. case NODE_GEOM_N:
  27. data = sd->N;
  28. break;
  29. #ifdef __DPDU__
  30. case NODE_GEOM_T:
  31. data = primitive_tangent(kg, sd);
  32. break;
  33. #endif
  34. case NODE_GEOM_I:
  35. data = sd->I;
  36. break;
  37. case NODE_GEOM_Ng:
  38. data = sd->Ng;
  39. break;
  40. #ifdef __UV__
  41. case NODE_GEOM_uv:
  42. data = make_float3(sd->u, sd->v, 0.0f);
  43. break;
  44. #endif
  45. default:
  46. data = make_float3(0.0f, 0.0f, 0.0f);
  47. }
  48. stack_store_float3(stack, out_offset, data);
  49. }
  50. ccl_device void svm_node_geometry_bump_dx(
  51. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  52. {
  53. #ifdef __RAY_DIFFERENTIALS__
  54. float3 data;
  55. switch (type) {
  56. case NODE_GEOM_P:
  57. data = sd->P + sd->dP.dx;
  58. break;
  59. case NODE_GEOM_uv:
  60. data = make_float3(sd->u + sd->du.dx, sd->v + sd->dv.dx, 0.0f);
  61. break;
  62. default:
  63. svm_node_geometry(kg, sd, stack, type, out_offset);
  64. return;
  65. }
  66. stack_store_float3(stack, out_offset, data);
  67. #else
  68. svm_node_geometry(kg, sd, stack, type, out_offset);
  69. #endif
  70. }
  71. ccl_device void svm_node_geometry_bump_dy(
  72. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  73. {
  74. #ifdef __RAY_DIFFERENTIALS__
  75. float3 data;
  76. switch (type) {
  77. case NODE_GEOM_P:
  78. data = sd->P + sd->dP.dy;
  79. break;
  80. case NODE_GEOM_uv:
  81. data = make_float3(sd->u + sd->du.dy, sd->v + sd->dv.dy, 0.0f);
  82. break;
  83. default:
  84. svm_node_geometry(kg, sd, stack, type, out_offset);
  85. return;
  86. }
  87. stack_store_float3(stack, out_offset, data);
  88. #else
  89. svm_node_geometry(kg, sd, stack, type, out_offset);
  90. #endif
  91. }
  92. /* Object Info */
  93. ccl_device void svm_node_object_info(
  94. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  95. {
  96. float data;
  97. switch (type) {
  98. case NODE_INFO_OB_LOCATION: {
  99. stack_store_float3(stack, out_offset, object_location(kg, sd));
  100. return;
  101. }
  102. case NODE_INFO_OB_INDEX:
  103. data = object_pass_id(kg, sd->object);
  104. break;
  105. case NODE_INFO_MAT_INDEX:
  106. data = shader_pass_id(kg, sd);
  107. break;
  108. case NODE_INFO_OB_RANDOM: {
  109. if (sd->lamp != LAMP_NONE) {
  110. data = lamp_random_number(kg, sd->lamp);
  111. }
  112. else {
  113. data = object_random_number(kg, sd->object);
  114. }
  115. break;
  116. }
  117. default:
  118. data = 0.0f;
  119. break;
  120. }
  121. stack_store_float(stack, out_offset, data);
  122. }
  123. /* Particle Info */
  124. ccl_device void svm_node_particle_info(
  125. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  126. {
  127. switch (type) {
  128. case NODE_INFO_PAR_INDEX: {
  129. int particle_id = object_particle_id(kg, sd->object);
  130. stack_store_float(stack, out_offset, particle_index(kg, particle_id));
  131. break;
  132. }
  133. case NODE_INFO_PAR_RANDOM: {
  134. int particle_id = object_particle_id(kg, sd->object);
  135. float random = hash_int_01(particle_index(kg, particle_id));
  136. stack_store_float(stack, out_offset, random);
  137. break;
  138. }
  139. case NODE_INFO_PAR_AGE: {
  140. int particle_id = object_particle_id(kg, sd->object);
  141. stack_store_float(stack, out_offset, particle_age(kg, particle_id));
  142. break;
  143. }
  144. case NODE_INFO_PAR_LIFETIME: {
  145. int particle_id = object_particle_id(kg, sd->object);
  146. stack_store_float(stack, out_offset, particle_lifetime(kg, particle_id));
  147. break;
  148. }
  149. case NODE_INFO_PAR_LOCATION: {
  150. int particle_id = object_particle_id(kg, sd->object);
  151. stack_store_float3(stack, out_offset, particle_location(kg, particle_id));
  152. break;
  153. }
  154. #if 0 /* XXX float4 currently not supported in SVM stack */
  155. case NODE_INFO_PAR_ROTATION: {
  156. int particle_id = object_particle_id(kg, sd->object);
  157. stack_store_float4(stack, out_offset, particle_rotation(kg, particle_id));
  158. break;
  159. }
  160. #endif
  161. case NODE_INFO_PAR_SIZE: {
  162. int particle_id = object_particle_id(kg, sd->object);
  163. stack_store_float(stack, out_offset, particle_size(kg, particle_id));
  164. break;
  165. }
  166. case NODE_INFO_PAR_VELOCITY: {
  167. int particle_id = object_particle_id(kg, sd->object);
  168. stack_store_float3(stack, out_offset, particle_velocity(kg, particle_id));
  169. break;
  170. }
  171. case NODE_INFO_PAR_ANGULAR_VELOCITY: {
  172. int particle_id = object_particle_id(kg, sd->object);
  173. stack_store_float3(stack, out_offset, particle_angular_velocity(kg, particle_id));
  174. break;
  175. }
  176. }
  177. }
  178. #ifdef __HAIR__
  179. /* Hair Info */
  180. ccl_device void svm_node_hair_info(
  181. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
  182. {
  183. float data;
  184. float3 data3;
  185. switch (type) {
  186. case NODE_INFO_CURVE_IS_STRAND: {
  187. data = (sd->type & PRIMITIVE_ALL_CURVE) != 0;
  188. stack_store_float(stack, out_offset, data);
  189. break;
  190. }
  191. case NODE_INFO_CURVE_INTERCEPT:
  192. break; /* handled as attribute */
  193. case NODE_INFO_CURVE_RANDOM:
  194. break; /* handled as attribute */
  195. case NODE_INFO_CURVE_THICKNESS: {
  196. data = curve_thickness(kg, sd);
  197. stack_store_float(stack, out_offset, data);
  198. break;
  199. }
  200. /*case NODE_INFO_CURVE_FADE: {
  201. data = sd->curve_transparency;
  202. stack_store_float(stack, out_offset, data);
  203. break;
  204. }*/
  205. case NODE_INFO_CURVE_TANGENT_NORMAL: {
  206. data3 = curve_tangent_normal(kg, sd);
  207. stack_store_float3(stack, out_offset, data3);
  208. break;
  209. }
  210. }
  211. }
  212. #endif
  213. CCL_NAMESPACE_END