Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CopyShader for Three.js?

I see a lot of projects using CopyShader at the end of a post-processing chain. I cannot find any documentation of it on Three.js. What does it do exactly? Additionally, why is setRenderTarget necessary here? If removed, the effects are not applied. But if it is included, then it will 'freeze' an a-scene in place, stopping all animations. I am able to use tick and setInterval to resume the animation, but the performance takes a huge hit.

For example:

var composer = new THREE.EffectComposer( renderer );

renderer.setRenderTarget( composer.readBuffer );

var renderPass = new THREE.RenderPass( scene, camera );

var copyPass = new THREE.ShaderPass( CopyShader );
composer.addPass( renderPass );

var vignettePass = new ShaderPass( VignetteShader );
vignettePass.uniforms[ "darkness" ].value = 1.0;

composer.addPass( vignettePass );
composer.addPass( copyPass );
composer.render();

this.composer = composer; // To run as composer.render()
like image 549
Dan Avatar asked Jul 24 '19 00:07

Dan


People also ask

What is post processing 3 js?

Post-processing is a widely used approach to implement such effects. First, the scene is rendered to a render target which represents a buffer in the video card's memory. In the next step one or more post-processing passes apply filters and effects to the image buffer before it is eventually rendered to the screen.

What is Copypass?

In copy-pass mode, cpio copies files from one directory tree to another, combining the copy-out and copy-in steps without actually using an archive. It reads the list of files to copy from the standard input; the directory into which it will copy them is given as a non-option argument.

What is 3 js used for?

js is a cross-browser JavaScript library and application programming interface (API) used to create and display animated 3D computer graphics in a web browser using WebGL.

What is a scene in three Js?

Scenes allow you to set up what and where is to be rendered by three. js. This is where you place objects, lights and cameras.


1 Answers

The postprocessing pipeline renders back and forth between 2 offscreen buffers. When the final pass is complete, the result needs to be copied to the actual screen. That's what the CopyShader does. Conceivably you could architect your passes so that the final pass rendered directly to the visible screen, but in practice, that introduces some complexity.

like image 160
manthrax Avatar answered Oct 29 '22 18:10

manthrax