node_hair_bsdf.osl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2011, Blender Foundation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include "stdosl.h"
  19. shader node_hair_bsdf(color Color = 0.8,
  20. string component = "reflection",
  21. float Offset = 0.0,
  22. float RoughnessU = 0.1,
  23. float RoughnessV = 1.0,
  24. normal Tangent = normal(0, 0, 0),
  25. output closure color BSDF = 0)
  26. {
  27. float roughnessh = clamp(RoughnessU, 0.001, 1.0);
  28. float roughnessv = clamp(RoughnessV, 0.001, 1.0);
  29. float offset = -Offset;
  30. normal T;
  31. float IsCurve = 0;
  32. getattribute("geom:is_curve", IsCurve);
  33. if (isconnected(Tangent)) {
  34. T = Tangent;
  35. }
  36. else if (!IsCurve) {
  37. T = normalize(dPdv);
  38. offset = 0.0;
  39. }
  40. else {
  41. T = normalize(dPdu);
  42. }
  43. if (backfacing() && IsCurve) {
  44. BSDF = transparent();
  45. }
  46. else {
  47. if (component == "reflection")
  48. BSDF = Color * hair_reflection(Ng, roughnessh, roughnessv, T, offset);
  49. else
  50. BSDF = Color * hair_transmission(Ng, roughnessh, roughnessv, T, offset);
  51. }
  52. }