I'm a bit of a novice at OpenGL and I've implemented lighting to a scene with instanced asteroids circling a planet. For some reason, the only output I'm getting seems to be the ambient lighting for the scene. I can't get diffuse or specular to work.
Here's an image of the scene as it is (very hard to see...)ambient only
The fragment shader code is below. FragPos, Normal and TexCoords are as you'd expect. texture_diffuse1 is the planet/asteroid texture depending on the shader used. LightPos can be moved, it's represented by the smaller planet in the image (so directly above the centre planet) and viewPos is the camera position.
Any more information needed please let me know, but there rest of the code is really straight forward (vertex shader really standard, assimp loaded models drawn in the scene, asteroids instanced 200,000 times).
Thanks Jon
Fragment Shader:
`
#version 330 core
out vec4 fragColor;
in VS_OUT{
vec3 FragPos;
vec3 Normal;
vec2 TexCoords;
} fs_in;
uniform sampler2D texture_diffuse1;
uniform vec3 lightPos;
uniform vec3 viewPos;
void main()
{
vec3 color = texture(texture_diffuse1, fs_in.TexCoords).rgb;
//Ambient
vec3 ambient = 0.05f * color;
//Diffuse
vec3 lightDir = normalize(lightPos - fs_in.FragPos);
vec3 normal = normalize(fs_in.Normal);
float diff = max(dot(lightDir, normal), 0.0);
vec3 diffuse = diff * color;
//Specular
vec3 viewDir = normalize(viewPos - fs_in.FragPos);
float spec = 0.0f;
vec3 halfwayDir = normalize(lightDir + viewDir);
spec = pow(max(dot(normal, halfwayDir), 0.0), 32.0f);
vec3 specular = vec3(0.3f) * spec * color;
float distance = length(lightPos - fs_in.FragPos);
float attenuation = 1.0f/distance;
//fragColor = vec4(ambient + (diffuse + specular), 1.0f);
fragColor = vec4( pow(ambient + attenuation * (diffuse + specular),vec3(1.0f/2.2f)), 1.0f);
}
`