summaryrefslogtreecommitdiff
path: root/shadeop.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-06-10 15:59:57 +0000
committerrodri <rgl@antares-labs.eu>2024-06-10 15:59:57 +0000
commit213c3a4e99c3085ee89fda550897213abbc888ad (patch)
tree6dead68a5f64ca4d23285ab3dd13a7a36e4fea92 /shadeop.c
parent239a319b41474a35e4c9c4b7c6ae3c6e0b0b7185 (diff)
downloadlibgraphics-213c3a4e99c3085ee89fda550897213abbc888ad.tar.gz
libgraphics-213c3a4e99c3085ee89fda550897213abbc888ad.tar.bz2
libgraphics-213c3a4e99c3085ee89fda550897213abbc888ad.zip
add spotlight params and a light color shading routine. other things.
among these other things are clamping the color channels to [0,1] internally, and adding a modulation function for mixing colors/points.
Diffstat (limited to 'shadeop.c')
-rw-r--r--shadeop.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/shadeop.c b/shadeop.c
index c6080e3..4b74256 100644
--- a/shadeop.c
+++ b/shadeop.c
@@ -30,3 +30,21 @@ smoothstep(double edge0, double edge1, double n)
t = fclamp((n-edge0)/(edge1-edge0), 0, 1);
return t*t * (3 - 2*t);
}
+
+/* TODO apply attenuation for punctual lights */
+Color
+getlightcolor(LightSource *l, Point3 dir)
+{
+ double cθs, cθu, cθp, t;
+
+ /* see “Spotlights”, Real-Time Rendering 4th ed. § 5.2.2 */
+ if(l->type == LIGHT_SPOT){
+ cθs = dotvec3(mulpt3(dir, -1), l->dir);
+ cθu = cos(l->θu);
+ cθp = cos(l->θp);
+// return mulpt3(l->c, smoothstep(cθu, cθp, cθs));
+ t = fclamp((cθs - cθu)/(cθp - cθu), 0, 1);
+ return mulpt3(l->c, t*t);
+ }
+ return l->c;
+}