PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class3/deferred/giDownsampleF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
text | 106 lines | 88 code | 18 blank | 0 comment | 0 complexity | 8eb355a1f330345649ec4213c7b73c7b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file giDownsampleF.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. uniform sampler2DRect giLightMap;
  26. uniform vec2 kern[32];
  27. uniform float dist_factor;
  28. uniform float blur_size;
  29. uniform vec2 delta;
  30. uniform int kern_length;
  31. uniform float kern_scale;
  32. uniform vec3 blur_quad;
  33. varying vec2 vary_fragcoord;
  34. uniform mat4 inv_proj;
  35. uniform vec2 screen_res;
  36. vec4 getPosition(vec2 pos_screen)
  37. {
  38. float depth = texture2DRect(depthMap, pos_screen.xy).a;
  39. vec2 sc = pos_screen.xy*2.0;
  40. sc /= screen_res;
  41. sc -= vec2(1.0,1.0);
  42. vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
  43. vec4 pos = inv_proj * ndc;
  44. pos /= pos.w;
  45. pos.w = 1.0;
  46. return pos;
  47. }
  48. float getDepth(vec2 pos_screen)
  49. {
  50. float z = texture2DRect(depthMap, pos_screen.xy).a;
  51. z = z*2.0-1.0;
  52. vec4 ndc = vec4(0.0, 0.0, z, 1.0);
  53. vec4 p = inv_proj*ndc;
  54. return p.z/p.w;
  55. }
  56. void main()
  57. {
  58. vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
  59. norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
  60. float depth = getDepth(vary_fragcoord.xy);
  61. vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
  62. vec2 dlt = kern_scale * delta/(vec2(1.0,1.0)+norm.xy*norm.xy);
  63. dlt /= clamp(-depth*blur_quad.x, 1.0, 3.0);
  64. float defined_weight = kern[0].x;
  65. vec3 col = ccol*kern[0].x;
  66. for (int i = 0; i < kern_length; i++)
  67. {
  68. vec2 tc = vary_fragcoord.xy + kern[i].y*dlt;
  69. vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz;
  70. sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm
  71. float d = dot(norm.xyz, sampNorm);
  72. if (d > 0.5)
  73. {
  74. float sampdepth = getDepth(tc.xy);
  75. sampdepth -= depth;
  76. if (sampdepth*sampdepth < blur_quad.z)
  77. {
  78. col += texture2DRect(giLightMap, tc).rgb*kern[i].x;
  79. defined_weight += kern[i].x;
  80. }
  81. }
  82. }
  83. col /= defined_weight;
  84. //col = ccol;
  85. col = col*blur_quad.y;
  86. gl_FragData[0].xyz = col;
  87. //gl_FragColor = ccol;
  88. }