Skip to content

Instantly share code, notes, and snippets.

const imageRatio = texture.width / texture.height;
const canvasRatio = innerWidth / innerHeight;
const aspecRatio =
canvasRatio > imageRatio
? [1, imageRatio / canvasRatio]
: [canvasRatio / imageRatio, 1];
vec2 tunnelDistortion(vec4 deform, vec2 uv){
float DEFORM_SIZE = deform.z;
float MAX_DISTORTION = deform.w;
vec2 sample_shift;
vec2 dist = 0.5 - uv;
float distortion = -sqrt(0.25 - pow(uv.y * deform.x - deform.x * 0.5, 2.0)) * DEFORM_SIZE + DEFORM_SIZE * 0.5;
mat3 gx = mat3(-1., 0., 1., -2., 0., 2., -1., 0., 1.);
mat3 gy = mat3(-1., -2., -1., 0., 0., 0., 1., 2., 1.);
float sobelEdge(sampler2D u_text,vec2 resolution, vec2 uv){
float h = 0.;
float v = 0.;
for(int y = 0; y < 3; y++){
for(int x = 0; x < 3; x++){
vec2 d = vec2(y, x) / resolution;
vec4 img = texture2D(u_text, uv + d);
vec2 centerUV(vec2 coord, vec2 coord2){
return (coord - .5 * coord2) / min(coord2.x, coord2.y);
}
vec2 centeredAspectRatio(vec2 uv, vec2 factor){
return ( uv - .5 ) * factor + .5;
}
float voronoi(vec2 uv){
float t = u_time;
vec2 i_st = floor(uv * 5.);
vec2 f_st = fract(uv * 5.);
float m_dist = 1.;
vec2 m_point;
for(int x = -1; x <= 1; x++){
float random (vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
mat2 scale2D(vec2 _scale){
return mat2(_scale.x,0.0,
0.0,_scale.y);
}
@AlainBarrios
AlainBarrios / distortion.frag
Created April 25, 2019 03:46
distortion function
vec2 distortion(vec2 p, float freq, float amp, float t, float map, float speed){
float phase = -1. * speed * freq;
float x = p.y * freq + t * phase;
float y = p.x * freq + t * .001 * phase;
float distX = cos(x+y) * amp;
float distY = sin(x-y) * amp;
vec2 distortion = vec2(distX * map, distY * map);
@AlainBarrios
AlainBarrios / rotate3d.frag
Created April 17, 2019 17:22
Rotation in 3d for uv space
mat4 rotationMatrix(vec3 axis, float angle) {
axis = normalize(axis);
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0);