PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 2ms RepoModel.GetById 38ms app.codeStats 0ms

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

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