node_voxel_texture.osl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2011-2015 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. shader node_voxel_texture(string filename = "",
  18. string interpolation = "linear",
  19. int use_mapping = 0,
  20. matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
  21. point Vector = P,
  22. output float Density = 0,
  23. output color Color = 0)
  24. {
  25. point p = Vector;
  26. if (use_mapping) {
  27. p = transform(mapping, p);
  28. }
  29. else {
  30. p = transform("object", Vector);
  31. matrix tfm;
  32. if (getattribute("geom:generated_transform", tfm))
  33. p = transform(tfm, p);
  34. }
  35. if (p[0] < 0.0 || p[1] < 0.0 || p[2] < 0.0 || p[0] > 1.0 || p[1] > 1.0 || p[2] > 1.0) {
  36. Density = 0;
  37. Color = color(0, 0, 0);
  38. }
  39. else {
  40. Color = (color)texture3d(
  41. filename, p, "wrap", "periodic", "interp", interpolation, "alpha", Density);
  42. }
  43. }