38 lines
889 B
GLSL
38 lines
889 B
GLSL
#version 450
|
|
|
|
const int MAX_LIGHTS = 4;
|
|
|
|
struct Light {
|
|
vec4 direction;
|
|
vec4 color;
|
|
};
|
|
|
|
layout(location = 0) in vec2 fragUV;
|
|
layout(location = 1) in vec3 fragNormal;
|
|
layout(location = 2) in vec3 fragWorldPos;
|
|
|
|
layout(location = 0) out vec4 outColor;
|
|
|
|
layout(set = 0, binding = 0) uniform UniformBufferObject {
|
|
mat4 view;
|
|
mat4 proj;
|
|
vec4 ambientColor;
|
|
Light lights[MAX_LIGHTS];
|
|
} ubo;
|
|
|
|
layout(set = 1, binding = 0) uniform sampler2D texSampler;
|
|
|
|
void main() {
|
|
vec3 albedo = texture(texSampler, fragUV).rgb;
|
|
vec3 N = normalize(fragNormal);
|
|
|
|
vec3 result = ubo.ambientColor.rgb * albedo;
|
|
|
|
for (int i = 0; i < MAX_LIGHTS; ++i) {
|
|
vec3 L = normalize(-ubo.lights[i].direction.xyz);
|
|
float diff = max(dot(N, L), 0.0);
|
|
result += ubo.lights[i].color.rgb * ubo.lights[i].color.a * diff * albedo;
|
|
}
|
|
|
|
outColor = vec4(result, 1.0);
|
|
} |