- remove TriVertex::NumVaryings as this did not help on readability at all

This commit is contained in:
Magnus Norddahl 2017-03-28 10:52:19 +02:00
parent 5adf7463cd
commit d15def7d41
12 changed files with 155 additions and 176 deletions

View file

@ -92,13 +92,13 @@ public:
ScreenTriangleStepVariables start; ScreenTriangleStepVariables start;
gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w); gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w); gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
gradientX.U = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
gradientY.U = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
gradientX.V = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
gradientY.V = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
start.W = v1.w + gradientX.W * (startX - v1.x) + gradientY.W * (startY - v1.y); start.W = v1.w + gradientX.W * (startX - v1.x) + gradientY.W * (startY - v1.y);
for (int i = 0; i < TriVertex::NumVarying; i++) start.U = v1.u * v1.w + gradientX.U * (startX - v1.x) + gradientY.U * (startY - v1.y);
{ start.V = v1.v * v1.w + gradientX.V * (startX - v1.x) + gradientY.V * (startY - v1.y);
gradientX.Varying[i] = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.varying[i] * v1.w, v2.varying[i] * v2.w, v3.varying[i] * v3.w);
gradientY.Varying[i] = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.varying[i] * v1.w, v2.varying[i] * v2.w, v3.varying[i] * v3.w);
start.Varying[i] = v1.varying[i] * v1.w + gradientX.Varying[i] * (startX - v1.x) + gradientY.Varying[i] * (startY - v1.y);
}
// Output // Output
uint32_t * RESTRICT destOrg = (uint32_t*)args->dest; uint32_t * RESTRICT destOrg = (uint32_t*)args->dest;
@ -157,17 +157,16 @@ public:
ScreenTriangleStepVariables blockPosY; ScreenTriangleStepVariables blockPosY;
blockPosY.W = start.W + gradientX.W * (span.X - startX) + gradientY.W * (span.Y - startY); blockPosY.W = start.W + gradientX.W * (span.X - startX) + gradientY.W * (span.Y - startY);
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U = start.U + gradientX.U * (span.X - startX) + gradientY.U * (span.Y - startY);
blockPosY.Varying[j] = start.Varying[j] + gradientX.Varying[j] * (span.X - startX) + gradientY.Varying[j] * (span.Y - startY); blockPosY.V = start.V + gradientX.V * (span.X - startX) + gradientY.V * (span.Y - startY);
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
@ -175,16 +174,14 @@ public:
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -201,15 +198,15 @@ public:
// Sample fgcolor // Sample fgcolor
unsigned int ifgcolor[2], ifgshade[2]; unsigned int ifgcolor[2], ifgshade[2];
ifgcolor[0] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[0] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[0] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[0] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
ifgcolor[1] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[1] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[1] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[1] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
// Setup light // Setup light
int lightpos0 = lightpos >> 8; int lightpos0 = lightpos >> 8;
@ -240,8 +237,8 @@ public:
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }
@ -253,8 +250,8 @@ public:
ScreenTriangleStepVariables blockPosY; ScreenTriangleStepVariables blockPosY;
blockPosY.W = start.W + gradientX.W * (block.X - startX) + gradientY.W * (block.Y - startY); blockPosY.W = start.W + gradientX.W * (block.X - startX) + gradientY.W * (block.Y - startY);
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U = start.U + gradientX.U * (block.X - startX) + gradientY.U * (block.Y - startY);
blockPosY.Varying[j] = start.Varying[j] + gradientX.Varying[j] * (block.X - startX) + gradientY.Varying[j] * (block.Y - startY); blockPosY.V = start.V + gradientX.V * (block.X - startX) + gradientY.V * (block.Y - startY);
uint32_t *dest = destOrg + block.X + block.Y * pitch; uint32_t *dest = destOrg + block.X + block.Y * pitch;
uint32_t mask0 = block.Mask0; uint32_t mask0 = block.Mask0;
@ -266,24 +263,21 @@ public:
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -304,15 +298,15 @@ public:
// Sample fgcolor // Sample fgcolor
unsigned int ifgcolor[2], ifgshade[2]; unsigned int ifgcolor[2], ifgshade[2];
ifgcolor[0] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[0] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[0] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[0] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
ifgcolor[1] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[1] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[1] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[1] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
// Setup light // Setup light
int lightpos0 = lightpos >> 8; int lightpos0 = lightpos >> 8;
@ -346,8 +340,8 @@ public:
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }
@ -358,24 +352,21 @@ public:
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -396,15 +387,15 @@ public:
// Sample fgcolor // Sample fgcolor
unsigned int ifgcolor[2], ifgshade[2]; unsigned int ifgcolor[2], ifgshade[2];
ifgcolor[0] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[0] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[0] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[0] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
ifgcolor[1] = Sample<FilterModeT>(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, oneU, oneV, color, translation); ifgcolor[1] = Sample<FilterModeT>(posU, posV, texPixels, texWidth, texHeight, oneU, oneV, color, translation);
ifgshade[1] = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); ifgshade[1] = SampleShade(posU, posV, texPixels, texWidth, texHeight);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
// Setup light // Setup light
int lightpos0 = lightpos >> 8; int lightpos0 = lightpos >> 8;
@ -438,8 +429,8 @@ public:
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }

