Skip to content

Commit

Permalink
webgl2
Browse files Browse the repository at this point in the history
  • Loading branch information
CME42 committed Apr 6, 2016
1 parent a52dcb5 commit b31c249
Show file tree
Hide file tree
Showing 30 changed files with 440 additions and 379 deletions.
136 changes: 69 additions & 67 deletions media/glsl_effect/6balls.glsl
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform float time;
uniform float param0;
uniform sampler2D texture0;

#define t time
#define r resolution
#define c gl_FragCoord.xy
#define v vec2( 0., 1. )

float f( vec3 p )
{
float tt = t;
p.xy = p.xy*mat2( cos(t), -sin(t), sin(t), cos(t) );
tt = sin( t );
p.zx = p.zx*mat2( cos(tt), -sin(tt), sin(tt), cos(tt) );
tt = 2.*time;
p.yz = p.yz*mat2( cos(tt), -sin(tt), sin(tt), cos(tt) );
float r = .1+param0*.4;
float k = .3+param0*.1;
float d = length( p+v.yxx*k )-r;
d = min( d, length( p-v.yxx*k )-r);
d = min( d, length( p+v.xyx*k )-r);
d = min( d, length( p-v.xyx*k )-r);
d = min( d, length( p+v.xxy*k )-r);
d = min( d, length( p-v.xxy*k )-r);
return d;
}

vec3 n( vec3 p )
{
vec2 d = v*.01;
return normalize( vec3( f( p+d.yxx )-f( p-d.yxx ), f( p+d.xyx )-f( p-d.xyx ), f( p+d.xxy )-f( p-d.xxy ) ) );
}

void main()
{
vec2 uv = c/r;
vec2 p = (c*2.-r)/r.x;
vec3 ray = normalize( vec3( p.x, p.y, -1. ) );

float minL = 1E-3;
float maxL = 1E4;
float rL = 0.;
float rD = minL*2.;
vec3 rP = v.xxy;
for( int i=0; i<16; i++ )
{
if( abs(rD)<minL || maxL<rL )break;
rD = f( rP );
rL += rD;
rP = v.xxy+ray*rL;
}

vec4 col = v.xxxx;
if( rD < 1E-2 )
{
vec2 texp = vec2( .5+n(rP).xy/r*min( r.x, r.y )*.5 );
col.xyz = texture2D( texture0, vec2( texp.x, 1.-texp.y ) ).xyz * ( .1/rL*n(rP).z+.9 );
col.w = 1.;
}
gl_FragColor = col;
}
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform vec2 resolution;
uniform float time;
uniform float param0;
uniform sampler2D texture0;

#define t time
#define r resolution
#define c gl_FragCoord.xy
#define v vec2( 0., 1. )

float f( vec3 p )
{
float tt = t;
p.xy = p.xy*mat2( cos(t), -sin(t), sin(t), cos(t) );
tt = sin( t );
p.zx = p.zx*mat2( cos(tt), -sin(tt), sin(tt), cos(tt) );
tt = 2.*time;
p.yz = p.yz*mat2( cos(tt), -sin(tt), sin(tt), cos(tt) );
float r = .1+param0*.4;
float k = .3+param0*.1;
float d = length( p+v.yxx*k )-r;
d = min( d, length( p-v.yxx*k )-r);
d = min( d, length( p+v.xyx*k )-r);
d = min( d, length( p-v.xyx*k )-r);
d = min( d, length( p+v.xxy*k )-r);
d = min( d, length( p-v.xxy*k )-r);
return d;
}

vec3 n( vec3 p )
{
vec2 d = v*.01;
return normalize( vec3( f( p+d.yxx )-f( p-d.yxx ), f( p+d.xyx )-f( p-d.xyx ), f( p+d.xxy )-f( p-d.xxy ) ) );
}

void main()
{
vec2 uv = c/r;
vec2 p = (c*2.-r)/r.x;
vec3 ray = normalize( vec3( p.x, p.y, -1. ) );

float minL = 1E-3;
float maxL = 1E4;
float rL = 0.;
float rD = minL*2.;
vec3 rP = v.xxy;
for( int i=0; i<16; i++ )
{
if( abs(rD)<minL || maxL<rL )break;
rD = f( rP );
rL += rD;
rP = v.xxy+ray*rL;
}

vec4 col = v.xxxx;
if( rD < 1E-2 )
{
vec2 texp = vec2( .5+n(rP).xy/r*min( r.x, r.y )*.5 );
col.xyz = texture( texture0, vec2( texp.x, 1.-texp.y ) ).xyz * ( .1/rL*n(rP).z+.9 );
col.w = 1.;
}
color = col;
}
6 changes: 4 additions & 2 deletions media/glsl_effect/ascii.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#version 300 es
// referenced the method of bitmap of iq : https://www.shadertoy.com/view/4dfXWj

#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture0;
Expand All @@ -24,7 +26,7 @@ void main()
{
vec2 uv = vec2(floor(gl_FragCoord.x/8./zoom)*8.*zoom,floor(gl_FragCoord.y/12./zoom)*12.*zoom)/r;
ivec2 pos = ivec2(mod(gl_FragCoord.x/zoom,8.),mod(gl_FragCoord.y/zoom,12.));
vec4 tex = texture2D(texture0,vec2(uv.x,1.-uv.y));
vec4 tex = texture(texture0,vec2(uv.x,1.-uv.y));
float cha = 0.;

{
Expand Down Expand Up @@ -152,5 +154,5 @@ void main()
}

vec3 col = vec3(1.);
gl_FragColor = vec4(cha*col,1.);
color = vec4(cha*col,1.);
}
8 changes: 5 additions & 3 deletions media/glsl_effect/blendAlpha.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform float time;
uniform vec2 resolution;
uniform float param0;
Expand All @@ -17,8 +19,8 @@ void main()
vec2 uv = c/r;
float p = mod( param0, 2. );

vec4 t0 = texture2D( texture0, vec2( uv.x, 1.-uv.y ) );
vec4 t1 = texture2D( texture1, vec2( uv.x, 1.-uv.y ) );
vec4 t0 = texture( texture0, vec2( uv.x, 1.-uv.y ) );
vec4 t1 = texture( texture1, vec2( uv.x, 1.-uv.y ) );

gl_FragColor = mix(t0, t1, p);
color = mix(t0, t1, p);
}
6 changes: 4 additions & 2 deletions media/glsl_effect/brightnessToColor.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture0;
Expand All @@ -18,9 +20,9 @@ float gray(vec3 _i)
void main()
{
vec2 uv = c/r;
vec4 tex = texture2D( texture0, vec2( uv.x, 1.-uv.y ) );
vec4 tex = texture( texture0, vec2( uv.x, 1.-uv.y ) );

float g = gray( tex.xyz )*6.;

gl_FragColor = vec4( sin( g )*.5+.5, sin( g+4. )*.5+.5, sin( g+2. )*.5+.5, 1. );
color = vec4( sin( g )*.5+.5, sin( g+4. )*.5+.5, sin( g+2. )*.5+.5, 1. );
}
12 changes: 7 additions & 5 deletions media/glsl_effect/delta.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform vec2 resolution;
uniform sampler2D texture0;

Expand All @@ -13,9 +15,9 @@ uniform sampler2D texture0;
void main()
{
vec2 uv = c/r;
vec3 l = texture2D( texture0, vec2( uv.x-DELTA, 1.-uv.y ) ).xyz;
vec3 r = texture2D( texture0, vec2( uv.x+DELTA, 1.-uv.y ) ).xyz;
vec3 u = texture2D( texture0, vec2( uv.x, 1.-uv.y+DELTA ) ).xyz;
vec3 d = texture2D( texture0, vec2( uv.x, 1.-uv.y-DELTA ) ).xyz;
gl_FragColor = vec4( vec3( abs( l-r ) + abs( u-d ) ), 1. );
vec3 l = texture( texture0, vec2( uv.x-DELTA, 1.-uv.y ) ).xyz;
vec3 r = texture( texture0, vec2( uv.x+DELTA, 1.-uv.y ) ).xyz;
vec3 u = texture( texture0, vec2( uv.x, 1.-uv.y+DELTA ) ).xyz;
vec3 d = texture( texture0, vec2( uv.x, 1.-uv.y-DELTA ) ).xyz;
color = vec4( vec3( abs( l-r ) + abs( u-d ) ), 1. );
}
46 changes: 24 additions & 22 deletions media/glsl_effect/dots.glsl
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform sampler2D texture0;

#define r resolution
#define c gl_FragCoord.xy

float gray( vec3 _i )
{
return (_i.x+_i.y+_i.z)/3.;
}

void main()
{
vec2 uv = floor( c/6. ) * 6./r + vec2( 3. )/r;
vec2 pos = mod( c, 6. );
vec4 tex = texture2D( texture0, vec2( uv.x, 1.-uv.y ) );
gl_FragColor = vec4( clamp( vec3( gray( tex.xyz )*3. - length( pos-vec2(3.) )*1. ), 0., 1. )*tex.xyz, 1. );
}
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform vec2 resolution;
uniform sampler2D texture0;

