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

Add GET_WORLD_COORD_FROM_SCREEN_COORD for RedM #2370

Merged
merged 3 commits into from
Feb 21, 2024

Conversation

Disquse
Copy link
Contributor

@Disquse Disquse commented Feb 1, 2024

Goal of this PR

Add GET_WORLD_COORD_FROM_SCREEN_COORD native for RedM.

How is this PR achieving the goal

By adapting related FiveM code for Red Dead Redemption 2 and RedM.

This PR applies to the following area(s)

RedM

Successfully tested on

Game builds: 1311, 1355, 1436, 1491

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Fixes #1977

Demonstration:
Video

@gottfriedleibniz
Copy link
Contributor

gottfriedleibniz commented Feb 13, 2024

Are sure these grcViewport fields are correct?

Looking at the values in RedM, it seems what is labelled m_viewProjection is actually the (perspective) projection matrix and whatever is labelled m_projection is its view matrix.

Is it possible to rip these matrices from a shader (same applies to V)?

@Disquse
Copy link
Contributor Author

Disquse commented Feb 13, 2024

I'm sure they're not correctly named - I just used names from our -five component, I have no idea about proper names. If you want to suggest proper names, feel free :P

@gottfriedleibniz
Copy link
Contributor

gottfriedleibniz commented Feb 13, 2024

In V, and referencing cbuffer rage_matrices from a shader and empirically playing around with this:

struct grcViewport
{
    float m_world[16];
    float m_worldView[16];
    float m_worldViewProj[16];
    float m_inverseView[16]; // m_camMatrix in MumbleVoice; inverse(m_view)
    float m_view[16]; 
    float m_projection[16];
};

In RDR's case:

  1. m_viewProjection is actually m_projection (data looks like a perspective projection matrix);
  2. m_projection looks like m_view (lookat) matrix.

Putting this together:

struct grcViewport
{
    float m_world[16];
    float m_worldView[16];
    float m_projection[16];
    float m_inverseView[16];
    float m_unknown[16]; 
    float m_view[16];
};

Changing the parameter order here makes this function more consistent with DirectX's own impl

@github-actions github-actions bot added the RedM Issues/PRs related to RedM label Feb 13, 2024
@Disquse
Copy link
Contributor Author

Disquse commented Feb 13, 2024

Applied your suggestions, @gottfriedleibniz

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Feb 13, 2024
@gottfriedleibniz
Copy link
Contributor

gottfriedleibniz commented Feb 14, 2024

Actually, shit. Apologies for the hoops jumping here.

While I have no issue with just using m_view, in our case Transform from DirectX would be m_worldView (if-ever/whenever the world matrix is something other than an identity matrix).

Also took a look at the stuttering at extreme locations and something is causing small-but-noticeable fluctuations in the projection matrix. It seems 0x1426D8837 in 1491.18.2 (rage::grcViewport::RegeneratePerspective) called from 0x1426D9E24 (rage::grcViewport::SetTemporalOffsets) is suspect. My RDR IDB is incredibly bare however.

@gottfriedleibniz gottfriedleibniz added ready-to-merge This PR is enqueued for merging and removed triage Needs a preliminary assessment to determine the urgency and required action labels Feb 15, 2024
@github-actions github-actions bot added invalid Requires changes before it's considered valid and can be (re)triaged triage Needs a preliminary assessment to determine the urgency and required action and removed invalid Requires changes before it's considered valid and can be (re)triaged labels Feb 15, 2024
@Disquse Disquse removed the triage Needs a preliminary assessment to determine the urgency and required action label Feb 20, 2024
@thorium-cfx thorium-cfx merged commit 381dfa0 into citizenfx:master Feb 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR is enqueued for merging RedM Issues/PRs related to RedM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RDR3 REQUEST] Add support for GET_WORLD_COORD_FROM_SCREEN_COORD
3 participants