DotScreenPass.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.quad.frustumCulled = false; // Avoid getting clipped
  22. this.scene.add( this.quad );
  23. };
  24. THREE.DotScreenPass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  25. constructor: THREE.DotScreenPass,
  26. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  27. this.uniforms[ "tDiffuse" ].value = readBuffer.texture;
  28. this.uniforms[ "tSize" ].value.set( readBuffer.width, readBuffer.height );
  29. this.quad.material = this.material;
  30. if ( this.renderToScreen ) {
  31. renderer.render( this.scene, this.camera );
  32. } else {
  33. renderer.render( this.scene, this.camera, writeBuffer, this.clear );
  34. }
  35. }
  36. } );