ITotalJustice / notorious_beeg

gba emulator written in c++23
https://notorious-beeg.netlify.app/
GNU General Public License v3.0
41 stars 4 forks source link

Pokemon Emerald - broken fog effect #97

Closed ITotalJustice closed 1 year ago

ITotalJustice commented 2 years ago

image

this fog effect is used in a few places in game, one of which is the gym in lavender town.

the fog is actually an object and has the alpha bit set. the alpha bit in the object takes priority over winin / winout and bldmod when it comes to whether 2 layers can blend, and what blending can be done.

i figured that the window blend in/out flags took priority, but that doesnt seem to be the case. changing this https://github.com/ITotalJustice/notorious_beeg/blob/896c60b43fd38075ac85bc3a8fa79aa464fd5ef7/src/core/ppu/render.cpp#L1060-L1094 to the code below fixed the issue

// if obj has alpha bit set, it always does alpha blend as long
// as the bottom layer (dst) is enabled in bldmod
if (layers.is_obj_alpha())
{
    if (bldmod.is_alpha_bottom(layers.num[1]))
    {
        layers.pixel[0] = blend_alpha(layers.pixel[0], layers.pixel[1], coeff_src, coeff_dst);
    }
}
// check if we can blend within or outside the window and if the top
// layer is a src and bottom layer is a dst of bldmod.
else if (bounds.can_blend(x))
{
    if (bldmod.is_alpha(layers.num[0], layers.num[1]))
    {
        switch (blend_mode)
        {
            case Blend::None:
                break;

            case Blend::Alpha:
                layers.pixel[0] = blend_alpha(layers.pixel[0], layers.pixel[1], coeff_src, coeff_dst);
                break;

            case Blend::White:
                layers.pixel[0] = blend_white(layers.pixel[0], coeff_wb);
                break;

            case Blend::Black:
                layers.pixel[0] = blend_black(layers.pixel[0], coeff_wb);
                break;
        }
    }
}

image image image image

as can be seen in the above pics / code, i have fixed this locally.

ITotalJustice commented 1 year ago

Pokemon_-_Emerald_Version_U.zip

here is a save file for other emudevs to use for testing, remember to unzip it first 😄