PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
text | 81 lines | 65 code | 16 blank | 0 comment | 0 complexity | 5be00fc32e1233e07ff02535e80a8b23 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. uniform sampler2DRect depthMap;
  27. uniform sampler2DRect normalMap;
  28. varying vec2 vary_fragcoord;
  29. uniform float depth_cutoff;
  30. uniform float norm_cutoff;
  31. uniform mat4 inv_proj;
  32. uniform vec2 screen_res;
  33. float getDepth(vec2 pos_screen)
  34. {
  35. float z = texture2DRect(depthMap, pos_screen.xy).r;
  36. z = z*2.0-1.0;
  37. vec4 ndc = vec4(0.0, 0.0, z, 1.0);
  38. vec4 p = inv_proj*ndc;
  39. return p.z/p.w;
  40. }
  41. void main()
  42. {
  43. vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
  44. norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
  45. float depth = getDepth(vary_fragcoord.xy);
  46. vec2 tc = vary_fragcoord.xy;
  47. float sc = 0.75;
  48. vec2 de;
  49. de.x = (depth-getDepth(tc+vec2(sc, sc))) + (depth-getDepth(tc+vec2(-sc, -sc)));
  50. de.y = (depth-getDepth(tc+vec2(-sc, sc))) + (depth-getDepth(tc+vec2(sc, -sc)));
  51. de /= depth;
  52. de *= de;
  53. de = step(depth_cutoff, de);
  54. vec2 ne;
  55. vec3 nexnorm = texture2DRect(normalMap, tc+vec2(-sc,-sc)).rgb;
  56. nexnorm = vec3((nexnorm.xy-0.5)*2.0,nexnorm.z); // unpack norm
  57. ne.x = dot(nexnorm, norm);
  58. vec3 neynorm = texture2DRect(normalMap, tc+vec2(sc,sc)).rgb;
  59. neynorm = vec3((neynorm.xy-0.5)*2.0,neynorm.z); // unpack norm
  60. ne.y = dot(neynorm, norm);
  61. ne = 1.0-ne;
  62. ne = step(norm_cutoff, ne);
  63. gl_FragColor.a = dot(de,de)+dot(ne,ne);
  64. //gl_FragColor.a = dot(de,de);
  65. }