Jump to content

Anti-Aliasing


Recommended Posts

  • 2 months later...
On 9/26/2023 at 12:17 AM, blaxis said:

How do we do this? Can you give information?

You must upgrade first of all directx from 8 to 9, because dx8 doesn´t support anti aliasing and some effects.. Second way can be used wrapper.. So you can instadead upgrade your source or use something like reshade, sweetfx etc.. (ReShade has 1000x better results and options how to make game better)

  • Love 1
Link to comment
Share on other sites

  • Active+ Member
34 minutes ago, Filachilla said:

You must upgrade first of all directx from 8 to 9, because dx8 doesn´t support anti aliasing and some effects.. Second way can be used wrapper.. So you can instadead upgrade your source or use something like reshade, sweetfx etc.. (ReShade has 1000x better results and options how to make game better)

I am already using directx 9. I tried Reshade but it has a problem. Whenever the Windows UAC screen comes up, the directx device resets itself and reshade also resets itself. Visual pollution occurs.

Link to comment
Share on other sites

  • Honorable Member
On 10/2/2023 at 6:17 PM, blaxis said:

I am already using directx 9. I tried Reshade but it has a problem. Whenever the Windows UAC screen comes up, the directx device resets itself and reshade also resets itself. Visual pollution occurs.

Try this:
Open StateManager.cpp and find this:

void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
{
    StateManager_Assert(lpDevice);
    lpDevice->AddRef();

    if (m_lpD3DDev)
    {
        m_lpD3DDev->Release();
        m_lpD3DDev = NULL;
    }

    m_lpD3DDev = lpDevice;

    D3DCAPS8 d3dCaps;
    m_lpD3DDev->GetDeviceCaps(&d3dCaps);

    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
        m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMagFilter = D3DTEXF_LINEAR;
    
    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
        m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMinFilter = D3DTEXF_LINEAR;

    DWORD dwMax = d3dCaps.MaxAnisotropy;
    dwMax = dwMax < 4 ? dwMax : 4;

    for (int i = 0; i < 8; ++i)
        m_lpD3DDev->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, dwMax);

    SetDefaultState();
}


And change to this:

void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
{
    StateManager_Assert(lpDevice);
    lpDevice->AddRef();

    if (m_lpD3DDev)
    {
        m_lpD3DDev->Release();
        m_lpD3DDev = NULL;
    }

    m_lpD3DDev = lpDevice;

    SetDefaultState();
}


Find this:

void CStateManager::SetDefaultState()
{

And change to this:

void CStateManager::SetDefaultState()
{
    D3DCAPS8 d3dCaps;
    m_lpD3DDev->GetDeviceCaps(&d3dCaps);

    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
        m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMagFilter = D3DTEXF_LINEAR;
    
    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
        m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMinFilter = D3DTEXF_LINEAR;

    DWORD dwMax = d3dCaps.MaxAnisotropy;
    dwMax = dwMax < 4 ? dwMax : 4;

    for (int i = 0; i < 8; ++i)
        m_lpD3DDev->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, dwMax);

Source of knowledge: 

 

  • Metin2 Dev 1

GhwYizE.gif

Link to comment
Share on other sites

  • Active+ Member
23 minutes ago, m2Ciaran said:

Looks like I got similar results. Kinda nice, also look good on weapons for example

before

spacer.png

after

spacer.png


 

  Hide contents

spacer.png

spacer.png

 

 

 

How can I do this?

 

9 hours ago, Tatsumaru said:

Try this:
Open StateManager.cpp and find this:

void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
{
    StateManager_Assert(lpDevice);
    lpDevice->AddRef();

    if (m_lpD3DDev)
    {
        m_lpD3DDev->Release();
        m_lpD3DDev = NULL;
    }

    m_lpD3DDev = lpDevice;

    D3DCAPS8 d3dCaps;
    m_lpD3DDev->GetDeviceCaps(&d3dCaps);

    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
        m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMagFilter = D3DTEXF_LINEAR;
    
    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
        m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMinFilter = D3DTEXF_LINEAR;

    DWORD dwMax = d3dCaps.MaxAnisotropy;
    dwMax = dwMax < 4 ? dwMax : 4;

    for (int i = 0; i < 8; ++i)
        m_lpD3DDev->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, dwMax);

    SetDefaultState();
}


