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 );
8 const float SUN_ANGLE = 0.0001;
9 const float PI = 3.14159265;
21 float luminance( vec3 v )
23 return dot( v, vec3(0.2126, 0.7152, 0.0722) );
26 vec3 clearskies_ambient( vec3 dir )
28 float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);
29 float sky_gradient = dir.y;
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);
37 ambient -= sky_gradient * luminance(ambient);
42 vec3 clearskies_sky( vec3 ray_dir )
44 ray_dir.y = abs( ray_dir.y );
45 vec3 sky_colour = clearskies_ambient( ray_dir );
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;
53 vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );
54 sun_colour *= sun_shape;
56 vec3 composite = sky_colour + sun_colour;
60 vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )
62 float fresnel = 1.0 - abs(dot(normal,halfview));
64 vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb,
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;
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,
75 return ambient + (light_sun + sky_reflection) * shadow;