Skip to content

Commit

Permalink
Proper implementation of crossfading effect
Browse files Browse the repository at this point in the history
Now it looks and feels like vanilla!
  • Loading branch information
JNechaevsky committed Apr 8, 2024
1 parent e176cd5 commit 0ea49bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,16 @@ const pixel_t I_BlendOverAltXlatab (const pixel_t bg, const pixel_t fg)
return amask | r | g | b;
}

// [crispy] Perform screen crossfading effect by given amount of opacity, used for Strife
const pixel_t I_BlendOverCrossfade (const pixel_t bg, const pixel_t fg, const int amount)
{
const uint32_t r = ((amount * (fg & rmask) + (0xff - amount) * (bg & rmask)) >> 8) & rmask;
const uint32_t g = ((amount * (fg & gmask) + (0xff - amount) * (bg & gmask)) >> 8) & gmask;
const uint32_t b = ((amount * (fg & bmask) + (0xff - amount) * (bg & bmask)) >> 8) & bmask;

return amask | r | g | b;
}

const pixel_t (*blendfunc) (const pixel_t fg, const pixel_t bg) = I_BlendOver;

const pixel_t I_MapRGB (const uint8_t r, const uint8_t g, const uint8_t b)
Expand Down
4 changes: 3 additions & 1 deletion src/strife/f_wipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ wipe_doColorXForm
#ifndef CRISPY_TRUECOLOR
*cur_screen = xlatab[(*cur_screen << 8) + *end_screen];
#else
*cur_screen = I_BlendOverXlatab(*cur_screen, *end_screen);
// [crispy] perform crossfading effect with 13 given opacity steps, multipled by 19:
// 247, 228, 209, 190, 171, 152, 133, 114, 95, 76, 57, 38, 19
*cur_screen = I_BlendOverCrossfade(*end_screen, *cur_screen, fade_safe_tics * 19);
#endif
}
++cur_screen;
Expand Down
1 change: 1 addition & 0 deletions src/v_trans.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern const pixel_t I_BlendOverTinttab (const pixel_t bg, const pixel_t fg);
extern const pixel_t I_BlendOverAltTinttab (const pixel_t bg, const pixel_t fg);
extern const pixel_t I_BlendOverXlatab (const pixel_t bg, const pixel_t fg);
extern const pixel_t I_BlendOverAltXlatab (const pixel_t bg, const pixel_t fg);
extern const pixel_t I_BlendOverCrossfade (const pixel_t bg, const pixel_t fg, const int amount);
#endif

int V_GetPaletteIndex(byte *palette, int r, int g, int b);
Expand Down

0 comments on commit 0ea49bc

Please sign in to comment.