#version 300 es precision mediump float; in vec4 color; in vec2 texCoord; in float textureIndex; uniform sampler2D textures[8]; uniform float threshold; uniform float smoothRange; out vec4 fragColor; void main() { float sample = 0.0; float smoothMin = threshold - smoothRange * 0.5; float smoothMax = smoothMin + smoothRange; sample += smoothstep(smoothMin, smoothMax, texture(textures[0], texCoord).r) * (step(-0.5, textureIndex) - step(0.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[1], texCoord).r) * (step(0.5, textureIndex) - step(1.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[2], texCoord).r) * (step(1.5, textureIndex) - step(2.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[3], texCoord).r) * (step(2.5, textureIndex) - step(3.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[4], texCoord).r) * (step(3.5, textureIndex) - step(4.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[5], texCoord).r) * (step(4.5, textureIndex) - step(5.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[6], texCoord).r) * (step(5.5, textureIndex) - step(6.5, textureIndex)); sample += smoothstep(smoothMin, smoothMax, texture(textures[7], texCoord).r) * (step(6.5, textureIndex) - step(7.5, textureIndex)); fragColor = vec4(max(1.0, sample)); fragColor *= color; }