SHADE_Y3/Assets/Shaders/Text_FS.glsl

59 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2022-11-10 08:28:44 +08:00
#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;
2022-11-10 08:28:44 +08:00
} In2;
2022-11-10 16:59:26 +08:00
2022-12-28 20:47:20 +08:00
layout(set = 2, binding = 0) uniform sampler2D fontBitmap;
2022-11-10 16:59:26 +08:00
layout(location = 0) out vec4 color;
2022-11-10 08:28:44 +08:00
layout(location = 1) out uint outEntityID;
2022-11-10 16:59:26 +08:00
float median(float r, float g, float b)
{
return max(min(r, g), min(max(r, g), b));
}
2022-11-10 08:28:44 +08:00
void main()
{
2022-11-10 16:59:26 +08:00
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;
2022-11-10 16:59:26 +08:00
if (opacity < 0.2f)
discard;
else
fragColor = mix(vec4(0.0f), vec4(In2.textColor, 1.0f), min (opacity, 1.0f));
2022-11-10 16:59:26 +08:00
// fragColor = vec4 (1.0f);
2022-11-10 08:28:44 +08:00
2022-11-10 16:59:26 +08:00
color = fragColor;
2022-11-10 08:28:44 +08:00
outEntityID = In2.eid;
}