CubeTexturePass.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @author bhouston / http://clara.io/
  3. */
  4. import {
  5. BackSide,
  6. BoxBufferGeometry,
  7. Mesh,
  8. PerspectiveCamera,
  9. Scene,
  10. ShaderLib,
  11. ShaderMaterial
  12. } from "../../../build/three.module.js";
  13. import { Pass } from "../postprocessing/Pass.js";
  14. var CubeTexturePass = function ( camera, envMap, opacity ) {
  15. Pass.call( this );
  16. this.camera = camera;
  17. this.needsSwap = false;
  18. this.cubeShader = ShaderLib[ 'cube' ];
  19. this.cubeMesh = new Mesh(
  20. new BoxBufferGeometry( 10, 10, 10 ),
  21. new ShaderMaterial( {
  22. uniforms: this.cubeShader.uniforms,
  23. vertexShader: this.cubeShader.vertexShader,
  24. fragmentShader: this.cubeShader.fragmentShader,
  25. depthTest: false,
  26. depthWrite: false,
  27. side: BackSide
  28. } )
  29. );
  30. this.envMap = envMap;
  31. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  32. this.cubeScene = new Scene();
  33. this.cubeCamera = new PerspectiveCamera();
  34. this.cubeScene.add( this.cubeMesh );
  35. };
  36. CubeTexturePass.prototype = Object.assign( Object.create( Pass.prototype ), {
  37. constructor: CubeTexturePass,
  38. render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {
  39. var oldAutoClear = renderer.autoClear;
  40. renderer.autoClear = false;
  41. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  42. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  43. this.cubeMesh.material.envMap = this.envMap;
  44. this.cubeMesh.material.opacity = this.opacity;
  45. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  46. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  47. if ( this.clear ) renderer.clear();
  48. renderer.render( this.cubeScene, this.cubeCamera );
  49. renderer.autoClear = oldAutoClear;
  50. }
  51. } );
  52. export { CubeTexturePass };