CubeTexturePass.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ( function () {
  2. var 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( new THREE.BoxGeometry( 10, 10, 10 ), new THREE.ShaderMaterial( {
  8. uniforms: THREE.UniformsUtils.clone( this.cubeShader.uniforms ),
  9. vertexShader: this.cubeShader.vertexShader,
  10. fragmentShader: this.cubeShader.fragmentShader,
  11. depthTest: false,
  12. depthWrite: false,
  13. side: THREE.BackSide
  14. } ) );
  15. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  16. get: function () {
  17. return this.uniforms.envMap.value;
  18. }
  19. } );
  20. this.envMap = envMap;
  21. this.opacity = opacity !== undefined ? opacity : 1.0;
  22. this.cubeScene = new THREE.Scene();
  23. this.cubeCamera = new THREE.PerspectiveCamera();
  24. this.cubeScene.add( this.cubeMesh );
  25. };
  26. CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  27. constructor: CubeTexturePass,
  28. render: function ( renderer, writeBuffer, readBuffer
  29. /*, deltaTime, maskActive*/
  30. ) {
  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. } );
  45. THREE.CubeTexturePass = CubeTexturePass;
  46. } )();