I'm currently learning how to import models. I created some code that works well following this tutorial which uses only one sampler2D in the fragment shader and the model loads just fine with all the textures. The thing is what happens when a mesh has more than one textures? The tutorial says to define inside the fragment shader N diffuse and specular samplers with the format texture_diffuseN, texture_specularN and set them via code, where N is 1,2,3, .. , max_samplers. I understand that but how do you use them inside the shader?
In the tutorial the shader is:
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{
FragColor = texture(texture_diffuse1, TexCoords);
} which works perfectly for the test model that the tutorial is giving us. Now lets say you have the general shader:
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_diffuse2;
uniform sampler2D texture_diffuse3;
uniform sampler2D texture_diffuse4;
uniform sampler2D texture_diffuse5;
uniform sampler2D texture_diffuse6;
uniform sampler2D texture_diffuse7;
uniform sampler2D texture_specular1;
uniform sampler2D texture_specular2;
uniform sampler2D texture_specular3;
uniform sampler2D texture_specular4;
uniform sampler2D texture_specular5;
uniform sampler2D texture_specular6;
uniform sampler2D texture_specular7;
void main()
{
//How am i going to decide here which diffuse texture to output?
FragColor = texture(texture_diffuse1, TexCoords);
} Can you explain me this with a cube example? Lets say i have a cube which is a mesh and i want to apply a different texture for each face (6 total).
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_diffuse2;
uniform sampler2D texture_diffuse3;
uniform sampler2D texture_diffuse4;
uniform sampler2D texture_diffuse5;
uniform sampler2D texture_diffuse6;
void main()
{
//How am i going to output the correct texture for each face?
FragColor = texture(texture_diffuse1, TexCoords);
} I know that the text coordinates will apply the texture at the correct face, but how do i now which sampler to use every time the fragments shader is called?
I hope you understand why I'm frustrated.
Thank you

