summaryrefslogtreecommitdiff
path: root/engine/fragment.glsl
blob: afeef252efc500f42475e252a669a57a90e8b25e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#version 330 core

#preinclude "light.glsl"
#preinclude "vertex_data.glsl"

#define MAX_POINT_LIGHT_CNT 64

out vec4 FragColor;

in vec2 in_texture_coords;

in vec3 in_frag_pos;
in vec3 in_normal;

uniform vec3 view_pos;
uniform sampler2D input_texture;
uniform Material material;
uniform PointLight point_lights[MAX_POINT_LIGHT_CNT];
uniform int point_light_cnt;

void main()
{
	VertexData vertex_data;

	vertex_data.texture_coords = in_texture_coords;
	vertex_data.world_space_pos = in_frag_pos;
	vertex_data.world_space_normal = in_normal;

	vec3 ambient_light = calc_ambient_light(material, in_texture_coords);

	vec3 point_light_sum = vec3(0.0, 0.0, 0.0);

	for (int pl_index = 0; pl_index < point_light_cnt; pl_index++) {
		point_light_sum += calc_point_light(
			point_lights[pl_index],
			vertex_data,
			view_pos,
			material
		);
	}

	FragColor = vec4((ambient_light + point_light_sum), 1.0);
}