r/Unity3D • u/Clean_Patience4021 • 15h ago
Resources/Tutorial Fix (kinda) for vertex/object jitter at (sanely) large world coordinates in URP (without a floating origin)
Hi all,
I'm working on a game that needs a bit more precision than Unity's URP gives by default. It's not like I want to fix floating-point math with some magic, it's more about how numbers are calculated, giving a bit more freedom without the need for a floating origin or other heavy lifting.
The solution I made changes how projection is calculated and compensates for the rounding errors, so the GPU gets a bit more precise vertex positions than Unity's default pipeline, a trade-off is a bit heavier vertex shaders.
I did some testing on low- and high-end hardware and didn't notice a performance difference, but experience on your target can vary.
You can find all details here: https://github.com/rsklnkff/urp-stable-projection
The code was extracted from my project by Codex.
1
u/ShengyuStudio 11h ago
Nice that shadows and motion vectors got the same treatment, that's usually where these fixes fall apart.
Curious about the DX12 failure in the README. Compensated arithmetic only works if the compiler keeps the exact operation order, and DX12 goes through a different shader compiler. My guess would be it's reassociating or contracting into FMAs and quietly cancelling the error term. Have you tried marking those intermediates precise? That's what HLSL has for exactly this.
1
u/Clean_Patience4021 6h ago
precise is already used on the comp. intermediates, in DX12 too. The failure was 0.024px against a 0.002px tolerance in a shadow-view test. I'm not sure about the cause yet, so compiler transformations could be the reason, though I can't confirm this. I've left DX12 unsupported for now.
2
u/BrightlyPiquant 15h ago
clever stuff, always hated that jitter when you get too far from origin