gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.38k stars 133 forks source link

WebGLPathTracer: Automatically position model to avoid numeric precision problems #678

Open Drosaca opened 3 days ago

Drosaca commented 3 days ago

Describe the bug I loaded a 3D model and applied OrbitControls to it. The path tracing work fine when the model is at the origin (0,0,0). However, after repositioning the model far from the origin and moving the camera to the new position, the path tracing is rendered on a low-quality texture, while the default renderer displays the correct texture.

chrome_raUJgxWO8g (1)

Expected behavior expected this at position ("x": -3761603.743620786, "y": 4105279.00727716, "z": 3870314.8490743843) and not only at (0,0,0)

chrome_HIKeW216JU

Repro Model can't upload: "We don’t support that file type." can be downloaded from here: https://mega.nz/file/faxFkAjI#kYYd7T3MVEgmjj6cC1PhPiqNpT2yaYaOaATuFIlTatc original source: https://sketchfab.com/3d-models/starlink-spacex-satellite-0a60f6720c5141c9a1c6d71aac108b31

AntonPalmqvist commented 3 days ago

Try increasing the textureSize parameter: https://github.com/gkjohnson/three-gpu-pathtracer?tab=readme-ov-file#texturesize

gkjohnson commented 3 days ago

When submitting an issue please follow the template and submit the information that's requested - you haven't provided enough information to say exactly what the issue is.

My guess is that this is related to floating point precision at large numbers away from zero (though you haven't said how far). This is something that's not currently handled internally so assuming that's what the issue is you'll have to adjust the model position and camera to be near zero.

Drosaca commented 3 days ago

When submitting an issue please follow the template and submit the information that's requested - you haven't provided enough information to say exactly what the issue is.

My guess is that this is related to floating point precision at large numbers away from zero (though you haven't said how far). This is something that's not currently handled internally so assuming that's what the issue is you'll have to adjust the model position and camera to be near zero.

Ok I updated the issue, the far away value is "x": -3761603.743620786, "y": 4105279.00727716, "z": 3870314.8490743843. it looks like a low poly version of my object when it's far but only with the path traced version.

Drosaca commented 3 days ago

Try increasing the textureSize parameter: https://github.com/gkjohnson/three-gpu-pathtracer?tab=readme-ov-file#texturesize

I tried with 4096 but it doesn't change anything :(

gkjohnson commented 1 day ago

Ok I updated the issue, the far away value is "x": -3761603.743620786, "y": 4105279.00727716, "z": 3870314.8490743843. it looks like a low poly version of my object when it's far but only with the path traced version.

Yes these numbers are very large and will likely cause numeric precision issues when rendering. I recommend moving the camera and model closer to the origin to address the issue. This could probably be fixed automatically by the renderer but it would need to be implemented.

I tried with 4096 but it doesn't change anything :(

Yeah this won't help in this case, unfortunately, since it's a numeric problem.