Last active
April 8, 2017 15:40
-
-
Save chimanaco/12df713640d3f71238074ec0546d0ced to your computer and use it in GitHub Desktop.
glsl.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// draw border with step | |
float drawBorder(vec2 st, float thickness) { | |
// bottom-left | |
vec2 bl = step(vec2(thickness),st); | |
// top-right | |
vec2 tr = step(vec2(thickness),1.0-st); | |
float pct = bl.x * bl.y * tr.x * tr.y; | |
return pct; | |
} | |
// draw border with smoothstep | |
float drawBorder(vec2 st, float thickness) { | |
// bottom-left | |
vec2 bl = smoothstep(0.0, thickness, st); | |
// top-right | |
vec2 tr = smoothstep(0.0, thickness, 1.0 - st); | |
float pct = bl.x * bl.y * tr.x * tr.y; | |
return pct; | |
} | |
// draw border with floor | |
float drawBorder(vec2 st, float thickness) { | |
// bottom-left | |
vec2 bl = floor(st + (1.0 - thickness)); | |
// top-right | |
vec2 tr = floor(st - (1.0 - thickness)); | |
float pct = bl.x * bl.y * tr.x * tr.y; | |
pct = bl.x * bl.y * tr.x * tr.y; | |
return pct; | |
} | |
float circle(in vec2 _st, in float _radius){ | |
vec2 dist = _st-vec2(0.5); | |
return 1.-smoothstep(_radius-(_radius*0.01), | |
_radius+(_radius*0.01), | |
dot(dist,dist)*4.0); | |
} | |
/** | |
* Draw Rect | |
* | |
* @param {vec2} angle - The callback that handles the response. | |
* @example | |
* rect(0.1); | |
* @returns {vec2} Returns the coordinate. | |
*/ | |
float rect(in vec2 st, in vec2 size){ | |
size = 0.25-size*0.25; | |
vec2 uv = smoothstep(size,size+size*vec2(0.002),st*(1.0-st)); | |
return uv.x*uv.y; | |
} | |
float box(vec2 _st, vec2 _size, float _smoothEdges){ | |
_size = vec2(0.5)-_size*0.5; | |
vec2 aa = vec2(_smoothEdges*0.5); | |
vec2 uv = smoothstep(_size,_size+aa,_st); | |
uv *= smoothstep(_size,_size+aa,vec2(1.0)-_st); | |
return uv.x*uv.y; | |
} | |
/** | |
* Rotate 2D | |
* | |
* @param {_angle} angle - The callback that handles the response. | |
* @example | |
* st = rotate2d( sin(u_time)*PI ) * st; | |
* @returns {mat2} Returns the coordinate. | |
*/ | |
mat2 rotate2d(float _angle){ | |
return mat2(cos(_angle),-sin(_angle), | |
sin(_angle),cos(_angle)); | |
} | |
/** | |
* Scale | |
* | |
* @param {_angle} angle - The callback that handles the response. | |
* @example | |
* st -= vec2(0.5); | |
* st = scale( vec2(sin(u_time)+1.0) ) * st; | |
* st += vec2(0.5); | |
* @returns {mat2} Returns the coordinate. | |
*/ | |
mat2 scale(vec2 _scale){ | |
return mat2(_scale.x,0.0, | |
0.0,_scale.y); | |
} | |
vec2 tile(vec2 _st, float _zoom){ | |
_st *= _zoom; | |
return fract(_st); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment