CubeTextureNode.js 1.1 KB

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