CubeTexturePass.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author bhouston / http://clara.io/
  4. */
  5. THREE.CubeTexturePass = function ( camera, envMap, opacity ) {
  6. THREE.Pass.call( this );
  7. this.camera = camera;
  8. this.needsSwap = false;
  9. this.cubeShader = THREE.ShaderLib[ 'cube' ];
  10. this.cubeMesh = new THREE.Mesh(
  11. new THREE.BoxBufferGeometry( 10, 10, 10 ),
  12. new THREE.ShaderMaterial( {
  13. uniforms: this.cubeShader.uniforms,
  14. vertexShader: this.cubeShader.vertexShader,
  15. fragmentShader: this.cubeShader.fragmentShader,
  16. depthTest: false,
  17. depthWrite: false,
  18. side: THREE.BackSide
  19. } )
  20. );
  21. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  22. get: function () {
  23. return this.uniforms.envMap.value;
  24. }
  25. } );
  26. this.envMap = envMap;
  27. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  28. this.cubeScene = new THREE.Scene();
  29. this.cubeCamera = new THREE.PerspectiveCamera();
  30. this.cubeScene.add( this.cubeMesh );
  31. };
  32. THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  33. constructor: THREE.CubeTexturePass,
  34. render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {
  35. var oldAutoClear = renderer.autoClear;
  36. renderer.autoClear = false;
  37. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  38. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  39. this.cubeMesh.material.uniforms.envMap.value = this.envMap;
  40. this.cubeMesh.material.uniforms.opacity.value = this.opacity;
  41. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  42. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  43. if ( this.clear ) renderer.clear();
  44. renderer.render( this.cubeScene, this.cubeCamera );
  45. renderer.autoClear = oldAutoClear;
  46. }
  47. } );