From 96d705fbefb76227fb501eeedaefbd878b162735 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 31 Dec 2018 15:03:16 +0100 Subject: [PATCH] - change the multisample option to sample in a more predictable manner --- src/lightmap/lightmap.cpp | 28 ++++++++++++---------------- src/main.cpp | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index 39428ee..85bbff8 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -417,27 +417,23 @@ void LightmapBuilder::TraceSurface(Surface *surface) { Vec3 c(0.0f, 0.0f, 0.0f); - for (int k = 0; k < multisampleCount; k++) + int totalsamples = (multisampleCount * 2 + 1); + float scale = 0.5f / totalsamples; + for (int yy = -multisampleCount; yy <= multisampleCount; yy++) { - Vec2 multisamplePos((float)j, (float)i); - if (k > 0) + for (int xx = -multisampleCount; xx <= multisampleCount; xx++) { - multisamplePos.x += rand() / (float)RAND_MAX - 0.5f; - multisamplePos.y += rand() / (float)RAND_MAX - 0.5f; - multisamplePos.x = std::max(multisamplePos.x, 0.0f); - multisamplePos.y = std::max(multisamplePos.y, 0.0f); - multisamplePos.x = std::min(multisamplePos.x, (float)sampleWidth); - multisamplePos.y = std::min(multisamplePos.y, (float)sampleHeight); + Vec2 multisamplePos((float)j + xx * scale, (float)i + yy * scale); + + // convert the texel into world-space coordinates. + // this will be the origin in which a line will be traced from + Vec3 pos = surface->lightmapOrigin + normal + (surface->lightmapSteps[0] * multisamplePos.x) + (surface->lightmapSteps[1] * multisamplePos.y); + + c += LightTexelSample(pos, surface); } - - // convert the texel into world-space coordinates. - // this will be the origin in which a line will be traced from - Vec3 pos = surface->lightmapOrigin + normal + (surface->lightmapSteps[0] * multisamplePos.x) + (surface->lightmapSteps[1] * multisamplePos.y); - - c += LightTexelSample(pos, surface); } - c /= multisampleCount; + c /= totalsamples * totalsamples; colorSamples[i * sampleWidth + j] = c; } diff --git a/src/main.cpp b/src/main.cpp index c9843bc..6654c15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -449,8 +449,8 @@ static void ParseArgs(int argc, char **argv) break; case 'M': Multisample = atoi(optarg); - if (Multisample <= 0) Multisample = 1; - if (Multisample > 64) Multisample = 64; + if (Multisample <= 0) Multisample = 0; + if (Multisample > 16) Multisample = 16; break; case 'B': LightBounce = atoi(optarg);