Skip to content

Commit

Permalink
Truecolor sky: Draw opaque black background on transparent texels
Browse files Browse the repository at this point in the history
Fixes HOM effect
  • Loading branch information
Cacodemon345 committed Sep 11, 2024
1 parent 55618fc commit 3c8a381
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/common/textures/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ void FImageSource::EndPrecaching()

void FImageSource::RegisterForPrecache(FImageSource *img, bool requiretruecolor)
{
img->CollectForPrecache(precacheInfo, requiretruecolor);
if (img)
img->CollectForPrecache(precacheInfo, requiretruecolor);
}

//==========================================================================
Expand Down
5 changes: 4 additions & 1 deletion src/gamedata/textures/animations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,10 @@ void FTextureAnimator::UpdateAnimations (uint64_t mstime)
if (updated)
{
fire->texture->CleanHardwareData();
delete fire->texture->GetSoftwareTexture();

if (fire->texture->GetSoftwareTexture())
delete fire->texture->GetSoftwareTexture();

fire->texture->SetSoftwareTexture(nullptr);
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/rendering/swrenderer/drawers/r_draw_sky32.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
*dest = source0[sample_index];
if (*dest == 0)
*dest |= 0xff000000;
dest += pitch;
frac += fracstep;
}
Expand All @@ -90,6 +92,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
uint32_t fg = source0[sample_index];
if (fg == 0)
fg |= 0xff000000;

uint32_t alpha = max(min(frac >> (16 - start_fade), 256), 0);
uint32_t inv_alpha = 256 - alpha;
Expand All @@ -110,6 +114,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
*dest = source0[sample_index];
if (*dest == 0)
*dest |= 0xff000000;

frac += fracstep;
dest += pitch;
Expand All @@ -121,6 +127,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
uint32_t fg = source0[sample_index];
if (fg == 0)
fg |= 0xff000000;

uint32_t alpha = max(min(((2 << 24) - frac) >> (16 - start_fade), 256), 0);
uint32_t inv_alpha = 256 - alpha;
Expand Down Expand Up @@ -189,6 +197,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

*dest = fg;
Expand Down Expand Up @@ -222,6 +232,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

uint32_t alpha = max(min(frac >> (16 - start_fade), 256), 0);
Expand All @@ -245,6 +257,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}
*dest = fg;

Expand All @@ -262,6 +276,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

uint32_t alpha = max(min(((2 << 24) - frac) >> (16 - start_fade), 256), 0);
Expand Down
16 changes: 16 additions & 0 deletions src/rendering/swrenderer/drawers/r_draw_sky32_sse2.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
*dest = source0[sample_index];
if (*dest == 0)
*dest |= 0xff000000;
dest += pitch;
frac += fracstep;
}
Expand All @@ -90,6 +92,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
uint32_t fg = source0[sample_index];
if (fg == 0)
fg |= 0xff000000;

__m128i alpha = _mm_set1_epi16(max(min(frac >> (16 - start_fade), 256), 0));
__m128i inv_alpha = _mm_sub_epi16(_mm_set1_epi16(256), alpha);
Expand All @@ -108,6 +112,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
*dest = source0[sample_index];
if (*dest == 0)
*dest |= 0xff000000;

frac += fracstep;
dest += pitch;
Expand All @@ -119,6 +125,8 @@ namespace swrenderer
{
uint32_t sample_index = (((((uint32_t)frac) << 8) >> FRACBITS) * textureheight0) >> FRACBITS;
uint32_t fg = source0[sample_index];
if (fg == 0)
fg |= 0xff000000;

__m128i alpha = _mm_set1_epi16(max(min(((2 << 24) - frac) >> (16 - start_fade), 256), 0));
__m128i inv_alpha = _mm_sub_epi16(_mm_set1_epi16(256), alpha);
Expand Down Expand Up @@ -173,6 +181,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

*dest = fg;
Expand Down Expand Up @@ -218,6 +228,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

__m128i alpha = _mm_set1_epi16(max(min(frac >> (16 - start_fade), 256), 0));
Expand All @@ -241,6 +253,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}
*dest = fg;

Expand All @@ -258,6 +272,8 @@ namespace swrenderer
{
uint32_t sample_index2 = min(sample_index, maxtextureheight1);
fg = source1[sample_index2];
if (fg == 0)
fg |= 0xff000000;
}

__m128i alpha = _mm_set1_epi16(max(min(((2 << 24) - frac) >> (16 - start_fade), 256), 0));
Expand Down

0 comments on commit 3c8a381

Please sign in to comment.