简体   繁体   English

规模在OpenGL中是否重要?

[英]Is scale important in OpenGL?

Does the scale of a scene matter in OpenGL? OpenGL中场景的比例是否重要? By scale I mean, for instance, drawing a 1 unit cube but setting the camera position 1000 pixels away vs setting the camera 100 pixels away from a 0.1 unit cube? 按比例我的意思是,例如,绘制1个单位的立方体,但将相机位置设置为1000像素,而将相机设置为距离0.1单位立方体100像素? I guess, firstly, am I correct in thinking this would yield the same results visually? 我想,首先,我认为这会在视觉上产生相同的结果吗? And if so, does anyone know how either would effect performance, if at all? 如果有的话,是否有人知道如果会影响性能?

My hunch would be that it would have no effect but a more definitive answer would be nice. 我的预感是它没有效果,但更明确的答案会很好。

It doesn't matter except for imprecisions using floating point arithmetic. 除了使用浮点运算的不精确之外没有关系。 So try not to use super small or large numbers. 所以尽量不要使用超小号或大号。

If you mean 2D this may not matter. 如果你的意思是2D,这可能无关紧要。 Image created both ways may look the same. 两种方式创建的图像看起来可能相同。

"Setting the camera" actually only changes the transformation matrix the vertices are multiplied by, so after the transformation is applied, the vertex positions are the same. “设置相机”实际上只会更改顶点乘以的变换矩阵,因此在应用变换后,顶点位置是相同的。 There might be minor differences resulting from the imprecision of floating-point values. 浮点值的不精确可能会导致细微差别。

If the camera has a constant near and far clipping distance, the resulting values in depth buffer will differ, and one of the cubes might get outside of the clipping plane range, which would make it appear different / not at all. 如果相机具有恒定的近和远剪切距离,则深度缓冲器中的结果值将不同,并且其中一个立方体可能超出剪切平面范围,这将使其看起来不同/根本不显示。

You should know that floats have two modes: normalized and unnormalized mode. 您应该知道浮点数有两种模式:标准化模式和非标准化模式。 For values below 0, you will have more bits and more precision. 对于低于0的值,您将拥有更多位和更高精度。 So, it is better if you keep everything between 0 and one. 因此,如果将所有内容保持在0和1之间,则会更好。

Also, looking to how the exp/mantissa works, the difference between numbers when a single bit changes, is bigger when you move away from zero, and things will start to make popping when you move very far from origin. 另外,看一下exp /尾数是如何工作的,单个位变化时数字之间的差异,当你离开零时会更大,当你离原点很远时,事情就会开始变成弹出。

Yes, it matters. 是的,这很重要。 Not because of OpenGL, but because of the nature of floating point operations - floating point precision degrades at larger magnitudes. 不是因为OpenGL,而是因为浮点运算的性质 - 浮点精度在较大幅度下降低。 Try and normalize your values such that you have values closer to zero. 尝试并规范化您的值,使您的值接近零。 That is, don't make a planet object 1,000,000 units wide just because you want a planet that's 1,000 KM in diameter. 也就是说,不要仅仅因为你想要一个直径为1000公里的行星而使行星物体的宽度达到1,000,000单位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM