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