aboutsummaryrefslogtreecommitdiffstats
path: root/frag.glsl
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-04-30 12:51:12 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-04-30 12:51:12 +0100
commit89b5603110c47e30450ce05573c6b95ef38d8fd7 (patch)
treeec999b76f6434ab1e0038b665145f6cf5820aa6c /frag.glsl
parent9e27cc3d7565d7c98957a517ecad8257a86265cd (diff)
downloadfaqe-89b5603110c47e30450ce05573c6b95ef38d8fd7.tar.gz
faqe-89b5603110c47e30450ce05573c6b95ef38d8fd7.tar.xz
faqe-89b5603110c47e30450ce05573c6b95ef38d8fd7.zip
Implement basic fixed point light source and phong shading
This patch places a single point light source in the scene and implements view-space phong shading around it. This is in preparation for texture values being fed in from a set of textures.
Diffstat (limited to 'frag.glsl')
-rw-r--r--frag.glsl21
1 files changed, 19 insertions, 2 deletions
diff --git a/frag.glsl b/frag.glsl
index c48ee57..41d98ad 100644
--- a/frag.glsl
+++ b/frag.glsl
@@ -2,9 +2,26 @@
// SPDX-License-Identifier: MIT
#version 330 core
out vec4 color;
-in vec3 vcolor;
+in vec3 vnorm;
+in vec3 fpos;
+in vec3 lipos;
void main()
{
- color = vec4(vcolor, 1.0);
+ vec3 objco = { 1.0, 0.5, 0.31 };
+ vec3 lico = { 1.0, 1.0, 1.0 };
+
+ float amb = 0.1;
+
+ vec3 norm = normalize(vnorm);
+ vec3 lidir = normalize(lipos - fpos);
+ float dif = max(dot(norm, lidir), 0.0);
+
+ float spestr = 0.5;
+ vec3 vwdir = normalize(-fpos);
+ vec3 redir = reflect(-lidir, norm);
+
+ float spe = spestr * pow(max(dot(vwdir, redir), 0.0), 32);
+
+ color = vec4((amb + dif + spe) * lico * objco, 1.0);
}