Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: GLSL Lighting Issue

  1. #1
    Junior Member Newbie
    Join Date
    May 2017
    Posts
    1

    Angry GLSL Lighting Issue

    Hello everyone,

    I'm currently developing a simple 3D game engine in C# using OpenTK. At the moment I'm implementing some lighting into my engine, I have a mesh that I've imported into the engine; also a method which calculates normals.

    So the issue is this: I've created a material structure in GLSL, that hold a vec3 called 'diffuseColor', I've also created two other structures which define a directional light. Here are the three structures (just to clarify):

    Code :
    struct Material
    {
        vec3 diffuseColor;
    };
     
    struct BaseLight
    {
        vec3 color;
        float energy;
    };
     
    struct DirectionalLight
    {
        BaseLight baseLight;
        vec3 direction;
    };

    For some reason, if I create a directional light in my scene, which a direction of vec3(1, 1, 1), and a color of vec3(1, 1, 1) with energy at 1.0 this is the result:

    Click image for larger version. 

Name:	snkyhi.jpg 
Views:	62 
Size:	30.7 KB 
ID:	2368

    Here's the calc light method, any help would be awesome! I've been at this for two days now!

    Code :
    vec3 CalculateDirectionalLight(DirectionalLight light, vec3 normal, vec3 viewDirection, Material material)
    {
        normal = normalize(normal);
     
        vec3 lightDir = normalize(-light.direction);    
        float diffuseFactor = max(dot(normal, lightDir), 0.0);   
     
        vec3 ambient = vec3(0.2, 0.2, 0.2);
        vec3 diffuse = (light.baseLight.color * light.baseLight.energy) * (diffuseFactor * material.diffuseColor);
     
        return (ambient + diffuse);
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,003
    How is light getting its value? Is it a uniform or an attribute? In the default uniform block or a named uniform block? shared, packed or std140 layout?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •