#define AMPLITUDE 0.1
#define SPEED 5.0
uniform sampler2D uSampler;
uniform float iTime;
uniform vec2 resolution;
vec4 rgbShift( in vec2 p, in vec4 shift ) {
shift *= 2.0*shift.w - 1.0;
vec2 rs = vec2(shift.x,-shift.y);
vec2 gs = vec2(shift.y,-shift.z);
vec2 bs = vec2(shift.z,-shift.x);
float r = texture(uSampler, p+rs, 0.0).x;
float g = texture(uSampler, p+gs, 0.0).y;
float b = texture(uSampler, p+bs, 0.0).z;
return vec4(r,g,b,1.0);
}
vec4 noise(in vec2 p ) {
return texture(uSampler, p, 0.0);
}
vec4 vec4pow( in vec4 v, in float p ) {
// Don't touch alpha (w), we use it to choose the direction of the shift
// and we don't want it to go in one direction more often than the other
return vec4(pow(v.x,p),pow(v.y,p),pow(v.z,p),v.w);
}
void main()
{
vec2 p = gl_fragCoord.xy / resolution.xy;
vec4 c = vec4(0.0,0.0,0.0,1.0);
// Elevating shift values to some high power (between 8 and 16 looks good)
// helps make the stuttering look more sudden
vec4 shift = vec4pow(noise(vec2(SPEED*iTime,2.0*SPEED*iTime/25.0 )),8.0)
*vec4(AMPLITUDE,AMPLITUDE,AMPLITUDE,1.0);
c += rgbShift(p, shift);
gl_fragColor = c;
}
ERROR: 0:15: 'texture' : no matching overloaded function found
ERROR: 0:15: 'x' : field selection requires structure or vector on left hand side
ERROR: 0:16: 'texture' : no matching overloaded function found
ERROR: 0:16: 'y' : field selection requires structure or vector on left hand side
ERROR: 0:17: 'texture' : no matching overloaded function found
ERROR: 0:17: 'z' : field selection requires structure or vector on left hand side
ERROR: 0:23: 'texture' : no matching overloaded function found
ERROR: 0:23: 'return' : function return is not matching type:
ERROR: 0:34: 'gl_fragCoord' : undeclared identifier
ERROR: 0:34: 'xy' : field selection requires structure or vector on left hand side
ERROR: 0:44: 'gl_fragColor' : undeclared identifier
ERROR: 0:44: 'assign' : l-value required (can't modify a const)
ERROR: 0:44: '=' : dimension mismatch
ERROR: 0:44: 'assign' : cannot convert from 'mediump 4-component vector of float'
renderer.bindTexture(base1, 0, true);
and renderer.bindTexture(base2, 1, true);
, you'll have to pass [0,1] to shader uniform of the sampler