/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl

https://bitbucket.org/lindenlab/viewer-beta/ · GLSL · 59 lines · 16 code · 13 blank · 30 comment · 0 complexity · c65d51acf5b9beb0f310f298ab74d6a2 MD5 · raw file

  1. /**
  2. * @file lightFuncV.glsl
  3. *
  4. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2007, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. float calcDirectionalLight(vec3 n, vec3 l)
  26. {
  27. float a = max(dot(n,l),0.0);
  28. return a;
  29. }
  30. float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight)
  31. {
  32. //get light vector
  33. vec3 lv = lp.xyz-v;
  34. //get distance
  35. float d = length(lv);
  36. //normalize light vector
  37. lv *= 1.0/d;
  38. //distance attenuation
  39. float da = clamp(1.0/(la * d), 0.0, 1.0);
  40. // spotlight coefficient.
  41. float spot = max(dot(-ln, lv), is_pointlight);
  42. da *= spot*spot; // GL_SPOT_EXPONENT=2
  43. //angular attenuation
  44. da *= calcDirectionalLight(n, lv);
  45. return da;
  46. }