And change to this:

void CStateManager::SetDevice(LPDIRECT3DDEVICE8 lpDevice)
{
    StateManager_Assert(lpDevice);
    lpDevice->AddRef();

    if (m_lpD3DDev)
    {
        m_lpD3DDev->Release();
        m_lpD3DDev = NULL;
    }

    m_lpD3DDev = lpDevice;

    SetDefaultState();
}


Find this:

void CStateManager::SetDefaultState()
{

And change to this:

void CStateManager::SetDefaultState()
{
    D3DCAPS8 d3dCaps;
    m_lpD3DDev->GetDeviceCaps(&d3dCaps);

    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFANISOTROPIC)
        m_dwBestMagFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMagFilter = D3DTEXF_LINEAR;
    
    if (d3dCaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFANISOTROPIC)
        m_dwBestMinFilter = D3DTEXF_ANISOTROPIC;
    else
        m_dwBestMinFilter = D3DTEXF_LINEAR;

    DWORD dwMax = d3dCaps.MaxAnisotropy;
    dwMax = dwMax < 4 ? dwMax : 4;

    for (int i = 0; i < 8; ++i)
        m_lpD3DDev->SetTextureStageState(i, D3DTSS_MAXANISOTROPY, dwMax);

Source of knowledge: 

 

Thank you. But I guess these don't apply MSAA. And unfortunately it didn't fix the ReShade issue

Edited by Metin2 Dev International
Core X - External 2 Internal
Link to comment
Share on other sites

On 10/8/2023 at 1:12 AM, blaxis said:

How can I do this?

 

Thank you. But I guess these don't apply MSAA. And unfortunately it didn't fix the ReShade issue

Your problem is not reshade but dx implementation..

@m2Ciaran yea, here are some my results

without:

Spoiler

.png

with:

Spoiler

.png

 

Edited by Filachilla
Link to comment
Share on other sites

  • Active+ Member
7 hours ago, Filachilla said:

Your problem is not reshade but dx implementation..

@m2Ciaran yea, here are some my results

without:

  Hide contents

.png

with:

  Hide contents

.png

 

There is no problem with Directx. I fixed all the problems and it works fine. Also, I don't understand why no one wants to help with how to apply effects like MSAA. I don't think there is such information worth hiding.

  • Good 2
Link to comment
Share on other sites

  • Forum Moderator

I used to work on that a year or two ago (preview in spoiler) when I focused on overall look. Honestly it is good to keep it as is, but MSAA has two issues. First thing, it messes with depth buffer, which makes any external shaders working on top of it to fail. Second thing, it outlines small flaws that used to be invisible or hardly noticeable when it was aliased, namely the lines on the ground that separates chunks and the taskbar / tooltip background, which appears with a gap. This creates a bit of additional work if you want to fix it (and you would most likely want). I think the most performance friendly and overall result would be to use SMAA with or without FXAA.

 

Spoiler

unknown.png?ex=65301395&is=651d9e95&hm=a

 

 

Edited by Metin2 Dev International
Core X - External 2 Internal
  • Good 2

Gurgarath
coming soon

Link to comment
Share on other sites

7 hours ago, Gurgarath said:

I used to work on that a year or two ago (preview in spoiler) when I focused on overall look. Honestly it is good to keep it as is, but MSAA has two issues. First thing, it messes with depth buffer, which makes any external shaders working on top of it to fail. Second thing, it outlines small flaws that used to be invisible or hardly noticeable when it was aliased, namely the lines on the ground that separates chunks and the taskbar / tooltip background, which appears with a gap. This creates a bit of additional work if you want to fix it (and you would most likely want). I think the most performance friendly and overall result would be to use SMAA with or without FXAA.

 

  Reveal hidden contents

unknown.png?ex=65301395&is=651d9e95&hm=a

 

 

 

FXAA is giving me font problems, the text is then not easy to read.. Using SMAA and idk but I never got your problems.. 


@blaxisMaybe for the same reason no one wants to post a dx9 fix.. The second thing may be that not everyone is interested in this.

Link to comment
Share on other sites

  • Forum Moderator
33 minutes ago, Filachilla said:

 

FXAA is giving me font problems, the text is then not easy to read.. Using SMAA and idk but I never got your problems.. 


@blaxisMaybe for the same reason no one wants to post a dx9 fix.. The second thing may be that not everyone is interested in this.

Font problems are most likely due to external aka injected FXAA, which works with the depth buffer and if you use the default font handling, you will understand why it is giving font issues, the thing has to be built from the ground up. You might use MSAA instead of SMAA and the issues I quoted (except depth buffer) are probably linked to my own implementation, but I ended up fixing these issues.

DX9 has already been published on this very website in 2015 with just an issue or two with minimap and ground textures. It's just that most people slept on it for a good 7 years before it started to reappear here and there. The main issue is that it requires many changes and it's usually better to either publish it all (with no support) or install it for people (which prompts it to be sold)

  • Good 1

Gurgarath
coming soon

Link to comment
Share on other sites

  • 1 month later...
  • Active+ Member

I found an ANTIALIASING FIX for Directx9

 

//Search for in EtherLib/GrpDevice.cpp:

ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;

//and it is added immediately on top:

    for (uint8_t i = 0; i <= D3DMULTISAMPLE_8_SAMPLES; i++)
    {
        const auto multisamplelevel = static_cast<D3DMULTISAMPLE_TYPE>(i);
        const auto result = ms_lpd3d->CheckDeviceMultiSampleType(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL, ms_d3dPresentParameter.BackBufferFormat, Windowed, multisamplelevel, nullptr); // !!! REMOVE nullptr FOR DX8 !!!

        if (SUCCEEDED(result))
        {
#ifdef _DEBUG
            TraceError("multisamplelevel == %u", multisamplelevel);
#endif
            ms_d3dPresentParameter.MultiSampleType = multisamplelevel;
        }
    }


// Search for in EtherLib/GrpScreen.cpp:

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)

