Hi,
I’m relatively new with shaders.
I’m trying to port a shader from shadertoy (https://www.shadertoy.com/view/4dK3Ww) on processing 3.
It’s days I’m trying, still didn’t find the/a solution, because at the moment I just get a black screen…
Here is my code (simplified) :
Processing :
PShader firstShader;
PShader secondShader;  
PGraphics pg1;
PGraphics pg2;
void setup() {
  size(displayWidth, displayHeight, P2D);  
  pg1=createGraphics(width, height, P2D); 
  firstShader = loadShader("firstShader.glsl");
  firstShader.set("resolution", float(width), float(height));
  secondShader = loadShader("secondShader.glsl");
  secondShader.set("resolution", float(width), float(height));
}
void draw() {
  firstShader.set("time", millis()/1000.0);
  firstShader.set("iFrame", frameCount);
  firstShader.set("iChannel0", pg1); // I tried pg1.get() also, also result with just a black screen
  pg1.beginDraw();
  // pg1.background(0);
  pg1.shader(firstShader);
  pg1.rect(0, 0, width, height); 
  pg1.endDraw();  
  secondShader.set("iChannel0", pg1); //tried pg1.get() also
  shader(secondShader);
  rect(0, 0, width, height);
}
firstShader.glsl :
#ifdef GL_ES
precision highp float;
#endif
#define PROCESSING_COLOR_SHADER
uniform float time;
uniform int iFrame;
uniform vec2 resolution;
uniform sampler2D iChannel0;
void main( void ) {
    vec3 e = vec3(vec2(1.)/resolution.xy,0.);
    vec2 q = gl_FragCoord.xy/resolution.xy;
    vec4 c;
    c = texture(iChannel0, q);
    float p11 = c.y;
    float p10 = texture(iChannel0, q-e.zy).x;
    float p01 = texture(iChannel0, q-e.xz).x;
    float p21 = texture(iChannel0, q+e.xz).x;
    float p12 = texture(iChannel0, q+e.zy).x;
    float d = 0.;
    
    // Simulate rain drops
    float t = time*2.;
    vec2 pos = fract(floor(t)*vec2(0.456665,0.708618))*resolution.xy;
    float amp = 1.-step(.05,fract(t));
    d = -amp*smoothstep(2.5,.5,length(pos - gl_FragCoord.xy));
    // The actual propagation:
    d += -(p11-.5)*2. + (p10 + p01 + p21 + p12 - 2.);
    d *= .99; // dampening
    d *= float(iFrame>=2); // clear the buffer at iFrame < 2
    d = d*.5 + .5;
    
    // Put previous state as "y":
    //fragColor = vec4(d, c.x, 0, 0);
    gl_FragColor= vec4(d, c.x, 0, 0);
}
secondShader.glsl
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// Type of shader expected by Processing
#define PROCESSING_COLOR_SHADER
uniform sampler2D iChannel0;
uniform vec2 resolution;
varying vec4 vertColor;
varying vec4 vertTexCoord;
void mainImage( out vec4 fragColor, in vec2 fragCoord );
void main() {
    mainImage(gl_FragColor,gl_FragCoord.xy);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 q = fragCoord.xy/resolution.xy;
    float h = texture(iChannel0, q).x;
    float sh = 1.35 - h*2.;
    vec3 c =
    vec3(exp(pow(sh-.75,2.)*-10.),
         exp(pow(sh-.50,2.)*-20.),
         exp(pow(sh-.25,2.)*-10.));
    fragColor = vec4(c,1.);
}
With this code, I juste have a black screen, but I should see drops automatically appear (I delete some stuff - the iChannel1 image for the secondShader, the mouse interaction, but I check directly on shadertoy, it’s working, so it’s my processing port that have a pb). I tried copy pgGraphics on PImage, use ppixels in firstshader, etc., but still no results…
I checked other possibilities :
https://forum.processing.org/two/discussion/22683/ripples-shader-demo
It’s also a ripple shader, but it’s not the same Hugo Elias algorithm, and the ripples are not as thick, it’s not as “luiquid” as I want it to be.
I try the .get()/flag for initial texture as discuss here : https://forum.processing.org/two/discussion/23359/ppixels-feedback-and-colors-determining-the-color-at-a-location-of-texture but with no sucess
Perhaps is it a pb of PGraphics/shadertoy buffer resolution comptability (as discuss here : https://forum.processing.org/two/discussion/17629/how-to-get-round-using-16-bit-image-buffers-shadertoy-question). If so, do you have an idea how to make it works?
Any help is welcome! 
Thanks,
A.





