phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.16k stars 7.1k forks source link

Pixel art per render instance #6886

Closed rexrainbow closed 2 months ago

rexrainbow commented 3 months ago

There has 2 kinds of solution to set pixel art rendering.

  1. set pixelArt to true to assign pixel art to all rendering instances
  2. texture.setFilter(1) to assign pixel art to rendering instances which using this texture.

Is it possible to assign pixel art by Image/Sprite's member method? i.e. render this Image/Sprite with Nearest filter?

Related issue : https://github.com/rexrainbow/phaser3-rex-notes/issues/448

photonstorm commented 2 months ago

We can look at doing this with the new renderer (@BenjaminDRichards) but it's not possible with the current one. The texture filtering mode is set on the texture itself, not the frame, so if you apply it to an atlas, every frame of that atlas is rendered as 'nearest'. It's not a WebGL setting you can toggle on a per-draw basis, it's set on the texture itself.

photonstorm commented 2 months ago

Hi - I had a chat with Ben about this, and basically, it's not possible. The only way it could be done is to duplicate the WebGL texture it is using and set a different filter mode on the duplicate. Which of course doubles VRAM for that texture, but might be an option. You could 'emulate' this behavior today by loading the image twice, with different keys, and one of them uses NEAREST as the filter mode.