diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 16:39:57 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 16:39:57 +0100 |
commit | 4a7cff8f634122314d0bb4766795ea2d1e652ed4 (patch) | |
tree | 89a30258618f2cd27be1fa222dec1b48a686de6e /gfx/gl | |
parent | Write applicable Texture Options into texture atlas texture data (diff) | |
download | ilt-4a7cff8f634122314d0bb4766795ea2d1e652ed4.tar.bz2 ilt-4a7cff8f634122314d0bb4766795ea2d1e652ed4.tar.xz ilt-4a7cff8f634122314d0bb4766795ea2d1e652ed4.zip |
Handle different mapmodes in basic shader
Diffstat (limited to 'gfx/gl')
-rw-r--r-- | gfx/gl/shaders/basicShader.fs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs index 8a72e6d..57eaba2 100644 --- a/gfx/gl/shaders/basicShader.fs +++ b/gfx/gl/shaders/basicShader.fs @@ -7,12 +7,37 @@ include(`geometryOut.glsl') layout(binding = 0) uniform sampler2D texture0; layout(binding = 1) uniform usampler2DRect material; +float map(uint mapmode, float value) +{ + switch (mapmode) { + case 0u: // Repeat + return fract(value); + case 1u: // Clamp to edge + return clamp(0.0, 1.0, value); + case 2u: // Mirror + discard; + case 3u: // Decal + if (value != clamp(0.0, 1.0, value)) { + discard; + } + } + return 0; +} + +vec2 map(uint mapmodeU, uint mapmodeV, vec2 value) +{ + return vec2(map(mapmodeU, value.x), map(mapmodeV, value.y)); +} + 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; + 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; } return texture(texture0, uv); } |