CubeTexturePass.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. THREE.CubeTexturePass = function ( camera, envMap, opacity ) {
  2. THREE.Pass.call( this );
  3. this.camera = camera;
  4. this.needsSwap = false;
  5. this.cubeShader = THREE.ShaderLib[ 'cube' ];
  6. this.cubeMesh = new THREE.Mesh(
  7. new THREE.BoxGeometry( 10, 10, 10 ),
  8. 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. );
  17. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  18. get: function () {
  19. return this.uniforms.envMap.value;
  20. }
  21. } );
  22. this.envMap = envMap;
  23. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  24. this.cubeScene = new THREE.Scene();
  25. this.cubeCamera = new THREE.PerspectiveCamera();
  26. this.cubeScene.add( this.cubeMesh );
  27. };
  28. THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  29. constructor: THREE.CubeTexturePass,
  30. render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {
  31. var oldAutoClear = renderer.autoClear;
  32. renderer.autoClear = false;
  33. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  34. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  35. this.cubeMesh.material.uniforms.envMap.value = this.envMap;
  36. this.cubeMesh.material.uniforms.flipEnvMap.value = ( this.envMap.isCubeTexture && this.envMap._needsFlipEnvMap ) ? - 1 : 1;
  37. this.cubeMesh.material.uniforms.opacity.value = this.opacity;
  38. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  39. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  40. if ( this.clear ) renderer.clear();
  41. renderer.render( this.cubeScene, this.cubeCamera );
  42. renderer.autoClear = oldAutoClear;
  43. }
  44. } );