glTF 2.0 models dark on Android of Qualcomm platform
See original GitHub issueHi, Recently I used cesium to work on the mobile side. I found that my 3dtile model will become very dark on the Android platform. I found similar problems in issues. #6622 and #7403 ,But it seems that I have not found a solution. I have done a lot of testing on this problem and found that the problem comes from the value of ellipsoid.radii.x in processPbrMaterials.js, but I found this to be a fixed value of 6378137.0 in the czm_getWgs84EllipsoidEC method. But I replaced ellipsoid.radii.x with a specific value, and the program works fine on mobile devices, so I don’t think this is a problem caused by float precision. I found some relevant information here, struct will have problems when initializing on Android devices, https://github.com/KhronosGroup/WebGL/issues/1302.
I tried to make the following modifications,Can display my model correctly on my phone。 I am not sure that this modification is the best. If there is a better way, please let me know, I am willing to continue working for it and contribute my code.
I wrote a test code that will display a green square on the pc, but will display a red square on Android, the phone processor is Snapdragon 845, the browser is chrome, Both tests failed on Xiaomi and Samsung phones… But I tested it on Huawei phones. pc: xiaomi:
this is my test code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Struct constructor/initializers highp bug.</title> </head> <body> <canvas id="canvas" width="256" height="256"> </canvas> <script type="application/javascript"> "use strict"; var canvas = document.getElementById('canvas'); var gl = canvas.getContext('webgl'); gl.viewport(0, 0, canvas.width, canvas.height); gl.clearColor(0, 0, 1, 1); gl.clear(gl.COLOR_BUFFER_BIT); var vs = gl.createShader(gl.VERTEX_SHADER);
var vs_code =`
attribute vec4 pos;
void main(){
gl_Position = pos;
}
`;
gl.shaderSource(vs, vs_code);
gl.compileShader(vs);
var fs = gl.createShader(gl.FRAGMENT_SHADER);
var fs_code =`
precision highp float;
struct Test {
vec3 color;
};
void main() {
vec3 color = vec3( 6378137.0, 0.0, 0.0 );
Test test;
test.color = color;
if (test.color.x == 6000000.0) {
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
} else {
gl_FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );
}
}
`;
gl.shaderSource(fs, fs_code);
gl.compileShader(fs);
var prg = gl.createProgram();
gl.attachShader(prg, vs);
gl.attachShader(prg, fs);
gl.linkProgram(prg);
gl.useProgram(prg);
var posLocation = gl.getAttribLocation(prg, 'pos');
gl.enableVertexAttribArray(posLocation);
var vertex = new Float32Array([
-0.8, -0.8, 0,
-0.8, 0.8, 0,
0.8, 0.8, 0,
0.8, -0.8, 0
]);
var index = new Uint8Array([0, 2, 1, 0, 3, 2]);
var vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertex, gl.STATIC_DRAW);
gl.vertexAttribPointer(posLocation, 3, gl.FLOAT, false, 0, 0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, index, gl.STATIC_DRAW);
gl.drawElements(gl.TRIANGLES, index.length, gl.UNSIGNED_BYTE, 0);
</script>
</body>
</html>Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (19 by maintainers)
Top GitHub Comments
Yeah the PR referenced above does solve this issue, I’m just reviewing for code style and tests now, I expect it to be merged end of this week/weekend.
Congratulations on closing the issue! I found these Cesium forum links in the comments above:
https://groups.google.com/d/msg/cesium-dev/qYjFtc3Ktg8/cjc_JId9BwAJ
If this issue affects any of these threads, please post a comment like the following: