aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pgm.ino (renamed from pgm.c)0
-rw-r--r--ray.ino (renamed from ray.c)10
-rw-r--r--raytrace.ino (renamed from main.c)38
-rw-r--r--scene.ino (renamed from scene.c)13
-rw-r--r--vector.ino (renamed from vector.c)2
-rw-r--r--viewpoint.ino (renamed from viewpoint.c)7
6 files changed, 33 insertions, 37 deletions
diff --git a/pgm.c b/pgm.ino
index eb0c101..eb0c101 100644
--- a/pgm.c
+++ b/pgm.ino
diff --git a/ray.c b/ray.ino
index a41866c..4ec0799 100644
--- a/ray.c
+++ b/ray.ino
@@ -89,7 +89,7 @@ COORD_T ray_intersect(object_t *o, ray_t *ray, bool skip_dist)
case TYPE_SPHERE:
return ray_intersect_sphere(&o->sph, ray, skip_dist);
default:
- printf("Unknown object type %d\n", o->type);
+ //printf("Unknown object type %d\n", o->type);
return -1;
}
}
@@ -262,15 +262,15 @@ int ray_trace_recur(space_t *s, color_t *dest, ray_t *ray, unsigned hop, COORD_T
color_t c;
color_set(&c, 0, 0, 0);
+ vector_t rdir, rstart;
+ ray_t r = {start: &rstart, direction: &rdir};
+
object_t *o = ray_cast(s, ray, &dist, false, 0);
if (!o) {
color_add(&c, &c, &s->back);
goto exit;
}
- vector_t rdir, rstart;
- ray_t r = {start: &rstart, direction: &rdir};
-
vector_scale(r.start, ray->direction, dist);
vector_add(r.start, r.start, ray->start);
@@ -323,7 +323,7 @@ void ray_trace(space_t *s, unsigned int x, unsigned int y, unsigned samples, col
// Multiple samples for antialias
// TODO better distribution of antialias probes
- for (int i = 0; i < samples; i++) {
+ for (unsigned i = 0; i < samples; i++) {
color_t ctmp;
color_set(&ctmp, 0, 0, 0);
//memset(&ctmp, 0, sizeof(color_t));
diff --git a/main.c b/raytrace.ino
index c27096c..8301758 100644
--- a/main.c
+++ b/raytrace.ino
@@ -7,37 +7,41 @@
#include "scene.h"
#include "pgm.h"
-#define TESTW 1000
-#define TESTH 1000
+#define TESTW 320
+#define TESTH 240
char container[ CONTAINER_SIZE(5, 4, 1) ];
// Implement random
COORD_T ray_rand(void *seed)
{
- return (COORD_T) rand_r( (int *)seed ) / RAND_MAX;
+ return (COORD_T) random(10000) / 10000;
}
-int main()
+void setup()
{
+ Serial.begin(115200);
+ Serial.println("Starting");
container_t *cont = (container_t *) container;
container_init(cont, 5, 4, 1);
// Init space_t
- space_t *s = container_prepare_space(cont);;
+ space_t *s = container_prepare_space(cont);
+ Serial.println("Starting");
// Set space options
color_set(&s->ambient, 0.09, 0.09, 0.09);
color_set(&s->back, 0.8, 0.8, 0.8);
color_set(&s->env_color, 0.13, 0.13, 0.13);
- s->env_samples = 16;
+ s->env_samples = 256;
// Set viewpoint options
vector_set(&s->view.position, 0, 16, 6);
vector_set(&s->view.target, 0, 0, 6);
s->view.width = TESTW;
s->view.height = TESTH;
+ Serial.println("Starting");
// Create materials
material_t *m = add_material(cont);
@@ -53,6 +57,7 @@ int main()
m3->specular = 0.0;
m3->shine = 80;
m3->reflective = 0.05;
+ Serial.println("Starting");
material_t *m2 = add_material(cont);
vector_set(&m2->color, 1, 1, 1);
@@ -60,6 +65,7 @@ int main()
m2->specular = 0.5;
m2->shine = 80;
m2->reflective = 1;
+ Serial.println("Starting");
material_t *mpl = add_material(cont);
//vector_set(&mpl.color, 0, 0.396, 0.7019);
@@ -81,6 +87,7 @@ int main()
vector_set(&o->sph.center, 8, 8, 4);
o->sph.radius = 2;
o->m = m3;
+ Serial.println("Starting");
o = add_object(cont, TYPE_SPHERE);
vector_set(&o->sph.center, -10, 9, 5);
@@ -104,25 +111,16 @@ int main()
pgm_write_header(stdout, TESTW, TESTH);
- // Height percentage
- unsigned percentstep = TESTH / 100;
- unsigned percent = 0;
- int seed;
-
for (int y = TESTH; y; y--) {
for (int x = TESTW; x; x--) {
// Random seed
- seed = x * y;
color_t c;
- ray_trace(&cont->space, x, y, 2, &c, &seed);
-
- pgm_write_pixel(stdout, &c);
-
- }
-
- if (y % percentstep == 0) {
- fprintf(stderr, "%d%\n", percent++);
+ ray_trace(&cont->space, x, y, 2, &c, NULL);
}
+ Serial.print("row "); Serial.println(y);
}
}
+
+void loop() {
+}
diff --git a/scene.c b/scene.ino
index 6221fe8..77dbdc1 100644
--- a/scene.c
+++ b/scene.ino
@@ -26,7 +26,12 @@ container_t *container_init(container_t *c, unsigned objs, unsigned mats, unsign
space_t *container_prepare_space(container_t *c)
{
- memset(&c->space, 0, sizeof(space_t));
+ //memset(&c->space, 0, sizeof(space_t));
+ for (int i = 0; i < sizeof(space_t); i++) {
+ *(uint8_t *)&c->space = 0;
+ }
+
+ return &c->space;
}
// Finds the next empty object_t space
@@ -34,7 +39,7 @@ space_t *container_prepare_space(container_t *c)
static inline object_t *container_obj_space(container_t *cont)
{
if (cont->obj_index >= cont->obj_cap) {
- fprintf(stderr, "Could not create object, because container is full\n");
+ //fprintf(stderr, "Could not create object, because container is full\n");
return NULL;
}
@@ -45,7 +50,7 @@ static inline object_t *container_obj_space(container_t *cont)
static inline material_t *container_mat_space(container_t *cont)
{
if (cont->mat_index >= cont->mat_cap) {
- fprintf(stderr, "Could not create material, because container is full\n");
+ //fprintf(stderr, "Could not create material, because container is full\n");
return NULL;
}
@@ -60,7 +65,7 @@ static inline material_t *container_mat_space(container_t *cont)
static inline light_t *container_lig_space(container_t *cont)
{
if (cont->lig_index >= cont->lig_cap) {
- fprintf(stderr, "Could not create light, because container is full\n");
+ //fprintf(stderr, "Could not create light, because container is full\n");
return NULL;
}
diff --git a/vector.c b/vector.ino
index 0bcd1dc..d56cf85 100644
--- a/vector.c
+++ b/vector.ino
@@ -116,5 +116,5 @@ vector_t *vector_cross(vector_t *dest, vector_t *a, vector_t *b)
void vector_print(vector_t *v)
{
- printf("[ %f, %f, %f ]\n", v->x, v->y, v->z);
+ Serial.println("Not implemented");
}
diff --git a/viewpoint.c b/viewpoint.ino
index e8d2a1e..62ff08a 100644
--- a/viewpoint.c
+++ b/viewpoint.ino
@@ -36,13 +36,6 @@ void viewpoint_init(viewpoint_t *view)
vector_sub(&view->blc, &view->blc, vector_scale(&b, &b, gx));
vector_sub(&view->blc, &view->blc, vector_scale(&v, &v, gy));
- // Debug print
- /*
- printf("Calculated the following viewpoint stuff\n");
- printf("qx"); vector_print(&view->qx);
- printf("qy"); vector_print(&view->qy);
- printf("blc"); vector_print(&view->blc);
- */
}
// Calculate ray for viewport w, h