uniform массивы в шейдерах

uniform массивы в шейдерах

Сообщение waruiyume 24 июл 2014, 00:24

Оказывается это всегда было возможно :-o
Aras писал(а):No, 4.5 does not add native support for uniform arrays.

You can index data passed in (like you always could), it's just quite cumbersome to set it up on the CPU side. Basically, you can have "uniform float4 foo[10];" in the shader, and that will appear as 10 individual vector properties, named float0..float9 to the script side. So to set them up, you'd have to call material.SetVector 10 times.

Noisecrime писал(а):Just define a uniform array in the shader, then use material Set<property> function using the name of the array and appending the index value to it. Remember that arrays start at 0.

In the shader

float4 _myArray[25];

in code,
material.SetVector("_myArray0", myVector);
material.SetVector("_myArray9", myVector);
material.SetVector("_myArray14", myVector);
material.SetVector("_myArray24", myVector);

If you check out the compiled source to a shader using an array in Unity for Dx9 you're see the arrays defined one element at a time, though I guess it may be treated as a single continuous piece of memory.

I can't be sure but in testing I suspect opengl/gles may not be as optimal as dx using this technique.
Аватара пользователя
waruiyume
Адепт
 
Сообщения: 6143
Зарегистрирован: 30 окт 2010, 05:03
Откуда: Ростов на Дону

Вернуться в Tips & Tricks

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2