From 2e88c5e0da4618dde5e391a3aa7337b272c12336 Mon Sep 17 00:00:00 2001 From: robnee Date: Thu, 1 Apr 2021 20:52:03 -0400 Subject: [PATCH] Clamp lighting value on export to fix flat colors Also, this fixes the Printf format for the ambient lighting entry on the configuration screen. This was causing string behavior when attempting to edit the ambient lighting value on Windows. Oddly this didn't seem to affect Linux. --- src/confscreen.cpp | 4 +--- src/export.cpp | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/confscreen.cpp b/src/confscreen.cpp index c7e2815a..4a4b7b23 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -236,9 +236,7 @@ void TextWindow::ShowConfiguration() { CO(SS.lightDir[i]), i, &ScreenChangeLightDirection, SS.lightIntensity[i], i, &ScreenChangeLightIntensity); } - Printf(false, "%Bp ambient lighting " - "%2 %Fl%D%f%Ll[c]%E", - (i & 1) ? 'd' : 'a', i, + Printf(false, "%Ba ambient lighting %2 %Fl%f%Ll[c]%E", SS.ambientIntensity, &ScreenChangeLightAmbient); Printf(false, ""); diff --git a/src/export.cpp b/src/export.cpp index b9ebb914..f1c331fd 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -366,9 +366,9 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s // And calculate lighting for the triangle Vector n = tt.Normal().WithMagnitude(1); - double lighting = SS.ambientIntensity + + double lighting = min(1.0, SS.ambientIntensity + max(0.0, (SS.lightIntensity[0])*(n.Dot(l0))) + - max(0.0, (SS.lightIntensity[1])*(n.Dot(l1))); + max(0.0, (SS.lightIntensity[1])*(n.Dot(l1)))); double r = min(1.0, tt.meta.color.redF() * lighting), g = min(1.0, tt.meta.color.greenF() * lighting), b = min(1.0, tt.meta.color.blueF() * lighting);