1
\$\begingroup\$

I am trying to make my first 3D game in OpenGL with Shaders (LWJGL3) I read and follow a lot of tutorials but can't figure it out what kind of light I am missing here? The wall doesn't get any effect from the light

enter image description here

It is supposed to be like this one: enter image description here

And my point light part in fragment:

vec4 calcLightColour(vec3 light_colour, float light_intensity, vec3 position, vec3 to_light_dir, vec3 normal)
{
    vec4 diffuseColour = vec4(0, 0, 0, 0);
    vec4 specColour = vec4(0, 0, 0, 0);

    // Diffuse Light
    float diffuseFactor = max(dot(normal, to_light_dir), 0.0);
    diffuseColour = diffuseC * vec4(light_colour, 1.0) * light_intensity * diffuseFactor;

    // Specular Light
    vec3 camera_direction = normalize(-position);
    vec3 from_light_dir = -to_light_dir;
    vec3 reflected_light = normalize(reflect(from_light_dir , normal));
    float specularFactor = max( dot(camera_direction, reflected_light), 0.0);
    specularFactor = pow(specularFactor, specularPower);
    specColour = speculrC * light_intensity  * specularFactor * material.reflectance * vec4(light_colour, 1.0);

    return (diffuseColour + specColour);
}

vec4 calcPointLight(PointLight light, vec3 position, vec3 normal)
{
    vec3 light_direction = light.position - position;
    vec3 to_light_dir  = normalize(light_direction);
    vec4 light_colour = calcLightColour(light.colour, light.intensity, position, to_light_dir, normal);

    // Apply Attenuation
    float distance = length(light_direction);
    float attenuationInv = light.att.constant + light.att.linear * distance +
        light.att.exponent * distance * distance;
    return light_colour / attenuationInv;
}
\$\endgroup\$
5
  • \$\begingroup\$ What "effect" are you expecting the light to have on the wall? Can you describe what you expect to see in more detail? Also, it would help to know what lights you already have in the scene. \$\endgroup\$ – user1118321 Mar 6 '18 at 5:32
  • \$\begingroup\$ I just added another pic (was taken from my blender). And I am only using point light \$\endgroup\$ – Thai Doan Nam Mar 6 '18 at 6:06
  • \$\begingroup\$ It's going to be hard to help you diagnose this without more information. How have you set up the scene in OpenGL? Are you using shaders or the older, deprecated fixed-function pipeline? \$\endgroup\$ – user1118321 Mar 6 '18 at 6:09
  • \$\begingroup\$ Sorry about that, I am using shaders and I just added my point light parts in fragment \$\endgroup\$ – Thai Doan Nam Mar 6 '18 at 6:17
  • \$\begingroup\$ @ThaiDoanNam are actually calling those two functions? You should add the relevant code, (like both the vertex and pixel shader for example). Right now, you just provided us with two functions, in the fragment shader. We don't know which values you passed in as parameters, where you are calling them, if you are calling them, which uniforms you are setting and so on. \$\endgroup\$ – user100681 Mar 6 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.