[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); Matrix view = Matrix.CreateLookAt( new Vector3(2, 0, 3), new Vector3(), new Vector3(0, 1, 0) ); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(90), GraphicsDevice.Viewport.AspectRatio, 0.1f, 100 ); effect.Parameters["Transform"].SetValue(view * projection); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }
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; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); Matrix view = Matrix.CreateLookAt( new Vector3(2, 0, 3), new Vector3(), new Vector3(0, 1, 0) ); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(90), GraphicsDevice.Viewport.AspectRatio, 0.1f, 100 ); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }
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); foreach (EffectParameter parameter in effect.Parameters) { System.Console.WriteLine(parameter.Name); }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); } 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) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }
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(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { if(color.r % 0.1f < 0.05f) return float4(1,1,1,1); else return color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
型名 | 説明 |
bool | 真偽を表します。trueかfalseです。 |
int | 32bitの符号付き整数です。 |
half | 16bitの浮動小数点数です。 |
float | 32bitの浮動小数点数です。 |
double | 64bitの浮動小数点数です。 |
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { color.r = 0; return color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { color.rb = 0; return color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { color.rb = color.br; return color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { return 1 - color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { return input; } float4 MyPixelShader(float4 color : COLOR) : COLOR { float4 lightColor = float4(1, 0, 0.5f, 1); return lightColor * color; } technique MyTechnique { pass MyPass { VertexShader = compile vs_2_0 MyVertexShader(); PixelShader = compile ps_2_0 MyPixelShader(); } }
struct VertexPositionColor { float4 Position : POSITION; float4 Color : COLOR; }; VertexPositionColor MyVertexShader(VertexPositionColor input) { 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(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class MyGame : Game { GraphicsDeviceManager graphics; 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); } protected override void LoadContent() { effect = Content.Load<Effect>("Content/MyEffect"); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3 ); } } }