View file

@ -54,13 +54,13 @@ public:
ScreenTriangleStepVariables start; ScreenTriangleStepVariables start;
gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w); gradientX.W = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w); gradientY.W = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.w, v2.w, v3.w);
gradientX.U = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
gradientY.U = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.u * v1.w, v2.u * v2.w, v3.u * v3.w);
gradientX.V = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
gradientY.V = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.v * v1.w, v2.v * v2.w, v3.v * v3.w);
start.W = v1.w + gradientX.W * (startX - v1.x) + gradientY.W * (startY - v1.y); start.W = v1.w + gradientX.W * (startX - v1.x) + gradientY.W * (startY - v1.y);
for (int i = 0; i < TriVertex::NumVarying; i++) start.U = v1.u * v1.w + gradientX.U * (startX - v1.x) + gradientY.U * (startY - v1.y);
{ start.V = v1.v * v1.w + gradientX.V * (startX - v1.x) + gradientY.V * (startY - v1.y);
gradientX.Varying[i] = FindGradientX(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.varying[i] * v1.w, v2.varying[i] * v2.w, v3.varying[i] * v3.w);
gradientY.Varying[i] = FindGradientY(v1.x, v1.y, v2.x, v2.y, v3.x, v3.y, v1.varying[i] * v1.w, v2.varying[i] * v2.w, v3.varying[i] * v3.w);
start.Varying[i] = v1.varying[i] * v1.w + gradientX.Varying[i] * (startX - v1.x) + gradientY.Varying[i] * (startY - v1.y);
}
// Output // Output
uint8_t * RESTRICT destOrg = args->dest; uint8_t * RESTRICT destOrg = args->dest;
@ -89,17 +89,16 @@ public:
ScreenTriangleStepVariables blockPosY; ScreenTriangleStepVariables blockPosY;
blockPosY.W = start.W + gradientX.W * (span.X - startX) + gradientY.W * (span.Y - startY); blockPosY.W = start.W + gradientX.W * (span.X - startX) + gradientY.W * (span.Y - startY);
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U = start.U + gradientX.U * (span.X - startX) + gradientY.U * (span.Y - startY);
blockPosY.Varying[j] = start.Varying[j] + gradientX.Varying[j] * (span.X - startX) + gradientY.Varying[j] * (span.Y - startY); blockPosY.V = start.V + gradientX.V * (span.X - startX) + gradientY.V * (span.Y - startY);
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (int)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
@ -107,16 +106,14 @@ public:
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -126,18 +123,18 @@ public:
{ {
int lightshade = lightpos >> 8; int lightshade = lightpos >> 8;
uint8_t bgcolor = dest[x * 8 + ix]; uint8_t bgcolor = dest[x * 8 + ix];
uint8_t fgcolor = Sample(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, color, translation); uint8_t fgcolor = Sample(posU, posV, texPixels, texWidth, texHeight, color, translation);
uint32_t fgshade = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); uint32_t fgshade = SampleShade(posU, posV, texPixels, texWidth, texHeight);
dest[x * 8 + ix] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); dest[x * 8 + ix] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha);
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
lightpos += lightstep; lightpos += lightstep;
} }
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }
@ -149,8 +146,8 @@ public:
ScreenTriangleStepVariables blockPosY; ScreenTriangleStepVariables blockPosY;
blockPosY.W = start.W + gradientX.W * (block.X - startX) + gradientY.W * (block.Y - startY); blockPosY.W = start.W + gradientX.W * (block.X - startX) + gradientY.W * (block.Y - startY);
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U = start.U + gradientX.U * (block.X - startX) + gradientY.U * (block.Y - startY);
blockPosY.Varying[j] = start.Varying[j] + gradientX.Varying[j] * (block.X - startX) + gradientY.Varying[j] * (block.Y - startY); blockPosY.V = start.V + gradientX.V * (block.X - startX) + gradientY.V * (block.Y - startY);
uint8_t *dest = destOrg + block.X + block.Y * pitch; uint8_t *dest = destOrg + block.X + block.Y * pitch;
uint32_t mask0 = block.Mask0; uint32_t mask0 = block.Mask0;
@ -162,24 +159,21 @@ public:
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -191,21 +185,21 @@ public:
{ {
int lightshade = lightpos >> 8; int lightshade = lightpos >> 8;
uint8_t bgcolor = dest[x]; uint8_t bgcolor = dest[x];
uint8_t fgcolor = Sample(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, color, translation); uint8_t fgcolor = Sample(posU, posV, texPixels, texWidth, texHeight, color, translation);
uint32_t fgshade = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); uint32_t fgshade = SampleShade(posU, posV, texPixels, texWidth, texHeight);
dest[x] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); dest[x] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha);
} }
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
lightpos += lightstep; lightpos += lightstep;
mask0 <<= 1; mask0 <<= 1;
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }
@ -216,24 +210,21 @@ public:
ScreenTriangleStepVariables blockPosX = blockPosY; ScreenTriangleStepVariables blockPosX = blockPosY;
float rcpW = 0x01000000 / blockPosX.W; float rcpW = 0x01000000 / blockPosX.W;
int32_t varyingPos[TriVertex::NumVarying]; int32_t posU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t posV = (int32_t)(blockPosX.V * rcpW);
varyingPos[j] = (int32_t)(blockPosX.Varying[j] * rcpW);
fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightpos = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosY.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask); lightpos = (lightpos & lightmask) | ((light << 8) & ~lightmask);
blockPosX.W += gradientX.W * 8; blockPosX.W += gradientX.W * 8;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosX.U += gradientX.U * 8;
blockPosX.Varying[j] += gradientX.Varying[j] * 8; blockPosX.V += gradientX.V * 8;
rcpW = 0x01000000 / blockPosX.W; rcpW = 0x01000000 / blockPosX.W;
int32_t varyingStep[TriVertex::NumVarying]; int32_t nextU = (int32_t)(blockPosX.U * rcpW);
for (int j = 0; j < TriVertex::NumVarying; j++) int32_t nextV = (int32_t)(blockPosX.V * rcpW);
{ int32_t stepU = (nextU - posU) / 8;
int32_t nextPos = (int32_t)(blockPosX.Varying[j] * rcpW); int32_t stepV = (nextV - posV) / 8;
varyingStep[j] = (nextPos - varyingPos[j]) / 8;
}
fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT); fixed_t lightnext = FRACUNIT - (fixed_t)(clamp(shade - MIN(24.0f / 32.0f, globVis * blockPosX.W), 0.0f, 31.0f / 32.0f) * (float)FRACUNIT);
fixed_t lightstep = (lightnext - lightpos) / 8; fixed_t lightstep = (lightnext - lightpos) / 8;
@ -245,21 +236,21 @@ public:
{ {
int lightshade = lightpos >> 8; int lightshade = lightpos >> 8;
uint8_t bgcolor = dest[x]; uint8_t bgcolor = dest[x];
uint8_t fgcolor = Sample(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight, color, translation); uint8_t fgcolor = Sample(posU, posV, texPixels, texWidth, texHeight, color, translation);
uint32_t fgshade = SampleShade(varyingPos[0], varyingPos[1], texPixels, texWidth, texHeight); uint32_t fgshade = SampleShade(posU, posV, texPixels, texWidth, texHeight);
dest[x] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha); dest[x] = ShadeAndBlend(fgcolor, bgcolor, fgshade, lightshade, colormaps, srcalpha, destalpha);
} }
for (int j = 0; j < TriVertex::NumVarying; j++) posU += stepU;
varyingPos[j] += varyingStep[j]; posV += stepV;
lightpos += lightstep; lightpos += lightstep;
mask1 <<= 1; mask1 <<= 1;
} }
blockPosY.W += gradientY.W; blockPosY.W += gradientY.W;
for (int j = 0; j < TriVertex::NumVarying; j++) blockPosY.U += gradientY.U;
blockPosY.Varying[j] += gradientY.Varying[j]; blockPosY.V += gradientY.V;
dest += pitch; dest += pitch;
} }

