From 6ed208747005774f3fbc90256b9da0c6890a0814 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 27 Apr 2023 18:36:45 +0100 Subject: Lookup material details once in the vertex shader ... instead of per texel in the fragment shader --- gfx/gl/shaders/material.fs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'gfx/gl/shaders/material.fs') 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); } -- cgit v1.2.3