MaxMipLevelNode.js 938 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import UniformNode from '../core/UniformNode.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. import { nodeProxy } from '../shadernode/ShaderNode.js';
  4. import { addNodeClass } from '../core/Node.js';
  5. class MaxMipLevelNode extends UniformNode {
  6. constructor( textureNode ) {
  7. super( 0 );
  8. this.textureNode = textureNode;
  9. this.updateType = NodeUpdateType.FRAME;
  10. }
  11. get texture() {
  12. return this.textureNode.value;
  13. }
  14. update() {
  15. const texture = this.texture;
  16. const images = texture.images;
  17. const image = ( images && images.length > 0 ) ? ( ( images[ 0 ] && images[ 0 ].image ) || images[ 0 ] ) : texture.image;
  18. if ( image && image.width !== undefined ) {
  19. const { width, height } = image;
  20. this.value = Math.log2( Math.max( width, height ) );
  21. }
  22. }
  23. }
  24. export default MaxMipLevelNode;
  25. export const maxMipLevel = nodeProxy( MaxMipLevelNode );
  26. addNodeClass( 'MaxMipLevelNode', MaxMipLevelNode );