Fragment Shader bloomrender.frag

I copied texblinn.frag to bloomrender.frag under the shaders directory.

In addition to the version number, the only change I made is to add more specular light for the demonstration of highlights.

    // assuming a light source with a bright white colour
    vec3 specular = vec3(1.0, 0.0, 0.0) * spec * 2;

Full Source Code

// bloomrender.frag for rendering the scene
#version 430

// for lighting
in vec3 fragPos;
in vec3 normal;
in vec2 texCoord;

uniform vec3 lightPos;
uniform vec3 viewPos;

uniform sampler2D textureMap;

out vec4 colour_out;

void main()
{
 
    vec3 colour = texture(textureMap, texCoord).rgb;

    // 1. ambient
    vec3 ambient = 0.05 * colour;

    // 2. diffuse
    vec3 lightDir = normalize(lightPos - fragPos);
    vec3 norm = normalize(normal);
    float diff = max(dot(lightDir, norm), 0.0);
    vec3 diffuse = diff * colour;
    
    // 3. specular
    vec3 viewDir = normalize(viewPos - fragPos);
    vec3 halfwayDir = normalize(lightDir + viewDir);
    
    // the shininess coefficient beta = 32.0 
    float spec = pow(max(dot(norm, halfwayDir), 0.0), 32.0);

    // assuming a light source with a bright white colour
    vec3 specular = vec3(1.0, 0.0, 0.0) * spec * 2;

    // The final output fragment colour 
    // combination of ambient, diffuse and specular
    colour_out = vec4(ambient + diffuse + specular, 1.0);
}

Last updated