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

https://bitbucket.org/lindenlab/viewer-beta/ · GLSL · 143 lines · 93 code · 26 blank · 24 comment · 6 complexity · 9f23262ec1f7b1633cdc3efd16d6e22f 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. uniform sampler2DRectShadow shadowMap0;
  30. uniform sampler2DRectShadow shadowMap1;
  31. uniform sampler2DRectShadow shadowMap2;
  32. uniform sampler2DRectShadow shadowMap3;
  33. uniform sampler2DRect depthMap;
  34. uniform sampler2D diffuseMap;
  35. uniform mat4 shadow_matrix[6];
  36. uniform vec4 shadow_clip;
  37. uniform vec2 screen_res;
  38. uniform vec2 shadow_res;
  39. vec3 atmosLighting(vec3 light);
  40. vec3 scaleSoftClip(vec3 light);
  41. VARYING vec3 vary_ambient;
  42. VARYING vec3 vary_directional;
  43. VARYING vec3 vary_fragcoord;
  44. VARYING vec3 vary_position;
  45. VARYING vec3 vary_pointlight_col;
  46. VARYING vec2 vary_texcoord0;
  47. VARYING vec4 vertex_color;
  48. uniform float shadow_bias;
  49. uniform mat4 inv_proj;
  50. vec4 getPosition(vec2 pos_screen)
  51. {
  52. float depth = texture2DRect(depthMap, pos_screen.xy).a;
  53. vec2 sc = pos_screen.xy*2.0;
  54. sc /= screen_res;
  55. sc -= vec2(1.0,1.0);
  56. vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
  57. vec4 pos = inv_proj * ndc;
  58. pos.xyz /= pos.w;
  59. pos.w = 1.0;
  60. return pos;
  61. }
  62. float pcfShadow(sampler2DRectShadow shadowMap, vec4 stc, float scl)
  63. {
  64. stc.xyz /= stc.w;
  65. stc.z += shadow_bias;
  66. float cs = shadow2DRect(shadowMap, stc.xyz).x;
  67. float shadow = cs;
  68. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, scl, 0.0)).x, cs);
  69. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, -scl, 0.0)).x, cs);
  70. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, scl, 0.0)).x, cs);
  71. shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, -scl, 0.0)).x, cs);
  72. return shadow/5.0;
  73. }
  74. void main()
  75. {
  76. vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
  77. frag *= screen_res;
  78. float shadow = 1.0;
  79. vec4 pos = vec4(vary_position, 1.0);
  80. vec4 spos = pos;
  81. if (spos.z > -shadow_clip.w)
  82. {
  83. vec4 lpos;
  84. if (spos.z < -shadow_clip.z)
  85. {
  86. lpos = shadow_matrix[3]*spos;
  87. lpos.xy *= shadow_res;
  88. shadow = pcfShadow(shadowMap3, lpos, 1.5);
  89. shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
  90. }
  91. else if (spos.z < -shadow_clip.y)
  92. {
  93. lpos = shadow_matrix[2]*spos;
  94. lpos.xy *= shadow_res;
  95. shadow = pcfShadow(shadowMap2, lpos, 1.5);
  96. }
  97. else if (spos.z < -shadow_clip.x)
  98. {
  99. lpos = shadow_matrix[1]*spos;
  100. lpos.xy *= shadow_res;
  101. shadow = pcfShadow(shadowMap1, lpos, 1.5);
  102. }
  103. else
  104. {
  105. lpos = shadow_matrix[0]*spos;
  106. lpos.xy *= shadow_res;
  107. shadow = pcfShadow(shadowMap0, lpos, 1.5);
  108. }
  109. }
  110. vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy);
  111. vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, vertex_color.a);
  112. vec4 color = diff * col;
  113. color.rgb = atmosLighting(color.rgb);
  114. color.rgb = scaleSoftClip(color.rgb);
  115. color.rgb += diff.rgb * vary_pointlight_col.rgb;
  116. gl_FragColor = color;
  117. }