<commit_before>#version 120

float ray_sphere(vec3 p, vec3 d, vec3 o, float r) {
    vec3 l = o - p;
    float a = dot(d, d);
    float b = 2 * dot(d, l);
    float c = dot(l, l) - r * r;

    float discr = b * b - 4 * a * c;
    if (discr < 0.0) return 0.0;
    // assert discr >= 0

    return (-b + sqrt(discr)) / (2 * a);
}

// computes the distance in meters from the position to the edge of the atmosphere
// assuming the earth is at (0, -6371km, 0) and the atmosphere has height 50km
//
// assumes the point is between the earth's surface and atmosphere
// dir need not be normalized
float atmospheric_depth(vec3 pos, vec3 dir) {
    const vec3 earth_center = vec3(0, -6371e3, 0);
    const float atmo_radius = 6371e3 + 50e3;

    return ray_sphere(pos, normalize(dir), earth_center, atmo_radius);
}

// computes how much the given ray is occluded by the horizon (i.e. if it
// intersects the surface of the Earth then it will not contribute at all)
float horizon_extinction(vec3 pos, vec3 dir) {
    return 1.0; // TODO: implement this
}

varying vec3 pos;
uniform vec3 skycolor;

float phase(float alpha, float g){
    float a = 3.0*(1.0-g*g);
    float b = 2.0*(2.0+g*g);
    float c = 1.0+alpha*alpha;
    float d = pow(1.0+g*g-2.0*g*alpha, 1.5);
    return (a/b)*(c/d);
}

vec3 absorb(float dist, vec3 color, float factor){
    return color-color*pow(skycolor, vec3(factor/dist));
}
const int step_count = 16;
void main()
{
    if (pos.y < 0) {
        gl_FragColor = vec4(0, 0, 0, 1);
        return;
    }

	vec3 ray = -normalize(pos);
	vec3 light_dir = normalize(gl_LightSource[0].position.xyz);
	float dotP = dot(ray,light_dir);
	float rayleigh = phase(dotP,-0.01)*33;
	float mie = phase(dotP,-0.575)*100;
	float spot = smoothstep(0.0, 15.0, phase(dotP,0.9995))*1000;

	vec3 eye_pos = vec3(0, 1.8, 0);
	float eye_atmo_dist = atmospheric_depth(eye_pos, ray);
	float step_size = eye_atmo_dist / float(step_count);

	vec3 eye_dir = -normalize(pos);

	vec3 mie_collected = vec3(0);
	vec3 rayleigh_collected = vec3(0);

	for(int i=0;i<step_count;i++) {
		float sample_distance = step_size*float(i);
		vec3 sample_pos = sample_distance*ray + eye_pos;

		float extinction = 1;//horizon_extinction(sample_pos,light_dir,1.8);

		float sample_depth = atmospheric_depth(sample_pos,light_dir);

		vec3 influx = absorb(sample_depth, vec3(1.8), 6000)*extinction;

		rayleigh_collected += absorb(sqrt(sample_distance), skycolor*influx, 23900.0);
		mie_collected += absorb(sample_distance, influx, 36400.0);
	}

	float eye_extinction = 1/*horizon_extinction(eye_position, ray,surface_height - 0.3)*/;
	rayleigh_collected = (
		rayleigh_collected *
		eye_extinction *
		pow(eye_atmo_dist / 2500e3, 1)
	)/float(step_count);
	mie_collected = (
		mie_collected *
		eye_extinction *
		pow(eye_atmo_dist / 2500e3, 1)
	)/float(step_count);

	vec3 color = vec3(
		spot*mie_collected +
		mie*mie_collected +
		rayleigh*rayleigh_collected
	);
    gl_FragColor = vec4(color * 5,1);
}
<commit_msg>blue sky<commit_after>#version 120

float ray_sphere(vec3 p, vec3 d, vec3 o, float r) {
    vec3 l = o - p;
    float a = dot(d, d);
    float b = 2 * dot(d, l);
    float c = dot(l, l) - r * r;

    float discr = b * b - 4 * a * c;
    if (discr < 0.0) return 0.0;
    // assert discr >= 0

    return (-b + sqrt(discr)) / (2 * a);
}

// computes the distance in meters from the position to the edge of the atmosphere
// assuming the earth is at (0, -6371km, 0) and the atmosphere has height 50km
//
// assumes the point is between the earth's surface and atmosphere
// dir need not be normalized
float atmospheric_depth(vec3 pos, vec3 dir) {
    const vec3 earth_center = vec3(0, -6371e3, 0);
    const float atmo_radius = 6371e3 + 50e3;

    return ray_sphere(pos, normalize(dir), earth_center, atmo_radius);
}

// computes how much the given ray is occluded by the horizon (i.e. if it
// intersects the surface of the Earth then it will not contribute at all)
float horizon_extinction(vec3 pos, vec3 dir) {
    return 1.0; // TODO: implement this
}

varying vec3 pos;
uniform vec3 skycolor;

float phase(float alpha, float g){
    float a = 3.0*(1.0-g*g);
    float b = 2.0*(2.0+g*g);
    float c = 1.0+alpha*alpha;
    float d = pow(1.0+g*g-2.0*g*alpha, 1.5);
    return (a/b)*(c/d);
}

vec3 absorb(float dist, vec3 color, float factor){
    return color * pow(skycolor, vec3(factor/dist));
}
const int step_count = 16;
void main()
{
    if (pos.y < 0) {
        gl_FragColor = vec4(0, 0, 0, 1);
        return;
    }

	vec3 ray = -normalize(pos);
	vec3 light_dir = normalize(gl_LightSource[0].position.xyz);
	float dotP = dot(ray,light_dir);
	float rayleigh = phase(dotP,-0.01)*33;
	float mie = phase(dotP,-0.575)*100;
	float spot = smoothstep(0.0, 15.0, phase(dotP,0.9995))*1000;

	vec3 eye_pos = vec3(0, 1.8, 0);
	float eye_atmo_dist = atmospheric_depth(eye_pos, ray);
	float step_size = eye_atmo_dist / float(step_count);

	vec3 eye_dir = -normalize(pos);

	vec3 mie_collected = vec3(0);
	vec3 rayleigh_collected = vec3(0);

	for(int i=0;i<step_count;i++) {
		float sample_distance = step_size*float(i);
		vec3 sample_pos = sample_distance*ray + eye_pos;

		float extinction = 1;//horizon_extinction(sample_pos,light_dir,1.8);

		float sample_depth = atmospheric_depth(sample_pos,light_dir);

		vec3 influx = absorb(sample_depth, vec3(1.8), 36000)*extinction;

		rayleigh_collected += absorb(sqrt(sample_distance), skycolor*influx, 23900.0);
		mie_collected += absorb(sample_distance, influx, 36400.0);
	}

	float eye_extinction = 1/*horizon_extinction(eye_position, ray,surface_height - 0.3)*/;
	rayleigh_collected = (
		rayleigh_collected *
		eye_extinction *
		pow(eye_atmo_dist / 2500e3, 0)
	)/float(step_count);
	mie_collected = (
		mie_collected *
		eye_extinction *
		pow(eye_atmo_dist / 2500e3, 0)
	)/float(step_count);

	vec3 color = vec3(
		spot*mie_collected +
		mie*mie_collected +
		rayleigh*rayleigh_collected
	);
    gl_FragColor = vec4(color * 5,1);
}

{'fraction_non_alphanumeric': 0.1323381415632338, 'fraction_numerical': 0.05451190875545119, 'mean_word_length': 3.6842105263157894, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621922', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2259, 'n_words': 602}