mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.76k stars 35.3k forks source link

Is dynamic backface culling worth it? #47

Closed fabricasapiens closed 13 years ago

fabricasapiens commented 13 years ago

Since the culling of cube-faces is implemented recently by MrDoob, I wondered the following:

I've not implemented culling yet (but will do for static faces in-between cubes) and am wondering if it would be worthwile to do backface culling, i.e. only render the faces that are visible to the player? That would require quite some CPU as it has to be recalculated after every move of the camera, but it lessens the burden on the GPU quite some (right?). What would you advice?

mrdoob commented 13 years ago

Are we talking CanvasRenderer or WebGLRenderer here?

Both have back-face culling already. Depends of your scene and what the user is supposed to see. But yes, it's always good to remove faces that will never be seen (less computations), it's like having code that does nothing.

fabricasapiens commented 13 years ago

I currently use WebGLRenderer.

That they both already have backface-culling is great!

I then however wonder why you (here https://github.com/mrdoob/three.js/commit/52ef987a796a5728e265edc6f8b21f795611bb27) did remove the bottom faces of the cubes in the Minecraft demo. These faces are always backfaces, so they are already culled, right?

As for the culling of invisible faces, it save computations for the GPU, but it takes extra computations for the CPU every time the camera moves (because then, it should be recalculated what is visible and what is not...). There is a trade-off, I guess?

mrdoob commented 13 years ago

That was alteredq though... Anyway, it's not that we're -removing- the bottom sides of the cube. It's that we're -not adding- them. Kinda different ;)

Backface culling is useful for faces that may be seen at some point. Like the back of the Walt Disney head which you would be seeing. But, in theory, the bottom of the minecraft cubes shouldn't ever be seen, so you can -not add- them to save memory and CPU/GPU computations.

fabricasapiens commented 13 years ago

Ah, I see... Should have thought about that myself :-)

Thanks for the explanation!

How can I contribute back to the project and to you? Is there anything you would like?

mrdoob commented 13 years ago

You can contribute back by doing amazing stuff with it ;)

fabricasapiens commented 13 years ago

Will do ;-)