PageRenderTime 28ms CodeModel.GetById 23ms app.highlight 1ms RepoModel.GetById 2ms 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
 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 
26
27
28#extension GL_ARB_texture_rectangle : enable
29#extension GL_ARB_texture_multisample : enable
30
31uniform sampler2DMS depthMap;
32uniform sampler2DMS normalMap;
33
34varying vec2 vary_fragcoord;
35
36uniform float depth_cutoff;
37uniform float norm_cutoff;
38
39uniform mat4 inv_proj;
40uniform vec2 screen_res;
41
42float getDepth(ivec2 pos_screen, int sample)
43{
44	float z = texelFetch(depthMap, pos_screen, sample).r;
45	z = z*2.0-1.0;
46	vec4 ndc = vec4(0.0, 0.0, z, 1.0);
47	vec4 p = inv_proj*ndc;
48	return p.z/p.w;
49}
50
51void main() 
52{
53	float e = 0;
54	
55	ivec2 itc = ivec2(vary_fragcoord.xy);
56
57	for (int i = 0; i < samples; i++)
58	{	
59		vec3 norm = texelFetch(normalMap, itc, i).xyz;
60		norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
61		float depth = getDepth(itc, i);
62	
63		vec2 tc = vary_fragcoord.xy;
64	
65		int sc = 1;
66	
67		vec2 de;
68		de.x = (depth-getDepth(itc+ivec2(sc, sc),i)) + (depth-getDepth(itc+ivec2(-sc, -sc), i));
69		de.y = (depth-getDepth(itc+ivec2(-sc, sc),i)) + (depth-getDepth(itc+ivec2(sc, -sc), i));
70		de /= depth;
71		de *= de;
72		de = step(depth_cutoff, de);
73	
74		vec2 ne;
75		vec3 nexnorm = texelFetch(normalMap, itc+ivec2(-sc,-sc), i).rgb;
76		nexnorm = vec3((nexnorm.xy-0.5)*2.0,nexnorm.z); // unpack norm
77		ne.x = dot(nexnorm, norm);
78		vec3 neynorm = texelFetch(normalMap, itc+ivec2(sc,sc), i).rgb;
79		neynorm = vec3((neynorm.xy-0.5)*2.0,neynorm.z); // unpack norm
80		ne.y = dot(neynorm, norm);
81	
82		ne = 1.0-ne;
83	
84		ne = step(norm_cutoff, ne);
85
86		e += dot(de,de)+dot(ne,ne);
87	}
88
89	e /= samples;
90	
91	gl_FragColor.a = e;
92}