2022-04-05 17:10:08 +00:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
in vec2 uvCoordinates;
|
2022-04-11 23:08:57 +00:00
|
|
|
flat in int atlasPage;
|
2022-04-14 18:31:47 +00:00
|
|
|
in vec2 paintUVCoordinates;
|
2022-04-05 17:10:08 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
flat in float paintGradientAngleCos;
|
|
|
|
flat in float paintGradientAngleSin;
|
|
|
|
flat in float[2] paintGradientEndsUnrotated;
|
|
|
|
|
2022-04-11 23:08:57 +00:00
|
|
|
uniform sampler2DArray textureSampler;
|
2022-04-14 18:31:47 +00:00
|
|
|
|
|
|
|
uniform int paintType;
|
|
|
|
uniform vec4 paintColor;
|
|
|
|
|
|
|
|
uniform int paintGradientStopCount;
|
|
|
|
uniform vec4[16] paintGradientColors;
|
|
|
|
uniform float[16] paintGradientPositions;
|
|
|
|
uniform vec2[2] paintGradientEnds;
|
|
|
|
|
|
|
|
uniform float pxScale;
|
2022-04-05 17:10:08 +00:00
|
|
|
|
|
|
|
out vec4 out_Color;
|
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
vec4 solidColor(void)
|
|
|
|
{
|
|
|
|
return paintColor;
|
|
|
|
}
|
|
|
|
|
2022-04-14 23:56:39 +00:00
|
|
|
vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
2022-04-14 18:31:47 +00:00
|
|
|
{
|
2022-04-14 23:56:39 +00:00
|
|
|
float gamma = 2.2;
|
|
|
|
float one_over_gamma = 1 / gamma;
|
|
|
|
|
|
|
|
vec4 ilCol = vec4(pow(lCol.r, gamma), pow(lCol.g, gamma), pow(lCol.b, gamma), lCol.a);
|
|
|
|
vec4 irCol = vec4(pow(rCol.r, gamma), pow(rCol.g, gamma), pow(rCol.b, gamma), rCol.a);
|
2022-04-14 18:31:47 +00:00
|
|
|
|
2022-04-14 23:56:39 +00:00
|
|
|
vec4 fCol = mix(ilCol, irCol, ratio);
|
2022-04-14 18:31:47 +00:00
|
|
|
|
2022-04-14 23:56:39 +00:00
|
|
|
return vec4(pow(fCol.r, one_over_gamma), pow(fCol.g, one_over_gamma), pow(fCol.b, one_over_gamma), fCol.a);
|
|
|
|
}
|
2022-04-14 18:31:47 +00:00
|
|
|
|
2022-04-14 23:56:39 +00:00
|
|
|
vec4 gradientColor(void)
|
|
|
|
{
|
2022-04-29 21:57:19 +00:00
|
|
|
float tStart = paintGradientEndsUnrotated[0];
|
|
|
|
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
2022-04-14 18:31:47 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
2022-04-14 23:56:39 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
float ti = paintGradientPositions[0] * gradientLength;
|
|
|
|
float tni;
|
|
|
|
vec4 col = paintGradientColors[0];
|
2022-04-14 23:56:39 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
2022-04-14 23:56:39 +00:00
|
|
|
{
|
2022-04-29 21:57:19 +00:00
|
|
|
tni = paintGradientPositions[i + 1] * gradientLength;
|
|
|
|
|
|
|
|
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
|
|
|
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
|
|
|
|
|
|
|
ti = tni;
|
2022-04-14 23:56:39 +00:00
|
|
|
}
|
2022-04-14 18:31:47 +00:00
|
|
|
|
2022-04-14 23:56:39 +00:00
|
|
|
return col;
|
2022-04-14 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 17:10:08 +00:00
|
|
|
void main(void)
|
|
|
|
{
|
2022-04-14 18:31:47 +00:00
|
|
|
vec3 texCoords = vec3(uvCoordinates, atlasPage);
|
|
|
|
|
|
|
|
float threshold = 180.0 / 255.0 - 5.0 / pow(pxScale, 1.6); // Also help small text be readable
|
2022-04-05 17:10:08 +00:00
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
float signedDist = texture(textureSampler, texCoords).r - threshold;
|
2022-04-11 23:08:57 +00:00
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
vec4 col;
|
2022-04-11 23:08:57 +00:00
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
switch (paintType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
col = solidColor();
|
|
|
|
break;
|
2022-04-11 23:08:57 +00:00
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
case 1:
|
|
|
|
col = gradientColor();
|
|
|
|
break;
|
|
|
|
}
|
2022-04-11 23:08:57 +00:00
|
|
|
|
2022-04-14 18:31:47 +00:00
|
|
|
col.a *= smoothstep(0, 2.4 / pxScale, signedDist);
|
2022-04-11 23:08:57 +00:00
|
|
|
|
|
|
|
out_Color = col;
|
2022-04-05 17:10:08 +00:00
|
|
|
}
|