通过高范围位置提高DirectX的精度? [英] Increase precision in DirectX with high range positions?

查看:67
本文介绍了通过高范围位置提高DirectX的精度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Directx 9用c ++创建一个带有随机创建世界的小游戏,当玩家远离3d起源(0,0,0)时3D渲染变得非常不精确,导致视觉问题,这是一个问题.我认为这是因为发送到着色器的值是浮点数,并且增加时浮点数的精度降低.尽管我提出了一种解决方案,可以移动所有模型而不是移动相机,但是这样做会使计算量增加,但我担心性能可能会降低.

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 ?

谢谢

推荐答案

问题可能是您达到了单精度浮点数的精度极限.有多种方法可以避免这些问题,具体取决于您的设置以及遇到的特定问题.您可能会找到不需要严重影响性能的产品.

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!

这篇关于通过高范围位置提高DirectX的精度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