CubeTexturePass.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. ( function () {
  2. class CubeTexturePass extends THREE.Pass {
  3. constructor( camera, envMap, 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.envMap.value;
  19. }
  20. } );
  21. this.envMap = envMap;
  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
  28. /*, deltaTime, maskActive*/
  29. ) {
  30. const oldAutoClear = renderer.autoClear;
  31. renderer.autoClear = false;
  32. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  33. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  34. this.cubeMesh.material.uniforms.envMap.value = this.envMap;
  35. this.cubeMesh.material.uniforms.flipEnvMap.value = this.envMap.isCubeTexture && this.envMap.isRenderTargetTexture === false ? - 1 : 1;
  36. this.cubeMesh.material.uniforms.opacity.value = this.opacity;
  37. this.cubeMesh.material.transparent = this.opacity < 1.0;
  38. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  39. if ( this.clear ) renderer.clear();
  40. renderer.render( this.cubeScene, this.cubeCamera );
  41. renderer.autoClear = oldAutoClear;
  42. }
  43. }
  44. THREE.CubeTexturePass = CubeTexturePass;
  45. } )();