Minor simplification of the light calculation

This commit is contained in:
Magnus Norddahl 2016-12-01 09:00:24 +01:00
parent 3890c80b1a
commit 2203da0c93
2 changed files with 6 additions and 4 deletions

View file

@ -145,6 +145,8 @@ void DrawTriangleCodegen::Setup()
gradWX = gradWX * (float)q; gradWX = gradWX * (float)q;
for (int i = 0; i < TriVertex::NumVarying; i++) for (int i = 0; i < TriVertex::NumVarying; i++)
gradVaryingX[i] = gradVaryingX[i] * (float)q; 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) 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 globVis = SSAFloat(1706.0f);
SSAFloat vis = globVis * posx_w; SSAFloat vis = globVis * posx_w;
SSAFloat shade = 64.0f - (SSAFloat(light * 255 / 256) + 12.0f) * 32.0f / 128.0f; 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);
SSAFloat lightscale = SSAFloat::clamp((shade - SSAFloat::MIN(SSAFloat(24.0f), vis)) / 32.0f, SSAFloat(0.0f), SSAFloat(31.0f / 32.0f)); SSAInt diminishedlight = 256 - lightscale;
SSAInt diminishedlight = SSAInt(SSAFloat::clamp((1.0f - lightscale) * 256.0f + 0.5f, SSAFloat(0.0f), SSAFloat(256.0f)), false);
if (!truecolor) if (!truecolor)
{ {
SSAInt diminishedindex = SSAInt(lightscale * 32.0f, false); SSAInt diminishedindex = lightscale / 8;
SSAInt lightindex = SSAInt::MIN((256 - light) * 32 / 256, SSAInt(31)); SSAInt lightindex = SSAInt::MIN((256 - light) * 32 / 256, SSAInt(31));
SSAInt colormapindex = is_fixed_light.select(lightindex, diminishedindex); SSAInt colormapindex = is_fixed_light.select(lightindex, diminishedindex);
currentcolormap = Colormaps[colormapindex << 8]; currentcolormap = Colormaps[colormapindex << 8];

View file

@ -136,6 +136,7 @@ private:
SSAInt C1, C2, C3; SSAInt C1, C2, C3;
SSAFloat gradWX, gradWY; SSAFloat gradWX, gradWY;
SSAFloat gradVaryingX[TriVertex::NumVarying], gradVaryingY[TriVertex::NumVarying]; SSAFloat gradVaryingX[TriVertex::NumVarying], gradVaryingY[TriVertex::NumVarying];
SSAFloat shade;
SSAInt x, y; SSAInt x, y;
SSAInt x0, x1, y0, y1; SSAInt x0, x1, y0, y1;