K
K
Klaus Kater2016-11-13 18:28:58
Shaders
Klaus Kater, 2016-11-13 18:28:58

How to loop through an array in a shader?

Hello.
I ran into a problem, there is an array of textures, and I desperately need to sort through this very array, and process pixels from them with the same coordinates as the current one. I can't figure out how to iterate over an array of textures..

<script id="fragmentShader" type="x-shader/x-fragment">
    uniform sampler2D buffer_texture[16];
    const int count_textures = 16;
    void main() {
        int i;
        for(i=0;i<count_textures;++i)
        {
            vec4 this_pix = texture2D(buffer_texture[i], vUv);
            // Вот тут ругается на попытку обратиться к элементу массива по динамическому индексу, 
           // индекс по мнению компилятора, должен быть константой.
           // Каким образом в шейдерах можно перебирать массивы - непонятно.
        }
    }
</script>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question