diff options
author | Morten Hustveit <morten.hustveit@gmail.com> | 2014-12-02 15:50:45 -0500 |
---|---|---|
committer | Morten Hustveit <morten.hustveit@gmail.com> | 2014-12-02 15:50:45 -0500 |
commit | 64a24eff5995c44d21e42d0bc654739030eca76c (patch) | |
tree | 8c0e5eaabf695d6791b20ac9409188b02c539d7b /ray.c | |
parent | ce39f5c767ae25ed884aa24120e340d154442342 (diff) |
ray.c: Don't look for self in reflection on self
Diffstat (limited to 'ray.c')
-rw-r--r-- | ray.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -47,11 +47,13 @@ static Light lights[] = { }; static void -trace(float s[3], const float d[3], float pixel[3], int n) { +trace(const float s[3], const float d[3], float pixel[3], int n, unsigned int mask) { int i, j, k, m; float l[3], r[3], t, y[3]; for(j = 0; j < LENGTH(objects); ++j) { + if ((1 << j) & mask) continue; + t = sphere_intersect(y, r, s, d, objects[j].position, objects[j].radius); if(t > 0) { @@ -66,7 +68,7 @@ trace(float s[3], const float d[3], float pixel[3], int n) { pixel[k] += lights[m].diffuse[k] * objects[j].diffuse[k] * scale; } - trace(y, r, pixel, n + 1); + trace(y, r, pixel, n + 1, (1 << j)); } } } @@ -79,7 +81,7 @@ trace_line(int l, unsigned char *buf) { for(int i = 0; i < WIDTH; ++i, buf += 4) { float pixel[3] = { 0, 0, 0 }; - trace(s, trace_vectors[l][i], pixel, 1); + trace(s, trace_vectors[l][i], pixel, 1, 0); buf[0] = MIN(pixel[0], 1.0f) * 255; buf[1] = MIN(pixel[1], 1.0f) * 255; |