export function createWatermarkFilter(): PIXI.Filter {
const fragment = ` varying vec2 vTextureCoord; uniform sampler2D uSampler; uniform float uAlpha; uniform vec3 uColor; uniform vec2 uResolution; // Draws a simplified letter shape at a given position float drawLetter(vec2 uv, vec2 pos, float scale, int letter) { uv = (uv - pos) / scale; if (letter == 0) { // D return step(0.1, uv.x) * step(uv.x, 0.3) * step(0.1, uv.y) * step(uv.y, 0.9) + step(0.3, uv.x) * step(uv.x, 0.4) * step(0.1, uv.y) * step(uv.y, 0.9) + step(0.1, uv.y) * step(uv.y, 0.2) * step(0.1, uv.x) * step(uv.x, 0.4) + step(0.8, uv.y) * step(uv.y, 0.9) * step(0.1, uv.x) * step(uv.x, 0.4); } else if (letter == 1) { // E return step(0.1, uv.x) * step(uv.x, 0.2) * step(0.1, uv.y) * step(uv.y, 0.9) + step(0.1, uv.y) * step(uv.y, 0.2) * step(0.1, uv.x) * step(uv.x, 0.5) + step(0.45, uv.y) * step(uv.y, 0.55) * step(0.1, uv.x) * step(uv.x, 0.5) + step(0.8, uv.y) * step(uv.y, 0.9) * step(0.1, uv.x) * step(uv.x, 0.5); } else if (letter == 2) { // M return step(0.1, uv.x) * step(uv.x, 0.2) * step(0.1, uv.y) * step(uv.y, 0.9) + step(0.4, uv.x) * step(uv.x, 0.5) * step(0.1, uv.y) * step(uv.y, 0.9) + step(0.2, uv.x) * step(0.4, uv.y) * step(uv.y, 0.5); } else if (letter == 3) { // O return step(0.1, uv.x) * step(uv.x, 0.4) * (step(0.1, uv.y) * step(uv.y, 0.2) + step(0.8, uv.y) * step(uv.y, 0.9)) + step(0.1, uv.y) * step(uv.y, 0.9) * (step(0.1, uv.x) * step(uv.x, 0.2) + step(0.3, uv.x) * step(uv.x, 0.4)); } return 0.0; } void main(void) { vec4 baseColor = texture2D(uSampler, vTextureCoord); // Normalized UV coordinates vec2 uv = vTextureCoord; // Rotate slightly for a diagonal watermark float angle = -0.5; float s = sin(angle); float c = cos(angle); uv = vec2(c * (uv.x - 0.5) - s * (uv.y - 0.5) + 0.5, s * (uv.x - 0.5) + c * (uv.y - 0.5) + 0.5); // Repeat pattern across the surface vec2 grid = fract(uv * 4.0); float demo = 0.0; // Draw the word "DEMO" demo += drawLetter(grid, vec2(0.05, 0.2), 0.3, 0); demo += drawLetter(grid, vec2(0.25, 0.2), 0.3, 1); demo += drawLetter(grid, vec2(0.45, 0.2), 0.3, 2); demo += drawLetter(grid, vec2(0.65, 0.2), 0.3, 3); demo = clamp(demo, 0.0, 1.0); // Blend watermark color with the base texture vec4 watermark = vec4(uColor, demo * uAlpha); gl_FragColor = mix(baseColor, watermark, watermark.a); } `; const uniforms = { uAlpha: 0.2, // Watermark transparency uColor: [1.0, 1.0, 1.0], // RGB color (white) uResolution: [800, 600], // Optional if you want dynamic scaling }; const filter = new PIXI.Filter(undefined, fragment, uniforms); (filter as any).isDemoFilter = true; // flag for easy removal later return filter; }