GLTF premultipliedAlpha seems to be ignored since 1.50

1. A concise explanation of the problem you’re experiencing.

My custom shaders pre-multiply alpha before output. GLTF models using these shaders have asset>premultipliedAlpha set to TRUE.

Opacity was working fine until Cesium 1.50

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

GLTF file “asset” section

"asset": {
    "generator": "collada2gltf@6779c094d694e951beeb1012d03d4faa1edb0ddf",
    "premultipliedAlpha": true,
    "profile": {
        "api": "WebGL",
        "version": "1.0.2"
    },
    "version": "1.0.1"
},

My fragment shader:

precision highp float;
uniform sampler2D u_diffuse;
varying vec2 v_texcoord0;

void main(void) {

vec4 color;
vec4 diffuse;
float alpha;

// diffuse
diffuse = texture2D(u_diffuse, v_texcoord0);

// sum
alpha = diffuse.x; // take alpha from red channel
color = vec4(vec3(1.0, 1.0, 1.0) * alpha, alpha); // pre multiply alpha
gl_FragColor = color;

}


**3. Context. Why do you need to do this? We might know a better way to accomplish your goal.**

I use this shader to generate opacity from a JPG file without alpha channel

**4. The Cesium version you're using, your operating system and browser.**

Cesium 1.50 on Windows10/Chrome

Hey Xavier,

Can you share a sample model and the code you’re running with it in Cesium? A few things were added for glTF rendering in 1.50:

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/CHANGES.md#150---2018-10-01

Which mainly support more extensions, so I’m not sure off the top of my head what would have caused this. If you can share a Sandcastle or just a code snippet I can run across the versions that’ll help.

Hi Omar,

Please find attached the GLTF model + shaders I am experiencing the issue with.

Let me know if you need more information.

Regards,

Xavier

sample.zip (111 KB)

I just tested this with 1.49 and 1.50 and they look identical to me. Is this how it looks for you?

If not, can you post a screenshot of what you’re seeing?

I guess it’s matter of “point of view” :wink:

Note how 1.50 clearly does not take pre-multiplied alpha into account and renders semi-transparency as a dark color.

Thanks,

Xavier

I see what you mean now. I did a little bit of digging, and looks like this was a breaking change that slipped through the cracks and wasn’t mentioned in CHANGES.md. I opened a bug report with a bit more detail here:

https://github.com/AnalyticalGraphicsInc/cesium/issues/7419

This was driven by glTF 2 not supporting premultiplied alpha. But since this is a breaking change I think it might be something worth fixing (or at the very least mentioning it in CHANGES). For your case, it looks like changing this line:

color = vec4(vec3(1.0, 1.0, 1.0) * alpha, alpha); // pre multiply alpha

``

to:

color = vec4(vec3(1.0, 1.0, 1.0), alpha);

``

Makes it look as intended? Does that look right to you?

Hi Omar,

Yes, I can fix this on my end if this was on purpose and not just a bug.

Thanks,

Xavier.

Hi,

I just bumped into this problem again. iOS is always using pre-multiplied alpha, no matter what while on windows, it is never used.

This creates inconsistency and the impossibility to re-use models/shaders across platforms.

I updated the following issue with a description of the problem:

Thanks,

Xavier

Thanks for following up on this. This cross-platform inconsistency might make this a higher priority.