Hello,
I wrote an example that loads 3D model from DAE COLLADA using Qt 6. Source code: load-3d-model-from-dae-opengl-window-qt6-cpp.zip
OpenGL lighting works correctly on Desktop but incorrectly on Android and WebAssembly:
Android:
WebAssembly:
Vertex shader:
attribute vec4 aPosition;
attribute vec4 aNormal;
attribute vec2 aTexCoord;
uniform mat4 uMvpMatrix;
uniform mat4 uModelMatrix;
uniform mat4 uNormalMatrix;
varying vec3 vPosition;
varying vec3 vNormal;
varying vec2 vTexCoord;
void main()
{
gl_Position = uMvpMatrix * aPosition;
vPosition = vec3(uModelMatrix * aPosition);
vNormal = normalize(vec3(uNormalMatrix * aNormal));
vTexCoord = aTexCoord;
}
Fragment shader:
#ifdef GL_ES
precision mediump float;
#endif
const vec3 lightColor = vec3(0.8, 0.8, 0.8);
const vec3 ambientLight = vec3(0.3, 0.3, 0.3);
uniform sampler2D uSampler;
uniform vec3 uLightPosition;
varying vec3 vPosition;
varying vec3 vNormal;
varying vec2 vTexCoord;
void main()
{
vec4 color = texture2D(uSampler, vTexCoord);
vec3 normal = normalize(vNormal);
vec3 lightDirection = normalize(uLightPosition - vPosition);
float nDotL = max(dot(lightDirection, normal), 0.0);
vec3 diffuse = lightColor * color.rgb * nDotL;
vec3 ambient = ambientLight * color.rgb;
gl_FragColor = vec4(diffuse + ambient, color.a);
}
Cross-refs:
- Loading 3D model from DAE COLLADA using Qt 6. OpenGL lighting works incorrectly on Android and WebAssembly | Qt Forum
- c++ - OpenGL lighting works incorrectly on Android and WebAssembly - Stack Overflow
I created the bug report: Loading...