baby lock the door and turn the lights down low
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_scene.glsl
1 // :D
2
3 in vec2 aUv;
4 in vec4 aNorm;
5 in vec3 aCo;
6 in vec3 aWorldCo;
7
8 #include "common_world.glsl"
9
10 float sdLine( vec3 p, vec3 a, vec3 b )
11 {
12 vec3 pa = p - a;
13 vec3 ba = b - a;
14
15 float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
16 return length( pa - ba*h );
17 }
18
19 float compute_board_shadow()
20 {
21 // player shadow
22 float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
23 float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
24 player_shadow *= player_shadow*player_shadow*player_shadow;
25
26 return 1.0 - player_shadow*0.8;
27 }
28
29 vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )
30 {
31 return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );
32 }