//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 ); //const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 ); //const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 ); //const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 ); //const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 ); //const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 ); const float SUN_ANGLE = 0.0001; const float PI = 3.14159265; //struct world_info //{ // float time, // time_of_day, // day_phase, // sunset_phase; // // vec3 sun_dir; //}; float luminance( vec3 v ) { return dot( v, vec3(0.2126, 0.7152, 0.0722) ); } vec3 clearskies_ambient( vec3 dir ) { float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6); float sky_gradient = dir.y; /* Blend phase colours */ vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1); ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth; ambient += g_nightsky_colour.rgb * (1.0-g_day_phase); /* Add gradient */ ambient -= sky_gradient * luminance(ambient); return ambient; } vec3 clearskies_sky( vec3 ray_dir ) { ray_dir.y = abs( ray_dir.y ); vec3 sky_colour = clearskies_ambient( ray_dir ); /* Sun */ float sun_theta = dot( ray_dir, g_sun_dir.xyz ); float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE ); float sun_shape = pow( sun_size, 2000.0 ); sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5; vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 ); sun_colour *= sun_shape; vec3 composite = sky_colour + sun_colour; return composite; } vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview ) { float fresnel = 1.0 - abs(dot(normal,halfview)); vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, g_sunset_phase ); vec3 sky_reflection = 0.5 * fresnel * reflect_colour; vec3 light_sun = max(0.0,dot(normal,g_sun_dir.xyz)*0.75+0.25) * g_sun_colour.rgb * g_day_phase; float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) ); vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, g_sunset_phase ); return ambient + (light_sun + sky_reflection) * shadow; }