diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-22 01:47:07 +0300 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-22 01:47:07 +0300 |
commit | accfd0b069897c1a07b7ee7dd1f35a345fb76c30 (patch) | |
tree | d073a602daa15b6c9578bfc776fa979cf6b4c3e2 | |
parent | 06d028e6a6b7d32de7201b2acfec7e54d08103dc (diff) | |
download | faqe-accfd0b069897c1a07b7ee7dd1f35a345fb76c30.tar.gz faqe-accfd0b069897c1a07b7ee7dd1f35a345fb76c30.tar.xz faqe-accfd0b069897c1a07b7ee7dd1f35a345fb76c30.zip |
main shader: Use an interface block for neatness
-rw-r--r-- | shaders/main/frag.glsl | 20 | ||||
-rw-r--r-- | shaders/main/vert.glsl | 18 |
2 files changed, 21 insertions, 17 deletions
diff --git a/shaders/main/frag.glsl b/shaders/main/frag.glsl index 8aa9a6a..f6ed7c3 100644 --- a/shaders/main/frag.glsl +++ b/shaders/main/frag.glsl @@ -2,25 +2,27 @@ * 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; +in iface { + vec3 norm; + vec3 pos; + vec2 uv; + vec3 lipos; +} i; void main() { - vec3 fdiff = vec3(texture(tdiff, fuv)); - vec3 fspec = vec3(texture(tspec, fuv)); + 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(fnorm); - vec3 lidir = normalize(lipos - fpos); + 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(-fpos); + vec3 vwdir = normalize(-i.pos); vec3 mid = normalize(lidir + vwdir); vec3 spec = pow(max(dot(norm, mid), 0.0), 256) * specen * fspec; diff --git a/shaders/main/vert.glsl b/shaders/main/vert.glsl index f710067..3b145e3 100644 --- a/shaders/main/vert.glsl +++ b/shaders/main/vert.glsl @@ -2,17 +2,19 @@ * 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; +out iface { + vec3 norm; + vec3 pos; + vec2 uv; + vec3 lipos; +} o; void main() { gl_Position = proj * view * model * vec4(pos, 1.0); - fpos = vec3(view * model * vec4(pos, 1.0)); - fuv = uv; + o.pos = vec3(view * model * vec4(pos, 1.0)); + o.uv = 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)); + o.norm = mat3(transpose(inverse(view * model))) * norm; + o.lipos = vec3(view * vec4(light, 1.0)); } |