[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
public class MyGame : Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Effect effect;
VertexPositionTexture[] vertices = {
new VertexPositionTexture(new Vector3(0, 1, 0), new Vector2(0.5f, 0)),
new VertexPositionTexture(new Vector3(1, 0, 0), new Vector2(1, 1)),
new VertexPositionTexture(new Vector3(-1, 0, 0), new Vector2(0, 1))
};
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
effect = content.Load<Effect>("MyEffect");
Matrix view = Matrix.CreateLookAt(
new Vector3(1, 0, 1),
new Vector3(),
new Vector3(0, 1, 0)
);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(90),
(float)Window.ClientBounds.Width/Window.ClientBounds.Height,
0.1f, 100
);
effect.Parameters["View"].SetValue(view);
effect.Parameters["Projection"].SetValue(projection);
effect.Parameters["MyTexture"].SetValue(content.Load<Texture2D>("Xnalogo"));
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionTexture.VertexElements
);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent) { content.Unload(); }
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
effect.End();
}
}
float4x4 View;
float4x4 Projection;
texture MyTexture;
sampler mySampler = sampler_state{
Texture = <MyTexture>;
};
struct VertexPositionTexture
{
float4 Position : POSITION;
float4 TextureCoordinate : TEXCOORD;
};
VertexPositionTexture MyVertexShader(VertexPositionTexture input)
{
VertexPositionTexture output;
output.Position = mul(input.Position, mul(View, Projection));
output.TextureCoordinate = input.TextureCoordinate;
return output;
}
float4 MyPixelShader(float2 textureCoordinate : TEXCOORD) : COLOR
{
return tex2D(mySampler, textureCoordinate);
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}
| 定数名 | 解説 |
| None | 「MipMapは無効になり、ラスタライザはかわりにMagFilterを使います。」だそうです。 |
| Point | 滑らかになりません。一番近いテクセルの色が使われます。ギザギザです。 |
| Linear | バイリニアフィルターです。周りの2x2の領域の中での平均値が使われます。いろんなサンプルを見たところ、これが一番使われているようですね。 |
| Anisotropic | 異方性フィルターです。 |
| PyramidalQuad | 4サンプル・テントフィルターです。 |
| GaussianQuad | 4サンプル・ガウシアンフィルターです。画像をぼかすことで滑らかにするそうです。 |
float4x4 View;
float4x4 Projection;
texture MyTexture;
sampler mySampler = sampler_state{
Texture = <MyTexture>;
MagFilter = Linear;
};
struct VertexPositionTexture
{
float4 Position : POSITION;
float4 TextureCoordinate : TEXCOORD;
};
VertexPositionTexture MyVertexShader(VertexPositionTexture input)
{
VertexPositionTexture output;
output.Position = mul(input.Position, mul(View, Projection));
output.TextureCoordinate = input.TextureCoordinate;
return output;
}
float4 MyPixelShader(float2 textureCoordinate : TEXCOORD) : COLOR
{
return tex2D(mySampler, textureCoordinate);
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}
float4x4 View;
float4x4 Projection;
texture MyTexture;
sampler mySampler = sampler_state{
Texture = <MyTexture>;
MagFilter = Linear;
MinFilter = Linear;
};
struct VertexPositionTexture
{
float4 Position : POSITION;
float4 TextureCoordinate : TEXCOORD;
};
VertexPositionTexture MyVertexShader(VertexPositionTexture input)
{
VertexPositionTexture output;
output.Position = mul(input.Position, mul(View, Projection));
output.TextureCoordinate = input.TextureCoordinate;
return output;
}
float4 MyPixelShader(float2 textureCoordinate : TEXCOORD) : COLOR
{
return tex2D(mySampler, textureCoordinate);
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
public class MyGame : Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Effect effect;
VertexPositionColor[] vertices = {
new VertexPositionColor(new Vector3(0, 1, 0), Color.White),
new VertexPositionColor(new Vector3(1, 0, 0), Color.Blue),
new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red)
};
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
effect = content.Load<Effect>("MyEffect");
Matrix view = Matrix.CreateLookAt(
new Vector3(2, 0, 3),
new Vector3(),
new Vector3(0, 1, 0)
);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(90),
(float)Window.ClientBounds.Width/Window.ClientBounds.Height,
0.1f, 100
);
effect.Parameters["Transform"].SetValue(
view * projection
);
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionColor.VertexElements
);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent) { content.Unload(); }
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
effect.End();
}
}
float4x4 Transform;
struct VertexPositionColor
{
float4 Position : POSITION;
float4 Color : COLOR;
};
VertexPositionColor MyVertexShader(VertexPositionColor input)
{
VertexPositionColor output = input;
output.Position = mul(input.Position, Transform);
return output;
}
float4 MyPixelShader(float4 color : COLOR) : COLOR
{
return color;
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
public class MyGame : Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Effect effect;
VertexPositionColor[] vertices = {
new VertexPositionColor(new Vector3(0, 1, 0), Color.White),
new VertexPositionColor(new Vector3(1, 0, 0), Color.Blue),
new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red)
};
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
effect = content.Load<Effect>("MyEffect");
Matrix view = Matrix.CreateLookAt(
new Vector3(2, 0, 3),
new Vector3(),
new Vector3(0, 1, 0)
);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(90),
(float)Window.ClientBounds.Width/Window.ClientBounds.Height,
0.1f, 100
);
effect.Parameters["View"].SetValue(view);
effect.Parameters["Projection"].SetValue(projection);
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionColor.VertexElements
);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent) { content.Unload(); }
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
effect.End();
}
}
float4x4 View;
float4x4 Projection;
struct VertexPositionColor
{
float4 Position : POSITION;
float4 Color : COLOR;
};
VertexPositionColor MyVertexShader(VertexPositionColor input)
{
VertexPositionColor output = input;
output.Position = mul(input.Position, mul(View, Projection));
return output;
}
float4 MyPixelShader(float4 color : COLOR) : COLOR
{
return color;
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}
BasicEffect effect = new BasicEffect(graphics.GraphicsDevice, null);
foreach (EffectParameter parameter in effect.Parameters)
{
System.Console.WriteLine(parameter.Name);
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
public class MyGame : Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Effect effect;
VertexPositionColor[] vertices = {
new VertexPositionColor(new Vector3(0, 1, 0), Color.White),
new VertexPositionColor(new Vector3(1, 0, 0), Color.Blue),
new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red)
};
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
effect = content.Load<Effect>("MyEffect");
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
graphics.GraphicsDevice,
VertexPositionColor.VertexElements
);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent) { content.Unload(); }
}
protected override void Update(GameTime gameTime)
{
double angle = gameTime.TotalGameTime.TotalSeconds;
effect.Parameters["offset"].SetValue(
new Vector3((float)System.Math.Cos(angle), (float)System.Math.Sin(angle), 0)
);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.TriangleList,
vertices,
0,
vertices.Length / 3
);
pass.End();
}
effect.End();
}
}
float3 offset;
struct VertexPositionColor
{
float4 Position : POSITION;
float4 Color : COLOR;
};
VertexPositionColor MyVertexShader(VertexPositionColor input)
{
input.Position.xyz += offset;
return input;
}
float4 MyPixelShader(float4 color : COLOR) : COLOR
{
return color;
}
technique MyTechnique
{
pass MyPass
{
VertexShader = compile vs_2_0 MyVertexShader();
PixelShader = compile ps_2_0 MyPixelShader();
}
}