環境
Unity2022.2.2f1
概要
カラム(列/縦)順に入っています。
ComputeShaderでByteAddressBufferでアクセスした場合、勝手に転置してしまいます。
仕方ない面倒なのでtransposeしています。まぁ逆掛けしたり、_m30_m31_m32でアクセスするのもややこしいので。
コード
ByteAddressBuffer Matrices; RWByteAddressBuffer OutMatrices; float4 m0 = asfloat(Matrices.Load4(Address + 0 * 4)); float4 m1 = asfloat(Matrices.Load4(Address + 4 * 4)); float4 m2 = asfloat(Matrices.Load4(Address + 8 * 4)); float4 m3 = asfloat(Matrices.Load4(Address + 12 * 4)); float4x4 Matrix = transpose(float4x4(m0, m1, m2, m3)); //set translation Matrix._m03_m13_m23 = float3(0,1,2); Matrix = transpose(Matrix); OutMatrices.Store4(Address + 0 * 4, asuint(Matrix[0])); OutMatrices.Store4(Address + 4 * 4, asuint(Matrix[1])); OutMatrices.Store4(Address + 8 * 4, asuint(Matrix[2])); OutMatrices.Store4(Address + 12 * 4, asuint(Matrix[3]));