#ifdef GL_ES // Set default precision to medium precision mediump int; precision mediump float; #endif uniform mat3 n_matrix; uniform sampler2D texture; uniform struct Light { vec3 position; vec3 intensities; } light; uniform bool b_transparent; uniform bool b_light; varying vec2 v_surfaceUV; varying vec3 v_surfacePosition; varying vec3 v_surfaceNormal; void main() { // variables vec3 diffuse; // get fragment color from texture vec4 surfaceColor = vec4(texture2D(texture, v_surfaceUV)); // if not transparent, ignore alpha value and set it to 1 if(!b_transparent) surfaceColor.a = 1.0f; if(b_light) { // calculate normals in worldspace vec3 normalWorld = normalize(n_matrix * v_surfaceNormal); //get the surface - light vector (cause this is a point light) vec3 surfaceToLight = normalize(light.position - v_surfacePosition); // calculate the brightness depending on the angle float diffuseCoefficient = max(0.0, dot(normalWorld, surfaceToLight)); // result diffuse color diffuse = diffuseCoefficient * surfaceColor.rgb * light.intensities; } else { diffuse = surfaceColor.rgb; } // put all together gl_FragColor = vec4(diffuse, surfaceColor.a); }