summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/shaders')
-rw-r--r--gfx/gl/shaders/basicShader.fs31
-rw-r--r--gfx/gl/shaders/basicShader.vs12
-rw-r--r--gfx/gl/shaders/geometryOut.glsl3
-rw-r--r--gfx/gl/shaders/landmassShader.fs9
-rw-r--r--gfx/gl/shaders/landmassShader.vs12
-rw-r--r--gfx/gl/shaders/lightingShader.vs2
-rw-r--r--gfx/gl/shaders/materialInterface.glsl7
-rw-r--r--gfx/gl/shaders/meshIn.glsl5
-rw-r--r--gfx/gl/shaders/shadowDynamicPoint.vs2
-rw-r--r--gfx/gl/shaders/shadowFixedPoint.vs2
-rw-r--r--gfx/gl/shaders/waterShader.fs9
-rw-r--r--gfx/gl/shaders/waterShader.vs9
12 files changed, 49 insertions, 54 deletions
diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs
index 24b2791..8a72e6d 100644
--- a/gfx/gl/shaders/basicShader.fs
+++ b/gfx/gl/shaders/basicShader.fs
@@ -1,22 +1,29 @@
#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
-in vec3 FragPos;
-in vec2 TexCoords;
-in vec3 Normal;
-in vec4 Colour;
+include(`materialInterface.glsl')
+include(`geometryOut.glsl')
-out vec4 gPosition;
-out vec4 gNormal;
-out vec4 gAlbedoSpec;
+layout(binding = 0) uniform sampler2D texture0;
+layout(binding = 1) uniform usampler2DRect material;
-uniform sampler2D texture0;
+vec4 getTextureColour(uint midx, vec2 uv)
+{
+ if (midx > 0u) {
+ const vec2 tSize = textureSize(texture0, 0);
+ const vec4 sPosSize = texture(material, uvec2(0, midx - 1u));
+ uv = (sPosSize.xy + sPosSize.zw * fract(uv)) / tSize;
+ }
+ return texture(texture0, uv);
+}
void
main()
{
- vec4 textureColour = texture(texture0, TexCoords);
- float clear = round(mix(textureColour.a, 1, Colour.a));
- gPosition = vec4(FragPos, clear);
- gNormal = vec4(Normal, clear);
+ vec4 textureColour = getTextureColour(Material, TexCoords);
+ float opaque = step(0.5, mix(textureColour.a, 1, Colour.a));
+ gPosition = vec4(FragPos, opaque);
+ gNormal = vec4(Normal, opaque);
+ gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque);
gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a);
}
diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs
index ff9a401..e1701ed 100644
--- a/gfx/gl/shaders/basicShader.vs
+++ b/gfx/gl/shaders/basicShader.vs
@@ -1,14 +1,7 @@
#version 330 core
-in vec3 position;
-in vec2 texCoord;
-in vec3 normal;
-in vec4 colour;
-
-out vec3 FragPos;
-out vec2 TexCoords;
-out vec3 Normal;
-out vec4 Colour;
+include(`meshIn.glsl')
+include(`materialInterface.glsl')
uniform mat4 viewProjection;
uniform mat4 model;
@@ -22,6 +15,7 @@ main()
TexCoords = texCoord;
Normal = (model * vec4(normal, 0.0)).xyz;
Colour = colour;
+ Material = material;
gl_Position = viewProjection * worldPos;
}
diff --git a/gfx/gl/shaders/geometryOut.glsl b/gfx/gl/shaders/geometryOut.glsl
new file mode 100644
index 0000000..dc5f8e8
--- /dev/null
+++ b/gfx/gl/shaders/geometryOut.glsl
@@ -0,0 +1,3 @@
+layout(location = 0) out vec4 gPosition;
+layout(location = 1) out vec4 gNormal;
+layout(location = 2) out vec4 gAlbedoSpec;
diff --git a/gfx/gl/shaders/landmassShader.fs b/gfx/gl/shaders/landmassShader.fs
index 7c08e8e..f3cc3e8 100644
--- a/gfx/gl/shaders/landmassShader.fs
+++ b/gfx/gl/shaders/landmassShader.fs
@@ -1,12 +1,7 @@
#version 330 core
-in vec3 FragPos;
-in vec2 TexCoords;
-in vec3 Normal;
-
-layout(location = 0) out vec4 gPosition;
-layout(location = 1) out vec4 gNormal;
-layout(location = 2) out vec4 gAlbedoSpec;
+include(`materialInterface.glsl')
+include(`geometryOut.glsl')
uniform sampler2D texture0;
diff --git a/gfx/gl/shaders/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs
index 30c4ef4..0cc8153 100644
--- a/gfx/gl/shaders/landmassShader.vs
+++ b/gfx/gl/shaders/landmassShader.vs
@@ -1,14 +1,7 @@
#version 330 core
-in vec3 position;
-in vec2 texCoord;
-in vec3 normal;
-in vec4 colour;
-
-out vec3 FragPos;
-out vec2 TexCoords;
-out vec3 Normal;
-out vec4 Colour;
+include(`meshIn.glsl')
+include(`materialInterface.glsl')
uniform mat4 viewProjection;
@@ -19,6 +12,7 @@ main()
TexCoords = texCoord;
Normal = normal;
Colour = colour;
+ Material = material;
gl_Position = viewProjection * vec4(position, 1.0);
}
diff --git a/gfx/gl/shaders/lightingShader.vs b/gfx/gl/shaders/lightingShader.vs
index 2271d2e..e07cd0a 100644
--- a/gfx/gl/shaders/lightingShader.vs
+++ b/gfx/gl/shaders/lightingShader.vs
@@ -1,6 +1,6 @@
#version 330 core
-in vec4 position;
+in ivec4 position;
out vec2 TexCoords;
diff --git a/gfx/gl/shaders/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl
new file mode 100644
index 0000000..5735cf9
--- /dev/null
+++ b/gfx/gl/shaders/materialInterface.glsl
@@ -0,0 +1,7 @@
+ifelse(TYPE, .fs, in, out) vec3 FragPos;
+ifelse(TYPE, .fs, in, out) vec2 TexCoords;
+ifelse(TYPE, .fs, in, out) vec3 Normal;
+ifelse(TYPE, .fs, in, out) vec4 Colour;
+flat
+ifelse(TYPE, .fs, in, out)
+uint Material;
diff --git a/gfx/gl/shaders/meshIn.glsl b/gfx/gl/shaders/meshIn.glsl
new file mode 100644
index 0000000..dd84a10
--- /dev/null
+++ b/gfx/gl/shaders/meshIn.glsl
@@ -0,0 +1,5 @@
+layout(location = 0) in vec3 position;
+layout(location = 1) in vec2 texCoord;
+layout(location = 2) in vec3 normal;
+layout(location = 3) in vec4 colour;
+layout(location = 4) in uint material;
diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs
index 6ea352f..531d8de 100644
--- a/gfx/gl/shaders/shadowDynamicPoint.vs
+++ b/gfx/gl/shaders/shadowDynamicPoint.vs
@@ -1,6 +1,6 @@
#version 330 core
-in vec3 position;
+include(`meshIn.glsl')
uniform mat4 viewProjection;
uniform mat4 model;
diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs
index 246890c..c9fa19b 100644
--- a/gfx/gl/shaders/shadowFixedPoint.vs
+++ b/gfx/gl/shaders/shadowFixedPoint.vs
@@ -1,6 +1,6 @@
#version 330 core
-layout(location = 0) in vec3 position;
+include(`meshIn.glsl')
uniform mat4 viewProjection;
diff --git a/gfx/gl/shaders/waterShader.fs b/gfx/gl/shaders/waterShader.fs
index d242566..5936da4 100644
--- a/gfx/gl/shaders/waterShader.fs
+++ b/gfx/gl/shaders/waterShader.fs
@@ -1,13 +1,8 @@
#version 330 core
#extension GL_ARB_shading_language_420pack : enable
-in vec3 FragPos;
-in vec2 TexCoords;
-in vec3 Normal;
-
-out vec4 gPosition;
-out vec4 gNormal;
-out vec4 gAlbedoSpec;
+include(`materialInterface.glsl')
+include(`geometryOut.glsl')
uniform sampler2D texture0;
uniform vec3 waves;
diff --git a/gfx/gl/shaders/waterShader.vs b/gfx/gl/shaders/waterShader.vs
index fe9206f..a21b49f 100644
--- a/gfx/gl/shaders/waterShader.vs
+++ b/gfx/gl/shaders/waterShader.vs
@@ -1,12 +1,7 @@
#version 330 core
-in vec3 position;
-in vec2 texCoord;
-in vec3 normal;
-
-out vec3 FragPos;
-out vec2 TexCoords;
-out vec3 Normal;
+include(`meshIn.glsl')
+include(`materialInterface.glsl')
uniform mat4 viewProjection;
uniform vec3 waves;