now we're doing a bunch of them
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_scene.glsl
index 4a78fbcf01ca8a721a055dfb21a4b758b52dcb58..c71f5e2dbb4dbbd3359be1afa933eaaf5ba6f1c3 100644 (file)
@@ -1,7 +1,33 @@
 // :D
 
+in vec2 aUv;
+in vec4 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+flat in vec4 light_colours[3];
+flat in vec4 light_positions[3];
+
 #include "common_world.glsl"
 
+float sdLine( vec3 p, vec3 a, vec3 b )
+{
+  vec3 pa = p - a;
+  vec3 ba = b - a;
+
+  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
+  return length( pa - ba*h );
+}
+
+float compute_board_shadow()
+{
+   // player shadow
+   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
+   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
+   player_shadow *= player_shadow*player_shadow*player_shadow;
+
+   return 1.0 - player_shadow*0.8;
+}
+
 vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
 {
    // Lighting
@@ -18,29 +44,31 @@ vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
    world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
 
    float world_shadow = newlight_compute_sun_shadow();
+   float board_shadow = compute_board_shadow();
 
-   total_light += world_light * world_shadow;
+   total_light += world_light * min( board_shadow, world_shadow );
 
    // Compute the other lights that exist in the map, not effected by the sun
    // shadow
+
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.x ].xyz,
-                     g_point_light_colours[ aLights.x ].rgb 
-                  );
+                     light_positions[0].xyz,
+                     light_colours[0].rgb 
+                  ) * board_shadow;
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.y ].xyz,
-                     g_point_light_colours[ aLights.y ].rgb 
-                  );
+                     light_positions[1].xyz,
+                     light_colours[1].rgb 
+                  ) * board_shadow;
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.z ].xyz,
-                     g_point_light_colours[ aLights.z ].rgb 
-                  );
+                     light_positions[2].xyz,
+                     light_colours[2].rgb 
+                  ) * board_shadow;
 
    return apply_fog( diffuse * total_light, fdist );
 }