We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi guys...i'm working on this glitch shader i've found on this website: https://www.shadertoy.com/view/ls3Xzf
now i am editing part of the code to make it compile by processing.
It actually compile but it doesn't work
processing code:
PShader glitch;
PImage img, glitchImg;
void setup() {
size(540, 540, P3D);
img=loadImage("pietroGogh.jpg");
glitchImg=loadImage("glitch.jpg");
glitch = loadShader("glitch2.glsl");
stroke(255);
background(0);
glitch.set("iResolution", new PVector(800., 600., 0.0) );
}
void draw() {
strokeWeight(1);
//glitch.set("iGlobalTime", random(0, 60.0));
glitch.set("iTime", millis());
if (random(0.0, 1.0) < 0.4) {
shader(glitch);
}
image(img, 0, 0);
}
glsl code:
uniform sampler2D texture;
uniform vec2 iResolution;
uniform float iTime;
//varying vec4 vertTexCoord;
float rand () {
return fract(sin(iTime)*1e4);
}
void main()
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
vec2 uvR = uv;
vec2 uvB = uv;
uvR.x = uv.x * 1.0 - rand() * 0.02 * 0.8;
uvB.y = uv.y * 1.0 + rand() * 0.02 * 0.8;
//
if(uv.y < rand() && uv.y > rand() -0.1 && sin(iTime) < 0.0)
{
uv.x = (uv + 0.02 * rand()).x;
}
vec4 c;
c.r = texture(texture, uvR).r;
c.g = texture(texture, uv).g;
c.b = texture(texture, uvB).b;
float scanline = sin( uv.y * 800.0 * rand())/30.0;
c *= 1.0 - scanline;
//vignette
float vegDist = length(( 0.5 , 0.5 ) - uv);
c *= 1.0 - vegDist * 0.6;
gl_FragColor = c;
}
does anyone have any idea why this happens? sorry if there are trivial mistakes, but i'm quite new to shader language thank you all!!
Answers
If you are working with a ShaderToy demo, then the PixelFlow library has a wrapper for them so that (I believe, untested) you don't even need to adapt them:
https://forum.processing.org/two/discussion/comment/106411/#Comment_106411
really interesting...just update the library. but for me would be usefull to learn something about shader...not just import it!! thank you for the reply :)
It also might be worth looking t the source code of the library to see how it works. And / or talking to the author....
why not? i'm doing it just now! thanks you for the reply!! :)
if someone is interested i've debugged the code...this is a working version:
glsl code:
processing code:
@pietroLama Really cool. Thxs for sharing.
Kf
@kfrajer thank you so much :)