CubeTexturePass.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. 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. THREE.CubeTexturePass.prototype = Object.assign( Object.create( THREE.Pass.prototype ), {
  27. constructor: THREE.CubeTexturePass,
  28. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  29. var oldAutoClear = renderer.autoClear;
  30. renderer.autoClear = false;
  31. this.cubeCamera.projectionMatrix.copy( this.camera.projectionMatrix );
  32. this.cubeCamera.quaternion.setFromRotationMatrix( this.camera.matrixWorld );
  33. this.cubeMesh.material.uniforms[ "tCube" ].value = this.envMap;
  34. this.cubeMesh.material.uniforms[ "opacity" ].value = this.opacity;
  35. this.cubeMesh.material.transparent = ( this.opacity < 1.0 );
  36. renderer.render( this.cubeScene, this.cubeCamera, this.renderToScreen ? null : readBuffer, this.clear );
  37. renderer.autoClear = oldAutoClear;
  38. }
  39. } );