question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating a CubeTexture from 6 CompressedTextures doesn't work after r136

See original GitHub issue

Describe the bug

Prior to version r136 of the library, creating a CubeTexture from 6 CompressedTextures used to work just fine. However, it seems like this change introduced in r136 changed the behaviour of how textures are loaded into the GPU when WebGL 2 APIs are available, which broke this use-case.

As a work-around, I have been able to get the cube texture to render by setting texture.isVideoTexture = true on the CubeTexture. According to this line, that forces Three to opt-out of using texStorage2D which seems to be causing the issue

Code


const loader = new KTX2Loader()
    .setTranscoderPath( 'js/libs/basis/' )
    .detectSupport( renderer );

const textures = await Promise.all([
  loader.loadAsync( './textures/nx.ktx2' ),
  loader.loadAsync( './textures/px.ktx2' ),
  loader.loadAsync( './textures/ny.ktx2' ),
  loader.loadAsync( './textures/py.ktx2' ),
  loader.loadAsync( './textures/nz.ktx2' ),
  loader.loadAsync( './textures/pz.ktx2' )
]);

textures.forEach((texture) => {
  texture.generateMipmaps = false;
  texture.encoding = THREE.LinearEncoding;
  texture.needsUpdate = true;
});

const cubeTexture = new THREE.CubeTexture(textures);
cubeTexture.encoding = textures[0].encoding;
cubeTexture.format = textures[0].format;
cubeTexture.minFilter = textures[0].minFilter;
cubeTexture.magFilter = textures[0].magFilter;
cubeTexture.generateMipmaps = false;

// HACK: Setting `isVideoTexture` opts-out of using `texStorage2D`
cubeTexture.isVideoTexture = true;

cubeTexture.needsUpdate = true;

// Set scene background
scene.background = cubeTexture

Live example

  • CodeSandbox (I’m using react-three-fiber, let me know if you want a vanilla Three.js version!)

Expected behavior

It should load the CubeTexture just fine as the scene background. Instead, the scene background is black and the following errors show in the console:

[.WebGL-0x700abe0a00] GL_INVALID_VALUE: Texture dimensions must all be greater than zero.

and

[.WebGL-0x700abe0a00] GL_INVALID_OPERATION: Level of detail outside of range.

Upgrading to r140.2, also shows this added error:

THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.

Screenshots

CleanShot 2022-05-15 at 10 56 44@2x

https://user-images.githubusercontent.com/8302959/168479550-cf0d681d-cd96-40a6-a816-18699047322b.mov

Platform:

  • Device: Desktop
  • OS: MacOS
  • Browser: Chrome
  • Three.js version: r136

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, May 16, 2022

Your platform probably does not fully support S3TC.

0reactions
Mugen87commented, Jun 7, 2022

THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.

This warning is generate in WebGLTextures.verifyColorSpace(). However, there is an early out for all compressed textures. So when RGBA_ASTC_4x4_Format is used in combination with sRGBEncoding, there is no warning and the renderer should pick COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR.

I think the main problem is that compressed cube textures also have to use CompressedTexture and not CubeTexture. So using new THREE.CubeTexture(textures); while textures is an array of compressed textures does not work. It’s required to organize the compress cube map similar to how DDSLoader works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot load cubemap because 6 files were not defined
I import glb-fie with PBRMatarial for Reflections. This Reflections works well in sandbox. But in the app Reflections does not work anymore. I ......
Read more >
Are cubemaps working with default compression on Android?
I have been using cubemaps with default compression for a custom skybox material without any issues on PC (even with mobile and high-end ......
Read more >
Runtime cubemap compression possible? - Unity Forum
None with compression work - giving me "Unable to retrieve image reference" errors. EDIT: The actual cubemap is created and compressed to DXT1 ......
Read more >
Tutorial 5 : A Textured Cube
How to load texture with GLFW; Compressed Textures. Creating compressed textures; Using the compressed texture ... This is done with UV coordinates.
Read more >
[gamux-mx commit] r136 - Google Groups
[gamux-mx commit] r136 - in trunk: Cubo Cubo/cubo Cubo/cubo/Content ... + /// Creates a black and white checkered texture of the specified dimensions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found