Hello,
I’m trying to use this metaballs shaders found on shaderToy with no results. I’ve got a black screen with this error :
OpenGL error 1282 at bot endDraw(): invalid operation
I adapt a little bit the code but I’m not a shader master.
Here’s the code that I would like to put in a PGraphics as a layer.
Thanks for help
#define PROCESSING_COLOR_SHADER
uniform vec3 iResolution;
uniform vec2 iMouse;
uniform float iTime;
uniform float divide;
uniform float intensity = 0.2;
uniform float coordX;
uniform float coordY;
uniform float ball1x;
uniform float ball1y;
uniform float ball1z;
uniform float ball2x;
uniform float ball2y;
uniform float ball2z;
uniform float ball3x;
uniform float ball3y;
uniform float ball3z;
uniform vec3 ball1;
uniform vec3 ball2;
uniform vec3 ball3;
uniform float sum = 0.0;
void mainImage( out vec4 fragColor, in vec2 fragCoord );
void main() {
mainImage(gl_FragColor,gl_FragCoord.xy);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Hold the mouse and drag to adjust
float ratio = iResolution.y / iResolution.x;
float divider = float(iMouse.y / iResolution.x * 10.0) + 1.0;
float intensity = float(iMouse.x / iResolution.y * 10.0) + 1.0;
float coordX = fragCoord.x / iResolution.x;
float coordY = fragCoord.y / iResolution.x;
float ball1x = sin(iTime * 2.1) * 0.5 + 0.5;
float ball1y = cos(iTime * 1.0) * 0.5 + 0.5;
float ball1z = sin(iTime * 2.0) * 0.1 + 0.2;
float ball2x = sin(iTime * 1.0) * 0.5 + 0.5;
float ball2y = cos(iTime * 1.8) * 0.5 + 0.5;
float ball2z = cos(iTime * 2.0) * 0.1 + 0.2;
float ball3x = sin(iTime * 0.7) * 0.5 + 0.5;
float ball3y = cos(iTime * 1.5) * 0.5 + 0.5;
float ball3z = cos(iTime * 1.0) * 0.1 + 0.2;
vec3 ball1 = vec3(ball1x, ball1y * ratio, ball1z);
vec3 ball2 = vec3(ball2x, ball2y * ratio, ball2z);
vec3 ball3 = vec3(ball3x, ball3y * ratio, ball3z);
float sum = 0.0;
sum += ball1.z / distance(ball1.xy, vec2(coordX, coordY));
sum += ball2.z / distance(ball2.xy, vec2(coordX, coordY));
sum += ball3.z / distance(ball3.xy, vec2(coordX, coordY));
sum = pow(sum / intensity, divider);
fragColor = vec4(sum * 0.2, sum * 0.2, sum * 0.4, 1.0);
}
PShader metaBalls;
void setup() {
size(896, 768, P2D);
noStroke();
metaBalls = loadShader("metaBalls.glsl");
metaBalls.set("iResolution", float(width), float(height));
}
void draw() {
metaBalls.set("iTime", millis() / 500.0);
shader(metaBalls);
rect(0, 0, width, height);
}