Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert D3DFVF_XYZRHW into D3DFVF_XYZW #188

Closed
wants to merge 8 commits into from

Conversation

dkollmann
Copy link
Contributor

You can now turn D3DFVF_XYZRHW rendering into D3DFVF_XYZW and it should look the same.

@Trass3r
Copy link
Contributor

Trass3r commented May 4, 2023

What's the use-case?

@dkollmann
Copy link
Contributor Author

If you want to use RTX Remix, your geometry has to be in XYZ or XYZW mode. D3DFVF_XYZRHW is not supported.

@@ -330,6 +330,28 @@ HRESULT m_IDirect3DDeviceX::SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStat
break;
}

if(Config.DdrawConvertHomogeneousW)
{
if(dtstTransformStateType == D3DTS_VIEW)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assumes that SetTransform is called, which is not the case for DK2 for example

{
float *pos = (float*) vertex;

pos[3] = 1.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you lose information here if rhw is != 1?
It's not used for many things, but at least for perspective-correct texture mapping and some exotic stuff like fog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation read that the use of W is undefined here, and not seen as part of the position vector. For me it made no difference if I had it or not. So it is probably better to just remove it then.

Copy link
Contributor

@Trass3r Trass3r May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah not sure if they use the W at all in this mode, also they also say it's "designed for, and can only be used with, the programmable vertex pipeline."
https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dfvf

So the input coordinates are in screen space and your view matrix transforms it back into clip space?

https://gamedev.net/forums/topic/582097-difference-between-d3dfvf_xyzw-and-d3dfvf_xyzrhw/4705397/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SetTransform function overrides the game matrices with its own, when the mode is active.

// Replace the matrix with one that handles D3DFVF_XYZRHW geometry
D3DVIEWPORT9 Viewport9;
if(SUCCEEDED((*d3d9Device)->GetViewport(&Viewport9)))
{
	ZeroMemory(lpD3DMatrix, sizeof(_D3DMATRIX));
	lpD3DMatrix->_11 = 2.0f / (float)Viewport9.Width;
	lpD3DMatrix->_22 = -2.0f / (float)Viewport9.Height;
	lpD3DMatrix->_33 = 1.0f;
	lpD3DMatrix->_41 = -1.0f;  // translate X
	lpD3DMatrix->_42 = 1.0f;   // translate Y
	lpD3DMatrix->_44 = 1.0f;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know.
I guess an identity viewport matrix would also suffice but not sure about this mode.
https://learn.microsoft.com/en-us/windows/win32/dxtecharts/the-direct3d-transformation-pipeline

@elishacloud
Copy link
Owner

This code does not work for me. Maybe there is something missing from your branch? When I compile it I get this:

image

image

@dkollmann
Copy link
Contributor Author

Okay let me take a look. It is definitely working on my side.

@dkollmann
Copy link
Contributor Author

Hey, I just wanted to say, I have not forgotten about this, but I will take until the weekend before I can take an actual look at it. Work is pretty rough right now.

@elishacloud
Copy link
Owner

No problem. Thanks.

@dkollmann
Copy link
Contributor Author

I created a new pull request #199.

@dkollmann dkollmann closed this May 14, 2023
@dkollmann dkollmann deleted the reverse_xyzrhw branch May 14, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants