PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 66 lines | 52 code | 14 blank | 0 comment | 0 complexity | 18c2b4889cf53c450e050bd2b8a87f1f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lightFuncSpecularV.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 calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)
  31. {
  32. return pow(max(dot(reflect(view, n),l), 0.0),8.0);
  33. }
  34. float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da)
  35. {
  36. specular.rgb += calcDirectionalSpecular(view,n,l)*lightCol*da;
  37. return max(dot(n,l),0.0);
  38. }
  39. vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol)
  40. {
  41. //get light vector
  42. vec3 lv = l-v;
  43. //get distance
  44. float d = length(lv);
  45. //normalize light vector
  46. lv *= 1.0/d;
  47. //distance attenuation
  48. float da = clamp(1.0/(r * d), 0.0, 1.0);
  49. //angular attenuation
  50. da *= calcDirectionalLightSpecular(specular, view, n, lv, lightCol, da);
  51. return da*lightCol;
  52. }