7 flat in ivec4 light_indices;
9 uniform samplerBuffer uLightsArray;
11 #include "common_world.glsl"
12 #include "light_clearskies.glsl"
14 float sdLine( vec3 p, vec3 a, vec3 b )
19 float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
20 return length( pa - ba*h );
23 float compute_board_shadow()
26 float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
27 float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
28 player_shadow *= player_shadow*player_shadow*player_shadow;
30 return 1.0 - player_shadow*0.8;
33 vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist )
35 float dist = pow(fdist*0.0010,0.78);
36 return mix( vfrag, colour, min( 1.0, dist ) );
39 vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
42 scene_state( g_time, world );
45 vec3 halfview = uCamera - aWorldCo;
46 float fdist = length(halfview);
49 vec3 total_light = vec3(0.0);
52 float world_shadow = newlight_compute_sun_shadow( world.sun_dir
53 * (1.0/(max(world.sun_dir.y,0.0)+0.2)) );
54 float board_shadow = compute_board_shadow();
56 total_light += scene_lighting( wnormal, min( board_shadow, world_shadow ),
59 //total_light += scene_lighting_old( wnormal, world );
61 // Compute the other lights that exist in the map, not effected by the sun
65 vec4 light_colour_0 = texelFetch( uLightsArray, light_indices.x*3+0 );
66 vec4 light_colour_1 = texelFetch( uLightsArray, light_indices.y*3+0 );
67 vec4 light_colour_2 = texelFetch( uLightsArray, light_indices.z*3+0 );
68 vec4 light_co_0 = texelFetch( uLightsArray, light_indices.x*3+1 );
69 vec4 light_co_1 = texelFetch( uLightsArray, light_indices.y*3+1 );
70 vec4 light_co_2 = texelFetch( uLightsArray, light_indices.z*3+1 );
71 vec4 light_dir_0 = texelFetch( uLightsArray, light_indices.x*3+2 );
72 vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );
73 vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );
75 //return vec3(fract(distance(light_co_0.xyz,aWorldCo)),
76 // fract(distance(light_co_1.xyz,aWorldCo)),
77 // fract(distance(light_co_2.xyz,aWorldCo)));
79 // return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),
80 // fract(light_indices.z * 0.125 ));
82 total_light += newlight_compute_spot
90 total_light += newlight_compute_spot
97 total_light += newlight_compute_spot
105 vec3 fog_colour = scene_sky( -halfview, world );
107 return scene_apply_fog( diffuse * total_light, fog_colour, fdist );