summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shaders/basicShader.fs16
-rw-r--r--gfx/gl/shaders/basicShader.vs1
-rw-r--r--gfx/gl/shaders/landmassShader.vs1
-rw-r--r--gfx/gl/shaders/materialInterface.glsl3
-rw-r--r--gfx/gl/shaders/meshIn.glsl1
5 files changed, 20 insertions, 2 deletions
diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs
index 8bb6350..ab5e58b 100644
--- a/gfx/gl/shaders/basicShader.fs
+++ b/gfx/gl/shaders/basicShader.fs
@@ -1,14 +1,26 @@
#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
include(`materialInterface.glsl')
include(`geometryOut.glsl')
-uniform sampler2D texture0;
+layout(binding = 0) uniform sampler2D texture0;
+layout(binding = 1) uniform usampler2DRect material;
+
+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);
+ vec4 textureColour = getTextureColour(Material, TexCoords);
float clear = round(mix(textureColour.a, 1, Colour.a));
gPosition = vec4(FragPos, clear);
gNormal = vec4(Normal, clear);
diff --git a/gfx/gl/shaders/basicShader.vs b/gfx/gl/shaders/basicShader.vs
index 4d648f3..e1701ed 100644
--- a/gfx/gl/shaders/basicShader.vs
+++ b/gfx/gl/shaders/basicShader.vs
@@ -15,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/landmassShader.vs b/gfx/gl/shaders/landmassShader.vs
index cabe39f..0cc8153 100644
--- a/gfx/gl/shaders/landmassShader.vs
+++ b/gfx/gl/shaders/landmassShader.vs
@@ -12,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/materialInterface.glsl b/gfx/gl/shaders/materialInterface.glsl
index 3e09c85..5735cf9 100644
--- a/gfx/gl/shaders/materialInterface.glsl
+++ b/gfx/gl/shaders/materialInterface.glsl
@@ -2,3 +2,6 @@ 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
index 2b244c1..dd84a10 100644
--- a/gfx/gl/shaders/meshIn.glsl
+++ b/gfx/gl/shaders/meshIn.glsl
@@ -2,3 +2,4 @@ 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;