PageRenderTime 18ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl

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