From eaec325ab48279b3b85767c3bee840935b8484df Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Thu, 8 Sep 2016 21:39:37 -0600 Subject: [PATCH] light: bounce: area-weight the patches when averaging them to get the light to emit for a face --- light/light.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/light/light.cc b/light/light.cc index 89ababeb..0c5ebf57 100644 --- a/light/light.cc +++ b/light/light.cc @@ -871,14 +871,18 @@ MakeBounceLightsThread (void *arg) DiceWinding(winding, 64.0f, SaveWindingFn, &args); winding = nullptr; // DiceWinding frees winding - // average them + // average them, area weighted vec3_t sum = {0,0,0}; + float totalarea = 0; if (patches.size()) { for (const auto &patch : patches) { - VectorAdd(sum, patch->directlight, sum); + const float patcharea = WindingArea(patch->w); + totalarea += patcharea; + + VectorMA(sum, patcharea, patch->directlight, sum); // printf(" %f %f %f\n", patch->directlight[0], patch->directlight[1], patch->directlight[2]); } - VectorScale(sum, 1.0/patches.size(), sum); + VectorScale(sum, 1.0/totalarea, sum); } vec3_t texturecolor;