MirrorNode.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. THREE.MirrorNode = function( renderer, camera, options ) {
  2. THREE.TempNode.call( this, 'v4' );
  3. this.mirror = renderer instanceof THREE.Mirror ? renderer : new THREE.Mirror( renderer, camera, options );
  4. this.textureMatrix = new THREE.Matrix4Node( this.mirror.textureMatrix );
  5. this.worldPosition = new THREE.PositionNode( THREE.PositionNode.WORLD );
  6. this.coord = new THREE.OperatorNode( this.textureMatrix, this.worldPosition, THREE.OperatorNode.MUL );
  7. this.coordResult = new THREE.OperatorNode( null, this.coord, THREE.OperatorNode.ADD );
  8. this.texture = new THREE.TextureNode( this.mirror.renderTarget.texture, this.coord, null, true );
  9. };
  10. THREE.MirrorNode.prototype = Object.create( THREE.TempNode.prototype );
  11. THREE.MirrorNode.prototype.constructor = THREE.MirrorNode;
  12. THREE.MirrorNode.prototype.generate = function( builder, output ) {
  13. var material = builder.material;
  14. if ( builder.isShader( 'fragment' ) ) {
  15. this.coordResult.a = this.offset;
  16. this.texture.coord = this.offset ? this.coordResult : this.coord;
  17. if ( output === 'sampler2D' ) {
  18. return this.texture.build( builder, output );
  19. }
  20. return builder.format( this.texture.build( builder, this.type ), this.type, output );
  21. } else {
  22. console.warn( "THREE.MirrorNode is not compatible with " + builder.shader + " shader." );
  23. return builder.format( 'vec4(0.0)', this.type, output );
  24. }
  25. };