aboutsummaryrefslogtreecommitdiffstats
path: root/shaders
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-10-19 23:22:07 +0300
committerTomasz Kramkowski <tk@the-tk.com>2018-10-19 23:30:23 +0300
commit7c1edef3ac501d40e3de495b9434df71f535e9bc (patch)
treefd7f4264bdf5c30f7182a147ed9e6c7935c69bf2 /shaders
parent91b543a29cb8852251908a49cd120a6f7d9f2f11 (diff)
downloadfaqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.tar.gz
faqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.tar.xz
faqe-7c1edef3ac501d40e3de495b9434df71f535e9bc.zip
Allow multiple shaders while reducing duplication
This change also stops using bie as eventually it will be replaced with a more sophisticated asset handling system which will also allow custom shaders.
Diffstat (limited to 'shaders')
-rw-r--r--shaders/data.h33
-rw-r--r--shaders/main/frag.glsl28
-rw-r--r--shaders/main/vert.glsl18
3 files changed, 79 insertions, 0 deletions
diff --git a/shaders/data.h b/shaders/data.h
new file mode 100644
index 0000000..e1a71c3
--- /dev/null
+++ b/shaders/data.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+#ifdef SH_PROG
+ SH_PROG(main)
+#undef SH_PROG
+#endif // SH_PROG
+#ifdef SH_VER
+ SH_VER("330 core")
+#undef SH_VER
+#endif // SH_VER
+#ifdef SH_IN
+ SH_IN(vec3, pos)
+ SH_IN(vec3, norm)
+ SH_IN(vec2, uv)
+#undef SH_IN
+#endif // SH_IN
+#ifdef SH_UNI
+ SH_UNI(mat4, model)
+ SH_UNI(mat4, view)
+ SH_UNI(mat4, proj)
+ SH_UNI(vec3, light)
+#undef SH_UNI
+#endif // SH_UNI
+#ifdef SH_TEX
+ SH_TEX(2D, tex)
+#undef SH_TEX
+#endif // SH_TEX
+#ifdef SH_OUT
+ SH_OUT(vec4, color)
+#undef SH_OUT
+#endif // SH_OUT
diff --git a/shaders/main/frag.glsl b/shaders/main/frag.glsl
new file mode 100644
index 0000000..c57598c
--- /dev/null
+++ b/shaders/main/frag.glsl
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+in vec3 fnorm;
+in vec3 fpos;
+in vec2 fuv;
+in vec3 lipos;
+
+void main()
+{
+ vec3 objco = vec3(texture(tex, fuv));
+ vec3 lico = vec3(1.0, 1.0, 1.0);
+
+ float amb = 0.1;
+
+ vec3 norm = normalize(fnorm);
+ vec3 lidir = normalize(lipos - fpos);
+ float dif = max(dot(norm, lidir), 0.0);
+
+ float speen = max(sign(dot(lidir, norm)), 0.0);
+ vec3 vwdir = normalize(-fpos);
+ vec3 mid = normalize(lidir + vwdir);
+
+ float spe = pow(max(dot(norm, mid), 0.0), 256) * speen;
+
+ color = vec4((amb + dif + spe) * lico * objco, 1.0);
+}
diff --git a/shaders/main/vert.glsl b/shaders/main/vert.glsl
new file mode 100644
index 0000000..f710067
--- /dev/null
+++ b/shaders/main/vert.glsl
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2018 Tomasz Kramkowski <tk@the-tk.com>
+ * SPDX-License-Identifier: MIT
+ */
+out vec3 fnorm;
+out vec3 fpos;
+out vec2 fuv;
+out vec3 lipos;
+
+void main()
+{
+ gl_Position = proj * view * model * vec4(pos, 1.0);
+ fpos = vec3(view * model * vec4(pos, 1.0));
+ fuv = uv;
+ // TODO: Try to work out how to only do this ONCE in C or see if it matters
+ fnorm = mat3(transpose(inverse(view * model))) *norm;
+ lipos = vec3(view * vec4(light, 1.0));
+}