now we're doing a bunch of them
[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 flat in vec4 light_colours[3];
8 flat in vec4 light_positions[3];
9
10 #include "common_world.glsl"
11
12 float sdLine( vec3 p, vec3 a, vec3 b )
13 {
14 vec3 pa = p - a;
15 vec3 ba = b - a;
16
17 float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
18 return length( pa - ba*h );
19 }
20
21 float compute_board_shadow()
22 {
23 // player shadow
24 float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
25 float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
26 player_shadow *= player_shadow*player_shadow*player_shadow;
27
28 return 1.0 - player_shadow*0.8;
29 }
30
31 vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
32 {
33 // Lighting
34 vec3 halfview = uCamera - aWorldCo;
35 float fdist = length(halfview);
36 halfview /= fdist;
37
38 vec3 total_light = newlight_compute_ambient();
39
40 // Compute world lighting contribution and apply it according to the
41 // shadow map
42 //
43 vec3 world_light = newlight_compute_world_diffuse( wnormal );
44 world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
45
46 float world_shadow = newlight_compute_sun_shadow();
47 float board_shadow = compute_board_shadow();
48
49 total_light += world_light * min( board_shadow, world_shadow );
50
51 // Compute the other lights that exist in the map, not effected by the sun
52 // shadow
53
54 total_light += newlight_compute_quadratic
55 (
56 wnormal, halfview,
57 light_positions[0].xyz,
58 light_colours[0].rgb
59 ) * board_shadow;
60 total_light += newlight_compute_quadratic
61 (
62 wnormal, halfview,
63 light_positions[1].xyz,
64 light_colours[1].rgb
65 ) * board_shadow;
66 total_light += newlight_compute_quadratic
67 (
68 wnormal, halfview,
69 light_positions[2].xyz,
70 light_colours[2].rgb
71 ) * board_shadow;
72
73 return apply_fog( diffuse * total_light, fdist );
74 }