Disable culling on an object
Asked Answered
P

2

0

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
Padding answered 29/6, 2011 at 18:27 Comment(0)
H
1

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.

Homomorphism answered 30/6, 2011 at 19:17 Comment(1)
Thanks for the research. Unity uses static skybox, but mine is of course dynamic. I have found a solution which is probably the only one in Unity. You are right about your zbuffering, so +1. I'll post my own solution with a bit more detail.Padding
P
0

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.

Padding answered 30/6, 2011 at 19:41 Comment(2)
I strongly suggest using other shaders or modifying them because option 1 is still causing artifacts and option 2 requires an extra pass whereas a correct shader will be very fast and precise.Homomorphism
@Erno That is true, I will check with the 3rd party company and see what they think about this issue.Padding

© 2022 - 2024 — McMap. All rights reserved.