PageRenderTime 16ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 146 lines | 110 code | 36 blank | 0 comment | 0 complexity | 0e63abd138d866aadff87091019a6227 MD5 | raw file
  1/** 
  2 * @file alphaV.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
 26uniform mat3 normal_matrix;
 27uniform mat4 texture_matrix0;
 28uniform mat4 modelview_matrix;
 29uniform mat4 modelview_projection_matrix;
 30
 31ATTRIBUTE vec3 position;
 32void passTextureIndex();
 33ATTRIBUTE vec3 normal;
 34ATTRIBUTE vec4 diffuse_color;
 35ATTRIBUTE vec2 texcoord0;
 36
 37vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
 38void calcAtmospherics(vec3 inPositionEye);
 39
 40float calcDirectionalLight(vec3 n, vec3 l);
 41
 42vec3 atmosAmbient(vec3 light);
 43vec3 atmosAffectDirectionalLight(float lightIntensity);
 44vec3 scaleDownLight(vec3 light);
 45vec3 scaleUpLight(vec3 light);
 46
 47VARYING vec3 vary_ambient;
 48VARYING vec3 vary_directional;
 49VARYING vec3 vary_fragcoord;
 50VARYING vec3 vary_position;
 51VARYING vec3 vary_light;
 52VARYING vec3 vary_pointlight_col;
 53
 54VARYING vec4 vertex_color;
 55VARYING vec2 vary_texcoord0;
 56
 57
 58uniform float near_clip;
 59uniform float shadow_offset;
 60uniform float shadow_bias;
 61
 62uniform vec4 light_position[8];
 63uniform vec3 light_direction[8];
 64uniform vec3 light_attenuation[8]; 
 65uniform vec3 light_diffuse[8];
 66
 67float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)
 68{
 69	//get light vector
 70	vec3 lv = lp.xyz-v;
 71	
 72	//get distance
 73	float d = length(lv);
 74	
 75	float da = 0.0;
 76
 77	if (d > 0.0 && la > 0.0 && fa > 0.0)
 78	{
 79		//normalize light vector
 80		lv *= 1.0/d;
 81	
 82		//distance attenuation
 83		float dist2 = d*d/(la*la);
 84		da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
 85
 86		// spotlight coefficient.
 87		float spot = max(dot(-ln, lv), is_pointlight);
 88		da *= spot*spot; // GL_SPOT_EXPONENT=2
 89
 90		//angular attenuation
 91		da *= calcDirectionalLight(n, lv);
 92	}
 93
 94	return da;	
 95}
 96
 97void main()
 98{
 99	//transform vertex
100	vec4 vert = vec4(position.xyz, 1.0);
101	passTextureIndex();
102	vec4 pos = (modelview_matrix * vert);
103	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
104	
105	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
106	
107	vec3 norm = normalize(normal_matrix * normal);
108	
109	float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz));
110	vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset;
111		
112	calcAtmospherics(pos.xyz);
113
114	//vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.));
115	vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a);
116
117	// Collect normal lights
118	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z);
119	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z);
120	col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z);
121	col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z);
122	col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z);
123	col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z);
124	
125	vary_pointlight_col = col.rgb*diffuse_color.rgb;
126
127	col.rgb = vec3(0,0,0);
128
129	// Add windlight lights
130	col.rgb = atmosAmbient(vec3(0.));
131	
132	vary_light = light_position[0].xyz;
133	
134	vary_ambient = col.rgb*diffuse_color.rgb;
135	vary_directional.rgb = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a)));
136	
137	col.rgb = col.rgb*diffuse_color.rgb;
138	
139	vertex_color = col;
140
141	
142	
143	pos = modelview_projection_matrix * vert;
144	vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
145	
146}