node_anisotropic_bsdf.osl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_anisotropic_bsdf(color Color = 0.0,
  18. string distribution = "GGX",
  19. float Roughness = 0.0,
  20. float Anisotropy = 0.0,
  21. float Rotation = 0.0,
  22. normal Normal = N,
  23. normal Tangent = normalize(dPdu),
  24. output closure color BSDF = 0)
  25. {
  26. /* rotate tangent around normal */
  27. vector T = Tangent;
  28. if (Rotation != 0.0)
  29. T = rotate(T, Rotation * M_2PI, point(0.0, 0.0, 0.0), Normal);
  30. /* compute roughness */
  31. float roughness = Roughness * Roughness;
  32. float roughness_u, roughness_v;
  33. float aniso = clamp(Anisotropy, -0.99, 0.99);
  34. if (aniso < 0.0) {
  35. roughness_u = roughness / (1.0 + aniso);
  36. roughness_v = roughness * (1.0 + aniso);
  37. }
  38. else {
  39. roughness_u = roughness * (1.0 - aniso);
  40. roughness_v = roughness / (1.0 - aniso);
  41. }
  42. if (distribution == "sharp")
  43. BSDF = Color * reflection(Normal);
  44. else if (distribution == "beckmann")
  45. BSDF = Color * microfacet_beckmann_aniso(Normal, T, roughness_u, roughness_v);
  46. else if (distribution == "GGX")
  47. BSDF = Color * microfacet_ggx_aniso(Normal, T, roughness_u, roughness_v);
  48. else if (distribution == "Multiscatter GGX")
  49. BSDF = Color * microfacet_multi_ggx_aniso(Normal, T, roughness_u, roughness_v, Color);
  50. else
  51. BSDF = Color * ashikhmin_shirley(Normal, T, roughness_u, roughness_v);
  52. }