TextureCubeNode.js 1.9 KB

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