TextureCubeNode.js 1.8 KB

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