accommodate inspector change
[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, g_board_0.xyz,
23 g_board_1.xyz )-0.1 );
24 float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
25 player_shadow *= player_shadow*player_shadow*player_shadow;
26
27 return 1.0 - player_shadow*0.8;
28 }
29
30 vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )
31 {
32 return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );
33 }