Skip to content

Instantly share code, notes, and snippets.

@ericjeker
Last active October 24, 2022 10:23
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 ericjeker/aacaff3d8ac3009dbc53ebe9ca645ea7 to your computer and use it in GitHub Desktop.
Save ericjeker/aacaff3d8ac3009dbc53ebe9ca645ea7 to your computer and use it in GitHub Desktop.
Animated Shader Eye
// Author:
// Title:
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.1415
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
const mat2 m = mat2( 0.80, 0.60, -0.60, 0.80 );
float hash( float n )
{
return fract(sin(n)*43758.5453);
}
float noise( in vec2 x )
{
vec2 p = floor(x);
vec2 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*57.0;
return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
}
float fbm( vec2 p )
{
float f = 0.0;
f += 0.50000*noise( p ); p = m*p*2.02;
f += 0.25000*noise( p ); p = m*p*2.03;
f += 0.12500*noise( p ); p = m*p*2.01;
f += 0.06250*noise( p ); p = m*p*2.04;
f += 0.03125*noise( p );
return f/0.984375;
}
void main() {
// space
vec2 q = gl_FragCoord.xy/u_resolution.xy;
// remapped space
vec2 p = -1.0 + q * 2.0;
// sqrt of dot product of the same vector is equal to the length
float r = length( p );
float a = atan(p.y, p.x);
// white background
vec3 color = vec3(1.0);
float anim = abs(sin(u_time));
float d = u_mouse.y / u_resolution.y ;
// iris
if (r < 0.8) {
// eye
color = vec3(0.0, 0.3, 0.6);
float f = fbm(5.*p);
color = mix(color, vec3(.1, .2, .4), f);
// yellow
f = 1.0 - smoothstep(0.1, 0.504 + d, r);
color = mix(color, vec3(.9, .6, .2), f);
a += u_mouse.x / u_resolution.x * fbm(20. * p);
f = smoothstep(0.344, 1.640, fbm(vec2(5.*r, 20.*a)));
color = mix(color, vec3(0.893,0.900,0.852), f);
// black streaks
f = 1.0 - smoothstep(0.344, 1.168, fbm(vec2(10.440*r, 22.*PI*a)));
color *= f;
// light reflection
f = 1.0 - smoothstep(0.0, 0.516, length(p - vec2(.25, .23)));
color += vec3(1.0, .9, .8) * f * 0.716;
//
f = 1.0 - smoothstep(0.526, 0.8, r) * .3;
color *= f;
// border
f = smoothstep(0.75, 0.8, r);
color = mix(color, vec3(1.0), f);
// pupil
f = smoothstep(0.2, 0.25 + d, r);
color *= f;
} else {
}
gl_FragColor = vec4(color,1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment