PDA

View Full Version : GLSL Lighting Issue



tdkr80
05-18-2017, 09:00 AM
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):



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:

2368

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



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);
}

GClements
05-20-2017, 04:48 AM
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?