I’m using 2 WebGLRenderTargets
that have a cumulative shader. Over time, the output of the previous frame gets added to the current frame, so the colors get brighter and brighter. Upon the click of a button, I’d like to reset the textures back to their original black state. Is there a built-in way to achieve this?
WebGLRenderTarget doesn’t have any clear()
or clearBuffer()
methods and neither does Texture. Is the only available approach to render a screen-sized black plane with these targets as render destinations to reset the two textures? I’ve thought of an approach, but it’s very burdensome and requires the creation of a lot more objects. Is there something simpler, like clearColorBuffer()
?
const geom = new PlaneBufferGeometry(2, 2);
const mat = new MeshBasicMaterial({color: new THREE.Color(0x000000)});
const clearMesh = new Mesh(geom, mat);
const clearCam = new Camera();
renderer.setRenderTarget(renderTarget1);
renderer.render(clearMesh, clearCam);
renderer.setRenderTarget(renderTarget2);
renderer.render(clearMesh, clearCam);