CubeTextureNode.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.CubeTextureNode = function ( value, coord, bias ) {
  5. THREE.InputNode.call( this, 'v4', { shared: true } );
  6. this.value = value;
  7. this.coord = coord || new THREE.ReflectNode();
  8. this.bias = bias;
  9. };
  10. THREE.CubeTextureNode.prototype = Object.create( THREE.InputNode.prototype );
  11. THREE.CubeTextureNode.prototype.constructor = THREE.CubeTextureNode;
  12. THREE.CubeTextureNode.prototype.nodeType = "CubeTexture";
  13. THREE.CubeTextureNode.prototype.getTexture = function ( builder, output ) {
  14. return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
  15. };
  16. THREE.CubeTextureNode.prototype.generate = function ( builder, output ) {
  17. if ( output === 'samplerCube' ) {
  18. return this.getTexture( builder, output );
  19. }
  20. var cubetex = this.getTexture( builder, output );
  21. var coord = this.coord.build( builder, 'v3' );
  22. var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
  23. if ( bias == undefined && builder.requires.bias ) {
  24. bias = builder.requires.bias.build( builder, 'fv1' );
  25. }
  26. var code;
  27. if ( bias ) code = 'texCubeBias(' + cubetex + ',' + coord + ',' + bias + ')';
  28. else code = 'texCube(' + cubetex + ',' + coord + ')';
  29. if ( builder.isSlot( 'color' ) ) {
  30. code = 'mapTexelToLinear(' + code + ')';
  31. } else if ( builder.isSlot( 'emissive' ) ) {
  32. code = 'emissiveMapTexelToLinear(' + code + ')';
  33. } else if ( builder.isSlot( 'environment' ) ) {
  34. code = 'envMapTexelToLinear(' + code + ')';
  35. }
  36. return builder.format( code, this.type, output );
  37. };
  38. THREE.CubeTextureNode.prototype.toJSON = function ( meta ) {
  39. var data = this.getJSONNode( meta );
  40. if ( ! data ) {
  41. data = this.createJSONNode( meta );
  42. data.value = this.value.uuid;
  43. data.coord = this.coord.toJSON( meta ).uuid;
  44. if ( this.bias ) data.bias = this.bias.toJSON( meta ).uuid;
  45. }
  46. return data;
  47. };