What I want is if one of the texture coordinates is less than 0.5 then I would sample another texture that has the digits ‘0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ’ in a 2D texture so I would display 2 of the digits. Even though there were errors my mesh shows up under my last model. I have excluded some features of the shader just to make things easier to see and I am a beginner.
here is my code
#version 330 core
struct Material
{
vec3 ambient;
sampler2D diffuseMap;
sampler2D digits;
vec3 specular;
float shininess;
int numVal;
};
struct DirectionalLight
{
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
in vec2 TexCoord;
in vec3 FragPos;
in vec3 Normal;
uniform DirectionalLight dirLight;
uniform Material material;
uniform vec3 viewPos;
out vec4 frag_color;
void main()
{
// Ambient -------------------------------------------------------------------------
vec3 ambient = dirLight.ambient * material.ambient * vec3(texture(material.diffuseMap, TexCoord));
// Diffuse -------------------------------------------------------------------------
vec3 normal = normalize(Normal);
vec3 lightDir = normalize(-dirLight.direction); // negate => Must be a direction from fragment towards the light
float NdotL = max(dot(normal, lightDir), 0.0);
vec3 diffuse = dirLight.diffuse * NdotL * vec3(texture(material.diffuseMap, TexCoord));
// Specular - Blinn-Phong ----------------------------------------------------------
vec3 viewDir = normalize(viewPos - FragPos);
vec3 halfDir = normalize(lightDir + viewDir);
float NDotH = max(dot(normal, halfDir), 0.0);
vec3 specular = dirLight.specular * material.specular * pow(NDotH, material.shininess);
if (texCoord.x < .5 || texCoord.y < .5){
frag_color = vec4(vec3(texture(material.diffuseMap, TexCoord)), 1.0f);
}else{
int xseg = mod(numval, 6);
int yseg = floor(numVal / 6);
vec2 addloc = vec2(xseg / 6, yseg / 6);
vec2 newloc;
if (TexCoord.x < .75){
newloc = vec2((TexCoord.x - .5) / 1.5, (TexCoord.y - .5) / 3);
}else{
newloc = vec2((TexCoord.x - .75) / 1.5, (TexCoord.y - .5) / 3);
}
frag_color = vec4(vec3(1, 1, 1) - vec3(texture(material.digits, addloc + newloc)), 1.0f);
}
}