40 lines
877 B
GLSL
40 lines
877 B
GLSL
#version 440
|
|
out vec4 FragColor;
|
|
|
|
in vec2 uv;
|
|
|
|
uniform sampler2D pos_tex;
|
|
uniform sampler2D normal_tex;
|
|
uniform sampler2D color_tex;
|
|
|
|
struct Light {
|
|
vec3 Position;
|
|
vec3 Color;
|
|
};
|
|
|
|
uniform int NLights;
|
|
uniform Light lights[64];
|
|
|
|
uniform vec3 view_pos;
|
|
|
|
void main()
|
|
{
|
|
vec3 FragPos = texture(pos_tex, uv).rgb;
|
|
vec3 Normal = texture(normal_tex, uv).rgb;
|
|
vec3 Albedo = texture(color_tex, uv).rgb;
|
|
float Specular = 0.5f;
|
|
|
|
// then calculate lighting as usual
|
|
vec3 lighting = Albedo * 0.1; // hard-coded ambient component
|
|
vec3 viewDir = normalize(view_pos - FragPos);
|
|
for (int i = 0; i < NLights; ++i)
|
|
{
|
|
// diffuse
|
|
vec3 lightDir = normalize(lights[i].Position - FragPos);
|
|
vec3 diffuse = max(dot(Normal, lightDir), 0.0) * Albedo * lights[i].Color;
|
|
lighting += diffuse;
|
|
}
|
|
|
|
FragColor = vec4(lighting, 1.0);
|
|
}
|