fand / veda

⚡VJ / Live Coding on Atom⚡

Home Page:http://veda.gl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About Sound

BrandonLSW opened this issue · comments

Hi there,

For triggering sound reactive visual,
Is there any variable equivalent to the "sound" variable in vertexshaderart.com?

uniform sampler2D spectrum;
uniform sampler2D samples;

When using the variables above, I could not get the same result in vertexshaderart.com

Thanks for your help!

Hi @BrandonLSW ,

Do you want the volume of current frame, or the history of volumes?
If the former, you can just use volume.

In vertexshaderart.com, sound stores the history of volumes of past 240 frames.
Currently there's no equivalent in VEDA.

Thanks @fand. If I want to come up with the same result in vertexshaderart.com, is it possible to obtain the history of volumes "sampler2D sound" by some calculations of the variable "sampler2D samples"?

is it possible to obtain the history of volumes "sampler2D sound" by some calculations

Maybe yes, but it's a bit difficult, and I haven't tried yet.
You can create sound texture by using multipass rendering; Update sound in 1st pass, then use it in 2nd pass.

The code will be like this;

/*{
  PASSES: [
    { TARGET: "sound", FLOAT: true, WIDTH: 240, HEIGHT: 1 },
    {}
  ]
}*/

uniform vec2 resolution;
uniform int PASSINDEX;
uniform float volume;
uniform sampler2D sound;

void main() {
  if (PASSINDEX == 0) {
    // Shader for 1nd pass.

    // Save the volume of current frame in x == 0.
    if (gl_FragCoord.x == 0.0) {
      gl_FragColor = texture2D(sound);
    }
    else {
      // Shift 1 pixel for other pixels.
      vec2 leftPixel = max((gl_FragCoord.x - 1.0) / resolution.x, 0.0);
      gl_FragColor = vec4(volume, vec2(leftPixel, 0.0));
    }
  }
  else {
    // Write shader for 2nd pass.
    // You can use `sound` here!
    float mySound = texture2D(sound, vec2(0.0, 0.0)).x;
  }
}

Thanks. Gonna try it!