- precision mediump float;
- varying vec2 v_texcoord;
- varying vec3 v_normal;
- varying vec3 v_fragPos;
- uniform sampler2D u_texture;
- uniform vec3 u_lightPos;
- uniform vec3 u_viewPos;
- void main() {
- vec3 a = vec3(1.0);
- vec3 b = vec3(1.0);
- vec3 c = vec3(1.0);
- mat3 abc = mat3(a, b, c);
- mat3 abcTranspose = transpose(abc); // error
- vec3 lightColor = vec3(1.0, 1.0, 1.0);
- vec3 objectColor = texture2D(u_texture, v_texcoord).rgb;
- // * ambient
- float ambientStrength = 0.1;
- vec3 ambient = ambientStrength * lightColor;
- // * diffuse
- vec3 normal = normalize(v_normal);
- vec3 lightDir = normalize(u_lightPos - v_fragPos);
- float diff = max(dot(normal, lightDir), 0.0);
- vec3 diffuse = diff * lightColor;
- // * specular
- float specularStrength = 0.5;
- vec3 viewDir = normalize(u_viewPos - v_fragPos);
- vec3 reflectDir = reflect(-lightDir, normal);
- float shininess = 32.0;
- float spec = pow(max(dot(viewDir, reflectDir), 0.0), shininess);
- vec3 specular = specularStrength * spec * lightColor;
- vec3 result = (ambient + diffuse + specular) * objectColor;
- gl_FragColor = vec4(result, 1.0);
- }