PageRenderTime 32ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 123 lines | 105 code | 18 blank | 0 comment | 0 complexity | edf52213de06b70bcb58d8dadf84cad6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file pointLightF.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. #extension GL_ARB_texture_rectangle : enable
  26. #ifdef DEFINE_GL_FRAGCOLOR
  27. out vec4 gl_FragColor;
  28. #endif
  29. uniform sampler2DRect diffuseRect;
  30. uniform sampler2DRect specularRect;
  31. uniform sampler2DRect normalMap;
  32. uniform samplerCube environmentMap;
  33. uniform sampler2D noiseMap;
  34. uniform sampler2D lightFunc;
  35. uniform sampler2DRect depthMap;
  36. uniform vec3 env_mat[3];
  37. uniform float sun_wash;
  38. uniform vec3 center;
  39. uniform vec3 color;
  40. uniform float falloff;
  41. uniform float size;
  42. VARYING vec4 vary_fragcoord;
  43. uniform vec2 screen_res;
  44. uniform mat4 inv_proj;
  45. uniform vec4 viewport;
  46. vec4 getPosition(vec2 pos_screen)
  47. {
  48. float depth = texture2DRect(depthMap, pos_screen.xy).r;
  49. vec2 sc = (pos_screen.xy-viewport.xy)*2.0;
  50. sc /= viewport.zw;
  51. sc -= vec2(1.0,1.0);
  52. vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
  53. vec4 pos = inv_proj * ndc;
  54. pos /= pos.w;
  55. pos.w = 1.0;
  56. return pos;
  57. }
  58. void main()
  59. {
  60. vec4 frag = vary_fragcoord;
  61. frag.xyz /= frag.w;
  62. frag.xyz = frag.xyz*0.5+0.5;
  63. frag.xy *= screen_res;
  64. vec3 pos = getPosition(frag.xy).xyz;
  65. vec3 lv = center.xyz-pos;
  66. float dist2 = dot(lv,lv);
  67. dist2 /= size;
  68. if (dist2 > 1.0)
  69. {
  70. discard;
  71. }
  72. vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
  73. norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
  74. float da = dot(norm, lv);
  75. if (da < 0.0)
  76. {
  77. discard;
  78. }
  79. norm = normalize(norm);
  80. lv = normalize(lv);
  81. da = dot(norm, lv);
  82. float noise = texture2D(noiseMap, frag.xy/128.0).b;
  83. vec3 col = texture2DRect(diffuseRect, frag.xy).rgb;
  84. float fa = falloff+1.0;
  85. float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
  86. float lit = da * dist_atten * noise;
  87. col = color.rgb*lit*col;
  88. vec4 spec = texture2DRect(specularRect, frag.xy);
  89. if (spec.a > 0.0)
  90. {
  91. float sa = dot(normalize(lv-normalize(pos)),norm);
  92. if (sa > 0.0)
  93. {
  94. sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0);
  95. sa *= noise;
  96. col += da*sa*color.rgb*spec.rgb;
  97. }
  98. }
  99. if (dot(col, col) <= 0.0)
  100. {
  101. discard;
  102. }
  103. gl_FragColor.rgb = col;
  104. gl_FragColor.a = 0.0;
  105. }