node_noise_texture.osl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /* Noise */
  19. float noise(point ip, float distortion, float detail, output color Color)
  20. {
  21. point r;
  22. point p = ip;
  23. int hard = 0;
  24. if (distortion != 0.0) {
  25. r[0] = safe_noise(p + point(13.5), "unsigned") * distortion;
  26. r[1] = safe_noise(p, "unsigned") * distortion;
  27. r[2] = safe_noise(p - point(13.5), "unsigned") * distortion;
  28. p += r;
  29. }
  30. float fac = noise_turbulence(p, detail, hard);
  31. Color = color(fac,
  32. noise_turbulence(point(p[1], p[0], p[2]), detail, hard),
  33. noise_turbulence(point(p[1], p[2], p[0]), detail, hard));
  34. return fac;
  35. }
  36. shader node_noise_texture(int use_mapping = 0,
  37. matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
  38. float Distortion = 0.0,
  39. float Scale = 5.0,
  40. float Detail = 2.0,
  41. point Vector = P,
  42. output float Fac = 0.0,
  43. output color Color = 0.0)
  44. {
  45. point p = Vector;
  46. if (use_mapping)
  47. p = transform(mapping, p);
  48. Fac = noise(p * Scale, Distortion, Detail, Color);
  49. }