dxwrapper icon indicating copy to clipboard operation
dxwrapper copied to clipboard

Added support for transforming homogenous W geometry into world geomtry

Open dkollmann opened this issue 2 years ago • 37 comments

This is an update on the previous pull request https://github.com/elishacloud/dxwrapper/pull/188.

dkollmann avatar May 14 '23 14:05 dkollmann

Thanks @dkollmann! I will take a look at this soon.

elishacloud avatar May 15 '23 17:05 elishacloud

Also FYI if you try this code with Black & White, things will have a blue tint. This is because the water plane which should be rendered before all the other geometry, is rendered on top of it instead of behind the other geometry.

dkollmann avatar May 15 '23 18:05 dkollmann

I made some fixes. Of course lpD3DMatrix has to be replaced, after getting the game camera properties from it. I added an option to disable the lighting which is needed when DdrawConvertHomogeneousW is true but DdrawConvertHomogeneousToWorld is false. At least for Black & White.

The force push was just an update on the commit comment.

dkollmann avatar May 16 '23 22:05 dkollmann

For some reason when I add this DdrawConvertHomogeneousW = 1 line to the ini file I just get the following:

image

elishacloud avatar May 17 '23 18:05 elishacloud

For some reason when I add this DdrawConvertHomogeneousW = 1 line to the ini file I just get the following:

Ok, I figured this out. You have to set DdrawDisableLighting = 1 for Black & White.

elishacloud avatar May 17 '23 18:05 elishacloud

My only last comment is that I prefer to create a struct and add it to the IDirect3DDeviceX.h file rather than a whole new RednerData class for the DdrawConvertHomogeneous settings/matrices. Since the code is in IDirect3DDeviceX.cpp the settings should be in IDirect3DDeviceX.h.

Other than that, I think this is about ready to merge.

elishacloud avatar May 17 '23 18:05 elishacloud

Ah okay, I created the RenderData.h, because it was not possbile to include the device header in the DebugOverlay.cpp file.

dkollmann avatar May 17 '23 19:05 dkollmann

I created the RenderData.h, because it was not possbile to include the device header in the DebugOverlay.cpp file.

DebugOverlay.h already has #include "ddraw.h", which includes IDirect3DDeviceX.h. So it is already covered.

elishacloud avatar May 17 '23 19:05 elishacloud

Now DdrawConvertHomogeneousW seems to be working great. However, I am not able to get DdrawConvertHomogeneousToWorld working at all. I just get a black screen.

elishacloud avatar May 17 '23 21:05 elishacloud

If possible, attach a few good looking screenshots (or even link a video) of the resulting rendering in RTX Remix!

PatrickvL avatar May 17 '23 21:05 PatrickvL

These are my settings

DdrawOverrideWidth = 1920 DdrawOverrideHeight = 1080 DdrawOverrideRefreshRate = 60 DdrawOverrideStencilFormat = 80 DdrawConvertHomogeneousW = 1 DdrawConvertHomogeneousToWorld = 1 DdrawConvertHomogeneousToWorldUseGameCamera = 1 DdrawConvertHomogeneousToWorldFOV = 90 DdrawConvertHomogeneousToWorldNearPlane = 1 DdrawConvertHomogeneousToWorldFarPlane = 1000 DdrawConvertHomogeneousToWorldDepthOffset = 0.001 DdrawEnableMouseHook = 0 DdrawDisableLighting = 1

dkollmann avatar May 17 '23 21:05 dkollmann

On my PC with the previous setings...

No RTX, the water plane which should be rendered first is just rendered alogn with the rest of the geometry. https://1drv.ms/v/s!As0-jjvsSN2xgft8Y6R-1Zsvta99uQ?e=453wxe

RTX, I ignore the water plane, so it is not rendered, since it does not serve the purpose of a raytraced surface anyway, since it is a plane facing the camera. https://1drv.ms/v/s!As0-jjvsSN2xgft9BREiXiT7RT6VAg?e=3t0yky

The RTX version is still quite experimental. I am fixing the issues one after another, but there is still work to do.

dkollmann avatar May 17 '23 21:05 dkollmann

Ok, thanks! I figured it out. With the latest check-in this all you should need in your ini file. The rest should be set by default or auto-detected:

[Compatibility]
Dd7to9                     = 1

[Dd7to9]
DdrawEnableMouseHook       = 0
DdrawDisableLighting       = 1
DdrawConvertHomogeneousW   = 1
DdrawConvertHomogeneousToWorld              = 1
DdrawConvertHomogeneousToWorldUseGameCamera = 1

elishacloud avatar May 17 '23 21:05 elishacloud

With these settings and the latest build I am not seeing any issues. Try this build with only the included settings.

Latest build: dxwrapper.zip

elishacloud avatar May 17 '23 22:05 elishacloud

Hmmm it works too well. Something seems off. Let me merge those changes into my branch and let me check.

RTX version crashes, with no explicit stencil format, but that is fine. DdrawOverrideStencilFormat = 80

dkollmann avatar May 17 '23 22:05 dkollmann

Looks correct in blender though. image

dkollmann avatar May 17 '23 22:05 dkollmann

RTX version crashes, with no explicit stencil format, but that is fine. DdrawOverrideStencilFormat = 80

Sounds like a bug in RTX. The stencil format is set later. Maybe we should default to setting a stencil and then let the game override that, if needed?

I defaulted to no stencil because 2D DirectDraw games don't need it. But I don't think it will hurt to have a default one set. I prefer having less options and letting dxwrapper figure out things for the user.

