+vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist )
+{
+ float dist = pow(fdist*0.0010,0.78);
+ return mix( vfrag, colour, min( 1.0, dist ) );
+}
+
+vec3 rand33(vec3 p3)
+{
+ p3 = fract(p3 * vec3(.1031, .1030, .0973));
+ p3 += dot(p3, p3.yxz+33.33);
+ return fract((p3.xxy + p3.yxx)*p3.zyx);
+}
+
+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.0f/( 1.0f + quadratic );
+ attenuation *= max( dot( light_delta, normal ), 0.0 );