CubeTexturePass.js 1.7 KB

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