• Runtimes
  • Enabling mipmaps on pixijs

Hi, i was wondering how to enable mipmaps using the pixijs runtime?

it seems that it needs to be done on the textures instead? is there a way to individualy set the textures?

when exporting i've set pow2. However when the spine container is scaled down, it looks quite blurry

Related Discussions
...

To enable mipmaps using the PIXIJS runtime, you can set the texture filters to use mipmaps. This is done on the textures themselves. If you have an atlas with a single page, you can enable mipmaps by setting the filters like this:

const atlas = PIXI.Assets.get("atlasKey");
atlas.pages[0].texture.setFilters(
  spine.TextureFilter.MipMapLinearLinear,
  spine.TextureFilter.MipMapLinearLinear,
);

This code will generate mipmaps for the texture, which should help in maintaining smoother edges when the Spine container is scaled down. If you have multiple textures, you will need to apply this setting to each texture individually.

This looks like its for v7? This doesnt look right for v8 though the atlast doesnt seem to have pages and texture

  • Davide ha risposto a questo messaggio

    benjaminhon

    Have you tried it? It should also work in Pixi v8.
    The atlas does have pages, and each texture is associated with a corresponding texture.

    Hmm i tried it its weird though, it makes it a more blurry, i've tried a few more of the options using nearest.

    does setting this generate the mipmaps, for 1/2 1/4 scale and auto uses it?

    • Davide ha risposto a questo messaggio

      benjaminhon

      We don’t do anything special with setFilters; we simply set Pixi constants and invoke Pixi functions to generate mipmaps when needed because we use the Pixi WebGL renderer. Here's the code:

      public setFilters (minFilter: TextureFilter, magFilter: TextureFilter): void {
      	const style = this.texture.source.style;
      
      	style.minFilter = SpineTexture.toPixiTextureFilter(minFilter);
      	style.magFilter = SpineTexture.toPixiTextureFilter(magFilter);
      	this.texture.source.autoGenerateMipmaps = SpineTexture.toPixiMipMap(minFilter);
      	this.texture.source.updateMipmaps();
      }

      Here, we have SpineTexture.toPixiTextureFilter:

      private static toPixiTextureFilter (filter: TextureFilter): SCALE_MODE {
      	switch (filter) {
      		case TextureFilter.Nearest:
      		case TextureFilter.MipMapNearestLinear:
      		case TextureFilter.MipMapNearestNearest:
      			return 'nearest';
      
      		case TextureFilter.Linear:
      		case TextureFilter.MipMapLinearLinear: // TextureFilter.MipMapLinearLinear == TextureFilter.MipMap
      		case TextureFilter.MipMapLinearNearest:
      			return 'linear';
      
      		default:
      			throw new Error(`Unknown texture filter: ${String(filter)}`);
      	}
      }

      And finally:

      private static toPixiMipMap (filter: TextureFilter): boolean {
      	switch (filter) {
      		case TextureFilter.Nearest:
      		case TextureFilter.Linear:
      			return false;
      
      		case TextureFilter.MipMapNearestLinear:
      		case TextureFilter.MipMapNearestNearest:
      		case TextureFilter.MipMapLinearLinear: // TextureFilter.MipMapLinearLinear == TextureFilter.MipMap
      		case TextureFilter.MipMapLinearNearest:
      			return true;
      
      		default:
      			throw new Error(`Unknown texture filter: ${String(filter)}`);
      	}
      }

      As you can see, if you set minFilter to:

      • Nearest or Linear, you get the respective filter (nearest or linear) without mipmaps.
      • MipMapNearest*, you get the Nearest filter with mipmaps.
      • MipMapLinear*, you get the Linear filter with mipmaps.

      That's it. Once these settings are applied, we invoke source.updateMipmaps, and the mipmaps will be updated accordingly.

      Have you tried doing the same thing without the Spine GameObject layer? Try rendering the texture using a Sprite, setting the filters and mipmaps as desired. Once you're satisfied, use the same settings for the textures of the Spine GameObject.
      Please try this and report back if the results you get with the Sprite differ from those with the Spine GameObject when using the same texture filter/mipmap configuration.

      ok thanks