# Send different uniform values to a single shader

**URL:** https://discourse.processing.org/t/send-different-uniform-values-to-a-single-shader/568
**Category:** Coding Questions
**Created:** [May 31, 2018, 3:53pm UTC](https://discourse.processing.org/t/send-different-uniform-values-to-a-single-shader/568 "2018-05-31T15:53:19Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vjjv](https://avatars.discourse-cdn.com/v4/letter/v/df705f/32.png) [@vjjv](https://discourse.processing.org/u/vjjv)
#### Post date: [May 31, 2018, 3:53pm UTC](https://discourse.processing.org/t/send-different-uniform-values-to-a-single-shader/568/1 "2018-05-31T15:53:19Z")

</div>

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.

```auto
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();
  }
}

```

---

<div class="post-metadata">

### Author: ![WakeMeAtThree](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wakemeatthree/32/38_2.png) [@WakeMeAtThree](https://discourse.processing.org/u/WakeMeAtThree)
#### Post date: [June 2, 2018, 7:34am UTC](https://discourse.processing.org/t/send-different-uniform-values-to-a-single-shader/568/2 "2018-06-02T07:34:20Z")

</div>

You can access the attribute positions from the vertex shader and have a varying variable that’s shared between fragment and vertex. Maybe post your glsl code so we can have a look? Also, [this thread](https://discourse.processing.org/t/depth-of-field-effect-with-a-shader/265) might be of interest to you.
