CubeTexturePass.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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: 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.opacity.value = this.opacity;
  37. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  38. renderer.setRenderTarget( this.renderToScreen ? null : readBuffer );
  39. if ( this.clear ) renderer.clear();
  40. renderer.render( this.cubeScene, this.cubeCamera );
  41. renderer.autoClear = oldAutoClear;
  42. }
  43. } );