2024-12-25 21:44:33 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
// Struct to hold an array of diffuse textures
|
|
|
|
struct TextureArray {
|
|
|
|
sampler2D texture_diffuse[32]; // Array of diffuse texture samplers
|
|
|
|
};
|
2024-12-25 21:44:33 +00:00
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
// Uniforms
|
|
|
|
uniform TextureArray uTextures; // Array of diffuse textures
|
|
|
|
uniform int uNumDiffuseTextures; // Number of active diffuse textures
|
|
|
|
|
|
|
|
// Input variables from the vertex shader
|
2024-12-30 06:51:58 +00:00
|
|
|
in vec2 TexCoords; // Texture coordinates
|
|
|
|
flat in int TextureIndex; // Texture index for this fragment
|
2024-12-30 04:25:16 +00:00
|
|
|
|
|
|
|
// Output fragment color
|
|
|
|
out vec4 FragColor;
|
2024-12-25 21:44:33 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2024-12-30 06:51:58 +00:00
|
|
|
// Clamp the texture index to prevent out-of-bounds access
|
|
|
|
int texIndex = clamp(TextureIndex, 0, uNumDiffuseTextures - 1);
|
|
|
|
|
|
|
|
// Sample the texture using the provided index and texture coordinates
|
|
|
|
vec4 sampledColor = texture(uTextures.texture_diffuse[texIndex], TexCoords);
|
|
|
|
|
2024-12-30 04:25:16 +00:00
|
|
|
// Set the final fragment color
|
2024-12-30 06:51:58 +00:00
|
|
|
FragColor = sampledColor;
|
2024-12-25 21:44:33 +00:00
|
|
|
}
|