node_tangent.osl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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_tangent(normal NormalIn = N,
  18. string attr_name = "geom:tangent",
  19. string direction_type = "radial",
  20. string axis = "z",
  21. output normal Tangent = normalize(dPdu))
  22. {
  23. vector T;
  24. if (direction_type == "uv_map") {
  25. getattribute(attr_name, T);
  26. }
  27. else if (direction_type == "radial") {
  28. point generated;
  29. if (!getattribute("geom:generated", generated))
  30. generated = P;
  31. if (axis == "x")
  32. T = vector(0.0, -(generated[2] - 0.5), (generated[1] - 0.5));
  33. else if (axis == "y")
  34. T = vector(-(generated[2] - 0.5), 0.0, (generated[0] - 0.5));
  35. else
  36. T = vector(-(generated[1] - 0.5), (generated[0] - 0.5), 0.0);
  37. }
  38. T = transform("object", "world", T);
  39. Tangent = cross(NormalIn, normalize(cross(T, NormalIn)));
  40. }