PageRenderTime 379ms CodeModel.GetById 139ms app.highlight 1ms RepoModel.GetById 235ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class3/deferred/giDownsampleF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
text | 106 lines | 88 code | 18 blank | 0 comment | 0 complexity | 8eb355a1f330345649ec4213c7b73c7b MD5 | raw file
  1/** 
  2 * @file giDownsampleF.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
 28uniform sampler2DRect giLightMap;
 29
 30uniform vec2 kern[32];
 31uniform float dist_factor;
 32uniform float blur_size;
 33uniform vec2 delta;
 34uniform int kern_length;
 35uniform float kern_scale;
 36uniform vec3 blur_quad;
 37
 38varying vec2 vary_fragcoord;
 39
 40uniform mat4 inv_proj;
 41uniform vec2 screen_res;
 42
 43vec4 getPosition(vec2 pos_screen)
 44{
 45	float depth = texture2DRect(depthMap, pos_screen.xy).a;
 46	vec2 sc = pos_screen.xy*2.0;
 47	sc /= screen_res;
 48	sc -= vec2(1.0,1.0);
 49	vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
 50	vec4 pos = inv_proj * ndc;
 51	pos /= pos.w;
 52	pos.w = 1.0;
 53	return pos;
 54}
 55
 56float getDepth(vec2 pos_screen)
 57{
 58	float z = texture2DRect(depthMap, pos_screen.xy).a;
 59	z = z*2.0-1.0;
 60	vec4 ndc = vec4(0.0, 0.0, z, 1.0);
 61	vec4 p = inv_proj*ndc;
 62	return p.z/p.w;
 63}
 64
 65void main() 
 66{
 67	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
 68	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm
 69	float depth = getDepth(vary_fragcoord.xy);
 70		
 71	vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
 72	vec2 dlt = kern_scale * delta/(vec2(1.0,1.0)+norm.xy*norm.xy);
 73	dlt /= clamp(-depth*blur_quad.x, 1.0, 3.0);
 74	float defined_weight = kern[0].x;
 75	vec3 col = ccol*kern[0].x;
 76	
 77	for (int i = 0; i < kern_length; i++)
 78	{
 79		vec2 tc = vary_fragcoord.xy + kern[i].y*dlt;
 80		vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz;
 81		sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm
 82		
 83		float d = dot(norm.xyz, sampNorm);
 84		
 85		if (d > 0.5)
 86		{
 87			float sampdepth = getDepth(tc.xy);
 88			sampdepth -= depth;
 89			if (sampdepth*sampdepth < blur_quad.z)
 90			{
 91	    		col += texture2DRect(giLightMap, tc).rgb*kern[i].x;
 92				defined_weight += kern[i].x;
 93			}
 94		}
 95	}
 96
 97	col /= defined_weight;
 98	
 99	//col = ccol;
100	
101	col = col*blur_quad.y;
102	
103	gl_FragData[0].xyz = col;
104	
105	//gl_FragColor = ccol;
106}