[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
| 名前 | 座標 | 色 | テクスチャ座標 | 法線 |
| VertexPositionColor | ○ | ○ | × | × |
| VertexPositionColorTexture | ○ | ○ | ○ | × |
| VertexPositionNormalTexture | ○ | × | ○ | ○ |
| VertexPositionTexture | ○ | × | ○ | × |
| メンバ名 | 説明 |
| Single | floatです。(32bit) |
| Vector2 | Vector2構造体です。 |
| Vector3 | Vector3構造体です。 |
| Vector4 | Vector4構造体です。 |
| HalfVector2 | 16bitの浮動少数点数が2つです。(VertexShaderのバージョンが2.0以上でなければなりません) |
| HalfVector4 | 16bitの浮動小数点数が4つです。(VertexShaderのバージョンが2.0以上でなければなりません) |
| Rgba64 | 符号なし16bit整数が4つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。(VertexShaderのバージョンが2.0以上でなければなりません) |
| Color | Color構造体です。 |
| Rgba32 | byte4つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。(VertexShaderのバージョンが2.0以上でなければなりません) |
| Rg32 | 符号なし16bit整数が2つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。(VertexShaderのバージョンが2.0以上でなければなりません) |
| NormalizedShort2 | 符号付き16bit整数が2つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。 |
| NormalizedShort4 | 符号付き16bit整数が4つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。 |
| Normalized101010 | 符号付き10bitが3つです。それぞれ小数に展開されて0~1の範囲内の大きさになります。 |
| Short2 | 符号付き16bit整数が2つです。 |
| Short4 | 符号付き16bit整数が4つです。 |
| Byte4 | unsinged byteが4つです。 |
| Uint101010 | 符号なし10bitが3つです。 |
| Unused | このメンバは特別で、普通は使いません。VertexElementMethod.UVとVertexElementMethod.LookUpPresampledで使われます。 |
| メンバ名 | 説明 |
| Position | 頂点の位置です。 |
| Normal | 法線です。 |
| Color | 色です。UsageIndexが0の時にはディフューズの色を表し、UsageIndexが1の時にはスペキュラの色を表します。 |
| TextureCoordinate | テクスチャの座標です。 |
| PointSize | ポイントスプライトの大きさです。 |
| Depth | 深度です。 |
| Sample | サンプラーデータです。 |
| Fog | フォグに使うデータです。 |
| Binormal | 従法線ベクトル(接ベクトル×法線ベクトル、接線と法線の両方に対して垂直です)データです。 |
| BlendIndices | ブレンディングのインデックスのデータです。 |
| BlendWeight | ブレンディングに使われる重みのデータです。 |
| Tangent | 接線ベクトルです。 |
| TessellateFactor | テセラレーションに使われる浮動小数点数です。 |
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public struct VertexPositionNormalColor
{
public Vector3 Position;
public Vector3 Normal;
public Color Color;
public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color)
{
this.Position = position;
this.Normal = normal;
this.Color = color;
}
public static readonly VertexElement[] VertexElements
= {
new VertexElement(
0,
0,
VertexElementFormat.Vector3,
VertexElementMethod.Default,
VertexElementUsage.Position,
0
),
new VertexElement(
0,
sizeof(float) * 3,
VertexElementFormat.Vector3,
VertexElementMethod.Default,
VertexElementUsage.Normal,
0
),
new VertexElement(
0,
sizeof(float)*(3 + 3),
VertexElementFormat.Color,
VertexElementMethod.Default,
VertexElementUsage.Color,
0
)
};
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class MyGame : Game
{
GraphicsDeviceManager graphics;
BasicEffect basicEffect;
VertexPositionNormalColor[] vertices = new VertexPositionNormalColor[3];
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
vertices[0].Position = new Vector3(0, 1, 0);
vertices[0].Color = Color.Red;
vertices[0].Normal = new Vector3(0, 0, 1);
vertices[1].Position = new Vector3(1, 0, 0);
vertices[1].Color = Color.Red;
vertices[1].Normal = new Vector3(0, 0, 1);
vertices[2].Position = new Vector3(-1, 0, 0);
vertices[2].Color = Color.Red;
vertices[2].Normal = new Vector3(0, 0, 1);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
basicEffect.View = Matrix.CreateLookAt(
new Vector3(0, 0, 3),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0)
);
basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
(float)Window.ClientBounds.Width / Window.ClientBounds.Height,
1, 100
);
basicEffect.VertexColorEnabled = true;
basicEffect.EnableDefaultLighting();
}
}
protected override void Update(GameTime gameTime)
{
basicEffect.World *= Matrix.CreateRotationY(0.05f);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionNormalColor.VertexElements
);
basicEffect.Begin();
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionNormalColor>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
basicEffect.End();
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public struct VertexPositionNormalColor
{
public Vector3 Position;
public Vector3 Normal;
public Color Color;
public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color)
{
this.Position = position;
this.Normal = normal;
this.Color = color;
}
public static readonly VertexElement[] VertexElements
= {
new VertexElement(
0,
0,
VertexElementFormat.Vector3,
VertexElementMethod.Default,
VertexElementUsage.Position,
0
),
new VertexElement(
0,
sizeof(float) * 3,
VertexElementFormat.Vector3,
VertexElementMethod.Default,
VertexElementUsage.Normal,
0
),
new VertexElement(
0,
sizeof(float)*(3 + 3),
VertexElementFormat.Color,
VertexElementMethod.Default,
VertexElementUsage.Color,
0
)
};
public static readonly int SizeInBytes = sizeof(float) * (3 + 3) + sizeof(byte) * 4;
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class MyGame : Game
{
GraphicsDeviceManager graphics;
BasicEffect basicEffect;
VertexPositionNormalColor[] vertices = new VertexPositionNormalColor[3];
VertexBuffer vertexBuffer;
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
vertices[0].Position = new Vector3(0, 1, 0);
vertices[0].Color = Color.Red;
vertices[0].Normal = new Vector3(0, 0, 1);
vertices[1].Position = new Vector3(1, 0, 0);
vertices[1].Color = Color.Red;
vertices[1].Normal = new Vector3(0, 0, 1);
vertices[2].Position = new Vector3(-1, 0, 0);
vertices[2].Color = Color.Red;
vertices[2].Normal = new Vector3(0, 0, 1);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
basicEffect.View = Matrix.CreateLookAt(
new Vector3(0, 0, 3),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0)
);
basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
(float)Window.ClientBounds.Width / Window.ClientBounds.Height,
1, 100
);
basicEffect.VertexColorEnabled = true;
basicEffect.EnableDefaultLighting();
vertexBuffer = new VertexBuffer(
graphics.GraphicsDevice,
vertices.Length * VertexPositionNormalColor.SizeInBytes,
ResourceUsage.None
);
vertexBuffer.SetData (vertices);
}
}
protected override void Update(GameTime gameTime)
{
basicEffect.World *= Matrix.CreateRotationY(0.05f);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionNormalColor.VertexElements
);
graphics.GraphicsDevice.Vertices[0].SetSource(
vertexBuffer,
0,
VertexPositionNormalColor.SizeInBytes
);
basicEffect.Begin();
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawPrimitives(
PrimitiveType.TriangleList,
0,
vertices.Length / 3
);
pass.End();
}
basicEffect.End();
}
}