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

Renderer: .setRenderObjectFunction() #27068

Merged
merged 4 commits into from
Oct 30, 2023
Merged

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 27, 2023

Related issue: #25822, #27053, #25933

Description

renderer.renderObjectFunction() offers the ability to filter or change the object in the rendering state, this fixes the current optimization problem in shadow rendering in WebGPURenderer and can also be used in cases like this #25933 and others where users use scene.traverse() to make the filter of objects could use this method which already pass through the frustumCulled filter.

Usage

function renderObjectFunction( object, ...params ) {

	if ( object.castShadow === true ) {

		renderer.renderObject( object, ...params );

	}

}


renderer.setRenderTarget( rtt );
renderer.setRenderObjectFunction( renderObject );

renderer.render( scene, camera );

@sunag sunag marked this pull request as ready for review October 27, 2023 05:21
@mrdoob
Copy link
Owner

mrdoob commented Oct 27, 2023

.setRenderObjectFunction() may be better?

@sunag sunag changed the title Renderer: .setRenderObject() Renderer: .setRenderObjectFunction() Oct 27, 2023
@sunag sunag added this to the r159 milestone Oct 29, 2023
@sunag sunag merged commit 8611778 into mrdoob:dev Oct 30, 2023
18 checks passed

renderer.setRenderObjectFunction( ( object, ...params ) => {

if ( object.castShadow === true ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be simpler to do something like... renderer.setRenderObjectFilter( object => object.castShadow === true )? /ping @sunag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setRenderObjectFunction is more handler-oriented than filter-oriented. If there were any changes I would suggest setRenderObjectHandler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I certainly agree "handler" would be a better name -- but I just think maybe it would be better for a user-facing API to be simpler and don't provide full "handling" behavior, but only the "filtering" one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have more applications this way, for example, such as adding onBeforeShadow and onAfterShadow soon.

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.

3 participants