- float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);
- vtotal += vcolour*flight;
+vec3 scene_calculate_light( int light_index,
+ vec3 halfview, vec3 co, vec3 normal )
+{
+ vec4 light_colour = texelFetch( uLightsArray, light_index+0 );
+ vec4 light_co = texelFetch( uLightsArray, light_index+1 );
+ vec4 light_dir = texelFetch( uLightsArray, light_index+2 );
+
+ vec3 light_delta = light_co.xyz-co;
+ float dist2 = dot(light_delta,light_delta);
+
+ light_delta = normalize( light_delta );
+
+ float quadratic = dist2*100.0;
+ float attenuation = 1.0/( 1.0 + quadratic );
+ attenuation *= max( dot( light_delta, normal ), 0.0 );
+
+ float falloff = max( 0.0, 1.0-(dist2*light_co.w) );
+
+ if( light_dir.w < 0.999999 ){
+ float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );
+ falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );