Cube texture, shader material errors

Constructing a material that uses a cube texture and a regular 2d texture, if the regular texture is not set results in errors for some browsers:

  • In Chromium the error GL_INVALID_OPERATION: Two textures of different types use the same sampler location is produced, and the material is not displayed.
  • In Safari the material is not displayed, but no errors are produced (silently fails).
  • In Firefox, it works as expected.

All browsers work as expected if the texture is set, or if two regular textures are used (i.e. one isn’t a cube texture.

Working pg (texture is set): Babylon.js Playground
Not working pg (except in Firefox): https://playground.babylonjs.com/#29NKQZ#1

This might be a browser bug, as I’d expect the usual behaviour for unbound textures (reads 0,0,0,1) to apply in this case too, across all browsers.

Yes, I don’t think we can do anything about this, we don’t check that all inputs are provided to shaders (for performance sake): it’s up to the user to ensure all bindings are provided.

In WebGPU you will also get an error that a texture has not been bound.

Strangely I’m also getting this bug and I dont understand how it works in Firefox but not Chrome

Hi!
I’ve just ran into the same issue with PBRCustomMaterial.

Simply by doing this

  const hdrTexture = new CubeTexture('/environments/environment.dds', scene);
  pbr.reflectionTexture = hdrTexture

EDIT:
If I set albedoTexture the error goes away and the reflection texture works.

Are you able to setup a repro in the Playground?

It should definitely work to use a reflection texture and no other textures.

Thanks for your response! I’ll try to mess around a bit and try to understand the reason behind the error before transforming the code to be runnable in the Playground.

Hi!

The custom material starts at line 30, the Playground task is obviosly at the end.

If you enable the albedo texture at line 1549 it will start to work. First I thought it will be a Mac issue but it is broken on Windows as well.

Can you have a look at it? I bet you will quickly point out what did I mess up :metal: :beers:

Thank you!

this.AddUniform('colors', 'sampler2D', null);

It’s invalid not to set a texture if the shader needs one.

If I replace this line by:

this.AddUniform('colors', 'sampler2D', new BABYLON.Texture("textures/crate.png", scene));

it does work.

1 Like

Wow, yes! :slight_smile: Thank you!

Is it possible to create a texture which is not bound to a scene? I’d like to create a 1px static texture which I will send instead of null to the shader but I don’t want to add this texture to the scene. Or are textures strictly bound to a scene?

No, you must pass a scene instance to the texture constructor (and if you don’t it will use the last created scene).

1 Like