Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLRenderer.customCullCallback and Soft Particles Example #5911

Closed
wants to merge 3 commits into from

Conversation

tsone
Copy link

@tsone tsone commented Jan 16, 2015

Two-line change in WebGLRenderer to support custom callback function to cull objects in the scene graph. This culling does not replace other culling mechanisms (frustum culling, visibility property), but it performs culling before these. The intent is to eliminate the need to perform unnecessary scene traversals or tweaking of object or material visibility to achieve same effect. With it one can easily perform custom culling for example in complex scenes with the aid of some accelerating structure.

The accompanying Soft Particles [1] [2] example demonstrates the use by culling all transparent objects when the depth texture is rendered.

@tsone
Copy link
Author

tsone commented Jan 16, 2015

Forgot to mention that the idea was discussed in the last comments of #5900.

@mrdoob
Copy link
Owner

mrdoob commented Jan 16, 2015

This is nice! Maybe you can give a go at the layers approach though? See #5562.

@tsone
Copy link
Author

tsone commented Jan 16, 2015

I read that discussion on culling mask/layer and I think that can be easily done using this cull callback. For example right now, one could use Object3D.userData property to store layerBits that tell which layers the object belongs to. Here's how the data would be laid out in that case:

// Set object to belong to layer 0
object.userData.layerBits = 0x01;

// Set object to belong to both layers 0 and 1
object.userData.layerBits = 0x03;

Then the cull callback could check this flag against a mask. Here is how:

function layerMaskCull( layerMask ) {

    return function ( object ) {
        return object.userData.layerBits && (( object.userData.layerBits & layerMask ) === 0 );
    };

};

// Render objects in layer 0
renderer.customCullCallback = layerMaskCull( 0x01 );
renderer.render( scene, camera );

// Render objects in both layer 0 and 1
renderer.customCullCallback = layerMaskCull( 0x03 );
renderer.render( scene, camera );

I think that does what the discussion is about. If bitwise operations are confusing to people, this functionality could be wrapped with a more intuitive API. Also to mention, this does not affect object.visible (or other visibility flags) or frustum culling, but is done before those.

@mrdoob
Copy link
Owner

mrdoob commented Jan 16, 2015

Yes I know, but that's not very pretty API-wise.
I think the API proposed in the other thread is prettied and more user friendly.

@tsone
Copy link
Author

tsone commented Jan 19, 2015

I'll modify this soft particles example to use culling layers instead.

@tsone tsone closed this Jan 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants