summaryrefslogtreecommitdiff
path: root/assets/shaders
diff options
context:
space:
mode:
authorJoshua Rowe <17525998+omnisci3nce@users.noreply.github.com>2024-06-09 14:59:01 +1000
committerGitHub <noreply@github.com>2024-06-09 14:59:01 +1000
commit9c79df522980eabdc5e52592cbd152e2a285c4cc (patch)
tree9082af194033e5e3e4a770456209d3bac7784943 /assets/shaders
parent8d116bd23d9441e33cb3377e90c08169109b438a (diff)
parentd4ff15d9cd82a6e3bc71da9d04ee0f250460cef1 (diff)
Merge pull request #16 from omnisci3nce/port-opengl-ral
Bring back OpenGL (part 1)
Diffstat (limited to 'assets/shaders')
-rw-r--r--assets/shaders/blinn_phong.frag6
-rw-r--r--assets/shaders/blinn_phong.vert27
-rw-r--r--assets/shaders/cube.frag5
-rw-r--r--assets/shaders/cube.vert14
-rw-r--r--assets/shaders/triangle.frag2
-rw-r--r--assets/shaders/triangle.metal33
-rw-r--r--assets/shaders/triangle.vert2
7 files changed, 68 insertions, 21 deletions
diff --git a/assets/shaders/blinn_phong.frag b/assets/shaders/blinn_phong.frag
index a0ba905..267c71b 100644
--- a/assets/shaders/blinn_phong.frag
+++ b/assets/shaders/blinn_phong.frag
@@ -1,4 +1,4 @@
-#version 410 core
+#version 430 core
out vec4 FragColor;
// A Blinn-Phong material with textures for diffuse and specular
@@ -32,7 +32,7 @@ in VS_OUT {
vec3 FragPos;
vec3 Normal;
vec2 TexCoords;
- vec4 FragPosLightSpace;
+ // vec4 FragPosLightSpace;
vec4 Color;
} fs_in;
@@ -94,4 +94,4 @@ vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
diffuse *= attentuation;
specular *= attentuation;
return (ambient + diffuse + specular);
-} \ No newline at end of file
+}
diff --git a/assets/shaders/blinn_phong.vert b/assets/shaders/blinn_phong.vert
index 06dc5e7..18609b7 100644
--- a/assets/shaders/blinn_phong.vert
+++ b/assets/shaders/blinn_phong.vert
@@ -1,28 +1,37 @@
#version 410 core
+
+struct Uniforms {
+ mat4 model;
+ mat4 view;
+ mat4 projection;
+};
+
+uniform Uniforms ubo;
+
// Inputs
layout (location = 0) in vec3 inPos;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec2 inTexCoords;
-uniform mat4 model;
-uniform mat4 view;
-uniform mat4 projection;
-uniform mat4 lightSpaceMatrix;
+// uniform mat4 model;
+// uniform mat4 view;
+// uniform mat4 projection;
+// uniform mat4 lightSpaceMatrix;
// Output
out VS_OUT {
vec3 FragPos;
vec3 Normal;
vec2 TexCoords;
- vec4 FragPosLightSpace;
+ // vec4 FragPosLightSpace;
vec4 Color;
} vs_out;
void main() {
- vs_out.FragPos = vec3(model * vec4(inPos, 1.0));
+ vs_out.FragPos = vec3(ubo.model * vec4(inPos, 1.0));
vs_out.Normal = inNormal;
vs_out.TexCoords = inTexCoords;
- vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0);
+ // 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
+ gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0);
+}
diff --git a/assets/shaders/cube.frag b/assets/shaders/cube.frag
index 292578f..9d8ab28 100644
--- a/assets/shaders/cube.frag
+++ b/assets/shaders/cube.frag
@@ -1,4 +1,4 @@
-#version 450
+#version 430
layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragTexCoord;
@@ -8,5 +8,6 @@ layout(binding = 1) uniform sampler2D texSampler;
layout(location = 0) out vec4 outColor;
void main() {
- outColor = texture(texSampler, fragTexCoord); // vec4(fragTexCoord, 0.0);
+ // outColor = texture(texSampler, fragTexCoord); // vec4(fragTexCoord, 0.0);
+ outColor = vec4(fragColor, 1.0);
}
diff --git a/assets/shaders/cube.vert b/assets/shaders/cube.vert
index dc625ec..e7d6a79 100644
--- a/assets/shaders/cube.vert
+++ b/assets/shaders/cube.vert
@@ -1,11 +1,13 @@
-#version 450
+#version 430
-layout(binding = 0) uniform UniformBufferObject {
+layout( binding = 0) uniform Matrices {
mat4 model;
mat4 view;
mat4 proj;
-}
-ubo;
+} ubo;
+uniform mat4 model;
+uniform mat4 view;
+uniform mat4 projection;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
@@ -15,7 +17,9 @@ 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);
+ // gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
+ gl_Position = projection * view * model * vec4(inPosition, 1.0);
+ // gl_Position = vec4(inPosition, 1.0);
fragColor = abs(inNormal);
fragTexCoord = inTexCoords;
}
diff --git a/assets/shaders/triangle.frag b/assets/shaders/triangle.frag
index c3ff328..ad6de8e 100644
--- a/assets/shaders/triangle.frag
+++ b/assets/shaders/triangle.frag
@@ -1,4 +1,4 @@
-#version 450
+#version 430
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
diff --git a/assets/shaders/triangle.metal b/assets/shaders/triangle.metal
new file mode 100644
index 0000000..6055705
--- /dev/null
+++ b/assets/shaders/triangle.metal
@@ -0,0 +1,33 @@
+#include <metal_stdlib>
+
+using namespace metal;
+
+struct VertexIn {
+ float2 position;
+ float3 color;
+};
+
+struct VertexOut {
+ float4 computedPosition [[position]];
+ float3 fragColor;
+};
+
+// Vertex shader
+vertex VertexOut basic_vertex(
+ const device VertexIn* vertex_array [[ buffer(0) ]],
+ unsigned int vid [[ vertex_id ]]
+ ) {
+ VertexIn v = vertex_array[vid];
+
+ VertexOut outVertex = VertexOut();
+ outVertex.computedPosition = float4(v.position.xy, 0.0, 1.0);
+ outVertex.fragColor = v.color;
+ return outVertex;
+}
+
+// Fragment shader
+fragment float4 basic_fragment(
+ VertexOut interpolated [[stage_in]]
+) {
+ return float4(interpolated.fragColor, 1.0);
+} \ No newline at end of file
diff --git a/assets/shaders/triangle.vert b/assets/shaders/triangle.vert
index 8030561..f98696c 100644
--- a/assets/shaders/triangle.vert
+++ b/assets/shaders/triangle.vert
@@ -1,4 +1,4 @@
-#version 450
+#version 430
layout(location = 0) in vec2 inPos;
layout(location = 1) in vec3 inColor;