aboutsummaryrefslogtreecommitdiffstats
path: root/assets/shaders
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-08-08 18:48:10 +0000
committernathan <nathansmith@disroot.org>2025-08-08 18:48:10 +0000
commite5acfb329827802fe2259f91701dc8762c2573b6 (patch)
tree8d461b2d0e1864633341d066f783172790c62dc9 /assets/shaders
parent94ca30b13bffe1f02313b7fd32b2320e5c490fa5 (diff)
downloadFindThings-e5acfb329827802fe2259f91701dc8762c2573b6.tar.gz
FindThings-e5acfb329827802fe2259f91701dc8762c2573b6.tar.bz2
FindThings-e5acfb329827802fe2259f91701dc8762c2573b6.zip
Mesh instancing test working
Diffstat (limited to 'assets/shaders')
-rw-r--r--assets/shaders/glsl100/instancing.fs77
-rw-r--r--assets/shaders/glsl100/instancing.vs36
-rw-r--r--assets/shaders/glsl330/instancing.fs20
-rw-r--r--assets/shaders/glsl330/instancing.vs31
4 files changed, 164 insertions, 0 deletions
diff --git a/assets/shaders/glsl100/instancing.fs b/assets/shaders/glsl100/instancing.fs
new file mode 100644
index 0000000..596da0f
--- /dev/null
+++ b/assets/shaders/glsl100/instancing.fs
@@ -0,0 +1,77 @@
+#version 100
+
+precision mediump float;
+
+// Input vertex attributes (from vertex shader)
+varying vec3 fragPosition;
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+varying vec3 fragNormal;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add your custom variables here
+
+#define MAX_LIGHTS 4
+#define LIGHT_DIRECTIONAL 0
+#define LIGHT_POINT 1
+
+struct Light {
+ int enabled;
+ int type;
+ vec3 position;
+ vec3 target;
+ vec4 color;
+};
+
+// Input lighting values
+uniform Light lights[MAX_LIGHTS];
+uniform vec4 ambient;
+uniform vec3 viewPos;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord);
+ vec3 lightDot = vec3(0.0);
+ vec3 normal = normalize(fragNormal);
+ vec3 viewD = normalize(viewPos - fragPosition);
+ vec3 specular = vec3(0.0);
+
+ vec4 tint = colDiffuse * fragColor;
+
+ // NOTE: Implement here your fragment shader code
+
+ for (int i = 0; i < MAX_LIGHTS; i++)
+ {
+ if (lights[i].enabled == 1)
+ {
+ vec3 light = vec3(0.0);
+
+ if (lights[i].type == LIGHT_DIRECTIONAL)
+ {
+ light = -normalize(lights[i].target - lights[i].position);
+ }
+
+ if (lights[i].type == LIGHT_POINT)
+ {
+ light = normalize(lights[i].position - fragPosition);
+ }
+
+ float NdotL = max(dot(normal, light), 0.0);
+ lightDot += lights[i].color.rgb*NdotL;
+
+ float specCo = 0.0;
+ if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewD, reflect(-(light), normal))), 16.0); // 16 refers to shine
+ specular += specCo;
+ }
+ }
+
+ vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
+ finalColor += texelColor*(ambient/10.0);
+
+ // Gamma correction
+ gl_FragColor = pow(finalColor, vec4(1.0/2.2));
+}
diff --git a/assets/shaders/glsl100/instancing.vs b/assets/shaders/glsl100/instancing.vs
new file mode 100644
index 0000000..59d7304
--- /dev/null
+++ b/assets/shaders/glsl100/instancing.vs
@@ -0,0 +1,36 @@
+#version 100
+
+// Input vertex attributes
+attribute vec3 vertexPosition;
+attribute vec2 vertexTexCoord;
+attribute vec3 vertexNormal;
+attribute vec4 vertexColor;
+
+attribute mat4 instanceTransform;
+
+// Input uniform values
+uniform mat4 mvp;
+uniform mat4 matNormal;
+
+// Output vertex attributes (to fragment shader)
+varying vec3 fragPosition;
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+varying vec3 fragNormal;
+
+// NOTE: Add your custom variables here
+
+void main()
+{
+ // Compute MVP for current instance
+ mat4 mvpi = mvp*instanceTransform;
+
+ // Send vertex attributes to fragment shader
+ fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0));
+ fragTexCoord = vertexTexCoord;
+ fragColor = vertexColor;
+ fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
+
+ // Calculate final vertex position
+ gl_Position = mvpi*vec4(vertexPosition, 1.0);
+}
diff --git a/assets/shaders/glsl330/instancing.fs b/assets/shaders/glsl330/instancing.fs
new file mode 100644
index 0000000..0044ac7
--- /dev/null
+++ b/assets/shaders/glsl330/instancing.fs
@@ -0,0 +1,20 @@
+#version 330 core
+
+// https://github.com/Rogeatic/raylib-instancing
+
+// Input vertex attributes (from vertex shader)
+in vec2 fragTexCoord;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// Output fragment color
+out vec4 finalColor;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture(texture0, fragTexCoord);
+ finalColor = texelColor*colDiffuse;
+} \ No newline at end of file
diff --git a/assets/shaders/glsl330/instancing.vs b/assets/shaders/glsl330/instancing.vs
new file mode 100644
index 0000000..800d6fd
--- /dev/null
+++ b/assets/shaders/glsl330/instancing.vs
@@ -0,0 +1,31 @@
+#version 330 core
+
+// https://github.com/Rogeatic/raylib-instancing
+
+// Input vertex attributes
+in vec3 vertexPosition;
+in vec2 vertexTexCoord;
+
+layout (location = 12) in mat4 instance;
+
+// Input uniform values
+uniform mat4 mvp;
+uniform mat4 projection;
+uniform mat4 view;
+
+// Output vertex attributes (to fragment shader)
+out vec2 fragTexCoord;
+out vec4 fragColor;
+out vec3 fragNormal;
+
+// NOTE: Add here your custom variables
+
+void main()
+{
+ // Send vertex attributes to fragment shader
+ fragTexCoord = vertexTexCoord;
+
+ // Calculate final vertex position
+ mat4 mvpi = mvp * instance;
+ gl_Position = mvpi * vec4(vertexPosition, 1.0);
+} \ No newline at end of file