#define r resolution
#define c gl_FragCoord.xy

float gray( vec3 _i )
{
return (_i.x+_i.y+_i.z)/3.;
}

void main()
{
vec2 uv = floor( c/6. ) * 6./r + vec2( 3. )/r;
vec2 pos = mod( c, 6. );
vec4 tex = texture( texture0, vec2( uv.x, 1.-uv.y ) );
color = vec4( clamp( vec3( gray( tex.xyz )*3. - length( pos-vec2(3.) )*1. ), 0., 1. )*tex.xyz, 1. );
}
82 changes: 42 additions & 40 deletions media/glsl_effect/fishRGB.glsl
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 resolution;
uniform sampler2D texture0;
uniform float param0;

#define PI 3.1415926

#define r resolution
#define c gl_FragCoord.xy
#define v vec2(0.,1.)

vec3 barrel( float _amp, vec2 _uv )
{
vec2 uv = _uv;
float corn = length( v.yy*.5 );
float amp = min( _amp*3., PI*corn );
float zoom = corn/(tan(corn*amp)+corn);
vec2 p = clamp( (uv+normalize(uv-.5)*tan(length(uv-.5)*amp))*zoom + .5*(1.-zoom), 0., 1. );
return texture2D( texture0, vec2( p.x, 1.-p.y ) ).xyz;
}

void main()
{
vec2 uv = c/r;
vec3 col = v.xxx;
float amp = clamp( param0, 0., 1. );
col.x += barrel( amp, uv ).x*.4;
col.x += barrel( amp*1.005, uv ).x*.4;
col.x += barrel( amp*1.01, uv ).x*.4;
col.y += barrel( amp*1.03, uv ).y*.4;
col.y += barrel( amp*1.035, uv ).y*.4;
col.y += barrel( amp*1.04, uv ).y*.4;
col.z += barrel( amp*1.06, uv ).z*.4;
col.z += barrel( amp*1.065, uv ).z*.4;
col.z += barrel( amp*1.07, uv ).z*.4;
gl_FragColor = vec4( col, 1. );
}
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform vec2 resolution;
uniform sampler2D texture0;
uniform float param0;

#define PI 3.1415926

#define r resolution
#define c gl_FragCoord.xy
#define v vec2(0.,1.)

vec3 barrel( float _amp, vec2 _uv )
{
vec2 uv = _uv;
float corn = length( v.yy*.5 );
float amp = min( _amp*3., PI*corn );
float zoom = corn/(tan(corn*amp)+corn);
vec2 p = clamp( (uv+normalize(uv-.5)*tan(length(uv-.5)*amp))*zoom + .5*(1.-zoom), 0., 1. );
return texture( texture0, vec2( p.x, 1.-p.y ) ).xyz;
}

void main()
{
vec2 uv = c/r;
vec3 col = v.xxx;
float amp = clamp( param0, 0., 1. );
col.x += barrel( amp, uv ).x*.4;
col.x += barrel( amp*1.005, uv ).x*.4;
col.x += barrel( amp*1.01, uv ).x*.4;
col.y += barrel( amp*1.03, uv ).y*.4;
col.y += barrel( amp*1.035, uv ).y*.4;
col.y += barrel( amp*1.04, uv ).y*.4;
col.z += barrel( amp*1.06, uv ).z*.4;
col.z += barrel( amp*1.065, uv ).z*.4;
col.z += barrel( amp*1.07, uv ).z*.4;
color = vec4( col, 1. );
}
12 changes: 7 additions & 5 deletions media/glsl_effect/four.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#version 300 es
#ifdef GL_ES
precision mediump float;
#endif

out vec4 color;
uniform float time;
uniform vec2 resolution;
uniform float param0;
Expand All @@ -22,20 +24,20 @@ void main()

if( p < 1. )
{
col = texture2D( texture0, vec2( uv.x, 1.-uv.y ) );
col = texture( texture0, vec2( uv.x, 1.-uv.y ) );
}
else if( p < 2. )
{
col = texture2D( texture1, vec2( uv.x, 1.-uv.y ) );
col = texture( texture1, vec2( uv.x, 1.-uv.y ) );
}
else if( p < 3. )
{
col = texture2D( texture2, vec2( uv.x, 1.-uv.y ) );
col = texture( texture2, vec2( uv.x, 1.-uv.y ) );
}
else
{
col = texture2D( texture3, vec2( uv.x, 1.-uv.y ) );
col = texture( texture3, vec2( uv.x, 1.-uv.y ) );
}

gl_FragColor = col;
color = col;
}
Loading

0 comments on commit b31c249

Please sign in to comment.