Skip to content

Conversation

@takahirox
Copy link
Collaborator

Description

This PR fixes WebGLMultisampleRenderTarget mipmaps generation.

Problem that this PR fixes

If I create the multisample render target with generateMipmaps: true and minFilter: THREE.LinearMipmapLinearFilter, first render to multisample render target, and then render an object with the render target to screen, the object is black. (Note: no animation loop.)

https://jsfiddle.net/zfusoyde/

image

If the object is close to the camera, the object is rendered correctly.

https://jsfiddle.net/z87wr690/

image

Root issue

The mipmaps of multisample render target doesn't seem to be generated correctly.

This is the code in WebGLRenderer which updates mipmaps for render target.

https://github.com/mrdoob/three.js/blob/r129/src/renderers/WebGLRenderer.js#L1087-L1093

// Generate mipmap if we're using any kind of mipmap filtering
textures.updateRenderTargetMipmap( _currentRenderTarget );

// resolve multisample renderbuffers to a single-sample texture if necessary
textures.updateMultisampleRenderTarget( _currentRenderTarget );

Solution

If I flip the order of the code above to first call textures.updateMultisampleRenderTarget() and then call textures.updateRenderTargetMipmap(), the problem is fixed.

It seems we first need to resolve multisample renderbuffers to a single-sample texture and then generate mipmap (because mipmaps are generated from single-sample texture).

@mrdoob
Copy link
Owner

mrdoob commented Jun 30, 2021

Good catch!

@mrdoob mrdoob added this to the r130 milestone Jun 30, 2021
@mrdoob mrdoob merged commit 0a3a0ed into mrdoob:dev Jun 30, 2021
@takahirox takahirox deleted the FixMultisampleRenderTargetMipmaps branch June 30, 2021 07:37
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