Note that there are some explanatory texts on larger screens.

plurals
  1. POGLSL array is not passing through data
    primarykey
    data
    text
    <p>I am currently working on GLSL shader that passes through a 256 length array of ints that is pulled from audio. I am using Javascript and Three.js to do the actual rendering. I get the audio object later in the script by first defining a list of uniforms:</p> <pre><code>uniforms1 = { time: { type: "f", value: 1.0 }, resolution: { type: "v2", value: new THREE.Vector2() }, mouse: { type: "v2", value: new THREE.Vector2() }, audio:{ type: "int", value: new Array(256) }, }; </code></pre> <p>Each rendering frame, I am calling the following:</p> <pre><code>freqByteData = new Uint8Array(audio.analyser.frequencyBinCount); audio.analyser.getByteFrequencyData(freqByteData); uniforms1.audio.value = freqByteData; </code></pre> <p>Where audio.analyser is a web audio analyser node. This part of the code works fine, and I have verified that uniforms1.audio is an Uint8Array populated with the analyser data. The issue I am having is that I can't seem to pull this data into the fragment shader itself. I am very new to GLSL, so I am assuming it is a basic problem, but I have spent some time looking around for a solution and cannot seem to find one. Below is the fragment shader code:</p> <pre><code>&lt;script id="fragment_shader2" type="x-shader/x-fragment"&gt; uniform vec2 resolution; uniform float time; uniform vec2 mouse; uniform int audio[256]; #define N 100 void main( void ) { vec2 v = (gl_FragCoord.xy - resolution) / min(resolution.y,resolution.x) *0.5; float pi2 = 3.1415926535 * 2.0; float C = cos(mouse.x * pi2); float S = sin(mouse.y * pi2); //C = v.x; //S = v.y; float a = float(audio[20]/100); for ( int i = 0; i &lt; N; i++ ){ float x = v.x*v.x - v.y*v.y + C; float y = v.y * v.x + v.x * v.y+ S; v = vec2(x,y); } float col = v.x*v.x + v.y*v.y; gl_FragColor = vec4( a, sin(col*3.0), (cos(col)+sin(col))/2.0, 1.0 ); } &lt;/script&gt; </code></pre> <p>This creates a typical 'Julia Set' explorer, with only blues and greens, which makes sense when there is no audio playing, however, I would expect that when audio starts playing, the float 'a' would be non-zero, and therefore red would be introduced to the set. That being said, throughout the entirety of the audio, no red is visible ( even though I have also checked to make sure that audio[20] is indeed non-zero.</p> <p>Again, I am a complete novice at GLSL, so I am sorry if the problem is painfully obvious, but any help is appreciated.</p> <p>Thanks in advance! Isaac</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload