#version 450 #extension GL_ARB_separate_shader_objects : enable #extension GL_ARB_shading_language_420pack : enable #extension GL_EXT_nonuniform_qualifier : require struct MatPropData { vec4 color; int textureIndex; float alpha; vec3 beta; }; layout(location = 0) in struct { vec4 vertPos; // location 0 vec2 uv; // location = 1 vec4 normal; // location = 2 } In; // material stuff layout(location = 3) flat in struct { uint eid; vec3 textColor; } In2; layout(set = 4, binding = 0) uniform sampler2D fontBitmap; layout(location = 0) out vec4 color; layout(location = 1) out uint outEntityID; float median(float r, float g, float b) { return max(min(r, g), min(max(r, g), b)); } void main() { vec3 msd = texture (fontBitmap, In.uv).rgb; float sd = median (msd.r, msd.g, msd.b); float screenPxDistance = 2 * (sd - 0.5f); float opacity = clamp (screenPxDistance + 0.5f, 0.0f, 2.0f); vec4 fragColor = vec4 (1.0f); if (opacity > 0.02f && opacity < 1.9f) { fragColor = vec4(0.0f, 1.0f, 1.0f, 1.0f); } fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f)); color = fragColor; outEntityID = In2.eid; }