elishacloud / dxwrapper

Fixes compatibility issues with older games running on Windows 10/11 by wrapping DirectX dlls. Also allows loading custom libraries with the file extension .asi into game processes.
zlib License
1.16k stars 83 forks source link

Keep Filter If Point Sampled (AnisotropicFiltering\AntiAliasing) #144

Closed Mitradis closed 2 years ago

Mitradis commented 2 years ago

Need support separation filtering objects on Point and non-Point. It need becouse now when AnisotropicFiltering\AntiAliasing is on in some games text and interface blurry screenshot0000 Space Rangers 2. If disable AnisotropicFiltering and AntiAliasing: screenshot0001 same feature have dgVoodoo, but he unsupported this game. DxWrapper good work with ddraw.dll and D3D9.dll and option FullscreenWindowMode (Dd7to9\EnableD3d9Wrapper).

Mitradis commented 2 years ago

Can someone tell me where to add such a check to the code? in order for these effects to work only on 3D elements.

elishacloud commented 2 years ago

Can someone tell me where to add such a check to the code? in order for these effects to work only on 3D elements.

I think the line of code you are looking for is here.

You could try changing this:

if (Value == D3DTEXF_POINT || Value == D3DTEXF_LINEAR)
{
    Value = D3DTEXF_ANISOTROPIC;
}

To this:

if (Value == D3DTEXF_LINEAR)
{
    Value = D3DTEXF_ANISOTROPIC;
}
Mitradis commented 2 years ago

@elishacloud wow! it work! My first compiled wrapper in my life)) Need for AntiAliasing too. Becouse AntiAliasing also causes blur.

elishacloud commented 2 years ago

Need for AntiAliasing too. Becouse AntiAliasing also causes blur.

There is probably not much that can be done about AntiAliasing. That is the way it works.

Mitradis commented 2 years ago

it's a pity. But at least it succeeded with AF!

elishacloud commented 2 years ago

I could try turning off AntiAliasing when using point filtering and then turning it back on when using other types of filtering. Not sure it this will work. I'll make a build at some point and have you test it.

Mitradis commented 2 years ago

thank! of course I will test.

elishacloud commented 2 years ago

I won't have time for a while, but you can try changing the function code here to this:

HRESULT m_IDirect3DDevice9Ex::SetSamplerState(THIS_ DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
{
    Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

    // Disable AntiAliasing when using point filtering
    if (Config.AntiAliasing)
    {
        if (Type == D3DSAMP_MAGFILTER || Type == D3DSAMP_MINFILTER || Type == D3DSAMP_MIPFILTER)
        {
            if (Value == D3DTEXF_NONE || Value == D3DTEXF_POINT)
            {
                ProxyInterface->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE);
            }
            else
            {
                ProxyInterface->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
            }
        }
    }

    // Enable Anisotropic Filtering
    if (MaxAnisotropy)
    {
        if (Type == D3DSAMP_MAXANISOTROPY)
        {
            if (SUCCEEDED(ProxyInterface->SetSamplerState(Sampler, D3DSAMP_MAXANISOTROPY, MaxAnisotropy)))
            {
                return D3D_OK;
            }
        }
        else if (Type == D3DSAMP_MAGFILTER || Type == D3DSAMP_MINFILTER)
        {
            ProxyInterface->SetSamplerState(Sampler, D3DSAMP_MAXANISOTROPY, MaxAnisotropy);

            if (Value == D3DTEXF_LINEAR)
            {
                Value = D3DTEXF_ANISOTROPIC;
            }
        }
    }

    return ProxyInterface->SetSamplerState(Sampler, Type, Value);
}

If you can test this let me know the results.

Edit: just updated the code.

Mitradis commented 2 years ago

Yes! It work! Now AF and AA work together: screenshot0000 screenshot0001 screenshot0002 Thanks a lot!

elishacloud commented 2 years ago

Thanks for testing this for me. I have updated the code for all future releases.

elishacloud commented 2 years ago

I actually don't see much need on any game of having Anisotropic or AntiAliasing on when using point or no filtering. The only potential issue would be if a game uses point or no filtering at one stage and then linear at another stage. This would confuse my code so that it could disable AntiAliasing in some places it should not. However, I don't think that will be very common. I will add an option later if this becomes an issue with any game.

Mitradis commented 2 years ago

I deleted previous post for a reason. I tested on 18 games this. I tested it the same way in dgVoodoo. I came to the conclusion that this feature (Keep Filter) should be enabled by default for all games and any situation. I noticed damage (blurry) elements (textures or interface\text), if used AF for all, in various games and even where I have not associated it with this before (e.g. blurry texture building block in warcraft3). I no longer find it necessary to make a separate option.