How to reset configured WEBGL color attachments in THREE.js?

Unfortunately KhronosGroup decided to break existing application code by changing the semantics of the WEBGL GL_EXT_draw_buffers API (see https://github.com/KhronosGroup/WebGL/pull/2780/files) in the second half of 2019.

This change broke some of my existing THREE.js based pages that rely on the original API (my pages had worked fine in the three years before the change).

Since I am not familiar with the implementation details of the THREE.js framework, I could use some help from somebody familiar with those details. To pinpoint the spot where I might put a fix to deal with the below issue (I do NOT want to migrate to a recent THREE.js since the effort would be significant and I see a high risk that the newer version might not deal with this special case either):

The problem that I am faceing is that I am using THREE.WebGLMultiRenderTarget (which was a development feature at the time I originally wrote my page in 2017 based on version 81dev). Unfortunately I only have a minimized version of the respective 81dev version - which even in its “prettyfied” form is not ideal for backward engineering…

Obviously the THREE.js infrastructure at some point attaches the respective color attachments to the gl.framebuffer and/or passes them to drawBuffersWEBGL() - and this still works nicely as long as all the fragment shaders actually write to all attachments.

To address WEBGL’s incompatible change I already reorganized my code to use separate scenes according to the number of attachments that the used shaders write, i.e. I now have one scene containing all the “traditional” stuff that does not use any additional color attachments, and a 2nd scene that exclusively uses shaders that write to 2 color attachments. The problem is the reinitialization when switching from a scene that used 2 color attachments to one that only uses 1. It seems that the additinal color attachments are never removed once they have been attached… consequenty I cannot get any regular 1-attachment shaders (i.e. all the built-in THREE.js shaders) to work since the new WEBGL impl now always will throw a “Active draw buffers with missing fragment shader outputs.” error as long as that additional earlier used color attachment has not been “detached”…

I am looking for some hack that allows me to reinitialize the respective state between be different render passes. I would have thought that I might fix my problem by patching THREE.js’s “setRenderTarget” but my respective attempts so far have not been successful.

Three.js r81 source files aren’t lost forever. You can still get access to that build on Github. Maybe you could checkout that release and make the modifications to the source files, instead of fiddling with a minified version?

Alternatively, there’s a pending PR for MultiRenderTarget that’s been in the backlog for about a year. Should be easy to go through that file and see how they deal with your case.

Thanks for the links. My slow internet connection was still downloading three.js-r81.zip when I finally found a setRenderTarget hack that does seem to work.

As far as I see all the discussions in the “PR for MultiRenderTarget” date from before KhronosGroup decided to break the WEBGL API. I doubt that they already solved the issue and rather suspect that they will fall into the same trap eventually.I left them a comment just in case.