Try this one and see if this has the same issue with RTX: dxwrapper.zip

elishacloud avatar May 17 '23 22:05 elishacloud

I would not worry. To use RTX, you have to install all this as a mod anyway, so you also get the correct overrides and new assets.

I want to replace the water shader as well as the terrain shader. And add lights to the spells and so on.

dkollmann avatar May 17 '23 22:05 dkollmann

Okay I found the issue. But still, not using DdrawConvertHomogeneousToWorldUseGameCamera currently yields the better results.

Maybe it would be better to just move the light, instead of transforming the geometry into insane values which then generate Z fighting. For the raytracing it should make no difference and the geometry we see is only the visible area anyway, so moving it around the world has no benefit.

dkollmann avatar May 17 '23 23:05 dkollmann

Try this one and see if this has the same issue with RTX: dxwrapper.zip

Still crashes. Sorry. But as mentioned it does not matter, the user will get an installer anyway, and that will also install the dxwrapper.ini.

Also keep in mind that they just relased RTX Remix 0.2.0 like a week ago. It is still quite an experimental tool.

dkollmann avatar May 17 '23 23:05 dkollmann

Still crashes. Sorry. [...] it does not matter, the user will get an installer anyway [...] they just relased RTX Remix 0.2.0 like a week ago. It is still quite an experimental tool.

Ok, no problem. Then I will not worry about it right now.

not using DdrawConvertHomogeneousToWorldUseGameCamera currently yields the better results.

Ok. What's the purpose of DdrawConvertHomogeneousToWorldUseGameCamera?

Maybe it would be better to just move the light, instead of transforming the geometry into insane values which then generate Z fighting.

I can't reproduce this issue. I'll wait until you have this resolved before merging the code.

elishacloud avatar May 18 '23 04:05 elishacloud

Ok. What's the purpose of DdrawConvertHomogeneousToWorldUseGameCamera?

The idea is to transform the geometry back to its "original" world position, so it is correctly placed relative to other world geometry. So when I remove the 2D sky and replace it with a sky dome, so the raytracing has something it can actually hit, the game geometry will be correctly placed.

But it will probably be better to transform the sky dome instead into the homogenous space.

dkollmann avatar May 18 '23 10:05 dkollmann

But still, not using DdrawConvertHomogeneousToWorldUseGameCamera

I think I fixed this issue. It should now be using the Game Camera. See check-in here: 44d43381e096a1fbff974f593ef68abc4d5c7efd

elishacloud avatar May 18 '23 16:05 elishacloud

I can't reproduce this issue.

Now I can see the problem with the DdrawConvertHomogeneousToWorldUseGameCamera. It works fine as long as this option is disabled.

elishacloud avatar May 18 '23 16:05 elishacloud

Shouldn't these lines be changed? FROM:

position = DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
direction = DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);

TO:

position = DirectX::XMVectorSet(view._41, view._42, view._43, view._44);
direction = DirectX::XMVectorSet(view._31, view._32, view._33, view._34);

elishacloud avatar May 18 '23 17:05 elishacloud

Shouldn't these lines be changed?

The result of XMMatrixLookToLH should stay the same. So just using fixed values makes it easier for the compiler to optimize this and it simply represents what it does. A matrix which looks down the Z axis.

dkollmann avatar May 18 '23 18:05 dkollmann

The result of XMMatrixLookToLH should stay the same.

Are you sure? The position sent would be DirectX::XMVectorSet(-1.0f, 1.0f, 0.0f, 1.0f); rather than DirectX::XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);. Also, if we ever change the view later than having it set by view means it gets updated also. No need to manually change it later.

elishacloud avatar May 18 '23 20:05 elishacloud

It seems like there may be more than just something wrong with DdrawConvertHomogeneousToWorldUseGameCamera. I am seeing an issue in Dark Reign 2 when just using DdrawConvertHomogeneousToWorld. The sky seems stretched

With DdrawConvertHomogeneousToWorld enable:

image

How it is supposed to look:

image

I can also see it even when just DdrawConvertHomogeneousW is enabled, but it is not quite as pronounced.

elishacloud avatar May 18 '23 21:05 elishacloud

Okay, here are the things are are wrong here and why "position" is zero.

  • "lpD3DMatrix = &view;" is set after the whole "if (Config.DdrawConvertHomogeneousToWorld)" block.
  • toViewSpace should be "DirectX::XMMATRIX toViewSpace = DirectX::XMLoadFloat4x4((DirectX::XMFLOAT4X4*)&view);"

The result will be the same, but the code should be a bit clearer.

So what happens is...

  • With the inverse matrix, "view" is applied. So the geometry is centered in front of the camera.
  • Then the inverse view projection is added, so the geometry is transformed into world space.
  • From there, the view matrix does not need to contain "view", since the error was already corrected by the inverse matrix.

I hope this all makes sense and is correct. Please take a look.

dkollmann avatar May 20 '23 00:05 dkollmann

Not sure if it is related, but I noticed something curious with the reconstructed world space in Black & White.

image

The whole world is rotated by 24.4° degreees. But the thing is, if you look at the trees at the bottom left, they are straight, which implies that this is correct. I wonder why this is. Is this due to the angle of the reflection? In game, the camera is completely horizontal. I checked the original view matrix.

But I also noticed that the Y direction seems to be flipped. It is negative when looking up and positive when looking down.

dkollmann avatar May 20 '23 01:05 dkollmann