summaryrefslogtreecommitdiff
path: root/assets/shaders
diff options
context:
space:
mode:
authorJoshua Rowe <17525998+omnisci3nce@users.noreply.github.com>2024-05-20 10:50:11 +1000
committerGitHub <noreply@github.com>2024-05-20 10:50:11 +1000
commite904c22003c3a134201b222e6619e782fbe63947 (patch)
tree5295c8ce5f855ca4a0f1bebe50beee80bae66682 /assets/shaders
parent02e84ee4d18e705e3362be1e327fdb6f1397a032 (diff)
parent73d4145f46d2305f45761b8e456df692d1962dfb (diff)
Merge pull request #14 from omnisci3nce/realign
Realign
Diffstat (limited to 'assets/shaders')
-rw-r--r--assets/shaders/blinn_phong.frag4
-rw-r--r--assets/shaders/blinn_phong.vert2
-rw-r--r--assets/shaders/cube.frag12
-rw-r--r--assets/shaders/cube.vert21
-rw-r--r--assets/shaders/object.frag15
-rw-r--r--assets/shaders/object.vert29
-rw-r--r--assets/shaders/skinned.vert59
-rw-r--r--assets/shaders/triangle.frag6
-rw-r--r--assets/shaders/triangle.vert11
9 files changed, 158 insertions, 1 deletions
diff --git a/assets/shaders/blinn_phong.frag b/assets/shaders/blinn_phong.frag
index 095b19a..a0ba905 100644
--- a/assets/shaders/blinn_phong.frag
+++ b/assets/shaders/blinn_phong.frag
@@ -33,6 +33,7 @@ in VS_OUT {
vec3 Normal;
vec2 TexCoords;
vec4 FragPosLightSpace;
+ vec4 Color;
} fs_in;
// --- Uniforms
@@ -55,7 +56,8 @@ void main() {
result += CalcPointLight(pointLights[i], norm, fs_in.FragPos, viewDir);
}
- FragColor = vec4(result, 1.0);
+// FragColor = vec4(result, 1.0);
+ FragColor = fs_in.Color + 0.5;
}
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
diff --git a/assets/shaders/blinn_phong.vert b/assets/shaders/blinn_phong.vert
index 6028178..06dc5e7 100644
--- a/assets/shaders/blinn_phong.vert
+++ b/assets/shaders/blinn_phong.vert
@@ -15,6 +15,7 @@ out VS_OUT {
vec3 Normal;
vec2 TexCoords;
vec4 FragPosLightSpace;
+ vec4 Color;
} vs_out;
void main() {
@@ -22,5 +23,6 @@ void main() {
vs_out.Normal = inNormal;
vs_out.TexCoords = inTexCoords;
vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0);
+ vs_out.Color = vec4(1.0);
gl_Position = projection * view * model * vec4(inPos, 1.0);
} \ No newline at end of file
diff --git a/assets/shaders/cube.frag b/assets/shaders/cube.frag
new file mode 100644
index 0000000..292578f
--- /dev/null
+++ b/assets/shaders/cube.frag
@@ -0,0 +1,12 @@
+#version 450
+
+layout(location = 0) in vec3 fragColor;
+layout(location = 1) in vec2 fragTexCoord;
+
+layout(binding = 1) uniform sampler2D texSampler;
+
+layout(location = 0) out vec4 outColor;
+
+void main() {
+ outColor = texture(texSampler, fragTexCoord); // vec4(fragTexCoord, 0.0);
+}
diff --git a/assets/shaders/cube.vert b/assets/shaders/cube.vert
new file mode 100644
index 0000000..dc625ec
--- /dev/null
+++ b/assets/shaders/cube.vert
@@ -0,0 +1,21 @@
+#version 450
+
+layout(binding = 0) uniform UniformBufferObject {
+ mat4 model;
+ mat4 view;
+ mat4 proj;
+}
+ubo;
+
+layout(location = 0) in vec3 inPosition;
+layout(location = 1) in vec3 inNormal;
+layout(location = 2) in vec2 inTexCoords;
+
+layout(location = 0) out vec3 fragColor;
+layout(location = 1) out vec2 fragTexCoord;
+
+void main() {
+ gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
+ fragColor = abs(inNormal);
+ fragTexCoord = inTexCoords;
+}
diff --git a/assets/shaders/object.frag b/assets/shaders/object.frag
new file mode 100644
index 0000000..fa50fcf
--- /dev/null
+++ b/assets/shaders/object.frag
@@ -0,0 +1,15 @@
+#version 450
+#extension GL_ARB_separate_shader_objects : enable
+
+layout(location = 0) in vec3 in_position;
+layout(location = 1) in vec3 in_normal;
+layout(location = 2) in vec2 in_tex_coord;
+
+layout(set = 0, binding = 1) uniform sampler2D texSampler;
+
+layout(location = 0) out vec4 out_color;
+
+void main() {
+ // out_color = vec4(1.0);
+ out_color = texture(texSampler, in_tex_coord);
+} \ No newline at end of file
diff --git a/assets/shaders/object.vert b/assets/shaders/object.vert
new file mode 100644
index 0000000..23c0ffb
--- /dev/null
+++ b/assets/shaders/object.vert
@@ -0,0 +1,29 @@
+#version 450
+#extension GL_ARB_separate_shader_objects : enable
+
+layout(location = 0) in vec3 in_position;
+layout(location = 1) in vec3 in_normal;
+layout(location = 2) in vec2 in_tex_coord;
+
+layout(location = 0) out vec3 out_position;
+layout(location = 1) out vec3 out_normal;
+layout(location = 2) out vec2 out_tex_coord;
+
+layout(set = 0, binding = 0) uniform global_object_uniform {
+ mat4 projection;
+ mat4 view;
+}
+global_ubo;
+
+layout(push_constant) uniform push_constants {
+ mat4 model; // 64 bytes
+}
+u_push_constants;
+
+void main() {
+ gl_Position = global_ubo.projection * global_ubo.view * u_push_constants.model *
+ vec4(in_position.x, in_position.y, in_position.z, 1.0);
+ out_position = in_position;
+ out_normal = in_normal;
+ out_tex_coord = in_tex_coord;
+} \ No newline at end of file
diff --git a/assets/shaders/skinned.vert b/assets/shaders/skinned.vert
new file mode 100644
index 0000000..cb2ca85
--- /dev/null
+++ b/assets/shaders/skinned.vert
@@ -0,0 +1,59 @@
+#version 410 core
+// Inputs
+layout (location = 0) in vec3 inPos;
+layout (location = 1) in vec3 inNormal;
+layout (location = 2) in vec2 inTexCoords;
+layout (location = 3) in ivec4 inBoneIndices;
+layout (location = 4) in vec4 inWeights;
+
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
+uniform mat4 lightSpaceMatrix;
+
+const int MAX_BONES = 100;
+const int MAX_BONE_INFLUENCES = 4;
+uniform mat4 boneMatrices[MAX_BONES]; // TODO!
+
+// Output
+out VS_OUT {
+ vec3 FragPos;
+ vec3 Normal;
+ vec2 TexCoords;
+ vec4 FragPosLightSpace;
+ vec4 Color;
+} vs_out;
+
+void main() {
+ // vec4 totalPosition = vec4(0.0f);
+ // for(int i = 0 ; i < MAX_BONE_INFLUENCES ; i++) {
+ // if(inBoneIndices[i] == 0)
+ // continue;
+ // if(inBoneIndices[i] >=MAX_BONES)
+ // {
+ // totalPosition = vec4(inPos,1.0f);
+ // break;
+ // }
+ // vec4 localPosition = finalBoneMatrices[inBoneIndices[i]] * vec4(inPos,1.0f);
+ // totalPosition += localPosition * inWeights[i];
+ // vec3 localNormal = mat3(finalBoneMatrices[inBoneIndices[i]]) * inNormal;
+ // vs_out.Normal = localNormal;
+ // }
+
+
+ mat4 skinMatrix = // mat4(1.0)
+ // boneMatrices[int(inBoneIndices.z)]; // should just be the identtiy
+ inWeights.x * boneMatrices[int(inBoneIndices.x)] +
+ inWeights.y * boneMatrices[int(inBoneIndices.y)] +
+ inWeights.z * boneMatrices[int(inBoneIndices.z)] +
+ inWeights.w * boneMatrices[int(inBoneIndices.w)];
+
+ vec4 totalPosition = skinMatrix * vec4(inPos, 1.0);
+
+ vs_out.FragPos = vec3(model * totalPosition);
+ // vs_out.Normal = inNormal;
+ vs_out.TexCoords = inTexCoords;
+ vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0);
+ vs_out.Color = inWeights;
+ gl_Position = projection * view * model * totalPosition;
+} \ No newline at end of file
diff --git a/assets/shaders/triangle.frag b/assets/shaders/triangle.frag
new file mode 100644
index 0000000..c3ff328
--- /dev/null
+++ b/assets/shaders/triangle.frag
@@ -0,0 +1,6 @@
+#version 450
+
+layout(location = 0) in vec3 fragColor;
+layout(location = 0) out vec4 outColor;
+
+void main() { outColor = vec4(fragColor, 0.0); }
diff --git a/assets/shaders/triangle.vert b/assets/shaders/triangle.vert
new file mode 100644
index 0000000..8030561
--- /dev/null
+++ b/assets/shaders/triangle.vert
@@ -0,0 +1,11 @@
+#version 450
+
+layout(location = 0) in vec2 inPos;
+layout(location = 1) in vec3 inColor;
+
+layout(location = 0) out vec3 fragColor;
+
+void main() {
+ gl_Position = vec4(inPos, 0.0, 1.0);
+ fragColor = inColor;
+}