Skip to content

Commit

Permalink
make blending/fade accurate too (not quite sure about the 3D one)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Apr 1, 2022
1 parent 1dfcf20 commit 8796950
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/GPU2D_Soft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ SoftRenderer::SoftRenderer()

u32 SoftRenderer::ColorBlend4(u32 val1, u32 val2, u32 eva, u32 evb)
{
u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb)) >> 4;
u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb)) >> 4) & 0x007F00;
u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb)) >> 4) & 0x7F0000;
u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb) + 0x000008) >> 4;
u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb) + 0x000800) >> 4) & 0x007F00;
u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb) + 0x080000) >> 4) & 0x7F0000;

if (r > 0x00003F) r = 0x00003F;
if (g > 0x003F00) g = 0x003F00;
Expand All @@ -56,16 +56,16 @@ u32 SoftRenderer::ColorBlend5(u32 val1, u32 val2)

if (eva == 32) return val1;

u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb)) >> 5;
u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb)) >> 5) & 0x007F00;
u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb)) >> 5) & 0x7F0000;
u32 r = (((val1 & 0x00003F) * eva) + ((val2 & 0x00003F) * evb) + 0x000010) >> 5;
u32 g = ((((val1 & 0x003F00) * eva) + ((val2 & 0x003F00) * evb) + 0x001000) >> 5) & 0x007F00;
u32 b = ((((val1 & 0x3F0000) * eva) + ((val2 & 0x3F0000) * evb) + 0x100000) >> 5) & 0x7F0000;

if (eva <= 16)
/*if (eva <= 16)
{
r += 0x000001;
g += 0x000100;
b += 0x010000;
}
}*/

if (r > 0x00003F) r = 0x00003F;
if (g > 0x003F00) g = 0x003F00;
Expand All @@ -79,8 +79,8 @@ u32 SoftRenderer::ColorBrightnessUp(u32 val, u32 factor)
u32 rb = val & 0x3F003F;
u32 g = val & 0x003F00;

rb += ((((0x3F003F - rb) * factor) >> 4) & 0x3F003F);
g += ((((0x003F00 - g) * factor) >> 4) & 0x003F00);
rb += (((((0x3F003F - rb) * factor) + 0x080008) >> 4) & 0x3F003F);
g += (((((0x003F00 - g ) * factor) + 0x000800) >> 4) & 0x003F00);

return rb | g | 0xFF000000;
}
Expand All @@ -90,8 +90,8 @@ u32 SoftRenderer::ColorBrightnessDown(u32 val, u32 factor)
u32 rb = val & 0x3F003F;
u32 g = val & 0x003F00;

rb -= (((rb * factor) >> 4) & 0x3F003F);
g -= (((g * factor) >> 4) & 0x003F00);
rb -= ((((rb * factor) + 0x070007) >> 4) & 0x3F003F);
g -= ((((g * factor) + 0x000700) >> 4) & 0x003F00);

return rb | g | 0xFF000000;
}
Expand Down

0 comments on commit 8796950

Please sign in to comment.