Skip to content

Commit

Permalink
master brightness has different biases (are you serious, Nintendo)
Browse files Browse the repository at this point in the history
also add all these biases to the OpenGL compositor
  • Loading branch information
Arisotura committed Apr 7, 2022
1 parent f6a5535 commit 86f725f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
24 changes: 12 additions & 12 deletions src/GPU2D_Soft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ u32 SoftRenderer::ColorBlend5(u32 val1, u32 val2)
return r | g | b | 0xFF000000;
}

u32 SoftRenderer::ColorBrightnessUp(u32 val, u32 factor)
u32 SoftRenderer::ColorBrightnessUp(u32 val, u32 factor, u32 bias)
{
u32 rb = val & 0x3F003F;
u32 g = val & 0x003F00;

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

return rb | g | 0xFF000000;
}

u32 SoftRenderer::ColorBrightnessDown(u32 val, u32 factor)
u32 SoftRenderer::ColorBrightnessDown(u32 val, u32 factor, u32 bias)
{
u32 rb = val & 0x3F003F;
u32 g = val & 0x003F00;

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

return rb | g | 0xFF000000;
}
Expand Down Expand Up @@ -153,8 +153,8 @@ u32 SoftRenderer::ColorComposite(int i, u32 val1, u32 val2)
{
case 0: return val1;
case 1: return ColorBlend4(val1, val2, eva, evb);
case 2: return ColorBrightnessUp(val1, CurUnit->EVY);
case 3: return ColorBrightnessDown(val1, CurUnit->EVY);
case 2: return ColorBrightnessUp(val1, CurUnit->EVY, 0x8);
case 3: return ColorBrightnessDown(val1, CurUnit->EVY, 0x7);
case 4: return ColorBlend5(val1, val2);
}

Expand Down Expand Up @@ -328,7 +328,7 @@ void SoftRenderer::DrawScanline(u32 line, Unit* unit)

for (int i = 0; i < 256; i++)
{
dst[i] = ColorBrightnessUp(dst[i], factor);
dst[i] = ColorBrightnessUp(dst[i], factor, 0x0);
}
}
else if ((masterBrightness >> 14) == 2)
Expand All @@ -339,7 +339,7 @@ void SoftRenderer::DrawScanline(u32 line, Unit* unit)

for (int i = 0; i < 256; i++)
{
dst[i] = ColorBrightnessDown(dst[i], factor);
dst[i] = ColorBrightnessDown(dst[i], factor, 0xF);
}
}
}
Expand Down Expand Up @@ -445,8 +445,8 @@ void SoftRenderer::DoCapture(u32 line, u32 width)
u32 evy = (val3 >> 8) & 0x1F;

val1 = _3dval;
if (compmode == 2) val1 = ColorBrightnessUp(val1, evy);
else if (compmode == 3) val1 = ColorBrightnessDown(val1, evy);
if (compmode == 2) val1 = ColorBrightnessUp(val1, evy, 0x8);
else if (compmode == 3) val1 = ColorBrightnessDown(val1, evy, 0x7);
}
else
val1 = val2;
Expand Down
6 changes: 3 additions & 3 deletions src/GPU2D_Soft.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class SoftRenderer : public Renderer2D

u32 ColorBlend4(u32 val1, u32 val2, u32 eva, u32 evb);
u32 ColorBlend5(u32 val1, u32 val2);
u32 ColorBrightnessUp(u32 val, u32 factor);
u32 ColorBrightnessDown(u32 val, u32 factor);
u32 ColorBrightnessUp(u32 val, u32 factor, u32 bias);
u32 ColorBrightnessDown(u32 val, u32 factor, u32 bias);
u32 ColorComposite(int i, u32 val1, u32 val2);

template<u32 bgmode> void DrawScanlineBGMode(u32 line);
Expand Down Expand Up @@ -78,4 +78,4 @@ class SoftRenderer : public Renderer2D
void DoCapture(u32 line, u32 width);
};

}
}
13 changes: 6 additions & 7 deletions src/GPU_OpenGL_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ void main()
eva = (_3dpix.a & 0x1F) + 1;
evb = 32 - eva;

val1 = ((_3dpix * eva) + (val1 * evb)) >> 5;
if (eva <= 16) val1 += ivec4(1,1,1,0);
val1 = ((_3dpix * eva) + (val1 * evb) + 0x10) >> 5;
val1 = min(val1, 0x3F);
}
else
Expand All @@ -103,7 +102,7 @@ void main()
eva = val3.g;
evb = val3.b;

val1 = ((val1 * eva) + (_3dpix * evb)) >> 4;
val1 = ((val1 * eva) + (_3dpix * evb) + 0x8) >> 4;
val1 = min(val1, 0x3F);
}
else
Expand All @@ -123,8 +122,8 @@ void main()
evy = val3.g;

val1 = _3dpix;
if (compmode == 2) val1 += ((ivec4(0x3F,0x3F,0x3F,0) - val1) * evy) >> 4;
else if (compmode == 3) val1 -= (val1 * evy) >> 4;
if (compmode == 2) val1 += (((0x3F - val1) * evy) + 0x8) >> 4;
else if (compmode == 3) val1 -= ((val1 * evy) + 0x7) >> 4;
}
else
val1 = val2;
Expand All @@ -142,15 +141,15 @@ void main()
int evy = mbright.r & 0x1F;
if (evy > 16) evy = 16;

pixel += ((ivec4(0x3F,0x3F,0x3F,0) - pixel) * evy) >> 4;
pixel += ((0x3F - pixel) * evy) >> 4;
}
else if (brightmode == 2)
{
// down
int evy = mbright.r & 0x1F;
if (evy > 16) evy = 16;

pixel -= (pixel * evy) >> 4;
pixel -= ((pixel * evy) + 0xF) >> 4;
}
}

Expand Down

0 comments on commit 86f725f

Please sign in to comment.