♻️ Move edge mask to snippets

This commit is contained in:
Simon Schneegans
2022-01-16 05:31:00 +01:00
parent bb9f57fe83
commit 5287ac2614
4 changed files with 33 additions and 16 deletions
+27
View File
@@ -33,6 +33,33 @@ function standardUniforms() {
`;
}
// This method returns a mask which smoothly transitions towards zero when approaching
// the window's borders. There is a variant which takes the transition area width in
// pixels and one which takes this as a percentage.
function edgeMask() {
return `
float getEdgeMask(vec2 uv, vec2 maxUV, float fadeWidth) {
float mask = 1.0;
mask *= smoothstep(0, 1, clamp(uv.x / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp(uv.y / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.x - uv.x) / fadeWidth, 0, 1));
mask *= smoothstep(0, 1, clamp((maxUV.y - uv.y) / fadeWidth, 0, 1));
return mask;
}
float getAbsoluteEdgeMask(float fadePixels) {
vec2 uv = cogl_tex_coord_in[0].st * vec2(uSizeX, uSizeY);
return getEdgeMask(uv, vec2(uSizeX, uSizeY), fadePixels);
}
float getRelativeEdgeMask(float fadeAmount) {
vec2 uv = cogl_tex_coord_in[0].st;
return getEdgeMask(uv, vec2(1.0), fadeAmount);
}
`;
}
// These noise algorithms are based on implementations by various authors from
// shadertoy.com, which are all available under the MIT License. See the respective links
// in the comments below.