UNPKG

phaser4-rex-plugins

Version:
67 lines (47 loc) 1.53 kB
// Built-in fx in phaser3 const frag = `\ #pragma phaserTemplate(shaderName) #ifdef GL_FRAGMENT_PRECISION_HIGH #define highmedp highp #else #define highmedp mediump #endif precision highmedp float; // Scene buffer uniform sampler2D uMainSampler; varying vec2 outTexCoord; // Effect parameters uniform vec2 texSize; uniform vec3 color; uniform vec4 backgroundColor; uniform vec3 config; #pragma phaserTemplate(fragmentHeader) void main (void) { float thickness = config.x; float scale = config.y; float feather = config.z; vec4 texture = texture2D(uMainSampler, outTexCoord); vec2 position = (gl_FragCoord.xy / texSize.xy) * 2.0 - 1.0; float aspectRatio = texSize.x / texSize.y; position.x *= aspectRatio; float grad = length(position); // height > width float outer = aspectRatio; float inner = outer - (thickness * 2.0 / texSize.y); // width > height if (aspectRatio >= 1.0) { float f = 2.0 + (texSize.y / texSize.x); outer = 1.0; inner = 1.0 - (thickness * f / texSize.x); } outer *= scale; inner *= scale; float circle = smoothstep(outer, outer - 0.01, grad); float ring = circle - smoothstep(inner, inner - feather, grad); texture = mix(backgroundColor * backgroundColor.a, texture, texture.a); texture = (texture * (circle - ring)); gl_FragColor = vec4(texture.rgb + (ring * color), texture.a); } `; export default frag;