Skip to content

Commit

Permalink
Implement blocky fuzz
Browse files Browse the repository at this point in the history
Based on woof and bits from #359
  • Loading branch information
Pedro-Beirao committed Nov 22, 2024
1 parent 0b625b7 commit 5db8fac
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 51 deletions.
28 changes: 22 additions & 6 deletions prboom2/src/r_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static const byte *tempfuzzmap;
//#define FUZZOFF (SCREENWIDTH)
#define FUZZOFF 1

static const int fuzzoffset_org[FUZZTABLE] = {
static const int fuzzoffset[FUZZTABLE] = {
FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,
FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,
FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,
Expand All @@ -117,10 +117,11 @@ static const int fuzzoffset_org[FUZZTABLE] = {
FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF
};

static int fuzzoffset[FUZZTABLE];

static int fuzzpos = 0;

// Fuzz cell size for scaled software fuzz
static int fuzzcellsize;

// render pipelines
#define RDC_STANDARD 1
#define RDC_TRANSLUCENT 2
Expand Down Expand Up @@ -479,9 +480,11 @@ void R_InitBuffer(int width, int height)

drawvars.topleft = screens[0].data;
drawvars.pitch = screens[0].pitch;

for (i=0; i<FUZZTABLE; i++)
fuzzoffset[i] = fuzzoffset_org[i]*screens[0].pitch;

if (!tallscreen)
fuzzcellsize = (SCREENHEIGHT + 100) / 200;
else
fuzzcellsize = (SCREENWIDTH + 160) / 320;
}

//
Expand Down Expand Up @@ -587,3 +590,16 @@ int R_GetFuzzPos()
{
return fuzzpos;
}

void R_ResetFuzzCol(int height)
{
R_ResetColumnBuffer();

fuzzpos = (fuzzpos + (height / fuzzcellsize)) % FUZZTABLE;
}

void R_CheckFuzzCol(int x, int height)
{
if (!(x % fuzzcellsize))
R_ResetFuzzCol(height);
}
6 changes: 6 additions & 0 deletions prboom2/src/r_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,10 @@ void R_ResetColumnBuffer(void);
void R_SetFuzzPos(int fuzzpos);
int R_GetFuzzPos();

// height is the height of the last column, in pixels
void R_ResetFuzzCol(int height);

// Calls R_ResetFuzzCol if x is aligned to the fuzz cell grid
void R_CheckFuzzCol(int x, int height);

#endif
138 changes: 93 additions & 45 deletions prboom2/src/r_drawflush.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

#if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
#define GETDESTCOLOR(col1, col2) (temptranmap[((col1)<<8)+(col2)])
#elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
#define GETDESTCOLOR(col) (tempfuzzmap[6*256+(col)])
#else
#define GETDESTCOLOR(col) (col)
#endif
Expand All @@ -45,6 +43,87 @@
//
static void R_FLUSHWHOLE_FUNCNAME(void)
{
// Scaled software fuzz algorithm
#if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
dboolean cutoff = false;

if ((temp_x + startx) % fuzzcellsize)
{
return;
}

int x = temp_x;
int yl = tempyl[x - 1];
int yh = tempyh[x - 1];

if (!yl)
{
yl = 1;
}

if (yh == viewheight - 1)
{
yh = viewheight - 2;
cutoff = true;
}

int count = yh - yl + 1;

if (count < 0)
{
return;
}

#ifdef RANGECHECK
if ((unsigned)x >= video.width || yl < 0 || yh >= video.height)
{
I_Error("R_DrawFuzzColumn: %i to %i at %i", yl, yh , x);
}
#endif

++count;

byte *dest = drawvars.topleft + startx + yl * drawvars.pitch + x;

int lines = fuzzcellsize - (yl % fuzzcellsize);

do
{
count -= lines;

// if (count < 0)
// {
// lines += count;
// count = 0;
// }
const int mask = count >> (8 * sizeof(mask) - 1);
lines += count & mask;
count &= ~mask;

const byte fuzz =
fullcolormap[6 * 256 + dest[drawvars.pitch * fuzzoffset[fuzzpos]]];

do
{
memset(dest, fuzz, fuzzcellsize);
dest += drawvars.pitch;
} while (--lines);

++fuzzpos;

// Clamp table lookup index.
fuzzpos &= (fuzzpos - FUZZTABLE) >> (8 * sizeof(fuzzpos) - 1); // killough 1/99

lines = fuzzcellsize;
} while (count);

if (cutoff)
{
const byte fuzz = fullcolormap
[6 * 256 + dest[drawvars.pitch * (fuzzoffset[fuzzpos] - FUZZOFF) / 2]];
memset(dest, fuzz, fuzzcellsize);
}
#else
byte *source;
byte *dest;
int count, yl;
Expand All @@ -60,13 +139,6 @@ static void R_FLUSHWHOLE_FUNCNAME(void)
{
#if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
*dest = GETDESTCOLOR(*dest, *source);
#elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
// SoM 7-28-04: Fix the fuzz problem.
*dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);

// Clamp table lookup index.
if(++fuzzpos == FUZZTABLE)
fuzzpos = 0;
#else
*dest = *source;
#endif
Expand All @@ -75,6 +147,7 @@ static void R_FLUSHWHOLE_FUNCNAME(void)
dest += drawvars.pitch;
}
}
#endif
}

