MaxMipLevelNode.js 577 B

1234567891011121314151617181920212223242526272829303132
  1. import UniformNode from '../core/UniformNode.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. class MaxMipLevelNode extends UniformNode {
  4. constructor( texture ) {
  5. super( 0 );
  6. this.texture = texture;
  7. this.updateType = NodeUpdateType.Frame;
  8. }
  9. update() {
  10. const image = this.texture.images ? this.texture.images[ 0 ].image || this.texture.images[ 0 ] : this.texture.image;
  11. if ( image?.width !== undefined ) {
  12. const { width, height } = image;
  13. this.value = Math.log2( Math.max( width, height ) );
  14. }
  15. }
  16. }
  17. export default MaxMipLevelNode;