aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--frag.glsl21
-rw-r--r--vert.glsl14
2 files changed, 30 insertions, 5 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);
}
diff --git a/vert.glsl b/vert.glsl
index d33cc47..5e4e43a 100644
--- a/vert.glsl
+++ b/vert.glsl
@@ -2,16 +2,24 @@
// SPDX-License-Identifier: MIT
#version 330 core
layout (location = 0) in vec3 pos;
-layout (location = 1) in vec3 normal;
+layout (location = 1) in vec3 norm;
layout (location = 2) in vec2 uv;
-out vec3 vcolor;
+out vec3 vnorm;
+out vec3 fpos;
+out vec3 lipos;
+
uniform mat4 model;
uniform mat4 view;
uniform mat4 proj;
void main()
{
+ vec3 light = { 1.2, 1.0, 2.0 };
+
gl_Position = proj * view * model * vec4(pos, 1.0);
- vcolor = normal;
+ fpos = vec3(view * model * vec4(pos, 1.0));
+ // TODO: Try to work out how to only do this ONCE in C or see if it matters
+ vnorm = mat3(transpose(inverse(view * model))) * norm;
+ lipos = vec3(view * vec4(light, 1.0));
}