We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hey everybody. this time i've a problem sending invididual mensajes to a fragment shader. I've 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.
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();
}
}
Answers
Re:
We are moving to a new forum; you may wish to post this question there. Also, check out a recent discussion on the new forum of depth of field shading on spheres, here:
Thanks jeremy, i already posted there. What i understand now is that a uniform is a constant value, and i need a INPUT value that change everytime a shader instance is on, just like a texCoord input. How can i program my own input?