aboutsummaryrefslogtreecommitdiff
path: root/pgm.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-23 18:30:21 +0100
committerJulian T <julian@jtle.dk>2020-02-23 18:30:21 +0100
commitb0079eaa628a1f2fd99014cd12e6baac17f4d17a (patch)
tree5925033b7d27a7f0263c19b7babc97fbeb700a93 /pgm.c
parent9b40029e42f994aeff59ecc44a6d3b8fba93071d (diff)
Added phong light model and fixed sphere intersect
Diffstat (limited to 'pgm.c')
-rw-r--r--pgm.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/pgm.c b/pgm.c
index 90791de..efc50f7 100644
--- a/pgm.c
+++ b/pgm.c
@@ -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;
}