PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
text | 100 lines | 76 code | 24 blank | 0 comment | 0 complexity | 8da74362fb8772a0c0b1c3e8d56f9bfc MD5 | raw file
  1/** 
  2 * @file postDeferredF.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 diffuseRect;
 31uniform sampler2DRect specularRect;
 32
 33uniform sampler2DRect localLightMap;
 34uniform sampler2DRect sunLightMap;
 35uniform sampler2DRect giLightMap;
 36uniform sampler2DRect edgeMap;
 37
 38uniform sampler2D	  luminanceMap;
 39
 40uniform sampler2DRect lightMap;
 41
 42uniform sampler2D	  lightFunc;
 43uniform sampler2D	  noiseMap;
 44
 45uniform float sun_lum_scale;
 46uniform float sun_lum_offset;
 47uniform float lum_scale;
 48uniform float lum_lod;
 49uniform vec4 ambient;
 50uniform float gi_brightness;
 51uniform float gi_luminance;
 52
 53uniform vec4 sunlight_color;
 54
 55uniform vec2 screen_res;
 56varying vec2 vary_fragcoord;
 57
 58void main() 
 59{
 60	vec2 tc = vary_fragcoord.xy;
 61	vec4 lcol = texture2DLod(luminanceMap, vec2(0.5, 0.5), lum_lod);
 62	
 63	vec3 gi_col = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
 64	vec4 sun_col =	texture2DRect(sunLightMap, vary_fragcoord.xy);
 65	vec3 local_col = texture2DRect(localLightMap, vary_fragcoord.xy).rgb;
 66	
 67	float scol = texture2DRect(lightMap, vary_fragcoord.xy).r;
 68			
 69	vec3 diff = texture2DRect(diffuseRect, vary_fragcoord.xy).rgb;
 70	vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
 71	
 72	gi_col = gi_col*(diff.rgb+spec.rgb*spec.a);
 73
 74	float lum = 1.0-clamp(pow(lcol.r, gi_brightness)+sun_lum_offset, 0.0, 1.0);
 75	
 76	lum *= sun_lum_scale;
 77	
 78	sun_col *= 1.0+(lum*lum_scale*scol);
 79					  
 80	vec4 col;
 81	col.rgb = gi_col+sun_col.rgb+local_col;
 82	
 83	col.a = sun_col.a;
 84	
 85	vec3 bcol = vec3(0,0,0);
 86	float tweight = 0.0;
 87	for (int i = 0; i < 16; i++)
 88	{
 89		float weight = (float(i)+1.0)/2.0;
 90		bcol += texture2DLod(luminanceMap, vary_fragcoord.xy/screen_res, weight).rgb*weight*weight*weight;
 91		tweight += weight*weight;
 92	}
 93	
 94	bcol /= tweight;
 95	bcol *= gi_luminance;
 96	col.rgb += bcol*lum;
 97	
 98	gl_FragColor = col;
 99	//gl_FragColor.rgb = texture2DRect(giLightMap, vary_fragcoord.xy).rgb;
100}