PageRenderTime 71ms CodeModel.GetById 30ms app.highlight 1ms RepoModel.GetById 19ms 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
 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
30uniform sampler2DRect depthMap;
31uniform sampler2DRect normalMap;
32
33varying vec2 vary_fragcoord;
34
35uniform float depth_cutoff;
36uniform float norm_cutoff;
37
38uniform mat4 inv_proj;
39uniform vec2 screen_res;
40
41float getDepth(vec2 pos_screen)
42{
43	float z = texture2DRect(depthMap, pos_screen.xy).r;
44	z = z*2.0-1.0;
45	vec4 ndc = vec4(0.0, 0.0, z, 1.0);
46	vec4 p = inv_proj*ndc;
47	return p.z/p.w;
48}
49
50void main() 
51{
52	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
53	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
54	float depth = getDepth(vary_fragcoord.xy);
55	
56	vec2 tc = vary_fragcoord.xy;
57	
58	float sc = 0.75;
59	
60	vec2 de;
61	de.x = (depth-getDepth(tc+vec2(sc, sc))) + (depth-getDepth(tc+vec2(-sc, -sc)));
62	de.y = (depth-getDepth(tc+vec2(-sc, sc))) + (depth-getDepth(tc+vec2(sc, -sc)));
63	de /= depth;
64	de *= de;
65	de = step(depth_cutoff, de);
66	
67	vec2 ne;
68	vec3 nexnorm = texture2DRect(normalMap, tc+vec2(-sc,-sc)).rgb;
69	nexnorm = vec3((nexnorm.xy-0.5)*2.0,nexnorm.z); // unpack norm
70	ne.x = dot(nexnorm, norm);
71	vec3 neynorm = texture2DRect(normalMap, tc+vec2(sc,sc)).rgb;
72	neynorm = vec3((neynorm.xy-0.5)*2.0,neynorm.z); // unpack norm
73	ne.y = dot(neynorm, norm);
74	
75	ne = 1.0-ne;
76	
77	ne = step(norm_cutoff, ne);
78	
79	gl_FragColor.a = dot(de,de)+dot(ne,ne);
80	//gl_FragColor.a = dot(de,de);
81}