// :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 vec3 halfview = uCamera - aWorldCo; float fdist = length(halfview); halfview /= fdist; vec3 total_light = newlight_compute_ambient(); // Compute world lighting contribution and apply it according to the // shadow map // vec3 world_light = newlight_compute_world_diffuse( 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 * 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, light_positions[0].xyz, light_colours[0].rgb ) * board_shadow; total_light += newlight_compute_quadratic ( wnormal, halfview, light_positions[1].xyz, light_colours[1].rgb ) * board_shadow; total_light += newlight_compute_quadratic ( wnormal, halfview, light_positions[2].xyz, light_colours[2].rgb ) * board_shadow; return apply_fog( diffuse * total_light, fdist ); }