From 4ae26db5ec12560ee2d76a1bdc78b34a45c7442a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jul 2024 19:23:58 +0100 Subject: Pull material lookup functions into a common file --- gfx/gl/shaders/materialCommon.glsl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 gfx/gl/shaders/materialCommon.glsl (limited to 'gfx/gl/shaders/materialCommon.glsl') diff --git a/gfx/gl/shaders/materialCommon.glsl b/gfx/gl/shaders/materialCommon.glsl new file mode 100644 index 0000000..a915ce3 --- /dev/null +++ b/gfx/gl/shaders/materialCommon.glsl @@ -0,0 +1,35 @@ +layout(binding = 0) uniform sampler2D texture0; + +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(uvec2 mapmode, vec2 value) +{ + return vec2(map(mapmode.x, value.x), map(mapmode.y, value.y)); +} + +vec4 +getTextureColour(MaterialDetail mat, vec2 uv) +{ + if (mat.textureSize.x > 0) { + const vec2 tSize = textureSize(texture0, 0); + uv = (mat.textureOrigin + mat.textureSize * map(mat.mapmode, uv)) / tSize; + } + return texture(texture0, uv); +} -- cgit v1.2.3