It looks like you're new here. If you want to get involved, click one of these buttons!
#ifdef GL_ES precision mediump float; #endif uniform lowp vec4 fColor; uniform lowp sampler2D fTexture; uniform mediump vec4 fTextureInfo; uniform mediump float fResolution; uniform mediump vec4 fTexelSize; varying mediump vec2 fTexCoord; void main() { if (fResolution==64.0) {gl_FragColor=texture2D(fTexture,fTexCoord); return;} float fRes=fResolution*2.0-1.0; mediump vec2 coord; coord.y=(fTexCoord.y/fTextureInfo.y-0.5); coord.x=(fTexCoord.x/fTextureInfo.x-0.5)/fTextureInfo.z*fTextureInfo.x*fTextureInfo.w/fTextureInfo.y; mediump vec2 coordrounded; coordrounded.y= (floor(coord.y*fRes+mod(fRes,2.0)*0.5)/ fRes+0.5)*fTextureInfo.y; coordrounded.x= (floor(coord.x*fRes+mod(fRes,2.0)*0.5)/ fRes*fTextureInfo.z/fTextureInfo.x/fTextureInfo.w*fTextureInfo.y+0.5)*fTextureInfo.x; lowp vec4 col=texture2D(fTexture,coordrounded); gl_FragColor = vec4(col); } |
Comments
Fragmenter - animated loop machine and IKONOMIKON - the memory game
uniform mediump float fTime;
defined like this in lua:
{name="fTime",type=Shader.CFLOAT,vertex=false},
which works on desktop but is not updated on android. any remedies?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
all in all if precision is the issue it's still surprising to produce an image which is fine except for the middle part.
also, precision does not explain the other issue with time variant not being updated, any ideas about that one? thanks
Fragmenter - animated loop machine and IKONOMIKON - the memory game
so you say that it should correctly be:
{name="fTime",type=Shader.CFLOAT,sys=Shader.SYS_TIMER,vertex=false},
and then maybe it would work on android as well?
thanks
UPDATE: well, it did not seem to work, on android still nothing happens, on desktop it's still ok.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
precision mediump float;
#endif
uniform lowp vec4 fColor;
uniform lowp sampler2D fTexture;
uniform mediump vec4 fTextureInfo;
//uniform mediump float fStrength;
uniform mediump float fResolution;
uniform mediump float fTime;
uniform mediump vec4 fTexelSize;
varying mediump vec2 fTexCoord;
//uniform float iTime=60.0; // shader playback time (in seconds)
//2D (returns 0 - 1)
float random2d(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float randomRange (in vec2 seed, in float min, in float max) {
return min + random2d(seed) * (max - min);
}
// return 1 if v inside 1d range
float insideRange(float v, float bottom, float top) {
return step(bottom, v) - step(top, v);
}
void main()
{
//inputs
//float AMT = 1.0-fResolution/128.0; //0 - 1 glitch amount
//float AMT = 0.25-fResolution/512.0; //0 - 1 glitch amount
float AMT = 0.25-fResolution/256.0; //0 - 1 glitch amount
float SPEED = 0.5; //0 - 1 speed
if (fResolution==64.0) {gl_FragColor=texture2D(fTexture,fTexCoord); return;}
float time = floor(fTime * SPEED * 60.0);
//vec2 uv = fTexCoord.xy / fResolution.xy;
vec2 uv=fTexCoord.xy;
//copy orig
vec4 outCol = texture2D(fTexture, uv).rgba;
//randomly offset slices horizontally
float maxOffset = AMT/2.0;
for (float i = 0.0; i < 10.0 * AMT; i += 1.0) {
float sliceY = random2d(vec2(time , 2345.0 + float(i)));
float sliceH = random2d(vec2(time , 9035.0 + float(i))) * 0.25;
float hOffset = randomRange(vec2(time , 9625.0 + float(i)), -maxOffset, maxOffset);
vec2 uvOff = uv;
uvOff.x += hOffset;
if (insideRange(uv.y, sliceY, fract(sliceY+sliceH)) == 1.0 ){
outCol = texture2D(fTexture, uvOff).rgba;
}
}
//do slight offset on one entire channel
float maxColOffset = AMT/6.0;
float rnd = random2d(vec2(time , 9545.0));
vec2 colOffset = vec2(randomRange(vec2(time , 9545.0),-maxColOffset,maxColOffset),
randomRange(vec2(time , 7205.0),-maxColOffset,maxColOffset));
if (rnd < 0.33){
outCol.r = texture2D(fTexture, uv + colOffset).r;
}else if (rnd < 0.66){
outCol.g = texture2D(fTexture, uv + colOffset).g;
} else{
outCol.b = texture2D(fTexture, uv + colOffset).b;
}
//gl_FragColor = vec4(outCol,1.0);
outCol.a = texture2D(fTexture, uv + colOffset).a;
gl_FragColor = vec4(outCol);
}
defined like this in lua:
{
{name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true},
{name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false},
{name="fTextureInfo",type=Shader.CFLOAT4,sys=Shader.SYS_TEXTUREINFO,vertex=false},
{name="fTexture",type=Shader.CTEXTURE,vertex=false},
{name="fTexelSize",type=Shader.CFLOAT4,vertex=false},
{name="fResolution",type=Shader.CFLOAT,vertex=false},
{name="fTime",type=Shader.CFLOAT,vertex=false},
{name="fDir",type=Shader.CFLOAT2,vertex=false},
},
{
{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0},
{name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0},
{name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0},
});
UPDATE: ok, i've found it, that's how i update it on onEnterFrame (i completely forgot):
shader_glitch:setConstant("fTime", Shader.CFLOAT, 1, os.timer())
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Fragmenter - animated loop machine and IKONOMIKON - the memory game
i still don't know what should i change in the glitch shader to make it work.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
#ifdef GL_ES
precision highp float;
#endif
which made everything work fine on my two android machines.
in addition in the glitch shader there was an unnecessary rounding, changing
float time = floor(fTime * SPEED * 60.0);
to
time = floor(fTime * SPEED * 60.0);
made it function correctly.
i'm really grateful for your help (as it happens quite often).
Fragmenter - animated loop machine and IKONOMIKON - the memory game
I have same fps with and without pixelate effect.
Likes: MoKaLux
also i use different shaders as 'special fx' in my animation app and it's convenient to just simply change the shader when i need a new fx.
Fragmenter - animated loop machine and IKONOMIKON - the memory game