Skip to content

Angular velocity, HLSL mesh transforms, collision mechanics - #5

Closed
WrathfulSpatula wants to merge 1202 commits into
MITGameLab:masterfrom
vm6502q:master
Closed

WrathfulSpatula wants to merge 1202 commits into
MITGameLab:masterfrom
vm6502q:master

Conversation

@WrathfulSpatula

Copy link
Copy Markdown

As per email exchange, here is a fork that adds angular velocity support to shaders, includes a compute shader for up-pipeline mesh transformations, and attempts basic collision mechanics. (In addition to general housekeeping.)

@WrathfulSpatula

Copy link
Copy Markdown
Author

The collision mechanics are experimental, and that part I only present as such. Working on them more, I'm catching physical logic errors, but they are at least relatively stable between low player velocity and player velocity close to the speed of light. (That is, they at least naturally don't "bug-out" by deflecting a rigidbody at close to (or past) c, if that wouldn't make qualitative physical sense.) I will do more on collision. Perhaps the game lab can run with this.

The angular velocity handling in the shaders works by calculating a tangential velocity due to object rotation, and it relativistically adds the tangential velocity to the center-of-mass translational velocity to find a total velocity for each vertex. This component is physically simpler than collision and easier to verify, but the corresponding code could be easily commented out or removed, while keeping the new mesh geometry shader and various added shader optimizations.

@WrathfulSpatula

Copy link
Copy Markdown
Author

I know there's a huge amount of work to review here, but I'm getting to the point where I'm ready to use this in my own game, so my commits are going to slow down. This fork is the product of combining your OpenRelativity engine with non-overlapping features from my own special relativity engine, which was codenamed "Tachyoid." In brief, here are the major additions:

-Rigidbody and collision mechanics.
When RelativisticObjects change velocity, the shader previously mapped them to a discontinuous point. I (numerically) inverted your shader algorithm, so now the velocity setter can map to the original optical position and back based on the new velocity, so you can change velocities while keeping objects at fixed optical/Minkowski positions. Additionally, I added relativistic impulse collision mechanics. That is, the collision algorithm accounts for effects like length contraction, and it assumes that impulse relates rapidities rather than velocities. There are also penalty methods implemented, which are not highly physically accurate, but they let objects sit flush on static surfaces under the effects of gravity.

-Accelerated frames and "gravity" (i.e., applied Newtonian fields with Einstein equivalence principle)
The implied acceleration of the player in your game is itself on a relativistic scale, though the original engine ignores it. Player acceleration leads to a significant player relative position dependence in the "time-time" component of the Minkowski metric. (I cite a pedagogical source, and this can be easily verified.) The change in this component leads to an additional position dependent apparent time scaling effect, in addition to the time dilation you've already factored. The definition of the acceleration I use follows Einstein's equivalence principle, so you can use it for gravity. (i.e., no acceleration in free-fall, and player is rather in an accelerated frame when they're at rest on a surface with gravity.)

-Relativistic collider mesh transformation
Your collider meshes now inhabit optical space, meaning they are transformed the same way as the object image by the shader. This is necessary to make the collision mechanics work. This is done with a DirectX11 compute shader for MeshCollider meshes. (Compute shaders will also compile for OpenGLES 3.1)

-General optimization and housekeeping
Hope you don't mind, but I put the engine in a namespace. I got rid of single vector component operations in many places where SIMD and native shader mathematical functions could be used. I implemented cheap quaternion math in your shaders, for rotations. You were also trusting that division and trigonometry with float values like 1e-100f wouldn't lead to Inf or NaN. I tested your shaders on less robust devices, and cleaned up their edge cases. (Some problems with edge cases might have even been introduced by me at some point, but they've been tested and fixed, now. Your new shaders are safe enough and cheap enough run on mobile, now, by the way.)

Hope you get some mileage out of it. I was educated in physics, and I work as a software developer, and I already had a special relativity engine project with almost no overlap with yours, so it just made sense to combine the two engines for my own games. Thank you for your insightfully designed, clean, and awesome engine!

@WrathfulSpatula

Copy link
Copy Markdown
Author

(Just realized I introduced a "pop" in the shader on the last commit, but I'm fixing it right now. I do have a version of your shaders working on Google Cardboard.)

@WrathfulSpatula

Copy link
Copy Markdown
Author

As this PR hasn't been closed, I want to apologize for not knowing what I was doing with Github, back when I opened this. Without branches, I basically blew the opportunity for systematic code reviews. However, whether the original OpenRelativity project does anything with the large amount of work I added to it, for which I'm maintaining the MIT license, I'm available to go over anything and everything in my fork, piece-by-piece. Thanks again!

@WrathfulSpatula

Copy link
Copy Markdown
Author

Closed in favor of #15, and thanks again!

@WrathfulSpatula
WrathfulSpatula deleted the master branch March 10, 2023 12:56
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.

1 participant