//and the function is completely replaced;

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
    assert(ms_lpd3dDevice != NULL);

    SPDTVertexRaw vertices[4] =
    {
        // HARD FIX BEGIN
        { sx - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { sx - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        // HARD FIX END
    };

    if (SetPDTStream(vertices, 4))
    {
        STATEMANAGER.SetTexture(0, NULL);
        STATEMANAGER.SetTexture(1, NULL);
        STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
        STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
    }
}

 

spacer.png

Link to comment
Share on other sites

  • Active+ Member
5 minutes ago, SCOOB said:

I found an ANTIALIASING FIX for Directx9

 

//Search for in EtherLib/GrpDevice.cpp:

ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;

//and it is added immediately on top:

    for (uint8_t i = 0; i <= D3DMULTISAMPLE_8_SAMPLES; i++)
    {
        const auto multisamplelevel = static_cast<D3DMULTISAMPLE_TYPE>(i);
        const auto result = ms_lpd3d->CheckDeviceMultiSampleType(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL, ms_d3dPresentParameter.BackBufferFormat, Windowed, multisamplelevel, nullptr); // !!! REMOVE nullptr FOR DX8 !!!

        if (SUCCEEDED(result))
        {
#ifdef _DEBUG
            TraceError("multisamplelevel == %u", multisamplelevel);
#endif
            ms_d3dPresentParameter.MultiSampleType = multisamplelevel;
        }
    }


// Search for in EtherLib/GrpScreen.cpp:

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)