View file

@ -232,13 +232,12 @@ void PolyTriangleDrawer::draw_shaded_triangle(const ShadedTriVertex *vert, bool
// Keep varyings in -128 to 128 range if possible // Keep varyings in -128 to 128 range if possible
if (numclipvert > 0) if (numclipvert > 0)
{ {
for (int j = 0; j < TriVertex::NumVarying; j++) float newOriginU = floorf(clippedvert[0].u * 0.1f) * 10.0f;
{ float newOriginV = floorf(clippedvert[0].v * 0.1f) * 10.0f;
float newOrigin = floorf(clippedvert[0].varying[j] * 0.1f) * 10.0f;
for (int i = 0; i < numclipvert; i++) for (int i = 0; i < numclipvert; i++)
{ {
clippedvert[i].varying[j] -= newOrigin; clippedvert[i].u -= newOriginU;
} clippedvert[i].v -= newOriginV;
} }
} }
@ -424,8 +423,8 @@ int PolyTriangleDrawer::clipedge(const ShadedTriVertex *verts, TriVertex *clippe
v.y += verts[w].y * weight; v.y += verts[w].y * weight;
v.z += verts[w].z * weight; v.z += verts[w].z * weight;
v.w += verts[w].w * weight; v.w += verts[w].w * weight;
for (int iv = 0; iv < TriVertex::NumVarying; iv++) v.u += verts[w].u * weight;
v.varying[iv] += verts[w].varying[iv] * weight; v.v += verts[w].v * weight;
} }
} }
return inputverts; return inputverts;

