From b7d7bc23461e8992d8b9ebfc17aa74b69869a77c Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 14 Mar 2023 20:24:33 +0000 Subject: [PATCH] Add files --- shader/functions.glsl | 11 +++++++++++ shader/shape/basic.frag | 10 ++++++++++ shader/shape/basic.vert | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 shader/functions.glsl create mode 100644 shader/shape/basic.frag create mode 100644 shader/shape/basic.vert diff --git a/shader/functions.glsl b/shader/functions.glsl new file mode 100644 index 000000000..3acff054f --- /dev/null +++ b/shader/functions.glsl @@ -0,0 +1,11 @@ +float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) { + return dot(p - a,b-a) / dot(b-a,b-a); +} +vec2 closestPointOnSeg (vec2 a,vec2 b, vec2 p) { + float x = closestPointOnLineParam(a,b,p); + if (x < 0) { + return a; + } else{ if (x > 1) { return b; } + { return a + (x * (b- a));} + } +} diff --git a/shader/shape/basic.frag b/shader/shape/basic.frag new file mode 100644 index 000000000..d4882cdb3 --- /dev/null +++ b/shader/shape/basic.frag @@ -0,0 +1,10 @@ +#version 450 core +in vec4 vCol; +in vec4 vPos; +layout (location=0) out vec4 fCol; +layout (location=1) out vec4 fPos; +void main() +{ + fCol = vCol; + fPos = vec4(vPos.xyz,1); +} diff --git a/shader/shape/basic.vert b/shader/shape/basic.vert new file mode 100644 index 000000000..b7511a478 --- /dev/null +++ b/shader/shape/basic.vert @@ -0,0 +1,11 @@ +#version 450 core +layout (location = 0) in vec4 pos; +layout (location = 1) in vec4 col; +layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +out vec4 vCol; +out vec4 vPos; +void main() { + gl_Position = theMat * vec4(pos.xyz,1); + vCol = col; + vPos = pos; +}