PageRenderTime 62ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 18ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 130 lines | 104 code | 26 blank | 0 comment | 0 complexity | 79e60a3cdb4fe71ba962f71b94500244 MD5 | raw file
  1/** 
  2 * @file alphaF.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#extension GL_ARB_texture_rectangle : enable
 27
 28#ifdef DEFINE_GL_FRAGCOLOR
 29out vec4 gl_FragColor;
 30#endif
 31
 32VARYING vec4 vertex_color;
 33VARYING vec2 vary_texcoord0;
 34
 35uniform sampler2DRectShadow shadowMap0;
 36uniform sampler2DRectShadow shadowMap1;
 37uniform sampler2DRectShadow shadowMap2;
 38uniform sampler2DRectShadow shadowMap3;
 39uniform sampler2DRect depthMap;
 40
 41uniform mat4 shadow_matrix[6];
 42uniform vec4 shadow_clip;
 43uniform vec2 screen_res;
 44uniform vec2 shadow_res;
 45
 46vec3 atmosLighting(vec3 light);
 47vec3 scaleSoftClip(vec3 light);
 48
 49VARYING vec3 vary_ambient;
 50VARYING vec3 vary_directional;
 51VARYING vec3 vary_fragcoord;
 52VARYING vec3 vary_position;
 53VARYING vec3 vary_pointlight_col;
 54
 55uniform float shadow_bias;
 56
 57uniform mat4 inv_proj;
 58
 59float pcfShadow(sampler2DRectShadow shadowMap, vec4 stc, float scl)
 60{
 61	stc.xyz /= stc.w;
 62	stc.z += shadow_bias;
 63	
 64	float cs = shadow2DRect(shadowMap, stc.xyz).x;
 65	float shadow = cs;
 66
 67	shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, scl, 0.0)).x, cs);
 68	shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(scl, -scl, 0.0)).x, cs);
 69	shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, scl, 0.0)).x, cs);
 70	shadow += max(shadow2DRect(shadowMap, stc.xyz+vec3(-scl, -scl, 0.0)).x, cs);
 71			
 72	return shadow/5.0;
 73}
 74
 75
 76void main() 
 77{
 78	vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
 79	frag *= screen_res;
 80	
 81	float shadow = 1.0;
 82	vec4 pos = vec4(vary_position, 1.0);
 83	
 84	vec4 spos = pos;
 85		
 86	if (spos.z > -shadow_clip.w)
 87	{	
 88		vec4 lpos;
 89		
 90		if (spos.z < -shadow_clip.z)
 91		{
 92			lpos = shadow_matrix[3]*spos;
 93			lpos.xy *= shadow_res;
 94			shadow = pcfShadow(shadowMap3, lpos, 1.5);
 95			shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
 96		}
 97		else if (spos.z < -shadow_clip.y)
 98		{
 99			lpos = shadow_matrix[2]*spos;
100			lpos.xy *= shadow_res;
101			shadow = pcfShadow(shadowMap2, lpos, 1.5);
102		}
103		else if (spos.z < -shadow_clip.x)
104		{
105			lpos = shadow_matrix[1]*spos;
106			lpos.xy *= shadow_res;
107			shadow = pcfShadow(shadowMap1, lpos, 1.5);
108		}
109		else
110		{
111			lpos = shadow_matrix[0]*spos;
112			lpos.xy *= shadow_res;
113			shadow = pcfShadow(shadowMap0, lpos, 1.5);
114		}
115	}
116	
117	vec4 diff = diffuseLookup(vary_texcoord0.xy);
118
119	vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, vertex_color.a);
120	vec4 color = diff * col;
121	
122	color.rgb = atmosLighting(color.rgb);
123
124	color.rgb = scaleSoftClip(color.rgb);
125
126	color.rgb += diff.rgb * vary_pointlight_col.rgb;
127
128	gl_FragColor = color;
129}
130