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

PhysX 4.1 #690

Merged
merged 11 commits into from
Dec 16, 2020
Merged

PhysX 4.1 #690

merged 11 commits into from
Dec 16, 2020

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented Jul 25, 2020

This updates PhysX from version 2.6 to 4.1. I decided to go with PhysX 4.1 instead of other options such as Bullet Physics or Newton Game Dynamics due to our previous usage of PhysX. While the API has changed significantly in places, much of the simulation behavior is similar, which makes life easier. PhysX 4.1 is open source, cross platform, and supports 64-bit.

Note that this is intended to be tested with a set of minor asset fixes in H-uru/moul-assets#10. Please ensure that you are using these files before submitting commentary.

On a high level, this changeset:

  • Ports the libHSPlasma uncooking code for PhysX 2.6 data, to minimize data file churn.
  • Updates PhysX 2.6 APIs to PhysX 4.1 APIs.
  • Rewrites the CMake FindPhysX script for PhysX 4.1 with special considerations to the idiosyncrasies of vcpkg.
  • As much as possible, separates PhysX logic from Plasma logic by pulling the code into a separate file.
  • Removes or simplifies many of the bespoke aspects of the character controller in favor of functionality built in to PhysX 4.1.
  • Spreads some nice override all over the joint.

Aside from dealing with API changes, this changeset overhauls the character controller significantly. PhysX's built in character controller can at best be described as "functional" in the old PhysX 2.6 case. Indeed, in the case of Jalak, it is insufficient and a bespoke mode had to be engaged. In PhysX 4.1, I saw issues where the avatar would be able to get on top of kickables and "ride" them such that it was trivial to go out of bounds while running in place on a kickable. So, the character controller is a true dynamic actor now, controlled by directly setting its linear velocity each simulation frame. This results in more realistic world interactions for the most part and greatly simplified code.

Some changes to note from the 2.6 movement handling:

  • When attempting to walk on slopes, when the avatar reaches a slope of greater than 57 degrees, the falling animation begins. The falling animation discontinues when the slope is under 40 degrees.
  • Downward velocity (due to gravity) is calculated based on whether or not we are on the ground--if the ground is a kickable, we inherit its downward velocity. Otherwise, we compute the velocity based on the ground normal. This greatly improves walking on top of the fish baskets in Eder Gira.

Closes #4.
Depends on microsoft/vcpkg#12413 or NVIDIAGameWorks/PhysX#322.
Fixes #609.
Obsoletes and closes #667.
Depends on H-uru/moul-assets#10.

@dpogue
Copy link
Member

dpogue commented Jul 25, 2020

As part of this PR, can you remove the if(WIN32) wrappers around PhysX stuff in the CMakeLists (since this will allow it to be cross-platform)?

@Hoikas
Copy link
Member Author

Hoikas commented Sep 2, 2020

I am now largely happy with how physics behaves in game. There are still a few data file mitigations left to handle in m-a#10, but this is ready for more serious review and non-casual testing, I think..

@Hoikas Hoikas marked this pull request as ready for review September 2, 2020 23:44
@Hoikas Hoikas force-pushed the px_upgrade branch 2 times, most recently from 28ab946 to 936d0e8 Compare September 6, 2020 00:49
@Hoikas
Copy link
Member Author

Hoikas commented Sep 6, 2020

Pushed a fix for an observed crash when touching a kickable not owned by the local client.

@Hoikas
Copy link
Member Author

Hoikas commented Sep 24, 2020

Updated with the new devlibs URL containing the PhysX 4.1 SDK.

@Hoikas
Copy link
Member Author

Hoikas commented Nov 20, 2020

Rebased onto current master to aid compilation and review. (Someone is going to review this, right???)

This causes PhysX cooked physicals to always be uncooked on read then
re-cooked. This is a huge waste of time right now, but it allows us to
continue using the old cooked physical blobs in any arbitrary physics
engine.
Danger! Here be dra^H^H^Hbehavior changes:
- Detector regions were previously forced to convex hulls if possible.
Now they are exported as triangle mesh if set so by the artist.
- Dynamics (kickables) with convex hulls were exported as "polytopes."
This has been removed.
This is a rather large monolithic changeset due to the scope of the
changes. To summarize:
- PhysX 2.6 APIs have been upgraded to PhysX 4.1 APIs.
- The CMake FindPhysX script has been rewritten for PhysX 4.1 with
special considerations to the idiosyncrasies of vcpkg.
- As much as possible, PhysX logic has been separated from Plasma logic by
pulling the code into a separate file.
- Many of the special case or bespoke aspects of the character
controller have been either removed or simplified in favor of
functionality built in to PhysX 4.1.
With the PhysX CCT, it was too easy to get into situations where the
avatar could ride on top of a kickable to access out-of-bounds areas.
Additionally, the hit force applied in those situations was at best
comical and at worst frustrating due to the physics based puzzles.

This rewrites the character controller to be a true dynamic rigid body
in the simulation controlled by setting its linear velocity each
simulation frame. The result is greatly simplified code and better
interaction with the world.
Apparently, if collisions occur while we are forcibly setting the global
pose of an actor, this causes some kind of internal force accumulator
to, well, accumulate. Once we resume normal operation, this accumulator
causes the avatar to be flung into space. Simply setting the linear
velocity to zero does not fix the issue.

With that in mind, we now expose another flags field on the simulation
shader and selectively suppress collisions with non-triggers when the
avatar brain thinks there should be no physics.
Copy link
Member

@dpogue dpogue left a comment

Choose a reason for hiding this comment

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

Multiple people have built this locally and tested it to confirm it works. I've run one of those clients in wine and it worked. I've also been able to compile this code on Linux, and for Windows 64-bit.

@dpogue dpogue merged commit 36d486b into H-uru:master Dec 16, 2020
@Hoikas Hoikas deleted the px_upgrade branch December 16, 2020 02:27
Copy link
Member

@Deledrius Deledrius left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few minor things...

@Hoikas Hoikas mentioned this pull request Mar 11, 2021
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.

Swimming + RidingAnimatedPhysical Cross-Platform Physics Library
3 participants