// // Fragment Shader template // // Inputs from vertex shader in vec4 Position; // Vertex position in camera coordinates. in vec3 Normal; // Vertex normal in camera coordinates. in vec3 CamDir; // Direction from vertex to camera in vec2 FragTexcoord; #include #include #include // Final fragment color out vec4 FragColor; void main() { // Combine all texture colors vec4 texCombined = vec4(1); #if MAT_TEXTURES>0 for (int i = 0; i < MAT_TEXTURES; i++) { if (MatTexVisible(i) == false) { continue; } vec4 texcolor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i)); if (i == 0) { texCombined = texcolor; } else { texCombined = mix(texCombined, texcolor, texcolor.a); } } #endif // Combine material with texture colors vec4 matDiffuse = vec4(MatDiffuseColor, MatOpacity) * texCombined; vec4 matAmbient = vec4(MatAmbientColor, MatOpacity) * texCombined; // Inverts the fragment normal if not FrontFacing vec3 fragNormal = Normal; if (!gl_FrontFacing) { fragNormal = -fragNormal; } // Calculates the Ambient+Diffuse and Specular colors for this fragment using the Phong model. vec3 Ambdiff, Spec; phongModel(Position, fragNormal, CamDir, vec3(matAmbient), vec3(matDiffuse), Ambdiff, Spec); // Final fragment color FragColor = min(vec4(Ambdiff + Spec, matDiffuse.a), vec4(1.0)); }