44 lines
No EOL
1.2 KiB
GLSL
44 lines
No EOL
1.2 KiB
GLSL
#version 330 core
|
|
out vec4 FragColor;
|
|
|
|
in vec2 TexCoords;
|
|
|
|
uniform sampler2D gPosition;
|
|
uniform sampler2D gNormal;
|
|
uniform sampler2D gAlbedoSpec;
|
|
uniform sampler2D gShadow;
|
|
|
|
struct Light {
|
|
vec3 Position;
|
|
vec3 Color;
|
|
};
|
|
const int NR_LIGHTS = 32;
|
|
uniform Light lights[NR_LIGHTS];
|
|
uniform vec3 viewPos;
|
|
|
|
void main()
|
|
{
|
|
// retrieve data from G-buffer
|
|
vec3 FragPos = texture(gPosition, TexCoords).rgb;
|
|
vec3 Normal = texture(gNormal, TexCoords).rgb;
|
|
vec3 Albedo = texture(gAlbedoSpec, TexCoords).rgb;
|
|
float Specular = texture(gAlbedoSpec, TexCoords).a;
|
|
vec4 Shadow = texture(gShadow, TexCoords);
|
|
Shadow.x=1-(Shadow.x*0.4);
|
|
Shadow.y=1-(Shadow.y*0.4);
|
|
Shadow.z=1-(Shadow.z*0.4);
|
|
Shadow.w=1-(Shadow.w*0.4);
|
|
|
|
// then calculate lighting as usual
|
|
vec3 lighting = Albedo * 0.5; // hard-coded ambient component
|
|
vec3 viewDir = normalize(viewPos - FragPos);
|
|
for(int i = 0; i < NR_LIGHTS; ++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 * Shadow.xyz, 1.0);
|
|
} |