svm_convert.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /* Conversion Nodes */
  18. ccl_device void svm_node_convert(
  19. KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint from, uint to)
  20. {
  21. switch (type) {
  22. case NODE_CONVERT_FI: {
  23. float f = stack_load_float(stack, from);
  24. stack_store_int(stack, to, float_to_int(f));
  25. break;
  26. }
  27. case NODE_CONVERT_FV: {
  28. float f = stack_load_float(stack, from);
  29. stack_store_float3(stack, to, make_float3(f, f, f));
  30. break;
  31. }
  32. case NODE_CONVERT_CF: {
  33. float3 f = stack_load_float3(stack, from);
  34. float g = linear_rgb_to_gray(kg, f);
  35. stack_store_float(stack, to, g);
  36. break;
  37. }
  38. case NODE_CONVERT_CI: {
  39. float3 f = stack_load_float3(stack, from);
  40. int i = (int)linear_rgb_to_gray(kg, f);
  41. stack_store_int(stack, to, i);
  42. break;
  43. }
  44. case NODE_CONVERT_VF: {
  45. float3 f = stack_load_float3(stack, from);
  46. float g = average(f);
  47. stack_store_float(stack, to, g);
  48. break;
  49. }
  50. case NODE_CONVERT_VI: {
  51. float3 f = stack_load_float3(stack, from);
  52. int i = (int)average(f);
  53. stack_store_int(stack, to, i);
  54. break;
  55. }
  56. case NODE_CONVERT_IF: {
  57. float f = (float)stack_load_int(stack, from);
  58. stack_store_float(stack, to, f);
  59. break;
  60. }
  61. case NODE_CONVERT_IV: {
  62. float f = (float)stack_load_int(stack, from);
  63. stack_store_float3(stack, to, make_float3(f, f, f));
  64. break;
  65. }
  66. }
  67. }
  68. CCL_NAMESPACE_END