TextureCubeNode.js 1.6 KB

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