Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 174 forks source link

HTML5 - GPU / Game engine optimised textures #1351

Open onelsonic opened 3 years ago

onelsonic commented 3 years ago

Fixing GPU memory bottleneck with GPU optimised Textures.

the HTML5 backend workflow picks up textures as PNG, JPG or HDR.

However these textures are not optimised for GPUs. Having optimised GPU textures can really improve real-time performances and GPU available memory. It would be ideal to have ASTC format added. https://www.khronos.org/blog/create-astc-textures-faster-with-the-new-astcenc-2.0-open-source-compression-tool

ASTC Textures can be loaded as javascript Blob objects and generated using the appropriate tool:

ASTC: https://github.com/ARM-software/astc-encoder

Example : how to load AST textures in HTML5/WebGL:

var ext = gl.getExtension('WEBGL_compressed_texture_astc');

var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);

gl.compressedTexImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RGBA_ASTC_12x12_KHR, 512, 512, 0, textureData);
RobDangerous commented 3 years ago

It's generally just called compressed texture formats and there's some support for that already, however not for html5. It's activated using something like project.addAssets('assets/**', { quality: 0.5 }); in your khafile. Feel free to send a pull-request to make it work in html5. Also please note that the astc-encoder is currently only compiled for Windows (see Kha/Kinc/Tools/kraffiti/Datatypes).