feat: added lighting

This commit is contained in:
2025-12-20 21:07:16 +01:00
parent 7ab3825598
commit beacb9a985
2 changed files with 26 additions and 10 deletions

View File

@@ -58,6 +58,14 @@ struct polygon {
small = true;*/
}
vec3 avgNormal() {
vec3 result;
for (int i = 0; i++; i < 3) {
result += normals[i];
}
return result * decimal(0.3333);
}
const bool contains(const vec3 &p) {
// if (skip)
// return false;
@@ -82,7 +90,10 @@ struct polygon {
vec3 result = normals[0] * barycentrics[0] +
normals[1] * barycentrics[1] +
normals[2] * barycentrics[2];
return result.normalize();
if (result.isSmall())
return normals[0];
else
return result.normalize();
}
vec3 calcColor(vec3 barycentrics) {
@@ -97,8 +108,8 @@ struct polygon {
}
vec3 calcBarycentric(vec3 s) {
if (small)
return vec3(decimal(0.333), decimal(0.333), decimal(0.333));
// if (small)
// return vec3(decimal(0.333), decimal(0.333), decimal(0.333));
vec3 result;
result[0] = (points[1].x() - s.x()) * (points[2].y() - s.y()) -
(points[2].x() - s.x()) * (points[1].y() - s.y());
@@ -106,7 +117,9 @@ struct polygon {
(points[0].x() - s.x()) * (points[2].y() - s.y());
result = result * baryFactor;
result[2] = decimal(1.0) - result[1] - result[0];
return result;
// return result;
return vec3::max(vec3::min(result, vec3(1.0, 1.0, 1.0)),
vec3(0.0, 0.0, 0.0));
}
};