How to reduce the level of someMaterial.emissiveTexture while preserving the alpha?

Question Test Scene

Suppose I have an emissive texture on the sphere and I wish to darken it, because it’s too bright for the scene. However, the source texture for this emissive texture also has an alpha channel. If I darken the emissive texture by changing the levels, the alpha channel also gets affected. I figured that line 32:

queryMaterial.useAlphaFromDiffuseTexture = true;

would prevent this alpha from being affected. I have a feeling that it has something to do with variables as references to objects, and reassigning something, but I’m not sure.

Any idea how to change this so I can reduce the levels of the diffuse texture without making the opaque parts correspondingly more transparent?

Line 30 is where I am having the issues. If I try to adjust the levels of the emissive texture, I end up with a transparent (any, babylon palm tree in this case)

queryMaterial.emissiveTexture.level = 0.5;

Line 30 results in the loss of opacity for the normally-completely opaque texels on the sphere.

level is a property of the texture, and as you are using the same texture for diffuse / emissive / opacity, it impacts these 3 slots in the same way. You should create 3 textures instead:

2 Likes

Thanks for this info! Recognizing that it was a property of the texture (even tho the dot separator should have clued me in) was where I was having the hangup.

One additional question:
Would there be an issue with only cloning the texture once and just referring to the non-leveled texture for the opacity texture like here? https://playground.babylonjs.com/#MAM0M8#3

That’s ok if you only need to change the level of a single texture, you can use the same texture for the other 2.

1 Like