/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl

https://bitbucket.org/lindenlab/viewer-beta/ · GLSL · 130 lines · 80 code · 26 blank · 24 comment · 6 complexity · 79e60a3cdb4fe71ba962f71b94500244 MD5 · raw file

  1. /**
  2. * @file alphaF.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. VARYING vec4 vertex_color;
  30. VARYING vec2 vary_texcoord0;
  31. uniform sampler2DRectShadow shadowMap0;
  32. uniform sampler2DRectShadow shadowMap1;
  33. uniform sampler2DRectShadow shadowMap2;
  34. uniform sampler2DRectShadow shadowMap3;
  35. uniform sampler2DRect depthMap;
  36. uniform mat4 shadow_matrix[6];
  37. uniform vec4 shadow_clip;
  38. uniform vec2 screen_res;
  39. uniform vec2 shadow_res;
  40. vec3 atmosLighting(vec3 light);
  41. vec3 scaleSoftClip(vec3 light);
  42. VARYING vec3 vary_ambient;
  43. VARYING vec3 vary_directional;
  44. VARYING vec3 vary_fragcoord;
  45. VARYING vec3 vary_position;
  46. VARYING vec3 vary_pointlight_col;
  47. uniform float shadow_bias;
  48. uniform mat4 inv_proj;
  49. float pcfShadow(sampler2DRectShadow shadowMap, vec4 stc, float scl)
  50. {
  51. stc.xyz /= stc.w;
  52. stc.z += shadow_bias;
  53. float cs = shadow2DRect(shadowMap, stc.xyz).x;
  54. float shadow = cs;
  55. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, scl, 0.0)).x, cs);
  56. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, -scl, 0.0)).x, cs);
  57. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, scl, 0.0)).x, cs);
  58. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, -scl, 0.0)).x, cs);
  59. return shadow/5.0;
  60. }
  61. void main()
  62. {
  63. vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
  64. frag *= screen_res;
  65. float shadow = 1.0;
  66. vec4 pos = vec4(vary_position, 1.0);
  67. vec4 spos = pos;
  68. if (spos.z > -shadow_clip.w)
  69. {
  70. vec4 lpos;
  71. if (spos.z < -shadow_clip.z)
  72. {
  73. lpos = shadow_matrix[3]*spos;
  74. lpos.xy *= shadow_res;
  75. shadow = pcfShadow(shadowMap3, lpos, 1.5);
  76. shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
  77. }
  78. else if (spos.z < -shadow_clip.y)
  79. {
  80. lpos = shadow_matrix[2]*spos;
  81. lpos.xy *= shadow_res;
  82. shadow = pcfShadow(shadowMap2, lpos, 1.5);
  83. }
  84. else if (spos.z < -shadow_clip.x)
  85. {
  86. lpos = shadow_matrix[1]*spos;
  87. lpos.xy *= shadow_res;
  88. shadow = pcfShadow(shadowMap1, lpos, 1.5);
  89. }
  90. else
  91. {
  92. lpos = shadow_matrix[0]*spos;
  93. lpos.xy *= shadow_res;
  94. shadow = pcfShadow(shadowMap0, lpos, 1.5);
  95. }
  96. }
  97. vec4 diff = diffuseLookup(vary_texcoord0.xy);
  98. vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, vertex_color.a);
  99. vec4 color = diff * col;
  100. color.rgb = atmosLighting(color.rgb);
  101. color.rgb = scaleSoftClip(color.rgb);
  102. color.rgb += diff.rgb * vary_pointlight_col.rgb;
  103. gl_FragColor = color;
  104. }