View file

@ -61,11 +61,10 @@ struct WorkerThreadData
struct TriVertex struct TriVertex
{ {
TriVertex() { } TriVertex() { }
TriVertex(float x, float y, float z, float w, float u, float v) : x(x), y(y), z(z), w(w) { varying[0] = u; varying[1] = v; } TriVertex(float x, float y, float z, float w, float u, float v) : x(x), y(y), z(z), w(w), u(u), v(v) { }
enum { NumVarying = 2 };
float x, y, z, w; float x, y, z, w;
float varying[NumVarying]; float u, v;
}; };
struct TriDrawTriangleArgs struct TriDrawTriangleArgs
@ -126,8 +125,7 @@ public:
struct ScreenTriangleStepVariables struct ScreenTriangleStepVariables
{ {
float W; float W, U, V;
float Varying[TriVertex::NumVarying];
}; };
namespace TriScreenDrawerModes namespace TriScreenDrawerModes

View file

@ -199,7 +199,7 @@ ShadedTriVertex TriMatrix::operator*(TriVertex v) const
ShadedTriVertex sv; ShadedTriVertex sv;
_mm_storeu_ps(&sv.x, mv); _mm_storeu_ps(&sv.x, mv);
#endif #endif
for (int i = 0; i < TriVertex::NumVarying; i++) sv.u = v.u;
sv.varying[i] = v.varying[i]; sv.v = v.v;
return sv; return sv;
} }

