grid based
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_world.glsl
index ccf416eadd9a3d88469cb89388bab31167838ebc..a3b5ae3488b7acb8e083c82ab5827800a65c97b5 100644 (file)
@@ -2,6 +2,9 @@ layout (location = 0) out vec4 oColour;
 
 layout (std140) uniform ub_world_lighting
 {
+   vec4 g_cube_min;
+   vec4 g_cube_inv_range;
+
    vec4 g_light_colours[3];
    vec4 g_light_directions[3];
    vec4 g_ambient_colour;
@@ -117,16 +120,19 @@ float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )
    return pow(max(dot( halfview, specdir ), 0.0), exponent);
 }
 
-vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, 
+vec3 newlight_compute_quadratic( vec3 wnormal, float max_dist,
                                  vec3 light_colour, vec3 light_pos )
 {
-   vec3 light_delta = (light_pos-aWorldCo) * 10.0;
+   vec3 light_delta = light_pos-aWorldCo;
 
-   float quadratic = dot(light_delta,light_delta);
-   float attenuation = 1.0f/( 1.0f + quadratic );
-   attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) );
+   float dist2 = dot(light_delta,light_delta);
+
+   float quadratic = dist2*100.0;
+   float attenuation  = 1.0f/( 1.0f + quadratic );
+         attenuation *= max( dot( normalize(light_delta), wnormal ), 0.0 );
 
-   return light_colour*attenuation;
+   float falloff = max( 0.0, 1.0-(dist2*max_dist) );
+   return light_colour * attenuation * falloff;
 }
 
 vec3 newlight_compute_spot( vec3 wnormal, vec3 halfview,