CubeTextureNode.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.getTexture = function( builder, output ) {
  13. return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
  14. };
  15. THREE.CubeTextureNode.prototype.generate = function( builder, output ) {
  16. if ( output === 'samplerCube' ) {
  17. return this.getTexture( builder, output );
  18. }
  19. var cubetex = this.getTexture( builder, output );
  20. var coord = this.coord.build( builder, 'v3' );
  21. var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
  22. if ( bias == undefined && builder.requires.bias ) {
  23. bias = builder.requires.bias.build( builder, 'fv1' );
  24. }
  25. var code;
  26. if ( bias ) code = 'texCubeBias(' + cubetex + ',' + coord + ',' + bias + ')';
  27. else code = 'texCube(' + cubetex + ',' + coord + ')';
  28. if ( builder.isSlot( 'color' ) ) {
  29. code = 'mapTexelToLinear(' + code + ')';
  30. } else if ( builder.isSlot( 'emissive' ) ) {
  31. code = 'emissiveMapTexelToLinear(' + code + ')';
  32. } else if ( builder.isSlot( 'environment' ) ) {
  33. code = 'envMapTexelToLinear(' + code + ')';
  34. }
  35. return builder.format( code, this.type, output );
  36. };