From 2203da0c9360611060ee495966ebf29b7479caf2 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 1 Dec 2016 09:00:24 +0100 Subject: [PATCH] Minor simplification of the light calculation --- tools/drawergen/fixedfunction/drawtrianglecodegen.cpp | 9 +++++---- tools/drawergen/fixedfunction/drawtrianglecodegen.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp b/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp index 4184dc5362..fd4809e5d6 100644 --- a/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp +++ b/tools/drawergen/fixedfunction/drawtrianglecodegen.cpp @@ -145,6 +145,8 @@ void DrawTriangleCodegen::Setup() gradWX = gradWX * (float)q; for (int i = 0; i < TriVertex::NumVarying; i++) gradVaryingX[i] = gradVaryingX[i] * (float)q; + + shade = 64.0f - (SSAFloat(light * 255 / 256) + 12.0f) * 32.0f / 128.0f; } SSAFloat DrawTriangleCodegen::gradx(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2) @@ -244,13 +246,12 @@ void DrawTriangleCodegen::LoopBlockX() SSAFloat globVis = SSAFloat(1706.0f); SSAFloat vis = globVis * posx_w; - SSAFloat shade = 64.0f - (SSAFloat(light * 255 / 256) + 12.0f) * 32.0f / 128.0f; - SSAFloat lightscale = SSAFloat::clamp((shade - SSAFloat::MIN(SSAFloat(24.0f), vis)) / 32.0f, SSAFloat(0.0f), SSAFloat(31.0f / 32.0f)); - SSAInt diminishedlight = SSAInt(SSAFloat::clamp((1.0f - lightscale) * 256.0f + 0.5f, SSAFloat(0.0f), SSAFloat(256.0f)), false); + SSAInt lightscale = SSAInt(SSAFloat::clamp((shade - SSAFloat::MIN(SSAFloat(24.0f), vis)) / 32.0f, SSAFloat(0.0f), SSAFloat(31.0f / 32.0f)) * 256.0f, true); + SSAInt diminishedlight = 256 - lightscale; if (!truecolor) { - SSAInt diminishedindex = SSAInt(lightscale * 32.0f, false); + SSAInt diminishedindex = lightscale / 8; SSAInt lightindex = SSAInt::MIN((256 - light) * 32 / 256, SSAInt(31)); SSAInt colormapindex = is_fixed_light.select(lightindex, diminishedindex); currentcolormap = Colormaps[colormapindex << 8]; diff --git a/tools/drawergen/fixedfunction/drawtrianglecodegen.h b/tools/drawergen/fixedfunction/drawtrianglecodegen.h index bc894f1a21..584260a4d0 100644 --- a/tools/drawergen/fixedfunction/drawtrianglecodegen.h +++ b/tools/drawergen/fixedfunction/drawtrianglecodegen.h @@ -136,6 +136,7 @@ private: SSAInt C1, C2, C3; SSAFloat gradWX, gradWY; SSAFloat gradVaryingX[TriVertex::NumVarying], gradVaryingY[TriVertex::NumVarying]; + SSAFloat shade; SSAInt x, y; SSAInt x0, x1, y0, y1;