//
Expand All @@ -86,6 +159,12 @@ static void R_FLUSHWHOLE_FUNCNAME(void)
//
static void R_FLUSHHEADTAIL_FUNCNAME(void)
{
#if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
// Only whole flushes are supported for fuzz
R_FLUSHWHOLE_FUNCNAME();
return;
#endif

byte *source;
byte *dest;
int count, colnum = 0;
Expand All @@ -108,13 +187,6 @@ static void R_FLUSHHEADTAIL_FUNCNAME(void)
#if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
// haleyjd 09/11/04: use temptranmap here
*dest = GETDESTCOLOR(*dest, *source);
#elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
// SoM 7-28-04: Fix the fuzz problem.
*dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);

// Clamp table lookup index.
if(++fuzzpos == FUZZTABLE)
fuzzpos = 0;
#else
*dest = *source;
#endif
Expand All @@ -136,13 +208,6 @@ static void R_FLUSHHEADTAIL_FUNCNAME(void)
#if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
// haleyjd 09/11/04: use temptranmap here
*dest = GETDESTCOLOR(*dest, *source);
#elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
// SoM 7-28-04: Fix the fuzz problem.
*dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);

// Clamp table lookup index.
if(++fuzzpos == FUZZTABLE)
fuzzpos = 0;
#else
*dest = *source;
#endif
Expand All @@ -157,17 +222,14 @@ static void R_FLUSHHEADTAIL_FUNCNAME(void)

static void R_FLUSHQUAD_FUNCNAME(void)
{
#if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
// Only whole flushes are supported for fuzz
return;
#endif

byte *source = &tempbuf[commontop << 2];
byte *dest = drawvars.topleft + commontop*drawvars.pitch + startx;
int count;
#if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
int fuzz1, fuzz2, fuzz3, fuzz4;

fuzz1 = fuzzpos;
fuzz2 = (fuzz1 + tempyl[1]) % FUZZTABLE;
fuzz3 = (fuzz2 + tempyl[2]) % FUZZTABLE;
fuzz4 = (fuzz3 + tempyl[3]) % FUZZTABLE;
#endif

count = commonbot - commontop + 1;

Expand All @@ -181,20 +243,6 @@ static void R_FLUSHQUAD_FUNCNAME(void)
source += 4 * sizeof(byte);
dest += drawvars.pitch * sizeof(byte);
}
#elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
while(--count >= 0)
{
dest[0] = GETDESTCOLOR(dest[0 + fuzzoffset[fuzz1]]);
dest[1] = GETDESTCOLOR(dest[1 + fuzzoffset[fuzz2]]);
dest[2] = GETDESTCOLOR(dest[2 + fuzzoffset[fuzz3]]);
dest[3] = GETDESTCOLOR(dest[3 + fuzzoffset[fuzz4]]);
fuzz1 = (fuzz1 + 1) % FUZZTABLE;
fuzz2 = (fuzz2 + 1) % FUZZTABLE;
fuzz3 = (fuzz3 + 1) % FUZZTABLE;
fuzz4 = (fuzz4 + 1) % FUZZTABLE;
source += 4 * sizeof(byte);
dest += drawvars.pitch * sizeof(byte);
}
#else
if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) {
while(--count >= 0)
Expand Down
8 changes: 8 additions & 0 deletions prboom2/src/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ int *mfloorclip; // dropoff overflow
int *mceilingclip; // dropoff overflow
fixed_t spryscale;
int64_t sprtopscreen; // R_WiggleFix
int colheight; // Scaled software fuzz

void R_DrawMaskedColumn(
const rpatch_t *patch,
Expand All @@ -462,6 +463,8 @@ void R_DrawMaskedColumn(
int64_t topscreen; // R_WiggleFix
int64_t bottomscreen; // R_WiggleFix
fixed_t basetexturemid = dcvars->texturemid;

colheight = 0;

dcvars->texheight = patch->height; // killough 11/98
for (i=0; i<column->numPosts; i++) {
Expand Down Expand Up @@ -498,6 +501,8 @@ void R_DrawMaskedColumn(
dcvars->drawingmasked = 1; // POPE
colfunc (dcvars);
dcvars->drawingmasked = 0; // POPE

colheight += dcvars->yh - dcvars->yl + 1;
}
}
dcvars->texturemid = basetexturemid;
Expand Down Expand Up @@ -560,6 +565,7 @@ static void R_DrawVisSprite(vissprite_t *vis)

if (!dcvars.colormap) // NULL colormap = shadow draw
{
R_ResetFuzzCol(colheight); // Reset fuzz column for new sprite
colfunc = R_GetDrawColumnFunc(RDC_PIPELINE_FUZZ, RDRAW_FILTER_POINT); // killough 3/14/98
}
else if (vis->color)
Expand Down Expand Up @@ -609,6 +615,8 @@ static void R_DrawVisSprite(vissprite_t *vis)
{
texturecolumn = frac>>FRACBITS;

if (!dcvars.colormap) R_CheckFuzzCol(dcvars.x, colheight);

R_DrawMaskedColumn(
patch,
colfunc,
Expand Down

0 comments on commit 5db8fac

Please sign in to comment.