node_geometry.osl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. shader node_geometry(normal NormalIn = N,
  18. string bump_offset = "center",
  19. output point Position = point(0.0, 0.0, 0.0),
  20. output normal Normal = normal(0.0, 0.0, 0.0),
  21. output normal Tangent = normal(0.0, 0.0, 0.0),
  22. output normal TrueNormal = normal(0.0, 0.0, 0.0),
  23. output vector Incoming = vector(0.0, 0.0, 0.0),
  24. output point Parametric = point(0.0, 0.0, 0.0),
  25. output float Backfacing = 0.0,
  26. output float Pointiness = 0.0)
  27. {
  28. Position = P;
  29. Normal = NormalIn;
  30. TrueNormal = Ng;
  31. Incoming = I;
  32. Parametric = point(u, v, 0.0);
  33. Backfacing = backfacing();
  34. if (bump_offset == "dx") {
  35. Position += Dx(Position);
  36. Parametric += Dx(Parametric);
  37. }
  38. else if (bump_offset == "dy") {
  39. Position += Dy(Position);
  40. Parametric += Dy(Parametric);
  41. }
  42. /* first try to get tangent attribute */
  43. point generated;
  44. /* try to create spherical tangent from generated coordinates */
  45. if (getattribute("geom:generated", generated)) {
  46. normal data = normal(-(generated[1] - 0.5), (generated[0] - 0.5), 0.0);
  47. vector T = transform("object", "world", data);
  48. Tangent = cross(Normal, normalize(cross(T, Normal)));
  49. }
  50. else {
  51. /* otherwise use surface derivatives */
  52. Tangent = normalize(dPdu);
  53. }
  54. getattribute("geom:pointiness", Pointiness);
  55. if (bump_offset == "dx") {
  56. Pointiness += Dx(Pointiness);
  57. }
  58. else if (bump_offset == "dy") {
  59. Pointiness += Dy(Pointiness);
  60. }
  61. }