禁用对象剔除

发布于 2024-11-17 15:58:42 字数 507 浏览 4 评论 0原文

这个问题实际上是针对Unity3D的,但它也可以是一个更普遍的问题,因此我将尽可能普遍地提出这个问题。

假设我有一个带有相机的场景(near = 0.3,far = 1000,fov = 60),并且我想绘制一个半径为 10000 单位的天幕。

该物体没有被相机的视锥体剔除,因为我在圆顶内部。但顶点以某种方式被某些着色器剔除,最终结果如下所示:

My Clipped skydome

现在我的问题是:

我可以更改任何引擎的哪些设置来确保绘制完整的对象并且不会被相机的远平面剪切?

我不想要的是:

  • 将远平面更改为 10000,因为它使平截头体不太准确
  • 更改近平面,因为我的游戏实际上处于非常低的比例
  • 更改圆顶的比例,因为此设置看起来非常逼真

This question is actually for Unity3D, but it can also be a more general question, so therefore I'm going to make this question as general possible.

Suppose I have a scene with a camera (near = 0.3, far = 1000, fov = 60) and I want to draw a skydome that is 10000 units in radius.

The object is not culled by the frustum of the camera, because I'm inside of the dome. But the vertices are culled by some shader somehow and the end-result looks like this:

My clipped skydome

Now my question is:

what setting for any engine can I change to make sure that the complete object is drawn and not clipped by the far plane of the camera?

What I don't want is:

  • Change the far plane to 10000, because it makes the frustum less accurate
  • Change the near plane, because my game is actually on a very low scale
  • Change the scale of the dome, because this setting looks very realistic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-11-24 15:58:42

我不知道如何在 Unity 中执行此操作,但在 DirectX 和 OpenGL 中,您需要关闭 zbuffer(检查和写入)并首先绘制天空盒。

然后打开 zbuffer 并绘制场景的其余部分。

我的猜测是 Unity 可以做到这一切都是为了你。

I do not know how to do this in Unity but in DirectX and in OpenGL you switch off the zbuffer (both checks and writing) and draw the skybox first.

Then you switch on the zbuffer and draw the rest of the scene.

My guess is that Unity can do all this for you.

浊酒尽余欢 2024-11-24 15:58:42

对于我自己的问题,我有两种解决方案。第一个并不能解决所有问题。第二个确实如此,但违反了我自己的设计原则。

我不可能更改着色器的 z 书写,这是 @Erno 的一个很好的解决方案,因为使用的着色器是第三方的。

选项 1

在渲染对象之前,将远平面设置为 100,000,并在绘制天空后将其设置回 1000。

问题:深度缓冲区仍然充满非常低到 100,000 之间的值。这会降低深度缓冲区的准确性,并导致深度冲突和依赖于深度缓冲区的后期效果出现问题。

选项 2

创建两个相互链接的摄像机。摄像机 1 首先渲染天幕,设置为 far = 100000,near = 100。相机 2 清除深度缓冲区并使用 far = 1000,near = 0.3 设置绘制场景的其余部分。深度缓冲区现在不包含大值,因此解决了深度缓冲区不准确的问题。

问题:相机必须通过某些轮询系统链接,因为相机类上没有更改事件(例如,当 FoV 更改时)。我喜欢只有一台相机的事实,但这似乎不太容易实现。

I have two solutions for my own problem. The first one doesn't solve everything. The second does, but is against my own design principles.

There was no possibility for me to change the shader's z-writing, which is a great solution from @Erno, because the shaders used are 3rd party.

Option 1

Just before the object is rendered, set the far plane to 100,000 and set it back to 1000 after drawing the sky.

Problem: The depth buffer is still filled with values between very low and 100,000. This decreases the accuracy of the depth buffer and gives problems with z-fighting and post-effects that depend on the depth buffer.

Option 2

Create two cameras that are linked to each other. Camera 1 renders the skydome first with a setting of far = 100000, near = 100. Camera 2 clears the depth buffer and draws the rest of the scene with a setting of far = 1000, near = 0.3. The depth buffer doesn't contain big values now, so that solves the problems of inaccurate depth buffers.

Problem: The cameras have to be linked by some polling system, because there are no change events on the camera class (e.g. when FoV changes). I like the fact that there is only one camera, but this doesn't seem possible quite easily.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文