TextureCubeNode.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from '../core/TempNode.js';
  5. import { TextureCubeUVNode } from './TextureCubeUVNode.js';
  6. function TextureCubeNode( value, uv ) {
  7. TempNode.call( this, 'v4' );
  8. this.value = value;
  9. this.uv = uv || new TextureCubeUVNode();
  10. }
  11. TextureCubeNode.prototype = Object.create( TempNode.prototype );
  12. TextureCubeNode.prototype.constructor = TextureCubeNode;
  13. TextureCubeNode.prototype.nodeType = "TextureCube";
  14. TextureCubeNode.prototype.generate = function ( builder, output ) {
  15. if ( builder.isShader( 'fragment' ) ) {
  16. var uv_10 = this.uv.build( builder ) + '.uv_10',
  17. uv_20 = this.uv.build( builder ) + '.uv_20',
  18. t = this.uv.build( builder ) + '.t';
  19. builder.addContext( { encoding: builder.getTextureEncodingFromMap( this.value ), include: builder.isShader( 'vertex' ) } );
  20. var color10 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )',
  21. color20 = 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )';
  22. builder.removeContext();
  23. return builder.format( 'vec4( mix( ' + color10 + ', ' + color20 + ', ' + t + ' ).rgb, 1.0 )', this.getType( builder ), output );
  24. } else {
  25. console.warn( "THREE.TextureCubeNode is not compatible with " + builder.shader + " shader." );
  26. return builder.format( 'vec4( 0.0 )', this.getType( builder ), output );
  27. }
  28. };
  29. TextureCubeNode.prototype.toJSON = function ( meta ) {
  30. var data = this.getJSONNode( meta );
  31. if ( ! data ) {
  32. data = this.createJSONNode( meta );
  33. data.uv = this.uv.toJSON( meta ).uuid;
  34. data.textureSize = this.textureSize.toJSON( meta ).uuid;
  35. data.blinnExponentToRoughness = this.blinnExponentToRoughness.toJSON( meta ).uuid;
  36. if ( this.roughness ) data.roughness = this.roughness.toJSON( meta ).uuid;
  37. }
  38. return data;
  39. };
  40. export { TextureCubeNode };