CubeTexturePass.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ( function () {
  2. class CubeTexturePass extends THREE.Pass {
  3. constructor( camera, tCube, opacity = 1 ) {
  4. super();
  5. this.camera = camera;
  6. this.needsSwap = false;
  7. this.cubeShader = THREE.ShaderLib[ 'cube' ];
  8. this.cubeMesh = new THREE.Mesh( new THREE.BoxGeometry( 10, 10, 10 ), new THREE.ShaderMaterial( {
  9. uniforms: THREE.UniformsUtils.clone( this.cubeShader.uniforms ),
  10. vertexShader: this.cubeShader.vertexShader,
  11. fragmentShader: this.cubeShader.fragmentShader,
  12. depthTest: false,
  13. depthWrite: false,
  14. side: THREE.BackSide
  15. } ) );
  16. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  17. get: function () {
  18. return this.uniforms.tCube.value;
  19. }
  20. } );
  21. this.tCube = tCube;
  22. this.opacity = opacity;
  23. this.cubeScene = new THREE.Scene();
  24. this.cubeCamera = new THREE.PerspectiveCamera();
  25. this.cubeScene.add( this.cubeMesh );
  26. }
  27. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive*/ ) {
  28. const oldAutoClear = renderer.autoClear;
  29. renderer.autoClear = false;
  30. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  31. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  32. this.cubeMesh.material.uniforms.tCube.value = this.tCube;
  33. this.cubeMesh.material.uniforms.tFlip.value = this.tCube.isCubeTexture && this.tCube.isRenderTargetTexture === false ? - 1 : 1;
  34. this.cubeMesh.material.uniforms.opacity.value = this.opacity;
  35. this.cubeMesh.material.transparent = this.opacity < 1.0;
  36. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  37. if ( this.clear ) renderer.clear();
  38. renderer.render( this.cubeScene, this.cubeCamera );
  39. renderer.autoClear = oldAutoClear;
  40. }
  41. dispose() {
  42. this.cubeMesh.geometry.dispose();
  43. this.cubeMesh.material.dispose();
  44. }
  45. }
  46. THREE.CubeTexturePass = CubeTexturePass;
  47. } )();