TextureCubeNode.js 1.8 KB

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