We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wan't to use an extra texture with a shader. For some reason I get this error:
The shader doesn't have a uniform called "textureB" OR the uniform was removed during compilation because it was unused.
I know what the error means, but in this case it doesn't make sense to me. What is going wrong?
PShader psBlendLightest;
PGraphics pg;
PGraphics textureB;
void settings() {
size(512, 512, P2D);
}
void setup() {
psBlendLightest = loadShader("http://localhost:8888/shaders/blendLightest.glsl"); // set with processing LIGHTEST
pg = createGraphics(512, 512, P2D);
textureB = createGraphics(512, 512, P2D);
pg.beginDraw();
pg.background(0);
pg.fill(255);
pg.quad(25, 25, 400, 40, 450, 500, 40, 300);
pg.endDraw();
textureB.beginDraw();
textureB.background(0);
textureB.fill(255);
textureB.ellipse(256, 256, 400, 400);
textureB.endDraw();
}
void draw() {
image(textureB, 0, 0);
psBlendLightest.set("textureB", textureB);
shader(psBlendLightest);
image(pg, 0, 0);
}
The shader:
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
varying vec4 vertTexCoord;
uniform sampler2D textureB;
void main() {
vec3 texColorA = texture2D(texture, vertTexCoord.st).rgb;
vec3 texColorB = texture2D(textureB, vertTexCoord.st).rgb;
gl_FragColor = vec4(max(texColorA, texColorB), 1.0);
}
Answers
First of all you wanna use filter() instead of shader() or Processing won't set the texture uniform.
Well, your code works when using new PShader() directly:
blendLightest.vert
blendLightest.frag
But even if you include a custom vertex shader loadShader() will "optimize" textureB away. Looks like a bug to me.
I can't get it to work. Maybe due i'm on a mac again. I opened an issue.
https://github.com/processing/processing/issues/3968