2024-12-25 21:44:33 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
struct TextureArray {
|
2024-12-31 08:40:23 +00:00
|
|
|
sampler2D texture_diffuse[32]; // Array of diffuse textures
|
|
|
|
// You can add more texture types here (e.g., specular, normal) if needed
|
2024-12-30 04:25:16 +00:00
|
|
|
};
|
2024-12-25 21:44:33 +00:00
|
|
|
|
2024-12-31 08:40:23 +00:00
|
|
|
uniform TextureArray uTextures; // Array of textures
|
2024-12-30 04:25:16 +00:00
|
|
|
uniform int uNumDiffuseTextures; // Number of active diffuse textures
|
|
|
|
|
2024-12-31 08:40:23 +00:00
|
|
|
in vec2 TexCoord; // From vertex shader
|
|
|
|
in vec3 Normal; // From vertex shader
|
|
|
|
in vec3 FragPos; // From vertex shader
|
2024-12-30 04:25:16 +00:00
|
|
|
|
2024-12-31 08:40:23 +00:00
|
|
|
out vec4 FragColor; // Final fragment color
|
|
|
|
|
|
|
|
// Example lighting parameters
|
|
|
|
uniform vec3 lightPos; // Position of the light source
|
|
|
|
uniform vec3 viewPos; // Position of the camera/viewer
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2024-12-31 08:40:23 +00:00
|
|
|
// Normalize the normal vector
|
|
|
|
vec3 norm = normalize(Normal);
|
|
|
|
|
|
|
|
// Calculate the direction from the fragment to the light
|
|
|
|
vec3 lightDir = normalize(lightPos - FragPos);
|
|
|
|
|
|
|
|
// Compute the diffuse intensity
|
|
|
|
float diff = max(dot(norm, lightDir), 0.0);
|
|
|
|
|
|
|
|
// Initialize diffuse color
|
|
|
|
vec4 diffuseColor = vec4(0.0);
|
|
|
|
|
|
|
|
// Sample and accumulate diffuse textures
|
|
|
|
for(int i = 0; i < uNumDiffuseTextures; ++i)
|
|
|
|
{
|
|
|
|
diffuseColor += texture(uTextures.texture_diffuse[i], TexCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the diffuse intensity
|
|
|
|
diffuseColor *= diff;
|
|
|
|
|
|
|
|
// Simple ambient lighting
|
|
|
|
vec3 ambient = 0.1 * diffuseColor.rgb;
|
|
|
|
|
|
|
|
// Final color combining ambient and diffuse components
|
|
|
|
FragColor = vec4(ambient + diffuseColor.rgb, diffuseColor.a);
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|