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 ) * 1.125;
8 const float SUN_ANGLE = 0.0001;
9 const float TIME_RATE = 0.025;
11 const float PI = 3.14159265;
23 float luminance( vec3 v )
25 return dot( v, vec3(0.2126, 0.7152, 0.0722) );
28 vec3 scene_ambient( vec3 dir, const world_info w )
30 float sun_azimuth = dot( dir.xz, w.sun_dir.xz ) * 0.4 + 0.6;
31 float sky_gradient = dir.y;
33 /* Blend phase colours */
34 vec3 ambient = DAYSKY_COLOUR * (w.day_phase-w.sunset_phase*0.1);
35 ambient += SUNSET_COLOUR * (1.0-dir.y*0.5) * w.sunset_phase * sun_azimuth;
36 ambient += NIGHTSKY_COLOUR * (1.0-w.day_phase);
39 ambient -= sky_gradient * luminance(ambient);
44 vec3 scene_sky( vec3 ray_dir, const world_info w )
46 ray_dir.y = abs( ray_dir.y );
47 vec3 sky_colour = scene_ambient( ray_dir, w );
50 float sun_theta = dot( ray_dir, w.sun_dir );
51 float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );
52 float sun_shape = pow( sun_size, 2000.0 );
53 sun_shape += sun_size * max(w.sun_dir.y,0.0) * 0.5;
55 vec3 sun_colour = mix( vec3(1.0), SUNSET_COLOUR, w.sunset_phase*0.5 );
56 sun_colour *= sun_shape;
58 vec3 composite = sky_colour + sun_colour;
62 vec3 scene_compute_ambient( vec3 normal, const world_info w )
64 return scene_ambient( (normal * vec3(1.0,-1.0,1.0)) * 0.5 + 0.5, w );
67 vec3 SR_LIGHT( vec3 normal, vec2 dir, vec3 colour )
71 cos(dir.y) * cos(dir.x),
73 sin(dir.y) * cos(dir.x)
76 float flight = max( dot( normal, dir3 ) * 0.75 + 0.25, 0.0 );
78 return flight * colour;
81 vec3 scene_lighting_old( vec3 normal, const world_info w )
83 vec3 SR_COLOUR_SUN = vec3( 1.36, 1.35, 1.01 );
84 vec3 SR_COLOUR_FILL = vec3( 0.33, 0.56, 0.64 );
85 vec3 SR_COLOUR_RIM = vec3( 0.05, 0.05, 0.23 );
87 return SR_LIGHT( normal, vec2( 0.63, -0.08 ), SR_COLOUR_SUN ) +
88 SR_LIGHT( normal, vec2( -2.60, -0.13 ), SR_COLOUR_FILL ) +
89 SR_LIGHT( normal, vec2( 2.60, -0.84 ), SR_COLOUR_RIM ) ;
92 vec3 scene_lighting( vec3 normal, float shadow, vec3 halfview, const world_info w )
94 float fresnel = 1.0 - abs(dot(normal,halfview));
96 vec3 sky_reflection = 0.5 * fresnel * mix( DAYSKY_COLOUR, SUNSET_COLOUR, w.sunset_phase );
97 vec3 light_sun = max(0.0,dot(normal,w.sun_dir)*0.75+0.25) * SUN_COLOUR
100 float scaled_shadow = max( shadow, 1.0 - max(w.sun_dir.y,0.0) );
102 vec3 ambient = mix( AMBIENT_COLOUR, SUNSET_AMBIENT, w.sunset_phase );
104 return ambient + (light_sun + sky_reflection) * shadow;
111 float sun_theta = dot( normal, w.sun_dir );
113 float softness_min = 0.5;
114 float softness = softness_min + w.sunset_phase * (1.0-softness_min);
115 float light_min = 0.0 * w.day_phase;
116 float light_direct = light_min + smoothstep( -softness, softness, sun_theta ) * (1.0-light_min);
117 light_direct *= clamp(w.sun_dir.y * 4.0 + 1.0,0.0,1.0) * shadow;
119 float light_bounce = 0.5 + 0.5 * dot( -normal, w.sun_dir );
120 light_bounce *= light_bounce * max( w.sun_dir.y, 0.0 );
122 vec3 light_colour = SUN_COLOUR*w.day_phase + (SUNSET_COLOUR*w.sunset_phase + 0.1);
123 vec3 dark_colour = mix( AMBIENT_COLOUR, SUNSET_AMBIENT, w.sunset_phase );
125 float spec = newlight_specular( normal, w.sun_dir, halfview, 2.0 )
126 * 0.2 * shadow * w.day_phase;
128 return mix(dark_colour, light_colour, light_direct) +
130 dark_colour * light_bounce;
133 void scene_state( float world_time, out world_info w )
136 w.time_of_day = fract( w.time );
137 w.day_phase = cos( w.time_of_day * PI * 2.0 ) * 0.5 + 0.5;
138 w.sunset_phase = cos( w.time_of_day * PI * 4.0 + PI ) * 0.5 + 0.5;
139 w.sunset_phase = pow( w.sunset_phase, 6.0 );
141 float a = w.time_of_day * PI * 2.0;
142 w.sun_dir = normalize( vec3( sin( a ), cos( a ), 0.2) );