CubeTexturePass.js 1.9 KB

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