node_wave_texture.osl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /* Wave */
  19. float wave(point p, string type, string profile, float detail, float distortion, float dscale)
  20. {
  21. float n = 0.0;
  22. if (type == "bands") {
  23. n = (p[0] + p[1] + p[2]) * 10.0;
  24. }
  25. else if (type == "rings") {
  26. n = length(p) * 20.0;
  27. }
  28. if (distortion != 0.0) {
  29. n = n + (distortion * noise_turbulence(p * dscale, detail, 0));
  30. }
  31. if (profile == "sine") {
  32. return 0.5 + 0.5 * sin(n);
  33. }
  34. else {
  35. /* Saw profile */
  36. n /= M_2PI;
  37. n -= (int)n;
  38. return (n < 0.0) ? n + 1.0 : n;
  39. }
  40. }
  41. shader node_wave_texture(int use_mapping = 0,
  42. matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
  43. string type = "bands",
  44. string profile = "sine",
  45. float Scale = 5.0,
  46. float Distortion = 0.0,
  47. float Detail = 2.0,
  48. float DetailScale = 1.0,
  49. point Vector = P,
  50. output float Fac = 0.0,
  51. output color Color = 0.0)
  52. {
  53. point p = Vector;
  54. if (use_mapping)
  55. p = transform(mapping, p);
  56. Fac = wave(p * Scale, type, profile, Detail, Distortion, DetailScale);
  57. Color = Fac;
  58. }