<commit_before><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Raytracing</title>

<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec2 attribute_vertex_position;
uniform vec3 uniform_camera_up;
uniform vec3 uniform_camera_right;
varying vec3 varying_pixel_position;
void main()
{
	gl_Position = vec4(attribute_vertex_position, 0.0, 1.0);
	varying_pixel_position =
		attribute_vertex_position[0] * uniform_camera_right +
		attribute_vertex_position[1] * uniform_camera_up;
}
</script>

<script id="fragment-shader" type="x-shader/x-fragment">
precision highp float;
uniform vec3 uniform_camera_origin;
uniform float uniform_camera_near;
uniform float uniform_camera_far;
varying vec3 varying_pixel_position;
vec4 srgb(float r, float g, float b)
{
	r = clamp(r, 0.0, 1.0);
	g = clamp(g, 0.0, 1.0);
	b = clamp(b, 0.0, 1.0);
#if 1
	float K0 = 0.03928;
	float a = 0.055;
	float phi = 12.92;
	float gamma = 2.4;
	r = r <= K0 / phi ? r * phi : (1.0 + a) * pow(r, 1.0 / gamma) - a;
	g = g <= K0 / phi ? g * phi : (1.0 + a) * pow(g, 1.0 / gamma) - a;
	b = b <= K0 / phi ? b * phi : (1.0 + a) * pow(b, 1.0 / gamma) - a;
#endif
	return vec4(r, g, b, 1.0);
}
struct interval
{
	float min, max;
};
struct surface
{
	vec3 p, n;
};
struct ray
{
	vec3 o, d;
};
struct sphere {
	vec3 c;
	float r;
};
bool sphere_ray(inout interval l, out surface i, sphere s, ray r)
{
	vec3 dst = s.c - r.o;
	float b = dot(dst, r.d);
	float c = dot(dst, dst) - s.r * s.r;
	float d = b * b - c;
	float q = sqrt(d);
	float l0 = b - q;
	float l1 = b + q;
	float lx = l0 < l.min ? l1 : l0;
	i.p = lx * r.d + r.o;
	i.n = (i.p - s.c) / s.r;
	bool t = l.min < lx && lx < l.max;
	l.max = t ? lx : l.max;
	return t;
}
vec4 color(surface i, ray r, bool t)
{
	float v = t ? dot(i.n, r.d) : 0.0;
	return v < 0.0 ? srgb(0.0, -v, 0.0) : srgb(v, 0.0, 0.0);
}
void main()
{
	ray r;
	r.d = normalize(varying_pixel_position - uniform_camera_origin);
	r.o = uniform_camera_origin;
	sphere s = sphere(vec3(0.0, 0.0, 0.0), 0.5);
	interval l = interval(uniform_camera_near, uniform_camera_far);
	surface i;
	bool t = sphere_ray(l, i, s, r);
	gl_FragColor = color(i, r, t);
}
</script>
<commit_msg>also check for discriminant<commit_after><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Raytracing</title>

<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec2 attribute_vertex_position;
uniform vec3 uniform_camera_up;
uniform vec3 uniform_camera_right;
varying vec3 varying_pixel_position;
void main()
{
	gl_Position = vec4(attribute_vertex_position, 0.0, 1.0);
	varying_pixel_position =
		attribute_vertex_position[0] * uniform_camera_right +
		attribute_vertex_position[1] * uniform_camera_up;
}
</script>

<script id="fragment-shader" type="x-shader/x-fragment">
precision highp float;
uniform vec3 uniform_camera_origin;
uniform float uniform_camera_near;
uniform float uniform_camera_far;
varying vec3 varying_pixel_position;
vec4 srgb(float r, float g, float b)
{
	r = clamp(r, 0.0, 1.0);
	g = clamp(g, 0.0, 1.0);
	b = clamp(b, 0.0, 1.0);
#if 1
	float K0 = 0.03928;
	float a = 0.055;
	float phi = 12.92;
	float gamma = 2.4;
	r = r <= K0 / phi ? r * phi : (1.0 + a) * pow(r, 1.0 / gamma) - a;
	g = g <= K0 / phi ? g * phi : (1.0 + a) * pow(g, 1.0 / gamma) - a;
	b = b <= K0 / phi ? b * phi : (1.0 + a) * pow(b, 1.0 / gamma) - a;
#endif
	return vec4(r, g, b, 1.0);
}
struct interval
{
	float min, max;
};
struct surface
{
	vec3 p, n;
};
struct ray
{
	vec3 o, d;
};
struct sphere {
	vec3 c;
	float r;
};
bool sphere_ray(inout interval l, out surface i, sphere s, ray r)
{
	vec3 dst = s.c - r.o;
	float b = dot(dst, r.d);
	float c = dot(dst, dst) - s.r * s.r;
	float d = b * b - c;
	float q = sqrt(d);
	float l0 = b - q;
	float l1 = b + q;
	float lx = l0 < l.min ? l1 : l0;
	i.p = lx * r.d + r.o;
	i.n = (i.p - s.c) / s.r;
	bool t = d >= 0.0 && l.min < lx && lx < l.max;
	l.max = t ? lx : l.max;
	return t;
}
vec4 color(surface i, ray r, bool t)
{
	float v = t ? dot(i.n, r.d) : 0.0;
	return v < 0.0 ? srgb(0.0, -v, 0.0) : srgb(v, 0.0, 0.0);
}
void main()
{
	ray r;
	r.d = normalize(varying_pixel_position - uniform_camera_origin);
	r.o = uniform_camera_origin;
	sphere s = sphere(vec3(0.0, 0.0, 0.0), 0.5);
	interval l = interval(uniform_camera_near, uniform_camera_far);
	surface i;
	bool t = sphere_ray(l, i, s, r);
	gl_FragColor = color(i, r, t);
}
</script>

{'fraction_non_alphanumeric': 0.16979835013748854, 'fraction_numerical': 0.043538038496791935, 'mean_word_length': 3.3346573982125123, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '755776', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1950, 'n_words': 543}