Thursday, January 15, 2026
spot_img

Calculating Mild Route utilizing Regular Map


I have been following alongside the LearnOpenGL tutorials and I’ve arrived on the chapter on Regular Maps, however I have been caught for a short while on getting the specular highlights to seem accurately. Here’s a GIF of the impact I’m scuffling with – you possibly can see the specular highlights even when the dice is between the digital camera and the sunshine supply, as if the sunshine is "bleeding by way of" from behind the dice.

Calculating Mild Route utilizing Regular Map

Right here is my vertex after which fragment shader:

#model 330 core
format (location = 0) in vec3 aPos;
format (location = 1) in vec3 aNormal;
format (location = 2) in vec2 aTexCoord;
format (location = 3) in vec3 aTangent;
format (location = 4) in vec3 aBitangent;

out VertexOut {
    vec3 FragPos;
    vec2 TexCoord;
    vec3 TangentLightPos;
    vec3 TangentFragPos;
} VOut;

uniform vec3 uLightPosition;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProj;
uniform mat3 uNorm;

void most important()
{
    gl_Position = uProj * uView * uModel * vec4(aPos, 1.0);
    VOut.FragPos = vec3(uView * uModel * vec4(aPos, 1.0));
    VOut.TexCoord = aTexCoord;

    vec3 T = normalize(vec3(uView * uModel * vec4(aTangent, 0.0)));
    vec3 N = normalize(vec3(uView * uModel * vec4(aNormal, 0.0)));
    T = normalize(T - N * dot(N, T));
    vec3 B = cross(N, T); 
    mat3 TBN = transpose(mat3(T, B, N));
    //uLightPosition is in view-space
    VOut.TangentLightPos = TBN * uLightPosition;
    VOut.TangentFragPos = TBN * VOut.FragPos;
}
#model 330 core
out vec4 FragColor;

struct Materials
{
    sampler2D diffuseMap;
    sampler2D specularMap;
    sampler2D normalMap;
    float shininess;
};

struct LightColor
{
    vec3 ambientColor;
    vec3 diffuseColor;
    vec3 specularColor;
};

in VertexOut
{
    vec3 FragPos;
    vec2 TexCoord;
    vec3 TangentLightPos;
    vec3 TangentFragPos;
} VOut;

uniform Materials uMaterial;
uniform LightColor uLightColor;

void most important()
{
// Compute helpful vectors
    vec3 regular = texture(uMaterial.normalMap, VOut.TexCoord).rgb;
    regular = regular * 2.0 - 1.0;
    regular = normalize(regular);
    vec3 lightDirection = normalize(VOut.TangentLightPos - VOut.TangentFragPos);

// Ambient lighting
    vec3 ambientLight = vec3(texture(uMaterial.diffuseMap, VOut.TexCoord)) * uLightColor.ambientColor;

// Diffuse lighting
    float diffuseImpact = max(dot(regular, lightDirection), 0.0);
    vec3 diffuseLight = diffuseImpact * vec3(texture(uMaterial.diffuseMap, VOut.TexCoord)) * uLightColor.diffuseColor;

// Specular lighting
    vec3 viewDirection = normalize(-VOut.TangentFragPos);
    vec3 reflectDirection = replicate(-lightDirection, regular);

    float specularImpact = pow(max(dot(viewDirection, reflectDirection), 0.0), uMaterial.shininess);
    vec3 specularLight = specularImpact * vec3(texture(uMaterial.specularMap, VOut.TexCoord)) * uLightColor.specularColor;

// Mix all lighting elements
    vec3 resultLight = (0.0 + 0.0 + specularLight);
    FragColor = vec4(resultLight, 1.0);
}

If anybody’s run into this earlier than, I hope they will share the difficulty. I have been banging my head on this for a day or two now and I can not pin down the difficulty.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles