//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );
const float SUN_ANGLE = 0.0001;
-const float PI = 3.14159265;
+const float PI = 3.14159265358979323846264;
//struct world_info
//{
// vec3 sun_dir;
//};
+vec3 rand33(vec3 p3)
+{
+ p3 = fract(p3 * vec3(.1031, .1030, .0973));
+ p3 += dot(p3, p3.yxz+33.33);
+ return fract((p3.xxy + p3.yxx)*p3.zyx);
+}
+
+float stars( vec3 rd, float rr, float size ){
+ vec3 co = rd * rr;
+
+ float a = atan(co.y, length(co.xz)) + 4.0 * PI;
+
+ float spaces = 1.0 / rr;
+ size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;
+ a -= mod(a, spaces) - spaces * 0.5;
+
+ float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);
+
+ float plane = atan(co.z, co.x) + 4.0 * PI;
+ plane = plane - mod(plane, PI / count);
+
+ vec2 delta = rand33(vec3(plane, a, 0.0)).xy;
+
+ float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;
+ float ydist = sqrt(rr * rr - level * level);
+ float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);
+ vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);
+ float star = smoothstep(size, 0.0, distance(center, co));
+ return star;
+}
+
float luminance( vec3 v )
{
return dot( v, vec3(0.2126, 0.7152, 0.0722) );
vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );
sun_colour *= sun_shape;
+
+
+ float star = 0.0;
+ float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));
+
+ if( star_blend > 0.001 ){
+ for( float j = 1.0; j <= 4.1; j += 1.0 ){
+ float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));
+ star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));
+ }
+ }
- vec3 composite = sky_colour + sun_colour;
+ vec3 composite = sky_colour + sun_colour + star*star_blend;
return composite;
}
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;
+ vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN,
+ 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,