author ethereal Wed, 24 Jun 2015 04:14:32 +0000 (04:14 +0000) committer ethereal Wed, 24 Jun 2015 04:14:32 +0000 (04:14 +0000)
 src/ecore/render.c patch | blob | history src/ewrap/main.c patch | blob | history

index 3557e58..de9e8f9 100644 (file)
@@ -82,26 +82,36 @@ vector_t trace(vector_t *ray, vector_t *dir, int depth) {
intersection.c = ray->c + dir->c*min_i;
intersection.c = ray->c + dir->c*min_i;
intersection.c = ray->c + dir->c*min_i;
-
-    shm_mat_t *mat = materials + spheres[min_ind].mat;
+    intersection.c = 0.0;

/* Calculate normal. */
vector_t normal;
normal.c = intersection.c - spheres[min_ind].x;
normal.c = intersection.c - spheres[min_ind].y;
normal.c = intersection.c - spheres[min_ind].z;
+    normal.c = 0.0;
norm_vector(&normal);

/* Do we need to do a recursive raycast? */
vector_t ret;
ret.c = ret.c = ret.c = ret.c = 0.0;
-    if(mat->ref > 0 && depth) {
+
+    shm_mat_t *mat = materials + spheres[min_ind].mat;
+    if(mat->ref > 0 && depth && 0) {
vector_t r;
-        /* r = n*(2 * n.dot(-dir)) + dir */
+        /* formula: r = d - 2(dn)n */
mul_vector(&normal, -2 * dot_vectors(&normal, dir), &r);
+        norm_vector(&r);
+
+        set_vector(&r, 0.0, 0.0, -1.0, 0.0);
+
+        vector_t rloc;
+        mul_vector(&r, 1000, &rloc);

-        ret = trace(&intersection, &r, depth-1);
+        ret = trace(&rloc, &r, depth-1);
+        mul_vector(&ret, mat->ref, &ret);
}

/* Do lighting calculations for each light. */
@@ -212,7 +222,7 @@ void render_range() {
norm_vector(&ray_dir);

/* Begin trace */
-        vector_t col = trace(&cam_pos, &ray_dir, 2);
+        vector_t col = trace(&cam_pos, &ray_dir, 3);

/* Write back result into framebuffer. */
uint32_t result = 0;
index 24cd3a4..42eaf4a 100644 (file)
@@ -81,36 +81,39 @@ int main() {
material->shininess = 1.0;
material->sr = material->sg = material->sb = 1.0;
material->a = material->s = material->d = 1.0;
+    material->ref = 0.0;
+
material ++;
material->r = material->b = 0.0;
material->g = 1.0;
material->shininess = 1.0;
material->sr = material->sg = material->sb = 1.0;
material->a = material->s = material->d = 1.0;
+    material->ref = 0.0;

shm_region->sph_count = 2;
shm_region->sph_off = shm_region->mat_off + sizeof(*material)*shm_region->mat_count;
shm_sph_t *sphere = (void *)((uint8_t*)shm_region + shm_region->sph_off);
-    sphere->x = 0.3;
+    sphere->x = 0.5;
sphere->y = 0.0;
-    sphere->z = 1.1;
-    sphere->r = 0.3;
+    sphere->z = 3.1;
+    sphere->r = 0.5;
sphere->mat = 0;

sphere ++;
-    sphere->x = -0.3;
+    sphere->x = -0.5;
sphere->y = 0.0;
-    sphere->z = 1.0;
-    sphere->r = 0.3;
+    sphere->z = 3.1;
+    sphere->r = 0.5;
sphere->mat = 1;

shm_region->light_count = 1;
shm_region->light_off = shm_region->sph_off + sizeof(*sphere)*shm_region->sph_count;
shm_light_t *light = (void *)((uint8_t*)shm_region + shm_region->light_off);
-    light->x = 0;
+    light->x = 1;
light->y = 0;
light->z = 0;
-    light->a = 0.3;
+    light->a = 0.0;
light->d = 1.0;
light->s = 0.0;
light->r = 1.0;