DotScreenPass.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. */
  4. THREE.DotScreenPass = function ( center, angle, scale ) {
  5. THREE.Pass.call( this );
  6. if ( THREE.DotScreenShader === undefined )
  7. console.error( "THREE.DotScreenPass relies on THREE.DotScreenShader" );
  8. var shader = THREE.DotScreenShader;
  9. this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );
  10. if ( center !== undefined ) this.uniforms[ "center" ].value.copy( center );
  11. if ( angle !== undefined ) this.uniforms[ "angle" ].value = angle;
  12. if ( scale !== undefined ) this.uniforms[ "scale" ].value = scale;
  13. this.material = new THREE.ShaderMaterial( {
  14. uniforms: this.uniforms,
  15. vertexShader: shader.vertexShader,
  16. fragmentShader: shader.fragmentShader
  17. } );
  18. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  19. this.scene = new THREE.Scene();
  20. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
  21. this.scene.add( this.quad );
  22. };
  23. THREE.DotScreenPass.prototype = Object.create( THREE.Pass.prototype );
  24. Object.assign( THREE.DotScreenPass.prototype, {
  25. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  26. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  27. this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
  28. this.quad.material = this.material;
  29. if ( this.renderToScreen ) {
  30. renderer.render( this.scene, this.camera );
  31. } else {
  32. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  33. }
  34. }
  35. } );