I am creating an little game in c++ with directx 9 with a randomly created world and have an issue when the player goes far from the 3d origins (0,0,0) 3d rendering become very imprecise causing visual issues. I think it's because the values sent to the shader are floats and floats become less precise when increasing. I though about a solution to move all the models instead of moving the camera but it makes more calculating, I 'm afraid about the possible performances decrease.
Is there a trick to solve that problem ?
Thanks
The problem is probably that you are hitting the precision limits of single-precision floating point numbers. There are many ways to avoid these problems, depending on your setup and what particular issues you are experiencing; you can probably find one that will not require a serious performance hit.
From your question, I suspect that you've set up a big world with an arbitrary origin, which is rendered as a single mesh. If it is compatible with your setup, you might consider splitting your world into a set of tiles, each with its own origin. This will shift the precision problems from your points to your matrices; since everything in nearby tiles and objects will not be far from the origin, that might solve your problem in itself.
If you still have precision problems, it will be much cheaper to, say, use double precision to generate one matrix per tile/object than to fiddle the coordinates for each and every point in your landscape.
Note that this does raise the issue of switching origins when moving from tile to tile. This is unfortunate and annoying, but something of the sort is probably unavoidable if you want a world that is bigger than your floating point numbers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With