Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : GLSL shader help

$
0
0
I noticed you weren't actually using a lot of variables (mouse, time). Perhaps once you do actually use them, you can include them again. For now here is an example of your adapted code that sends the minim audiobuffers to the shader and utilizes them to change the color accordingly.

Adapted Fragment Shader
  1. #define PROCESSING_COLOR_SHADER
  2.  
  3. uniform vec2 resolution;
  4. uniform float bufferSize;
  5. uniform float audioLeft[1024];
  6. uniform float audioRight[1024];
  7.  
  8. varying vec4 vertColor;
  9.  
  10. void main(void) {
  11.   vec2 c = vec2 (-1.0 + 2.0 * gl_FragCoord.x / resolution.x, 1.0 - 2.0 * gl_FragCoord.y / resolution.y);
  12.   int bufX = int(bufferSize * gl_FragCoord.x / resolution.x);
  13.   float d1 = c.y - audioLeft[bufX];
  14.   float d2 = c.y - audioRight[bufX];
  15.   float y = c.y + d1 + d2;
  16.   float g = abs(0.3 / y);
  17.   float h = abs(c.x);
  18.   vec3 col = vec3(g * (1.0 - h), g * h, g * 1.5);
  19.   gl_FragColor = vec4(col, 1.0);
  20. }

Adaped Code
  1. import ddf.minim.*;
  2. Minim minim;
  3. AudioInput in;
  4.  
  5. PShader myShader;
  6.  
  7. void setup() {
  8.   size(1024, 1080, P2D);
  9.   minim = new Minim(this);
  10.   in = minim.getLineIn();
  11.   myShader = loadShader("shader.glsl");
  12.   myShader.set("resolution", float(width), float(height));
  13.   myShader.set("bufferSize", 1024.0);
  14.   noStroke();
  15.   shader(myShader);
  16. }
  17.  
  18. void draw() {
  19.   background(0);
  20.  
  21.   float[] left = new float[in.bufferSize()];
  22.   float[] right = new float[in.bufferSize()];
  23.   for (int i=0; i<in.bufferSize(); i++) {
  24.     left[i] = in.left.get(i);
  25.     right[i] = in.right.get(i);
  26.   }
  27.  
  28.   myShader.set("audioLeft", left);
  29.   myShader.set("audioRight", right);  
  30.  
  31.   rect(0, 0, width, height);
  32. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles