node_magic_texture.osl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include "stdosl.h"
  17. #include "node_texture.h"
  18. /* Magic */
  19. color magic(point p, int n, float distortion)
  20. {
  21. float dist = distortion;
  22. float x = sin((p[0] + p[1] + p[2]) * 5.0);
  23. float y = cos((-p[0] + p[1] - p[2]) * 5.0);
  24. float z = -cos((-p[0] - p[1] + p[2]) * 5.0);
  25. if (n > 0) {
  26. x *= dist;
  27. y *= dist;
  28. z *= dist;
  29. y = -cos(x - y + z);
  30. y *= dist;
  31. if (n > 1) {
  32. x = cos(x - y - z);
  33. x *= dist;
  34. if (n > 2) {
  35. z = sin(-x - y - z);
  36. z *= dist;
  37. if (n > 3) {
  38. x = -cos(-x + y - z);
  39. x *= dist;
  40. if (n > 4) {
  41. y = -sin(-x + y + z);
  42. y *= dist;
  43. if (n > 5) {
  44. y = -cos(-x + y + z);
  45. y *= dist;
  46. if (n > 6) {
  47. x = cos(x + y + z);
  48. x *= dist;
  49. if (n > 7) {
  50. z = sin(x + y - z);
  51. z *= dist;
  52. if (n > 8) {
  53. x = -cos(-x - y + z);
  54. x *= dist;
  55. if (n > 9) {
  56. y = -sin(x - y + z);
  57. y *= dist;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. if (dist != 0.0) {
  69. dist *= 2.0;
  70. x /= dist;
  71. y /= dist;
  72. z /= dist;
  73. }
  74. return color(0.5 - x, 0.5 - y, 0.5 - z);
  75. }
  76. shader node_magic_texture(int use_mapping = 0,
  77. matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
  78. int depth = 2,
  79. float Distortion = 5.0,
  80. float Scale = 5.0,
  81. point Vector = P,
  82. output float Fac = 0.0,
  83. output color Color = 0.0)
  84. {
  85. point p = Vector;
  86. if (use_mapping)
  87. p = transform(mapping, p);
  88. Color = magic(p * Scale, depth, Distortion);
  89. Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0);
  90. }