Hi,
I was trying to calculate an SDF inside a material using the built-in `DistanceField_Capsule` function and a WorldPosition. Everything works fine near the origin but if the mesh with the material is moved away from it some precision issues start to arise.
After debugging the generated HLSL code in renderdoc it looks like the culprit is `LWCLength`. As you can see in ok.png and wrong.png (attached) neighbouring pixels produce very different results when the length function is used. Note that we changed UE_LWC_RENDER_TILE_SIZE to 262144.0 but the error present in the vanilla UE version as well, as shown in the attached project.
Another thing that puzzles me is that LWCAdd doesn’t seem to increment the Tile when Offset overflows but I’m not sure this is causing the issue.
[Content removed] this question tackles a similar problem but it’s not clear what is the best solution.
For the time being placing a TruncateLWC between the WorldPosition node and the SDF function input seem to do the trick but I’m not sure this is safe. Thanks a lot,
Damiano
Hello,
Thank you for reaching out.
I’ve been assigned this issue, and we will be looking into these artifacts for you.
Hello,
Thank you for reporting this. I can confirm this issue can be reproduced as described in the latest CL, and will be opening a bug report.
We will send a public tracker when one is available.
Hi Damiano, this is a known limitation of LWCAdd, LWCLength and all the other LWC* functions. The recommended solution is to perform your math in translated world space instead of world space. You can find more details on these documentation pages:
https://dev.epicgames.com/community/learning/tutorials/DdzL/unreal-engine-fortnite-efficient-materials-for-large-worlds
https://dev.epicgames.com/documentation/en-us/unreal-engine/large-world-coordinates-rendering-in-unreal-engine-5
Hello,
We have opened a bug report:
The tracker will be visible after it is approved internally at Epic Games and is publicly accessible.
If you have any further questions, please let us know.
Hi there! Very interesting. Thanks for posting these. I will try to implement what it is suggested here.