「MonoGameで位置と色と法線とUV座標を持つカスタム頂点を使いたい」の版間の差分
imported>Administrator ページの作成:「テクスチャを貼らなければ頂点カラーで塗られ、テクスチャを貼ればテクスチャマッピングもバンプマッピングも...」 |
imported>Administrator 編集の要約なし |
||
| 54行目: | 54行目: | ||
} | } | ||
</source> | </source> | ||
== 関連項目 == | |||
* [[頂点バッファ]] | |||
* [[インデックスバッファ]] | |||
[[category: MonoGame]] | [[category: MonoGame]] | ||
2018年2月13日 (火) 05:29時点における版
テクスチャを貼らなければ頂点カラーで塗られ、テクスチャを貼ればテクスチャマッピングもバンプマッピングもされる。 そんな位置と頂点カラーと法線とUV座標を持つゴージャスなカスタム頂点フォーマット。 個人的にはゲームではなく細胞を3D表示するのにMonoGameを使っているので、動的に頂点を生成して、かつテクスチャはほぼ利用しないが、稀にマスク的にテクスチャマッピングとバンプマッピングを使いたいこともある。
MonoGameに標準搭載されている頂点フォーマット構造体たち。
| VertexPosition | 位置 |
| VertexPositionColor | 位置と頂点カラー |
| VertexPositionColorTexture | 位置と頂点カラーとUV座標 |
| VertexPositionNormalTexture | 位置と法線とUV座標 |
| VertexPositionTexture | 位置とUV座標 |
無いんだが、これが。
そんなときはIVertexTypeインターフェイスを実装するだけでカスタム頂点フォーマット構造体を作れるそうだ。
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public struct VertexPositionColorNormalTexture : IVertexType
{
public Vector3 Position;
public Color Color;
public Vector3 Normal;
public Vector2 TextureCoordinate;
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement((sizeof(float) * 3), VertexElementFormat.Color, VertexElementUsage.Color, 0),
new VertexElement((sizeof(float) * 3) + (4), VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement((sizeof(float) * 3 * 2) + (4), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
);
public VertexPositionColorNormalTexture(Vector3 position, Color color, Vector3 normal, Vector2 textureCoordinate)
{
Position = position;
Color = color;
normal.Normalize();
Normal = normal;
TextureCoordinate = textureCoordinate;
}
VertexDeclaration IVertexType.VertexDeclaration
{
get { return VertexDeclaration; }
}
}
}