TextureCubeNode.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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, coord ) {
  7. TempNode.call( this, 'v4' );
  8. this.value = value;
  9. this.coord = coord || 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.coord.build( builder ) + '.uv_10',
  17. uv_20 = this.coord.build( builder ) + '.uv_20',
  18. t = this.coord.build( builder ) + '.t';
  19. var color10 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_10 + ' )', this.value.value ),
  20. color20 = builder.getTexelDecodingFunctionFromTexture( 'texture2D( ' + this.value.build( builder, 'sampler2D' ) + ', ' + uv_20 + ' )', this.value.value );
  21. return builder.format( 'vec4( mix( ' + color10 + ', ' + color20 + ', ' + t + ' ).rgb, 1.0 )', this.getType( builder ), output );
  22. } else {
  23. console.warn( "THREE.TextureCubeNode is not compatible with " + builder.shader + " shader." );
  24. return builder.format( 'vec4( 0.0 )', this.getType( builder ), output );
  25. }
  26. };
  27. TextureCubeNode.prototype.toJSON = function ( meta ) {
  28. var data = this.getJSONNode( meta );
  29. if ( ! data ) {
  30. data = this.createJSONNode( meta );
  31. data.coord = this.coord.toJSON( meta ).uuid;
  32. data.textureSize = this.textureSize.toJSON( meta ).uuid;
  33. data.blinnExponentToRoughness = this.blinnExponentToRoughness.toJSON( meta ).uuid;
  34. if ( this.roughness ) data.roughness = this.roughness.toJSON( meta ).uuid;
  35. }
  36. return data;
  37. };
  38. export { TextureCubeNode };