node_checker_texture.osl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /* Checker */
  19. float checker(point ip)
  20. {
  21. point p;
  22. p[0] = (ip[0] + 0.000001) * 0.999999;
  23. p[1] = (ip[1] + 0.000001) * 0.999999;
  24. p[2] = (ip[2] + 0.000001) * 0.999999;
  25. int xi = (int)fabs(floor(p[0]));
  26. int yi = (int)fabs(floor(p[1]));
  27. int zi = (int)fabs(floor(p[2]));
  28. if ((xi % 2 == yi % 2) == (zi % 2)) {
  29. return 1.0;
  30. }
  31. else {
  32. return 0.0;
  33. }
  34. }
  35. shader node_checker_texture(
  36. 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 Scale = 5.0,
  39. point Vector = P,
  40. color Color1 = 0.8,
  41. color Color2 = 0.2,
  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 = checker(p * Scale);
  49. if (Fac == 1.0) {
  50. Color = Color1;
  51. }
  52. else {
  53. Color = Color2;
  54. }
  55. }