开发者

Disable culling on an object

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:

Disable culling on an object

开发者_JS百科

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