CubeTexturePass.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. console.warn( "THREE.CubeTexturePass: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. THREE.CubeTexturePass = function ( camera, envMap, opacity ) {
  3. THREE.Pass.call( this );
  4. this.camera = camera;
  5. this.needsSwap = false;
  6. this.cubeShader = THREE.ShaderLib[ 'cube' ];
  7. this.cubeMesh = new THREE.Mesh(
  8. new THREE.BoxBufferGeometry( 10, 10, 10 ),
  9. new THREE.ShaderMaterial( {
  10. uniforms: this.cubeShader.uniforms,
  11. vertexShader: this.cubeShader.vertexShader,
  12. fragmentShader: this.cubeShader.fragmentShader,
  13. depthTest: false,
  14. depthWrite: false,
  15. side: THREE.BackSide
  16. } )
  17. );
  18. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  19. get: function () {
  20. return this.uniforms.envMap.value;
  21. }
  22. } );
  23. this.envMap = envMap;
  24. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  25. this.cubeScene = new THREE.Scene();
  26. this.cubeCamera = new THREE.PerspectiveCamera();
  27. this.cubeScene.add( this.cubeMesh );
  28. };
  29. THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  30. constructor: THREE.CubeTexturePass,
  31. render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {
  32. var oldAutoClear = renderer.autoClear;
  33. renderer.autoClear = false;
  34. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  35. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  36. this.cubeMesh.material.uniforms.envMap.value = this.envMap;
  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. } );