TextureCubeNode.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from '../core/TempNode.js';
  5. import { FloatNode } from '../inputs/FloatNode.js';
  6. import { ExpressionNode } from '../core/ExpressionNode.js';
  7. import { TextureCubeUVNode } from './TextureCubeUVNode.js';
  8. import { ReflectNode } from '../accessors/ReflectNode.js';
  9. import { NormalNode } from '../accessors/NormalNode.js';
  10. import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
  11. function TextureCubeNode( value, uv, bias ) {
  12. TempNode.call( this, 'v4' );
  13. this.value = value;
  14. this.radianceNode = new TextureCubeUVNode(
  15. this.value,
  16. uv || new ReflectNode( ReflectNode.VECTOR ),
  17. // bias should be replaced in builder.context in build process
  18. bias
  19. );
  20. this.irradianceNode = new TextureCubeUVNode(
  21. this.value,
  22. new NormalNode( NormalNode.WORLD ),
  23. new FloatNode( 1 ).setReadonly( true )
  24. );
  25. }
  26. TextureCubeNode.prototype = Object.create( TempNode.prototype );
  27. TextureCubeNode.prototype.constructor = TextureCubeNode;
  28. TextureCubeNode.prototype.nodeType = "TextureCube";
  29. TextureCubeNode.prototype.generate = function ( builder, output ) {
  30. if ( builder.isShader( 'fragment' ) ) {
  31. builder.require( 'irradiance' );
  32. if ( builder.context.bias ) {
  33. builder.context.bias.setTexture( this.value );
  34. }
  35. var scopeNode = builder.slot === 'irradiance' ? this.irradianceNode : this.radianceNode;
  36. return scopeNode.build( builder, output );
  37. } else {
  38. console.warn( "THREE.TextureCubeNode is not compatible with " + builder.shader + " shader." );
  39. return builder.format( 'vec4( 0.0 )', this.getType( builder ), output );
  40. }
  41. };
  42. TextureCubeNode.prototype.copy = function ( source ) {
  43. TempNode.prototype.copy.call( this, source );
  44. this.value = source.value;
  45. return this;
  46. };
  47. TextureCubeNode.prototype.toJSON = function ( meta ) {
  48. var data = this.getJSONNode( meta );
  49. if ( ! data ) {
  50. data = this.createJSONNode( meta );
  51. data.value = this.value.toJSON( meta ).uuid;
  52. }
  53. return data;
  54. };
  55. export { TextureCubeNode };