「MonoGameでHLSLにMatrixを渡す」を編集中
この編集を取り消せます。 下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
15行目: | 15行目: | ||
// 仕方がないので「Vector4が4個」と指定する。 | // 仕方がないので「Vector4が4個」と指定する。 | ||
var vertexDeclaration = new VertexDeclaration( | var vertexDeclaration = new VertexDeclaration( | ||
− | + | new VertexElement( 0, VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 0), | |
− | + | new VertexElement(16, VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 1), | |
− | + | new VertexElement(32, VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 2), | |
− | + | new VertexElement(48, VertexElementFormat.Vector4, VertexElementUsage.BlendWeight, 3)); | |
// ダイナミックバーテックスバッファーを生成する | // ダイナミックバーテックスバッファーを生成する | ||
31行目: | 31行目: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | HLSL側はfloat4が4個で受け取り、シェーダー関数内でmatrixに合成している。 | |
<syntaxhighlight lang="hlsl"> | <syntaxhighlight lang="hlsl"> | ||
// 「float4が4個」として受け取る。 | // 「float4が4個」として受け取る。 | ||
− | struct | + | struct InstanceInput |
{ | { | ||
− | + | float4 w1 : BLENDWEIGHT0; | |
− | + | float4 w2 : BLENDWEIGHT1; | |
− | + | float4 w3 : BLENDWEIGHT2; | |
− | + | float4 w4 : BLENDWEIGHT3; | |
}; | }; | ||
− | + | VertexShaderOutput MainVS(VertexShaderInput input, InstanceInput instance) | |
{ | { | ||
− | + | VertexShaderOutput output = (VertexShaderOutput)0; | |
− | + | // 「float4が4個」をmatrixに変換する。 | |
− | + | matrix world = matrix(instance.w1, instance.w2, instance.w3, instance.w4); | |
// 〜以下略〜 | // 〜以下略〜 | ||
− | |||
return output; | return output; | ||
} | } |