//and the function is completely replaced;

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
    assert(ms_lpd3dDevice != NULL);

    SPDTVertexRaw vertices[4] =
    {
        // HARD FIX BEGIN
        { sx - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { sx - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        // HARD FIX END
    };

    if (SetPDTStream(vertices, 4))
    {
        STATEMANAGER.SetTexture(0, NULL);
        STATEMANAGER.SetTexture(1, NULL);
        STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
        STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
    }
}

 

I know this.

This is not a fix and it is dangerous to use it this way. Unfortunately, DirectX codes are not as simple as you think.

Link to comment
Share on other sites

  • Active+ Member
15 minutes ago, blaxis said:

I know this.

This is not a fix and it is dangerous to use it this way. Unfortunately, DirectX codes are not as simple as you think.

Another woraround:

Download dgVoodo2, put the files frfom folder MS -> x86 in your client, open then dgVoodooCpl.exe and select 8x on aliasing.(DirectX menu)

I managed to fix the anti aliasing, but i have an annoying bug. The spaces from spacebar have a weird dot. That's the only bug.

 

spacer.png

https://metin2.download/video/5ziLcW02Euopy91b49lPtNL7J1Hx52B4/.mp4

 

EDIT: I finally found a fix, I will create a new topic on a full tutorial.

Edited by Metin2 Dev International
Core X - External 2 Internal

spacer.png

Link to comment
Share on other sites

  • Active+ Member
25 minutes ago, SCOOB said:

Another woraround:

Download dgVoodo2, put the files frfom folder MS -> x86 in your client, open then dgVoodooCpl.exe and select 8x on aliasing.(DirectX menu)

I managed to fix the anti aliasing, but i have an annoying bug. The spaces from spacebar have a weird dot. That's the only bug.

 

spacer.png

https://metin2.download/video/5ziLcW02Euopy91b49lPtNL7J1Hx52B4/.mp4

I have used and tried many wrappers like dgvodo. ReShade, GShade,dgVodo etc. None of them satisfied me. I am more in favor of solving this issue by the source. Additionally, dgvodoo increases memory usage excessively. A single client consumes between 550-650mb. Using such large memory just to enable MSAA is pointless.

I've been trying for weeks and this is where I'm at now(Metin2 client source codes only )

spacer.png

 

Edited by Metin2 Dev International
Core X - External 2 Internal
Link to comment
Share on other sites

I got interested in this topic so I tried it myself. What I've found you can pretty easily enable antialiasing on dx9.

Search for:

int CGraphicDevice::Create

Now scroll down where the parameters of ms_d3dPresentParameter are set.

 

Add those two lines

ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
ms_d3dPresentParameter.MultiSampleQuality = 0;

And now that's a riddle. I haven't got too much time for a research, but ms_lpd3d->CheckDeviceMultiSampleType tells that multiSampling is indeed available, and it sets the quality to 1. But I can't get it working with it, so I left the quality set to 0, it still looks good enough, IDK what would be the difference.

 

Also there's one more thing to set in the parameters, and I don't know the long term effects of this change, but it looks like it works just fine, like I said I don't have too much time for doing research atm.

You'll be having a "D3DERR_INVALIDCALL" error if ms_d3dPresentParameter.Flags are set to D3DPRESENTFLAG_LOCKABLE_BACKBUFFER, and I don't know the answer for now, maybe I'm missing something, but setting the flag to 0 does the job.

After the device is created with success you must write last line to make it work:

ms_lpd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);

 

And now you can enjoy those SMOOTH EDGES:

Spoiler

.png

 

  • Think 1
Link to comment
Share on other sites

  • Active+ Member
4 hours ago, MysteriousDev said:

I got interested in this topic so I tried it myself. What I've found you can pretty easily enable antialiasing on dx9.

Search for:

int CGraphicDevice::Create

Now scroll down where the parameters of ms_d3dPresentParameter are set.

 

Add those two lines

ms_d3dPresentParameter.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
ms_d3dPresentParameter.MultiSampleQuality = 0;

