aboutsummaryrefslogtreecommitdiffstats
path: root/shaders/main/frag.glsl
blob: 9f8c5deb003184438bb771e4f679a733a5cf2427 (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
/*
 * Copyright (C) 2018, 2022 Tomasz Kramkowski <tk@the-tk.com>
 * SPDX-License-Identifier: MIT
 */
void main()
{
	vec3 fdiff = vec3(texture(tdiff, i.uv));
	vec3 fspec = vec3(texture(tspec, i.uv));
	vec3 lico = vec3(1.0, 1.0, 1.0);

	vec3 amb = vec3(0.1, 0.1, 0.1);

	vec3 norm = normalize(i.norm);
	vec3 lidir = normalize(i.lipos - i.pos);
	vec3 diff = max(dot(norm, lidir), 0.0) * fdiff;

	float specen = max(sign(dot(lidir, norm)), 0.0);
	vec3 vwdir = normalize(-i.pos);
	vec3 mid = normalize(lidir + vwdir);

	vec3 spec = pow(max(dot(norm, mid), 0.0), 256) * specen * fspec;

	color = vec4((amb + diff + spec) * lico, 1.0);
}