LoginSignup
7
5

More than 5 years have passed since last update.

GLSLで宣言時に配列を初期化する

Posted at

GLSLで以下のようにすると配列の宣言と初期化をまとめて行えます。

float[8] array = float[](
  1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0
);

vec4配列の場合は次のようになります。

vec4[4] array = vec4[](
  vec4(1.0, 2.0, 3.0, 4.0),
  vec4(5.0, 6.0, 7.0, 8.0),
  vec4(9.0, 10.0, 11.0, 12.0),
  vec4(13.0, 14.0, 15.0, 16.0)
);

GLSL3.1からは以下のように二重配列を扱えるらしいです。WebGL2はGLSL3.1に対応していないので試せてないですが...。

float[4][4] array = float[][](
  float[](1.0, 2.0, 3.0, 4.0),
  float[](5.0, 6.0, 7.0, 8.0),
  float[](9.0, 10.0, 11.0, 12.0),
  float[](13.0, 14.0, 15.0, 16.0)
);
7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5