PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 1ms

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

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