Skip to content

PassNode: Implement Auto-MRT. #28749

@Mugen87

Description

@Mugen87

Description

More advanced effects like AO, Bloom or Motion Blur require next to beauty and depth a normal and potentially a velocity buffer from the scene pass. It would be good for performance if normal and velocity would be generated in one pass with beauty and depth. To do that, the renderer needs to automatically configure the scene's materials so they output whatever is requested in the current render target.

Solution

In PassNode I have added the following two methods:

getTextureNormalNode() {

	if ( this._normalTextureNode === null ) {

		const normalTexture = this.renderTarget.textures[ 0 ].clone();
		normalTexture.name = 'PostProcessingNormal';
		normalTexture.isRenderTargetTexture = true;

		this.renderTarget.textures[ 1 ] = normalTexture;
		this._normalTextureNode = nodeObject( new PassTextureNode( this, normalTexture ) );

	}

	return this._normalTextureNode;

}

getTextureVelocityNode() {

	if ( this._velocityTextureNode === null ) {

		const velocityTexture = this.renderTarget.textures[ 0 ].clone();
		velocityTexture.name = 'PostProcessingVelocity';
		velocityTexture.isRenderTargetTexture = true;

		this.renderTarget.textures[ 2 ] = velocityTexture;
		this._velocityTextureNode = nodeObject( new PassTextureNode( this, velocityTexture ) );

	}

	return this._velocityTextureNode;

}

However, they only configure the render target and the texture nodes for further use in effects. It's also required to auto-configure all node materials in the scene to produce the correct output according to the render targets setting. I've seen OutputStructNode and its usage in webgpu_multiple_rendertargets but this class needs to be used internally somehow.

Alternatives

Doing post processing without MRT but this has performance implications when implementing more complex effects.

Additional context

#27808 tries to add this for WebGLRenderer but there is an unsolved material updating issue when switching render targets.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions