5 void print2(
int arg0,
int arg1);
7 void print3(
int arg0,
int arg1,
int arg2);
14 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
52 (struct
Node *node, float3 start, float3 dir);
54 (struct
Node *node, float3 start, float3 dir);
56 (struct
Node *node, float3 start, float3 dir);
65 0, 0, (float3){1,0,0} },
67 0, 0, (float3){0,0,1} },
69 0, 1, (float3){1,1,1} },
71 0, 0, (float3){0,1,0} },
73 3, 2, (float3){1,1,1} },
75 0, 0, (float3){0,1,1} },
77 4, 5, (float3){1,1,1} }
95 int ix = fabs(pos[0]);
96 int iy = fabs(pos[1]);
97 int iz = fabs(pos[2]);
98 return ((ix ^ iz) & 1) ?
106 (struct
Node *node, float3 start, float3 dir)
112 float4 plane = node->pos;
113 float n_dot_dir =
dot3f(plane, dir);
114 float n_dot_start =
dot3f(plane, start);
118 float t = (-plane[3] - n_dot_start)
121 float3 p = start + t * dir;
131 (struct
Node *node, float3 start, float3 dir)
133 float4 pos = node->pos;
138 float squared_radius = pos[3];
143 float3 v = start - center;
145 float a =
dot3f(dir, dir);
146 float b = 2 *
dot3f(v, dir);
147 float c =
dot3f(v,v) - squared_radius;
149 float det = b * b - 4 * a * c;
160 float t0 = (-b + s) / (2 * a);
161 float t1 = (-b - s) / (2 * a);
164 float dist = t0 < t1 ? t0 : t1;
167 float3 n = v + dist * dir;
169 float diffuse = fabs(n[0] - n[1] + n[2]);
172 diffuse = diffuse < 0 ? 0 : diffuse;
173 diffuse = diffuse > 1.0 ? 1.0 : diffuse;
177 diffuse * node->
color);
184 (struct
Node *node, float3 start, float3 dir)
187 int left = node->left;
188 int right = node->right;
209 float vx = (2.0/31.0) * x - 1.0;
210 float vy = (-2.0/31.0) * y + 1.0;
211 return (float3){vx, vy, 1};
216 int rgb(
float r,
float g,
float b)
218 return (
int)(r * 255)
219 + ((
int)(g * 255) << 8)
220 + ((int)(b * 255) << 16);
227 (float3 start, float3 dir)
231 (&nodes[6], start, dir);
245 float3 start = (float3){0,1,0};
250 int c =
rgb(color[0], color[1], color[2]);
struct Intersection sphere_intersect(struct Node *node, float3 start, float3 dir)
void raytrace(int x, int y)
struct Intersection(* intersect)(struct Node *node, float3 start, float3 dir)
struct Intersection intersection(float dist, float3 color)
float3 get_color(float3 pos)
struct Intersection plane_intersect(struct Node *node, float3 start, float3 dir)
float float3 __attribute__((vector_size(16)))
float3 view_vec(int x, int y)
float dot3f(float3 a, float3 b)
struct Intersection node_intersect(struct Node *node, float3 start, float3 dir)
float3 raytrace_color(float3 start, float3 dir)
void print3(int arg0, int arg1, int arg2)
x
Return the smallest n such that 2^n >= _x.
int rgb(float r, float g, float b)
void print2(int arg0, int arg1)