65 lines
1.5 KiB
GLSL
65 lines
1.5 KiB
GLSL
uniform sampler2D atlas_data;
|
|
in vec2 v_texCoord;
|
|
|
|
uniform vec4 uClipUV;
|
|
// uniform vec2 uSdfUV;
|
|
uniform vec4 uSdfConfig;
|
|
uniform int uMode;
|
|
uniform vec4 uBorder;
|
|
uniform vec4 uStroke;
|
|
uniform vec4 uFill;
|
|
|
|
float getUVScale(vec2 sdfUV) {
|
|
float dx = dFdx(sdfUV.x);
|
|
float dy = dFdy(sdfUV.y);
|
|
return (sqrt(dx * dx + dy * dy) + sqrt(dy * dy + dx * dx)) * 0.5;
|
|
}
|
|
|
|
struct SDF {
|
|
float outer;
|
|
float inner;
|
|
};
|
|
|
|
|
|
vec4 getTexture(vec2 uv) {
|
|
return texture(atlas_data, uv);
|
|
}
|
|
|
|
vec4 getMask(vec4 color, vec2 uv, vec2 st) {
|
|
return color; // 默认不修改颜色
|
|
}
|
|
|
|
out vec4 fragColor;
|
|
|
|
void main() {
|
|
vec4 fillColor = uFill;
|
|
vec4 strokeColor = uStroke;
|
|
|
|
float scale = getUVScale(v_texCoord);
|
|
|
|
vec4 texture = getTexture(v_texCoord);
|
|
float sdfRaw = 0.0;
|
|
float mark = 0.0;
|
|
|
|
float sdf;
|
|
|
|
float sdfRadius = uSdfConfig.x;
|
|
float expand = uBorder.x;
|
|
float bleed = uBorder.y;
|
|
|
|
float d = (texture.r - 0.75) * sdfRadius;
|
|
float s = (d + expand / uSdfConfig.y) / scale + 0.5 + bleed;
|
|
sdf = s; // Assuming SDF returns a single float, adjust as necessary
|
|
|
|
if (uMode == -2) {
|
|
fillColor = vec4(texture.rgb, fillColor.a);
|
|
}
|
|
|
|
if (gl_FragCoord.x < uClipUV.x || gl_FragCoord.y < uClipUV.y || gl_FragCoord.x > uClipUV.z || gl_FragCoord.y > uClipUV.w) {
|
|
discard;
|
|
}
|
|
// Compute mask based on SDF
|
|
float mask = clamp(sdf, 0.0, 1.0);
|
|
// Final color blending logic here
|
|
fragColor = vec4(fillColor.rgb + mark, fillColor.a * mask + mark);
|
|
} |