View file

@ -123,10 +123,10 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &
vertices[i].y = (float)p.Y; vertices[i].y = (float)p.Y;
vertices[i].z = (float)(zpos + spriteHeight * offsets[i].second - spriteHeight * 0.5); vertices[i].z = (float)(zpos + spriteHeight * offsets[i].second - spriteHeight * 0.5);
vertices[i].w = 1.0f; vertices[i].w = 1.0f;
vertices[i].varying[0] = (float)(offsets[i].first * tex->Scale.X); vertices[i].u = (float)(offsets[i].first * tex->Scale.X);
vertices[i].varying[1] = (float)((1.0f - offsets[i].second) * tex->Scale.Y); vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
if (flipTextureX) if (flipTextureX)
vertices[i].varying[0] = 1.0f - vertices[i].varying[0]; vertices[i].u = 1.0f - vertices[i].u;
} }
bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT; bool fullbrightSprite = (decal->RenderFlags & RF_FULLBRIGHT) == RF_FULLBRIGHT;

View file

@ -66,8 +66,8 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const PolyClipPlan
vertices[i].y = (float)p.Y; vertices[i].y = (float)p.Y;
vertices[i].z = (float)(zpos + psize * (2.0 * offsets[i].second - 1.0)); vertices[i].z = (float)(zpos + psize * (2.0 * offsets[i].second - 1.0));
vertices[i].w = 1.0f; vertices[i].w = 1.0f;
vertices[i].varying[0] = (float)(offsets[i].first); vertices[i].u = (float)(offsets[i].first);
vertices[i].varying[1] = (float)(1.0f - offsets[i].second); vertices[i].v = (float)(1.0f - offsets[i].second);
} }
bool fullbrightSprite = particle->bright != 0; bool fullbrightSprite = particle->bright != 0;

View file

@ -410,8 +410,8 @@ TriVertex RenderPolyPlane::PlaneVertex(vertex_t *v1, double height, const UVTran
v.y = (float)v1->fPos().Y; v.y = (float)v1->fPos().Y;
v.z = (float)height; v.z = (float)height;
v.w = 1.0f; v.w = 1.0f;
v.varying[0] = transform.GetU(v.x, v.y); v.u = transform.GetU(v.x, v.y);
v.varying[1] = transform.GetV(v.x, v.y); v.v = transform.GetV(v.x, v.y);
return v; return v;
} }

View file

@ -139,8 +139,8 @@ TriVertex PolySkyDome::SetVertexXYZ(float xx, float yy, float zz, float uu, floa
v.y = zz; v.y = zz;
v.z = yy; v.z = yy;
v.w = 1.0f; v.w = 1.0f;
v.varying[0] = uu; v.u = uu;
v.varying[1] = vv; v.v = vv;
return v; return v;
} }

View file

@ -128,10 +128,10 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane
vertices[i].y = (float)p.Y; vertices[i].y = (float)p.Y;
vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second); vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second);
vertices[i].w = 1.0f; vertices[i].w = 1.0f;
vertices[i].varying[0] = (float)(offsets[i].first * tex->Scale.X); vertices[i].u = (float)(offsets[i].first * tex->Scale.X);
vertices[i].varying[1] = (float)((1.0f - offsets[i].second) * tex->Scale.Y); vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
if (flipTextureX) if (flipTextureX)
vertices[i].varying[0] = 1.0f - vertices[i].varying[0]; vertices[i].u = 1.0f - vertices[i].u;
} }
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));

