开发者

Increase precision in DirectX with high range positions?

开发者 https://www.devze.com 2023-02-10 13:00 出处:网络
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 visua

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!


This is a very common problem in the Video Game industry

You can clamp your generated points to a fix grid to prevent rounding issues. then, you can adjust the density of your grid to get the right balance between not-enough-precision and visual-glitches.

It's also good to have your origin at the center of your map.


Take a look at Practical Post-Process Depth of Field.

0

精彩评论

暂无评论...
验证码 换一张
取 消