LoginSignup
1
0

More than 5 years have passed since last update.

Metalのシェーダーで転送した情報のうち、一部が欠ける

Posted at

MetalでVertexShaderにマテリアルの情報を転送するために、以下のような構造体を定義してmakebufferしてからの、データをマッピングしたとき、21個のマテリアル情報をセットしたのに、実際は17個分しか転送されなかった。

struct material
{
    float4 ambientColor;
    float4 diffuseColor;
    float4 specularColor;
    float specularPower;
};

以下のように構造体のByte数を無理やり16の倍数に変更すると正しく動作した。

struct material//計64Byte
{
    float4 ambientColor;// 4 * 4 = 16Byte
    float4 diffuseColor;// 4 * 4 = 16Byte
    float4 specularColor;// 4 * 4 = 16Byte
    float specularPower;// 4Byte
    float space1;// 4Byte
    float space2;// 4Byte
    float space3;// 4Byte
};

Metalへデータを転送するときに構造体を使用するときは、1つの構造体のByte数が16の倍数になるようにしないといけないみたいです。

1
0
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
1
0