CubeTexturePass.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. BackSide,
  3. BoxGeometry,
  4. Mesh,
  5. PerspectiveCamera,
  6. Scene,
  7. ShaderLib,
  8. ShaderMaterial,
  9. UniformsUtils
  10. } from '../../../build/three.module.js';
  11. import { Pass } from '../postprocessing/Pass.js';
  12. var CubeTexturePass = function ( camera, envMap, opacity ) {
  13. Pass.call( this );
  14. this.camera = camera;
  15. this.needsSwap = false;
  16. this.cubeShader = ShaderLib[ 'cube' ];
  17. this.cubeMesh = new Mesh(
  18. new BoxGeometry( 10, 10, 10 ),
  19. new ShaderMaterial( {
  20. uniforms: UniformsUtils.clone( this.cubeShader.uniforms ),
  21. vertexShader: this.cubeShader.vertexShader,
  22. fragmentShader: this.cubeShader.fragmentShader,
  23. depthTest: false,
  24. depthWrite: false,
  25. side: BackSide
  26. } )
  27. );
  28. Object.defineProperty( this.cubeMesh.material, 'envMap', {
  29. get: function () {
  30. return this.uniforms.envMap.value;
  31. }
  32. } );
  33. this.envMap = envMap;
  34. this.opacity = ( opacity !== undefined ) ? opacity : 1.0;
  35. this.cubeScene = new Scene();
  36. this.cubeCamera = new PerspectiveCamera();
  37. this.cubeScene.add( this.cubeMesh );
  38. };
  39. CubeTexturePass.prototype = Object.assign( Object.create( Pass.prototype ), {
  40. constructor: CubeTexturePass,
  41. render: function ( renderer, writeBuffer, readBuffer/*, deltaTime, maskActive*/ ) {
  42. var oldAutoClear = renderer.autoClear;
  43. renderer.autoClear = false;
  44. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  45. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  46. this.cubeMesh.material.uniforms.envMap.value = this.envMap;
  47. this.cubeMesh.material.uniforms.flipEnvMap.value = ( this.envMap.isCubeTexture && this.envMap._needsFlipEnvMap ) ? - 1 : 1;
  48. this.cubeMesh.material.uniforms.opacity.value = this.opacity;
  49. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  50. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  51. if ( this.clear ) renderer.clear();
  52. renderer.render( this.cubeScene, this.cubeCamera );
  53. renderer.autoClear = oldAutoClear;
  54. }
  55. } );
  56. export { CubeTexturePass };