PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
text | 92 lines | 72 code | 20 blank | 0 comment | 0 complexity | d45e21c51fbedecf54a88f3dfdbfb321 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file edgeF.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. #extension GL_ARB_texture_multisample : enable
  27. uniform sampler2DMS depthMap;
  28. uniform sampler2DMS normalMap;
  29. varying vec2 vary_fragcoord;
  30. uniform float depth_cutoff;
  31. uniform float norm_cutoff;
  32. uniform mat4 inv_proj;
  33. uniform vec2 screen_res;
  34. float getDepth(ivec2 pos_screen, int sample)
  35. {
  36. float z = texelFetch(depthMap, pos_screen, sample).r;
  37. z = z*2.0-1.0;
  38. vec4 ndc = vec4(0.0, 0.0, z, 1.0);
  39. vec4 p = inv_proj*ndc;
  40. return p.z/p.w;
  41. }
  42. void main()
  43. {
  44. float e = 0;
  45. ivec2 itc = ivec2(vary_fragcoord.xy);
  46. for (int i = 0; i < samples; i++)
  47. {
  48. vec3 norm = texelFetch(normalMap, itc, i).xyz;
  49. norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
  50. float depth = getDepth(itc, i);
  51. vec2 tc = vary_fragcoord.xy;
  52. int sc = 1;
  53. vec2 de;
  54. de.x = (depth-getDepth(itc+ivec2(sc, sc),i)) + (depth-getDepth(itc+ivec2(-sc, -sc), i));
  55. de.y = (depth-getDepth(itc+ivec2(-sc, sc),i)) + (depth-getDepth(itc+ivec2(sc, -sc), i));
  56. de /= depth;
  57. de *= de;
  58. de = step(depth_cutoff, de);
  59. vec2 ne;
  60. vec3 nexnorm = texelFetch(normalMap, itc+ivec2(-sc,-sc), i).rgb;
  61. nexnorm = vec3((nexnorm.xy-0.5)*2.0,nexnorm.z); // unpack norm
  62. ne.x = dot(nexnorm, norm);
  63. vec3 neynorm = texelFetch(normalMap, itc+ivec2(sc,sc), i).rgb;
  64. neynorm = vec3((neynorm.xy-0.5)*2.0,neynorm.z); // unpack norm
  65. ne.y = dot(neynorm, norm);
  66. ne = 1.0-ne;
  67. ne = step(norm_cutoff, ne);
  68. e += dot(de,de)+dot(ne,ne);
  69. }
  70. e /= samples;
  71. gl_FragColor.a = e;
  72. }