diff options
author | Julian T <julian@jtle.dk> | 2020-02-23 18:30:21 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-02-23 18:30:21 +0100 |
commit | b0079eaa628a1f2fd99014cd12e6baac17f4d17a (patch) | |
tree | 5925033b7d27a7f0263c19b7babc97fbeb700a93 /pgm.c | |
parent | 9b40029e42f994aeff59ecc44a6d3b8fba93071d (diff) |
Added phong light model and fixed sphere intersect
Diffstat (limited to 'pgm.c')
-rw-r--r-- | pgm.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -32,9 +32,14 @@ color_t *color_add(color_t *dest, color_t *a, color_t *b) dest = (color_t *) malloc(sizeof(dest)); } - dest->r = a->r + b->r; - dest->g = a->g + b->g; - dest->b = a->b + b->b; + unsigned int tmp = a->r + b->r; + dest->r = tmp > 255 ? 255 : tmp; + + tmp = a->g + b->g; + dest->g = tmp > 255 ? 255 : tmp; + + tmp = a->b + b->b; + dest->b = tmp > 255 ? 255 : tmp; return dest; } @@ -45,9 +50,14 @@ color_t *color_scale(color_t *dest, color_t *a, float b) dest = (color_t *) malloc(sizeof(dest)); } - dest->r = a->r * b; - dest->g = a->g * b; - dest->b = a->b * b; + unsigned int tmp = a->r * b; + dest->r = tmp > 255 ? 255 : tmp; + + tmp = a->g * b; + dest->g = tmp > 255 ? 255 : tmp; + + tmp = a->b * b; + dest->b = tmp > 255 ? 255 : tmp; return dest; } |