Hi, I use a custom pass to apply gamma correction to the foreground content and not to the background. I have used the same pattern for some time but a recent update (chrome? or three?) has introduced a warning:
[.WebGL-0x3de001ac3100] GL_INVALID_OPERATION: Feedback loop formed between Framebuffer and active Texture.
Followed by:
WebGL: too many errors, no more errors will be reported to the console for this context.
I’m using three r153
.
The custom pass contains a rendertarget, fullscreen quad, copy material and gamma correction material.
The render method:
-
copies the previously rendered content (accumulated background passes) from the read buffer to the write buffer.
-
renders the foreground content to the passes own render target
-
sets the fsquad material to the gamma correction material and the diffuse texture to the passes render target texture
-
renders the fsquad to the write buffer applying the gamma correction material.
render(
renderer: THREE.WebGLRenderer,
writeBuffer: THREE.WebGLRenderTarget,
readBuffer: THREE.WebGLRenderTarget,
deltaTime: number,
maskActive: boolean
) {
// Render the previous pass (readBuffer) to a full screen quad
this.fsQuad.material = this.materialCopy;
this.copyUniforms['tDiffuse'].value = readBuffer.texture;
// render the previous pass to the out buffer
renderer.setRenderTarget(this.renderToScreen ? null : writeBuffer);
renderer.clear();
this.fsQuad.render(renderer);
//// Render the main scene to a new buffer
// First store previous renderervalues
renderer.setRenderTarget(this.renderTargetBuffer);
const prevClearColour = renderer.getClearColor(new THREE.Color());
const prevClearAlpha = renderer.getClearAlpha();
const prevAutoClear = renderer.autoClear;
// Perform the render
renderer.autoClear = false;
renderer.setClearColor(0x000000, 0);
renderer.clear();
renderer.render(this.scene, this.camera);
// perform linear to sRGB on the new buffer and
// render it over the top of the previous pass
// with gamma correction and normal blending enabled
// on the material
this.fsQuad.material = this.gammaCorrectionMaterial;
this.gammaUniforms['tDiffuse'].value = this.renderTargetBuffer.texture;
renderer.setRenderTarget(this.renderToScreen ? null : writeBuffer);
this.fsQuad.render(renderer);
// restore previous settings to the renderer
renderer.setClearColor(prevClearColour, prevClearAlpha);
renderer.autoClear = prevAutoClear;
}
I’ve seen this pattern used elsewhere, like in the outline pass, and having just checked that example it isn’t producing the same error, so I’m wondering where I’ve gone wrong.