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

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 140 lines | 102 code | 38 blank | 0 comment | 0 complexity | 670097b7ce984a3f83f3c20058fc296c MD5 | raw file
  1/** 
  2 * @file alphaSkinnedV.glsl
  3 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  4 * Second Life Viewer Source Code
  5 * Copyright (C) 2007, Linden Research, Inc.
  6 * 
  7 * This library is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU Lesser General Public
  9 * License as published by the Free Software Foundation;
 10 * version 2.1 of the License only.
 11 * 
 12 * This library is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15 * Lesser General Public License for more details.
 16 * 
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this library; if not, write to the Free Software
 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 20 * 
 21 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 22 * $/LicenseInfo$
 23 */
 24
 25uniform mat4 projection_matrix;
 26uniform mat4 modelview_matrix;
 27
 28ATTRIBUTE vec3 position;
 29ATTRIBUTE vec3 normal;
 30ATTRIBUTE vec4 diffuse_color;
 31ATTRIBUTE vec2 texcoord0;
 32
 33mat4 getObjectSkinnedTransform();
 34void calcAtmospherics(vec3 inPositionEye);
 35
 36float calcDirectionalLight(vec3 n, vec3 l);
 37
 38vec3 atmosAmbient(vec3 light);
 39vec3 atmosAffectDirectionalLight(float lightIntensity);
 40
 41VARYING vec3 vary_position;
 42VARYING vec3 vary_ambient;
 43VARYING vec3 vary_directional;
 44VARYING vec3 vary_normal;
 45VARYING vec3 vary_fragcoord;
 46VARYING vec3 vary_pointlight_col;
 47VARYING vec4 vertex_color;
 48VARYING vec2 vary_texcoord0;
 49
 50
 51uniform float near_clip;
 52
 53uniform vec4 light_position[8];
 54uniform vec3 light_direction[8];
 55uniform vec3 light_attenuation[8]; 
 56uniform vec3 light_diffuse[8];
 57
 58float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)
 59{
 60	//get light vector
 61	vec3 lv = lp.xyz-v;
 62	
 63	//get distance
 64	float d = length(lv);
 65	
 66	float da = 0.0;
 67
 68	if (d > 0.0 && la > 0.0 && fa > 0.0)
 69	{
 70		//normalize light vector
 71		lv *= 1.0/d;
 72	
 73		//distance attenuation
 74		float dist2 = d*d/(la*la);
 75		da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
 76
 77		// spotlight coefficient.
 78		float spot = max(dot(-ln, lv), is_pointlight);
 79		da *= spot*spot; // GL_SPOT_EXPONENT=2
 80
 81		//angular attenuation
 82		da *= calcDirectionalLight(n, lv);
 83	}
 84
 85	return da;	
 86}
 87
 88void main()
 89{
 90	vary_texcoord0 = texcoord0;
 91				
 92	vec4 pos;
 93	vec3 norm;
 94	
 95	mat4 trans = getObjectSkinnedTransform();
 96	trans = modelview_matrix * trans;
 97	
 98	pos = trans * vec4(position.xyz, 1.0);
 99	
100	norm = position.xyz + normal.xyz;
101	norm = normalize(( trans*vec4(norm, 1.0) ).xyz-pos.xyz);
102	
103	vec4 frag_pos = projection_matrix * pos;
104	gl_Position = frag_pos;
105	
106	vary_position = pos.xyz;
107	vary_normal = norm;	
108	
109	calcAtmospherics(pos.xyz);
110
111	vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a);
112
113	// Collect normal lights
114	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);
115	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);
116	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);
117	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);
118	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);
119	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);
120
121	vary_pointlight_col = col.rgb*diffuse_color.rgb;
122
123	col.rgb = vec3(0,0,0);
124
125	// Add windlight lights
126	col.rgb = atmosAmbient(vec3(0.));
127	
128	vary_ambient = col.rgb*diffuse_color.rgb;
129	vary_directional = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a)));
130	
131	col.rgb = min(col.rgb*diffuse_color.rgb, 1.0);
132	
133	vertex_color = col;
134
135	
136	
137	vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip);
138}
139
140