hey everybody. this time ive a problem sending invididual mensajes to a fragment shader. Ive an array of spheres, and i want that every sphere have a different size of blur, witch is a uniform of the fragment. The main code is from an example, a post-processing effects.
Multiple objects sending different msj to one single uniform variable in a shader.
How can i do?
import controlP5.*;
ControlP5 cp5;
import peasy.*;
ArrayList<Sphere>s;
PGraphics canvas;
PGraphics brightPass;
PGraphics horizontalBlurPass;
PGraphics verticalBlurPass;
PShader bloomFilter;
PShader blurFilter;
PeasyCam cam;
float angle = 0;
final int surfaceWidth = 250;
final int surfaceHeight = 250;
float luminanceFilter = 0.02;
float blurSize = 100;
float sigma = 200;
void setup()
{
cam = new PeasyCam(this, 1400);
size(1000, 1000, P3D);
s = new ArrayList<Sphere>();
canvas = createGraphics(width, height, P3D);
brightPass = createGraphics(width, height, P2D);
brightPass.noSmooth();
horizontalBlurPass = createGraphics(width, height, P2D);
horizontalBlurPass.noSmooth();
verticalBlurPass = createGraphics(width, height, P2D);
verticalBlurPass.noSmooth();
bloomFilter = loadShader("bloomFrag.glsl");
blurFilter = loadShader("blurFrag.glsl");
}
void draw()
{
background(0);
bloomFilter.set("brightPassThreshold", luminanceFilter);
angle += 0.05;
for(Sphere s: s){
blurFilter.set("blurSize", s.p);
}
blurFilter.set("sigma", sigma);
canvas.beginDraw();
render(canvas);
canvas.endDraw();
// bright pass
brightPass.beginDraw();
brightPass.shader(bloomFilter);
brightPass.image(canvas, 0, 0);
brightPass.endDraw();
// blur horizontal pass
horizontalBlurPass.beginDraw();
blurFilter.set("horizontalPass", 1);
horizontalBlurPass.shader(blurFilter);
horizontalBlurPass.image(brightPass, 0, 0);
horizontalBlurPass.endDraw();
// blur vertical pass
verticalBlurPass.beginDraw();
blurFilter.set("horizontalPass", 0);
verticalBlurPass.shader(blurFilter);
verticalBlurPass.image(horizontalBlurPass, 0, 0);
verticalBlurPass.endDraw();
cam.beginHUD();
blendMode(BLEND);
blendMode(SCREEN);
image(brightPass, 0, 0);
image(verticalBlurPass, 0, 0);
cam.endHUD();
println(frameRate);
}
void render(PGraphics pg)
{
cam.getState().apply(pg);
pg.background(0, 50);
canvas.pushMatrix();
canvas.translate(width/2, height/2);
for(Sphere s: s){
s.display();
}
canvas.popMatrix();
}
void mousePressed() {
s.add(new Sphere(random(-width/2, width/2), random(-height/2, height/2), random(1000)));
}
class Sphere {
float p;
float w;
float h;
Sphere(float _w, float _h, float _p) {
p = _p;
w = _w;
h = _h;
}
void display() {
canvas.pushMatrix();
canvas.translate(w, h);
noFill();
canvas.sphere(100);
canvas.popMatrix();
}
}