怪异的线3D Unity [英] Weird Lines 3D Unity

查看:144
本文介绍了怪异的线3D Unity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Unity 5.4进行项目. 在此项目中,块彼此相邻堆叠.

I'm working on a project, using unity 5.4. In this projects blocks are stacked next to eachother.

但是,会出现一些令人讨厌的怪异线条.同样在Android上这些 行比在PC上发生的频率更高. 为了说明目的,我添加了图像和视频. 请放大图片以清楚地看到我说的那一行.

However there appear some annoying weird lines. Also on android these line occur more often than on PC. For illustration purposes I added an image and video. Please zoom in on the picture to see, the line I'm speaking of, clearly.

任何人都可以提供解决方案以消除这种麻烦. 预先感谢.

Could anyone please provide a solution to get red of this nuissance. Thanks in advance.

文献:

块对齐代码段:

for (int x = 0; x < xSize; x++)
        for (int z = 0; z < zSize; z++)
        {
            Vector3 pos = new Vector3(x, -layerDepth, z);
            InstantiateBlock(pos);
        }

视频链接: https://youtu.be/5wN1Wn51d_Y

推荐答案

您有对象接缝!

当对象之间存在物理或感知间隙时,会发生这种情况.

This occurs when there is a physical or perceived gap between objects.

有多种原因.

这可能是因为您将多维数据集的位置设置为int,但是它们具有浮点尺寸.这种现象的症状通常是当相机靠近物体时没有白缝,然后由于浮点的不精确性,当您离物体越来越远时,它们会逐渐出现. 更多.

This could be because you are setting the position of the cubes to int's but they have floating point dimensions. The symptom for this is usually no white seams when the camera is close to the objects, and then they gradually appear as you get further away due to floating point imprecision. More.

这些块中的大多数似乎都在大多数相机位置上精确对齐.但是从偶尔的不幸位置来看,A的位置加上其顶点在(0.5,0.5,-0.5)的确切值可能与对象B的位置加上其顶点在(-0.5,0.5,-0.5)的确切值略有不同.结果是Unity显示了一个很小的间隙,您可以在其中看到立方体A的阴影面.

Most of these blocks appear to line up exactly, from most camera positions. But from the occasional unfortunate position, the exact value for A's position plus its vertex at (0.5,0.5,-0.5) might be slightly different to object B's position plus its vertex at (-0.5,0.5,-0.5) . The result is that Unity shows a tiny gap, within which you can see the shadowed side of cube A.

如果在纸上3 == 1/3 * 3考虑以下内容,这在数学上是正确的,但是使用浮点数,1/3 == 0.333333...和随后的3 * 0.333333... == 0.999999... BINGO!物体之间的随机间隙!

If you consider the following on paper 3 == 1/3 * 3 this is mathematically correct, however using floats, 1/3 == 0.333333... and subsequently 3 * 0.333333... == 0.999999... BINGO! random gap between objects!

那么如何解决?使用浮点数计算对象的位置.例如,new vector3(1,1,1);应该是new vector3(1f,1f,1f);.有关此内容的更多信息,请尝试 SOP.

So how to solve? Use floats to calculate the positions of your objects. new vector3(1,1,1); should be new vector3(1f,1f,1f); - for example. For further reading on this try this SOP.

如果在对象上使用纹理,请尝试将纹理的环绕模式"从环绕"更改为夹紧",或者尝试增大纹理

If you are using textures on your objects, try changing the Wrap-Mode of your texture from wrap to clamp, or try upping the texture padding.

这是阴影中的像素的任意模式,当它们应该真正点亮或不点亮时.

This is the arbitrary patterns of pixels in shadow when they should really be lit or NOT lit.

为防止阴影痤疮,可以将Bias值添加到阴影贴图的距离中,以确保边界线上的像素确实通过了应有的比较,或者确保在渲染到阴影贴图时进行比较. .

在Unity中...转到光源,然后增加Shadow Type > shadow Bias,我建议将默认值0.05加倍,然后继续操作直至固定.您不想将这个值提高到最大值,因为...

In Unity... go to your light source and then increase the Shadow Type > shadow Bias I would suggest doubling the default value of 0.05 and then continue so until fixed. You don't want to crank this value to max because...

不要将Bias值设置得太高,因为GameObject投射附近的阴影周围的区域有时会被错误地照亮.这样会产生断开的阴影,使GameObject看起来好像在地面上飞行.

Do not set the Bias value too high, because areas around a shadow near the GameObject casting it are sometimes falsely illuminated. This results in a disconnected shadow, making the GameObject look as if it is flying above the ground.

这篇关于怪异的线3D Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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