0

In order to solve the problem of z-fighting, I limited the near and far of camera to a small range.But when I want to add a larger object,it was culled by view frustum.

I tried object3d.frustumCulled property,not working as expected,the reason is as follows: https://github.com/mrdoob/three.js/issues/12170

So,is there a way to ensure that some specific objects are not frustum culled without changing the camera near and far? THX.

ZhaDeveloper
  • 48
  • 1
  • 6
  • 2
    Setting `frustrumCulled = false` doesn't mean that it will show up when beyond the "far" camera range. Think of it this way: When the object goes too far right, it'll go off-screen until it's not visible by the camera. The same thing happens when you push it away from the camera, once it's beyond the "far" value, it's out of the camera's viewport, regardles on whether frustrum culling is enabled or not. You'll have to reconsider your z-fighting solution. Why don't you simply move the conflicting faces a little further apart? – M - Jan 14 '20 at 03:52
  • frustum^ If you need different near and far for culling on different objects, you could adjust near and far and render your scene in multiple passes? Also, you may want to look at .logarithmicDepthBuffer to get better z resolution near the near plane? Curious why changing near and far is not an option? – manthrax Jan 14 '20 at 03:57
  • 1
    If you want to chat about this in realtime, feel free to visit this slack channel.. https://join.slack.com/t/threejs/shared_invite/enQtMzYxMzczODM2OTgxLTQ1YmY4YTQxOTFjNDAzYmQ4NjU2YzRhNzliY2RiNDEyYjU2MjhhODgyYWQ5Y2MyZTU3MWNkOGVmOGRhOTQzYTk – manthrax Jan 14 '20 at 04:06
  • Thank you very much for your fast answer, i used .logarithmicDepthBuffer to slove z-fighting before,but there is an aliasing problem, so i want to find a sample way to disable frustum culling and ensure the accuracy of other objects by bot changing near and far at the same time. – ZhaDeveloper Jan 14 '20 at 06:43
  • i may try multiple passes, thanks again. And I also registered that slack channel,Studying how to use.... – ZhaDeveloper Jan 14 '20 at 06:48

1 Answers1

2

Culling doesn't mean that an object is drawn or not. It can be either drawn or not drawn depending on where it is. It is an optimization that tries to say something like this:

Hey, i have a really cheap check (plane/sphere intersection) that i can do and tell you if you need to attempt to draw this at all.

So you do a cheap check, and if the object is guaranteed to be entirely out of the frustum, you never issue the draw call. If it intersects, you have to issue a draw call, but you may still see nothing if none of the triangles are actually in the frustum.

If you download something like specter.js and inspect your draw calls, you will infact see that with frustumCulled = false you get a draw call for every object in your scene. Your screen may be empty.

pailhead
  • 5,162
  • 2
  • 25
  • 46
  • 2
    Sometimes we have things we're rendering that use vertex shaders and you cannot predict ahead of time any reasonable limit to their size or shape. This is a reasonable scenario for disabling frustum culling. – Steven Lu Apr 20 '22 at 23:16
  • It is also useful for something like uv rasterization for baking lightmaps. Everything need to be visible and rendered. – Ifeanyi Nmoye Aug 06 '22 at 18:33
  • Correct. I want to say that most custom shaders would want to start with a mesh with culling disabled, so it’s guaranteed that they are rendered and as to save headache :) – pailhead Aug 07 '22 at 19:08