Move true color sky drawing to its own drawers and chamge r_stretchsky to false as the new drawers can fade to a solid color
This commit is contained in:
parent
cfb985ceb3
commit
491a4e28c0
13 changed files with 482 additions and 17 deletions
169
src/r_plane.cpp
169
src/r_plane.cpp
|
|
@ -985,8 +985,177 @@ static const BYTE *R_GetTwoSkyColumns (FTexture *fronttex, int x)
|
|||
}
|
||||
}
|
||||
|
||||
static void R_DrawSkyColumn(int start_x, int y1, int y2, int columns)
|
||||
{
|
||||
uint32_t height = frontskytex->GetHeight();
|
||||
|
||||
for (int i = 0; i < columns; i++)
|
||||
{
|
||||
int x = start_x + i;
|
||||
|
||||
int uv_fracbits = 24 - frontskytex->HeightBits;
|
||||
double uv_stepd = skyiscale * frontskytex->Scale.Y;
|
||||
double v = (skymid * frontskytex->Scale.Y + uv_stepd * (y1 - CenterY + 0.5)) / height;
|
||||
v = v + 1.0f;
|
||||
v *= height;
|
||||
v *= (1 << uv_fracbits);
|
||||
uint32_t uv_pos = (uint32_t)v;
|
||||
uint32_t uv_step = xs_ToFixed(uv_fracbits, uv_stepd);
|
||||
if (uv_step == 0) // To prevent divide by zero elsewhere
|
||||
uv_step = 1;
|
||||
|
||||
if (MirrorFlags & RF_XFLIP)
|
||||
x = (viewwidth - x);
|
||||
|
||||
DWORD ang, angle1, angle2;
|
||||
|
||||
if (r_linearsky)
|
||||
{
|
||||
angle_t xangle = (angle_t)((0.5 - x / (double)viewwidth) * FocalTangent * ANGLE_90);
|
||||
ang = (skyangle + xangle) ^ skyflip;
|
||||
}
|
||||
else
|
||||
{
|
||||
ang = (skyangle + xtoviewangle[x]) ^ skyflip;
|
||||
}
|
||||
angle1 = (DWORD)((UMulScale16(ang, frontcyl) + frontpos) >> FRACBITS);
|
||||
angle2 = (DWORD)((UMulScale16(ang, backcyl) + backpos) >> FRACBITS);
|
||||
|
||||
bufplce[i] = (const BYTE *)frontskytex->GetColumnBgra(angle1, nullptr);
|
||||
bufplce2[i] = backskytex ? (const BYTE *)backskytex->GetColumnBgra(angle2, nullptr) : nullptr;
|
||||
buftexturefracx[i] = 0;
|
||||
vince[i] = uv_step;
|
||||
vplce[i] = uv_pos;
|
||||
}
|
||||
|
||||
bufheight[0] = height;
|
||||
bufheight[1] = backskytex ? backskytex->GetHeight() : height;
|
||||
dc_dest = (ylookup[y1] + start_x) * 4 + dc_destorg;
|
||||
dc_count = y2 - y1;
|
||||
|
||||
// To do: figure out how GZDoom calculates the solid top and bottom colors
|
||||
uint32_t solid_top = 0xff7f7f7f;
|
||||
uint32_t solid_bottom = 0xff3f3f3f;
|
||||
|
||||
if (columns == 4)
|
||||
if (!backskytex)
|
||||
R_DrawSingleSkyCol4(solid_top, solid_bottom);
|
||||
else
|
||||
R_DrawDoubleSkyCol4(solid_top, solid_bottom);
|
||||
else
|
||||
if (!backskytex)
|
||||
R_DrawSingleSkyCol1(solid_top, solid_bottom);
|
||||
else
|
||||
R_DrawDoubleSkyCol1(solid_top, solid_bottom);
|
||||
}
|
||||
|
||||
static void R_DrawTruecolorSky(visplane_t *pl)
|
||||
{
|
||||
R_SetColorMapLight(fixedcolormap, 0, 0);
|
||||
palookupoffse[0] = dc_colormap;
|
||||
palookupoffse[1] = dc_colormap;
|
||||
palookupoffse[2] = dc_colormap;
|
||||
palookupoffse[3] = dc_colormap;
|
||||
palookuplight[0] = 0;
|
||||
palookuplight[1] = 0;
|
||||
palookuplight[2] = 0;
|
||||
palookuplight[3] = 0;
|
||||
setupvline(FRACBITS);
|
||||
|
||||
int x1 = pl->left;
|
||||
int x2 = pl->right;
|
||||
short *uwal = (short *)pl->top;
|
||||
short *dwal = (short *)pl->bottom;
|
||||
|
||||
// Calculate where 4 column alignment begins and ends:
|
||||
int aligned_x1 = clamp((x1 + 3) / 4 * 4, x1, x2);
|
||||
int aligned_x2 = clamp(x2 / 4 * 4, x1, x2);
|
||||
|
||||
// First unaligned columns:
|
||||
for (int x = x1; x < aligned_x1; x++)
|
||||
{
|
||||
int y1 = uwal[x];
|
||||
int y2 = dwal[x];
|
||||
if (y2 <= y1)
|
||||
continue;
|
||||
|
||||
R_DrawSkyColumn(x, y1, y2, 1);
|
||||
}
|
||||
|
||||
// The aligned columns
|
||||
for (int x = aligned_x1; x < aligned_x2; x += 4)
|
||||
{
|
||||
// Find y1, y2, light and uv values for four columns:
|
||||
int y1[4] = { uwal[x], uwal[x + 1], uwal[x + 2], uwal[x + 3] };
|
||||
int y2[4] = { dwal[x], dwal[x + 1], dwal[x + 2], dwal[x + 3] };
|
||||
|
||||
// Figure out where we vertically can start and stop drawing 4 columns in one go
|
||||
int middle_y1 = y1[0];
|
||||
int middle_y2 = y2[0];
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
middle_y1 = MAX(y1[i], middle_y1);
|
||||
middle_y2 = MIN(y2[i], middle_y2);
|
||||
}
|
||||
|
||||
// If we got an empty column in our set we cannot draw 4 columns in one go:
|
||||
bool empty_column_in_set = false;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (y2[i] <= y1[i])
|
||||
empty_column_in_set = true;
|
||||
}
|
||||
|
||||
if (empty_column_in_set || middle_y2 <= middle_y1)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (y2[i] <= y1[i])
|
||||
continue;
|
||||
|
||||
R_DrawSkyColumn(x + i, y1[i], y2[i], 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Draw the first rows where not all 4 columns are active
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (y1[i] < middle_y1)
|
||||
R_DrawSkyColumn(x + i, y1[i], middle_y1, 1);
|
||||
}
|
||||
|
||||
// Draw the area where all 4 columns are active
|
||||
R_DrawSkyColumn(x, middle_y1, middle_y2, 4);
|
||||
|
||||
// Draw the last rows where not all 4 columns are active
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (middle_y2 < y2[i])
|
||||
R_DrawSkyColumn(x + i, middle_y2, y2[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
// The last unaligned columns:
|
||||
for (int x = aligned_x2; x < x2; x++)
|
||||
{
|
||||
int y1 = uwal[x];
|
||||
int y2 = dwal[x];
|
||||
if (y2 <= y1)
|
||||
continue;
|
||||
|
||||
R_DrawSkyColumn(x, y1, y2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void R_DrawSky (visplane_t *pl)
|
||||
{
|
||||
if (r_swtruecolor)
|
||||
{
|
||||
R_DrawTruecolorSky(pl);
|
||||
return;
|
||||
}
|
||||
|
||||
int x;
|
||||
float swal;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue