PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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