baby lock the door and turn the lights down low
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / light_clearskies.glsl
1 //const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );
2 //const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );
3 //const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );
4 //const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );
5 //const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );
6 //const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );
7
8 const float SUN_ANGLE = 0.0001;
9 const float PI = 3.14159265;
10
11 //struct world_info
12 //{
13 // float time,
14 // time_of_day,
15 // day_phase,
16 // sunset_phase;
17 //
18 // vec3 sun_dir;
19 //};
20
21 float luminance( vec3 v )
22 {
23 return dot( v, vec3(0.2126, 0.7152, 0.0722) );
24 }
25
26 vec3 clearskies_ambient( vec3 dir )
27 {
28 float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);
29 float sky_gradient = dir.y;
30
31 /* Blend phase colours */
32 vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);
33 ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;
34 ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);
35
36 /* Add gradient */
37 ambient -= sky_gradient * luminance(ambient);
38
39 return ambient;
40 }
41
42 vec3 clearskies_sky( vec3 ray_dir )
43 {
44 ray_dir.y = abs( ray_dir.y );
45 vec3 sky_colour = clearskies_ambient( ray_dir );
46
47 /* Sun */
48 float sun_theta = dot( ray_dir, g_sun_dir.xyz );
49 float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );
50 float sun_shape = pow( sun_size, 2000.0 );
51 sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;
52
53 vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );
54 sun_colour *= sun_shape;
55
56 vec3 composite = sky_colour + sun_colour;
57 return composite;
58 }
59
60 vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )
61 {
62 float fresnel = 1.0 - abs(dot(normal,halfview));
63
64 vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb,
65 g_sunset_phase );
66
67 vec3 sky_reflection = 0.5 * fresnel * reflect_colour;
68 vec3 light_sun = max(0.0,dot(normal,g_sun_dir.xyz)*0.75+0.25)
69 * g_sun_colour.rgb * g_day_phase;
70
71 float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );
72 vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb,
73 g_sunset_phase );
74
75 return ambient + (light_sun + sky_reflection) * shadow;
76 }