Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Created August 21, 2016 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makoConstruct/0e6d8e7196e6c288c12f879df47faef2 to your computer and use it in GitHub Desktop.
Save makoConstruct/0e6d8e7196e6c288c12f879df47faef2 to your computer and use it in GitHub Desktop.
precision mediump float;
varying vec4 color;
varying vec2 uv;
varying float pixelSize;
varying float innerRadius;
varying vec2 angleUnit;
float sq(float a){ return a*a; }
float clampUnit(float a){ return clamp(a,0.0,1.0); }
float lengthSquared(vec2 a){ return dot(a,a); }
vec2 orthoCloc(vec2 b){ return vec2(b.y, -b.x); }
vec2 orthoCoun(vec2 b){ return vec2(-b.y, b.x); }
float circleOpacity(vec2 uv, float pixelSize, float innerRadius, vec2 angleUnit){
float dist = length(uv);
float fringeSpan = 2.0*pixelSize;
float angleFade;
float distFromAngleUnit = (dot(uv,orthoCloc(angleUnit))+fringeSpan)/fringeSpan;
float distFromXAxis = (uv.y + fringeSpan)/fringeSpan;
if(angleUnit.y > 0.0){
angleFade = min(distFromAngleUnit, distFromXAxis);
}else{
angleFade = max(distFromAngleUnit, distFromXAxis);
}
return clampUnit(min(
min(
1.0 - dist, //outer fringe
dist + fringeSpan - innerRadius )/fringeSpan, //inner fringe
angleFade //angle of the unit thing
));
}
void main(){
float copa = circleOpacity(uv, pixelSize, innerRadius, angleUnit);
gl_FragColor = vec4(color.rgb, color.a*copa);
// gl_FragColor = vec4(color.rgb, color.a*circleOpacity(uv, pixelSize, innerRadius, angleUnit));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment