PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

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