Hello, I’m a long time Processing user and I’m currently getting extremely strange behavior from a shader I’m developing. I’ve stripped it down to the core, and I’ve simply never seen anything similar. When using the shader as a filter, I’m getting “stuck pixels” which persist between frames. My main code is just boilerplate to display a rotating cube and apply the filter:
PShader AOShader;
void setup() {
size(800,800,P3D);
AOShader = loadShader("ambient.glsl");
}
void draw() {
lights();
float r = frameCount/100.0;
camera(75*cos(r),100,75*sin(r),0,0,0,0,1,0);
background(255);
fill(128);
box(50);
filter(AOShader);
}
The filter itself is currently just hashing the coordinates of the pixel and using that to jitter the input (the full shader where I first observed this is a screen-space ambient occlusion implementation). To make sure the hash function wasn’t causing the issue, I’ve replaced it with a simple bad linear hash.
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexCoord;
// really using pcg3d16, but this shows the failure
float noise(int a, int b, int c) {
return fract(float(a+b+c)*0.1);
}
void main(void) {
int pi = int(vertTexCoord.x/texOffset.x);
int pj = int(vertTexCoord.y/texOffset.y);
float sf = 100.0;
vec2 shift = sf*(2*vec2(noise(pi,pj,0),noise(pi,pj,1)-1));
vec4 cur = texture2D(texture, vertTexCoord.st + shift*texOffset.st);
gl_FragColor = cur;
}
The thing that makes this particularly odd is that the behavior changes as you change sf
! If sf = 1.0
, there are no frozen pixels and everything behaves as you’d expect. If sf = 10.0
, then about 1-5% of the pixels are frozen at their value in the first frame. If sf=100.0
, then all pixels are frozen in their value from the first frame. As far as I can tell, the first frame always renders as expected.
Anyone have any thoughts? I’m quite stuck. Mac OS 10.15.7, Processing 3.5.4.