summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/material.fs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 18:36:45 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 18:36:45 +0100
commit6ed208747005774f3fbc90256b9da0c6890a0814 (patch)
treeb10a7a2a23bdfad799fb108687108798561ed866 /gfx/gl/shaders/material.fs
parentMerge branch 'instancing-pt2' (diff)
downloadilt-6ed208747005774f3fbc90256b9da0c6890a0814.tar.bz2
ilt-6ed208747005774f3fbc90256b9da0c6890a0814.tar.xz
ilt-6ed208747005774f3fbc90256b9da0c6890a0814.zip
Lookup material details once in the vertex shader
... instead of per texel in the fragment shader
Diffstat (limited to 'gfx/gl/shaders/material.fs')
-rw-r--r--gfx/gl/shaders/material.fs15
1 files changed, 5 insertions, 10 deletions
diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs
index cafb35d..20fa8ab 100644
--- a/gfx/gl/shaders/material.fs
+++ b/gfx/gl/shaders/material.fs
@@ -5,7 +5,6 @@ include(`materialInterface.glsl')
include(`materialOut.glsl')
layout(binding = 0) uniform sampler2D texture0;
-layout(binding = 1) uniform usampler2DRect material;
float map(uint mapmode, float value)
{
@@ -24,20 +23,16 @@ float map(uint mapmode, float value)
return 0;
}
-vec2 map(uint mapmodeU, uint mapmodeV, vec2 value)
+vec2 map(uvec2 mapmode, vec2 value)
{
- return vec2(map(mapmodeU, value.x), map(mapmodeV, value.y));
+ return vec2(map(mapmode.x, value.x), map(mapmode.y, value.y));
}
-vec4 getTextureColour(uint midx, vec2 uv)
+vec4 getTextureColour(MaterialDetail mat, vec2 uv)
{
- if (midx > 0u) {
+ if (mat.textureSize.x > 0) {
const vec2 tSize = textureSize(texture0, 0);
- const vec4 sPosSize = texture(material, uvec2(0, midx - 1u));
- const uvec4 sMode = texture(material, uvec2(1, midx - 1u));
- const uint mapmodeU = sMode.x & 0xFu;
- const uint mapmodeV = (sMode.x & 0xF0u) >> 1;
- uv = (sPosSize.xy + sPosSize.zw * map(mapmodeU, mapmodeV, uv)) / tSize;
+ uv = (mat.textureOrigin + mat.textureSize * map(mat.mapmode, uv)) / tSize;
}
return texture(texture0, uv);
}