2
0

TextureNode.js 973 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.TextureNode = function( value, coord, bias ) {
  5. THREE.InputNode.call( this, 'v4' );
  6. this.value = value;
  7. this.coord = coord || new THREE.UVNode();
  8. this.bias = bias;
  9. };
  10. THREE.TextureNode.prototype = Object.create( THREE.InputNode.prototype );
  11. THREE.TextureNode.prototype.constructor = THREE.TextureNode;
  12. THREE.TextureNode.prototype.getTexture = function( builder, output ) {
  13. return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
  14. };
  15. THREE.TextureNode.prototype.generate = function( builder, output ) {
  16. var tex = this.getTexture( builder, output );
  17. var coord = this.coord.build( builder, 'v2' );
  18. var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
  19. var code;
  20. if ( bias ) code = 'texture2D(' + tex + ',' + coord + ',' + bias + ')';
  21. else code = 'texture2D(' + tex + ',' + coord + ')';
  22. return builder.format( code, this.type, output );
  23. };