纹理/模型在远处闪烁(3D) [英] Texture/model flickering in distance (3D)

查看:40
本文介绍了纹理/模型在远处闪烁(3D)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在我的 XNA 项目中,我添加了简单的着色器 + 模型加载代码,一切正常.我在 3Ds Max 中创建了一个非常简单的低细节模型.以 FBX 格式导出和导入到 XNA.

Ok, in my XNA project i've added simple shader + model loading code, anything works. I created a very simple low-detailed model in 3Ds Max. Exported and imported to XNA with FBX format.

问题是:如果我将我的简单相机移到离这个模型一定距离的地方,它的一个组件开始闪烁.我尝试了另一个模型,但出现了同样的情况,只有当我与模型保持一定距离时,某些组件才会开始闪烁.

The problem is: if i move my simple camera to some distance from this model, one of its components starts to flicker. I tried another model and there is the same situation, some of components start to flicker and only if i get to some distance from model.

这种闪烁(或闪烁或 ..)仅在带纹理的对象(可能)中出现,看起来像:在每一帧中,模型的随机部分/像素(或不那么随机)被模型或其组件后面的对象替换...... :(

This flickering (or blinking or ..) appears only with textured objects (probably), and looks like: in each frame random parts/pixels of model (or not so random) replaced with object which is behind a model or its component... :(

更新:现在我知道了 - 问题出在我的模型中(我检查了一些其他模型).我不明白为什么,但平面对象会闪烁.也许问题不在 Plane 对象中.

UPDATE: Now i know - problem is in my model (i checked some other models). I dont understand why but Plane object gives that flickering. Maybe the problem is not in Plane object.

推荐答案

这只是一个有根据的猜测,但是:你的远平面太远,或者你的近平面太近,或者两者都有.

This is only an educated guess but: Your far-plane is too far away, or your near-plane is too close, or both.

透视相机为您提供如下所示的可视区域:

A perspective camera gives you a viewable area that looks like this:

您的 Z 缓冲区(深度缓冲区)涵盖近平面和远平面之间的范围.典型的 Z 缓冲区可能具有 24 位精度,为您提供 224 个可能的值.近平面和远平面的距离越远,每个可能值必须覆盖的世界空间距离就越大.换句话说:您的 Z 缓冲区不太准确.

Your Z-buffer (depth buffer) covers the range between the near and the far planes. A typical Z-buffer might have 24-bits of precision, giving you 224 possible values. The further apart your near and far planes are, the greater the world-space distance each possible value must covers. In other words: your Z buffer is less accurate.

您所看到的称为Z-fighting".这就是 Z 缓冲区不够准确的地方,无法区分两个给定像素的深度.因此,您最终会得到本应被拒绝的像素,因为它们位于已经渲染的后面",而是绘制出来的.

What you are seeing is known as "Z-fighting". This is where the Z-buffer is not accurate enough to differentiate between the depths of two given pixels. So you end up with pixels that should have been rejected as being "behind" what was already rendered, drawn instead.

(或者,您的模型有一些共面或接近共面的三角形 - 即表面靠得太近的三角形.同样的问题:Z 缓冲区中的精度不足以区分两个表面.)

(Alternately your model has some coplanar or nearly coplanar triangles - that is triangles who's surfaces are too close together. Same issue: Not enough precision in the Z-buffer to differentiate between the two surfaces.)

如果尚未启用背面剔除 (RasterizerState.CullCounterClockwise),您可能还希望启用它.这会剔除远离相机的三角形,从而消除 Z-fighting 的一种可能来源.

You may also wish to enable backface-culling (RasterizerState.CullCounterClockwise), if it is not already enabled. This culls triangles facing away from the camera, removing one possible source of Z-fighting.

这篇关于纹理/模型在远处闪烁(3D)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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