From af7e89988072a9df47a2622265e017c74936e6d2 Mon Sep 17 00:00:00 2001 From: Martin Opat Date: Mon, 30 Dec 2024 10:46:46 +0100 Subject: [PATCH] Exported phong into its own file --- src/illumination/shading.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/illumination/shading.h diff --git a/src/illumination/shading.h b/src/illumination/shading.h new file mode 100644 index 0000000..26c8db4 --- /dev/null +++ b/src/illumination/shading.h @@ -0,0 +1,20 @@ +#ifndef SHADING_H +#define SHADING_H + +#include "linalg/linalg.h" +#include "consts.h" + +// TODO: Consider wrapping this in a class (?) +__device__ Vec3 phongShading(const Vec3& normal, const Vec3& lightDir, const Vec3& viewDir, const Vec3& baseColor) { + Vec3 ambient = baseColor * ambientStrength; + double diff = fmax(normal.dot(lightDir), 0.0); + Vec3 diffuse = baseColor * (diffuseStrength * diff); + + Vec3 reflectDir = (normal * (2.0 * normal.dot(lightDir)) - lightDir).normalize(); + double spec = pow(fmax(viewDir.dot(reflectDir), 0.0), shininess); + Vec3 specular = Vec3(1.0, 1.0, 1.0) * (specularStrength * spec); + + return ambient + diffuse + specular; +} + +#endif // SHADING_H \ No newline at end of file