And now that's a riddle. I haven't got too much time for a research, but ms_lpd3d->CheckDeviceMultiSampleType tells that multiSampling is indeed available, and it sets the quality to 1. But I can't get it working with it, so I left the quality set to 0, it still looks good enough, IDK what would be the difference.

 

Also there's one more thing to set in the parameters, and I don't know the long term effects of this change, but it looks like it works just fine, like I said I don't have too much time for doing research atm.

You'll be having a "D3DERR_INVALIDCALL" error if ms_d3dPresentParameter.Flags are set to D3DPRESENTFLAG_LOCKABLE_BACKBUFFER, and I don't know the answer for now, maybe I'm missing something, but setting the flag to 0 does the job.

After the device is created with success you must write last line to make it work:

ms_lpd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);

 

And now you can enjoy those SMOOTH EDGES:

  Reveal hidden contents

.png

 

You just don't use the backbuffer with anti aliasing. With that said, the old screenshot method will not work, but this one might work:

bool CPythonGraphic::SaveScreenShot(const char * c_pszFileName)
{
    LPDIRECT3DSURFACE9 lpSurface;
    D3DSURFACE_DESC stSurfaceDesc;

    uint32_t uWidth = stSurfaceDesc.Width;
    uint32_t uHeight = stSurfaceDesc.Height;
    
    ms_lpd3dDevice->CreateOffscreenPlainSurface(uWidth, uHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &lpSurface, NULL);   
    if(SUCCEEDED(ms_lpd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &lpSurface)))     
    {        
        D3DXSaveSurfaceToFile(c_pszFileName, D3DXIFF_JPG, lpSurface, NULL, NULL); 
    }        
    if(lpSurface)
    {
        lpSurface->Release();
        lpSurface = nullptr;
    }

    return true;
}

If I remember correctly there is also problem with transparency in e.g. tooltip but i dont go deep into it. Its cool for us, but players dont give a fuck about edges so... i just don't work on it 😅

  • Good 1
Link to comment
Share on other sites

  • 1 month later...
On 11/23/2023 at 4:40 PM, HFWhite said:

I found an ANTIALIASING FIX for Directx9

 

//Search for in EtherLib/GrpDevice.cpp:

ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;

//and it is added immediately on top:

    for (uint8_t i = 0; i <= D3DMULTISAMPLE_8_SAMPLES; i++)
    {
        const auto multisamplelevel = static_cast<D3DMULTISAMPLE_TYPE>(i);
        const auto result = ms_lpd3d->CheckDeviceMultiSampleType(ms_iD3DAdapterInfo, D3DDEVTYPE_HAL, ms_d3dPresentParameter.BackBufferFormat, Windowed, multisamplelevel, nullptr); // !!! REMOVE nullptr FOR DX8 !!!

        if (SUCCEEDED(result))
        {
#ifdef _DEBUG
            TraceError("multisamplelevel == %u", multisamplelevel);
#endif
            ms_d3dPresentParameter.MultiSampleType = multisamplelevel;
        }
    }


// Search for in EtherLib/GrpScreen.cpp:

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)

//and the function is completely replaced;

void CScreen::RenderBar3d(float sx, float sy, float sz, float ex, float ey, float ez)
{
    assert(ms_lpd3dDevice != NULL);

    SPDTVertexRaw vertices[4] =
    {
        // HARD FIX BEGIN
        { sx - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { sx - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, sy - 0.5f, sz, ms_diffuseColor, 0.0f, 0.0f },
        { ex - 0.5f, ey - 0.5f, ez, ms_diffuseColor, 0.0f, 0.0f },
        // HARD FIX END
    };

    if (SetPDTStream(vertices, 4))
    {
        STATEMANAGER.SetTexture(0, NULL);
        STATEMANAGER.SetTexture(1, NULL);
        STATEMANAGER.SetVertexShader(D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1);
        STATEMANAGER.DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
    }
}

 

yes, i did this. but msaa really have performance impact. i get 200 fps if msaa on (normally i get 240 fps)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.