Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/excaliburjs/Excalibur. 🎮 Your friendly TypeScript 2D game engine for the web 🗡️ excaliburjs.com
excalibur excaliburjs game-development game-engine game-framework gamedev games html5-canvas typescript
Something went wrong. Try again.
1.1 kB · 55 lines
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556#version 300 esprecision highp float;
// UV coordin vec2 v_uv;
// Color coord to blend with imagein lowp vec4 v_color;
// Stroke color if usedin lowp vec4 v_strokeColor;
// Stroke thickness if usedin lowp float v_strokeThickness;
in float v_radius;
// Opacityin float v_opacity;
out vec4 fragColor;
void main() { // make (0, 0) the center the uv vec2 uv = v_uv * 2.0 - 1.0;
vec4 color = v_color; vec4 strokeColor = v_strokeColor;
float dist = 1.0 - length(uv); float radius = dist * v_radius; // 0 is the edge
// Fade based on fwidth float fade = fwidth(dot(uv, uv)) / 2.0;
float fill = smoothstep(-fade, fade, radius);
float stroke = smoothstep(0.0, fade, radius) - smoothstep(v_strokeThickness, v_strokeThickness + fade, radius);
strokeColor.a = stroke; strokeColor.rgb *= strokeColor.a;
// vec4 finalColor = strokeColor;
color.a *= fill * (1.0 - stroke); color.rgb *= color.a;
vec4 finalColor = mix(vec4(0.0), (color + strokeColor), fill); finalColor.rgb = finalColor.rgb * v_opacity; finalColor.a = finalColor.a * v_opacity;
fragColor = finalColor;}