Using S3TC textures

I want to load textures in S3TC format (DXT1 and DXT3) that use a weird container format. In Three.js I could simply strip the container and give the CompressedTexture class an ArrayBuffer with the S3TC data and it works. Is there a way to do something similar with Babylon?

The Three.js implementation: phantasmal-world/ninja_textures.ts at master · DaanVandenBosch/phantasmal-world · GitHub

Even if not meant to be used by the end user, you can call Engine._uploadCompressedDataToTextureDirectly:

public _uploadCompressedDataToTextureDirectly(texture: InternalTexture,
  internalFormat: number, width: number, height: number, data: ArrayBufferView,
  faceIndex: number = 0, lod: number = 0);

Use 33777 (DXT1) or 33778 (DXT3) for the internalFormat parameter. The texture parameter is retrieved from a Texture instance by calling getInternalTexture().

There’s a pending PR which when merged will allow you to use constants instead of direct values (Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT1 and Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT3).

2 Likes