summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/basicShader.fs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-13 02:15:41 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-13 02:15:41 +0100
commitf16a7df6135262c91fee2a2f6c46ad2f3caa7157 (patch)
tree29b5c52e1609d8df8a89a70f98503ae51fccf4e0 /gfx/gl/shaders/basicShader.fs
parentAdd material field to vertex and configure it in mesh (diff)
downloadilt-f16a7df6135262c91fee2a2f6c46ad2f3caa7157.tar.bz2
ilt-f16a7df6135262c91fee2a2f6c46ad2f3caa7157.tar.xz
ilt-f16a7df6135262c91fee2a2f6c46ad2f3caa7157.zip
Update shaders to use material to conditionally lookup sub-texture in the atlas
Diffstat (limited to 'gfx/gl/shaders/basicShader.fs')
-rw-r--r--gfx/gl/shaders/basicShader.fs16
1 files changed, 14 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);