WebGL on the new M1 chip Macs

Hey, not sure if anyone else has run into this. But we are using a custom shader in BabylonJS, and on the new M1 chip macs only, it is VERY reflective. On every other machine, materials look fine, but on the M1, everything looks like its made of shiny metal. We are trying to fake mip levels using the following function to choose a mip level between 0 and 3.

roughness = roughness * (1.7 - 0.7 * roughness);
float mip = clamp(roughness * 3.0, 0.0, 3.0);
float mipFloor = floor(mip);
float mipCeil = ceil(mip);
mat4 lods = mat4(textureCube(_EnvironmentMapLOD0, reflUVW, 0.0),
                textureCube(_EnvironmentMapLOD1, reflUVW, 0.0),
                textureCube(_EnvironmentMapLOD2, reflUVW, 0.0),
                textureCube(_EnvironmentMapLOD3, reflUVW, 0.0));
vec4 floors = clamp(vec4(1.0, mipFloor, mipFloor - 1.0, mipFloor - 2.0), vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
floors.x -= floors.y;
floors.y -= floors.z;
floors.z -= floors.w;
vec4 rgbFloor = lods * floors;
vec4 ceils = clamp(vec4(1.0, mipCeil, mipCeil - 1.0, mipCeil - 2.0), vec4(0.0, 0.0, 0.0, 0.0), vec4(1.0, 1.0, 1.0, 1.0));
ceils.x -= ceils.y;
ceils.y -= ceils.z;
ceils.z -= ceils.w;
vec4 rgbCeil = lods * ceils;
vec4 rgbm = mix(rgbFloor, rgbCeil, mip - mipFloor);
return GammaToLinearSpace(rgbm).rgb;

Unfortunately, on the M1, that final rgbm value seems like it should be cut in half to look correct. Has anyone else run into something similar?

Pinging @sebavan for thoughts on this one.

Ohhh this is surprising, is it happening on every browser ? it sounds like either a driver issue or and angle one, like all the textures would be bound to the same one for some reasons.

Yep, every browser. The textures seem bound correctly, because if we add some additional code to cut vec4 rgbm in half, then things start working the way we would kind of expect.

Wasn’t sure if this was something babylon dealt with at all in its own internal shaders

Ohhhh even worse :frowning: we never had to deal with it so far but if you find the culprit instruction please let us know :slight_smile: unfortunately can not help as I do not have an M1 to test on.

I think for now we’re just going to look at the unmasked renderer and set a flag to reduce the rgbm in half… there is a probably a real culprit, but we cant spend too much time on it unfortunately. The unmasked renderer is accurate in chrome and firefox, which are our main targets… unfortunately in safari (the apple product, which makes no sense), the unmasked renderer is not accurate.