AlpyneDreams / d8vk

Direct3D 8 to Vulkan translation for DXVK! Merged into dxvk: https://github.com/doitsujin/dxvk
zlib License
485 stars 8 forks source link

Missing fog in NFS Hot Pursuit 2 #190

Closed WinterSnowfall closed 4 months ago

WinterSnowfall commented 1 year ago

Reported on Discord. Both WineD3D and d3d8to9 + dxvk render fog correctly, while d8vk does not.

I've captured a trace using WineD3D which reproduces the issue. Fog should be instantly visible (or not) on race start, although it's a somewhat subtle effect. Looking at the lighthouse in the distance near the end of the trace provides more clarity on the matter.

Software information

Need for Speed: Hot Pursuit 2

System information

Apitrace file(s)

NFSHP2.trace.tar.xz

Log files

NFSHP2.log

WinterSnowfall commented 1 year ago

Apparently "fixed" by lopping a:

      case D3DRS_FOGDENSITY:
        // if D3DRS_FOGDENSITY is set to a nonzero value, use D3DFOG_EXP2
        if (Value)
          GetD3D9()->SetRenderState(d3d9::D3DRS_FOGTABLEMODE, d3d9::D3DFOG_EXP2);
        break;

Inside D3D8Device::SetRenderState, but I'm not sure what's going on with the game.

It resorts to a series of:

SetRenderState(this = 0xe223d0, State = D3DRS_FOGCOLOR, Value = 4285034087) = D3D_OK
SetRenderState(this = 0xe223d0, State = D3DRS_FOGDENSITY, Value = 3142694679) = D3D_OK
SetRenderState(this = 0xe223d0, State = D3DRS_FOGENABLE, Value = TRUE) = D3D_OK

But omits setting the proper D3DRS_FOGTABLEMODE, which is either EXP or EXP2, as implied by D3DRS_FOGDENSITY. EXP looks borked, but EXP2 looks spot on.

Excerpt from the MS docs: https://learn.microsoft.com/en-us/windows/win32/direct3d9/pixel-fog#using-pixel-fog

WinterSnowfall commented 1 year ago

Gained some more insight here. The FF fog is a fallback path that the game properly enables (without the above hacks) when we report the supported PS/VS versions as 0.0.

This would indicate a problem with d8vk's shader declaration transformation logic, I guess. The game does indeed use a lot of VS with exp oFog.x, -r1, but that doesn't currently do anything fog-wise.

WinterSnowfall commented 4 months ago

Now tracked here: https://github.com/doitsujin/dxvk/issues/4113.