View file

@ -230,14 +230,14 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
if (tex) if (tex)
{ {
PolyWallTextureCoords texcoords(tex, LineSeg, Line, Side, Texpart, TopZ, BottomZ, UnpeggedCeil); PolyWallTextureCoords texcoords(tex, LineSeg, Line, Side, Texpart, TopZ, BottomZ, UnpeggedCeil);
vertices[0].varying[0] = (float)texcoords.u1; vertices[0].u = (float)texcoords.u1;
vertices[0].varying[1] = (float)texcoords.v1; vertices[0].v = (float)texcoords.v1;
vertices[1].varying[0] = (float)texcoords.u2; vertices[1].u = (float)texcoords.u2;
vertices[1].varying[1] = (float)texcoords.v1; vertices[1].v = (float)texcoords.v1;
vertices[2].varying[0] = (float)texcoords.u2; vertices[2].u = (float)texcoords.u2;
vertices[2].varying[1] = (float)texcoords.v2; vertices[2].v = (float)texcoords.v2;
vertices[3].varying[0] = (float)texcoords.u1; vertices[3].u = (float)texcoords.u1;
vertices[3].varying[1] = (float)texcoords.v2; vertices[3].v = (float)texcoords.v2;
} }
// Masked walls clamp to the 0-1 range (no texture repeat) // Masked walls clamp to the 0-1 range (no texture repeat)
@ -294,8 +294,8 @@ void RenderPolyWall::ClampHeight(TriVertex &v1, TriVertex &v2)
{ {
float top = v1.z; float top = v1.z;
float bottom = v2.z; float bottom = v2.z;
float texv1 = v1.varying[1]; float texv1 = v1.v;
float texv2 = v2.varying[1]; float texv2 = v2.v;
float delta = (texv2 - texv1); float delta = (texv2 - texv1);
float t1 = texv1 < 0.0f ? -texv1 / delta : 0.0f; float t1 = texv1 < 0.0f ? -texv1 / delta : 0.0f;
@ -304,10 +304,10 @@ void RenderPolyWall::ClampHeight(TriVertex &v1, TriVertex &v2)
float inv_t2 = 1.0f - t2; float inv_t2 = 1.0f - t2;
v1.z = top * inv_t1 + bottom * t1; v1.z = top * inv_t1 + bottom * t1;
v1.varying[1] = texv1 * inv_t1 + texv2 * t1; v1.v = texv1 * inv_t1 + texv2 * t1;
v2.z = top * inv_t2 + bottom * t2; v2.z = top * inv_t2 + bottom * t2;
v2.varying[1] = texv1 * inv_t2 + texv2 * t2; v2.v = texv1 * inv_t2 + texv2 * t2;
} }
FTexture *RenderPolyWall::GetTexture() FTexture *RenderPolyWall::GetTexture()

View file

@ -90,10 +90,10 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPl
vertices[i].y = (float)p.Y; vertices[i].y = (float)p.Y;
vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second); vertices[i].z = (float)(pos.Z + spriteHeight * offsets[i].second);
vertices[i].w = 1.0f; vertices[i].w = 1.0f;
vertices[i].varying[0] = (float)(offsets[i].first * tex->Scale.X); vertices[i].u = (float)(offsets[i].first * tex->Scale.X);
vertices[i].varying[1] = (float)((1.0f - offsets[i].second) * tex->Scale.Y); vertices[i].v = (float)((1.0f - offsets[i].second) * tex->Scale.Y);
if (flipTextureX) if (flipTextureX)
vertices[i].varying[0] = 1.0f - vertices[i].varying[0]; vertices[i].u = 1.0f - vertices[i].u;
} }
bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT)); bool fullbrightSprite = ((thing->renderflags & RF_FULLBRIGHT) || (thing->flags5 & MF5_BRIGHT));