4a78fbcf01ca8a721a055dfb21a4b758b52dcb58
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / common_scene.glsl
1 // :D
2
3 #include "common_world.glsl"
4
5 vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
6 {
7 // Lighting
8 vec3 halfview = uCamera - aWorldCo;
9 float fdist = length(halfview);
10 halfview /= fdist;
11
12 vec3 total_light = newlight_compute_ambient();
13
14 // Compute world lighting contribution and apply it according to the
15 // shadow map
16 //
17 vec3 world_light = newlight_compute_world_diffuse( wnormal );
18 world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
19
20 float world_shadow = newlight_compute_sun_shadow();
21
22 total_light += world_light * world_shadow;
23
24 // Compute the other lights that exist in the map, not effected by the sun
25 // shadow
26 total_light += newlight_compute_quadratic
27 (
28 wnormal, halfview,
29 g_point_light_positions[ aLights.x ].xyz,
30 g_point_light_colours[ aLights.x ].rgb
31 );
32 total_light += newlight_compute_quadratic
33 (
34 wnormal, halfview,
35 g_point_light_positions[ aLights.y ].xyz,
36 g_point_light_colours[ aLights.y ].rgb
37 );
38 total_light += newlight_compute_quadratic
39 (
40 wnormal, halfview,
41 g_point_light_positions[ aLights.z ].xyz,
42 g_point_light_colours[ aLights.z ].rgb
43 );
44
45 return apply_fog( diffuse * total_light, fdist );
46 }