ビルボードでキラキラ色加算
■色加算の大好きな私は、ビルボードを使っていろいろと光らせてみました。
「kira.x」
xof 0302txt 0064 Mesh { 4; -1.00000;1.00000;0.00000;, 1.00000;1.00000;0.00000;, 1.00000;-1.00000;0.00000;, -1.00000;-1.00000;0.00000;; 1; 4;0,1,2,3;; MeshTextureCoords { 4; 0.00000;0.00000;, 1.00000;0.00000;, 1.00000;1.00000;, 0.00000;1.00000;; } MeshMaterialList { 1; 1; 0; Material { 1.000000;1.000000;1.000000;1.000000;; 0.000000; 0.000000;0.000000;0.000000;; 0.000000;0.000000;0.000000;; TextureFilename { "kira.png"; } } } }
テクスチャは
「kira.png」
■でプログラムが
namespace WindowsGame2_09 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; private float dAngX = 0; private float dAngY = 0; private Model model; private Matrix mainView; private Matrix mainWorld; private Matrix mainProjection; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { model = Content.Load<Model>("kira"); mainProjection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height, 1.0f, 100.0f ); mainWorld = Matrix.CreateTranslation(0, 0, 0); base.Initialize(); } protected override void Update(GameTime gameTime) { dAngX += 0.01f; if (dAngX > 3.141592f * 2) dAngX -= 3.141592f * 2; dAngY += 0.03f; if (dAngY > 3.141592f * 2) dAngY -= 3.141592f * 2; mainView = Matrix.CreateRotationX(dAngX) * Matrix.CreateRotationY(dAngY) * Matrix.CreateLookAt( new Vector3(30.0f, 15.0f, 0.0f), new Vector3(0, 0, 0), Vector3.Up); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { Matrix viewInvert = Matrix.Invert(mainView); viewInvert.M14 = 0.0f; viewInvert.M24 = 0.0f; viewInvert.M34 = 0.0f; viewInvert.M41 = 0.0f; viewInvert.M42 = 0.0f; viewInvert.M43 = 0.0f; viewInvert.M44 = 1.0f; graphics.GraphicsDevice.Clear(Color.Black); //色加算設定 graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; //デプス設定をOFF graphics.GraphicsDevice.RenderState.DepthBufferEnable = false; for (int k = -4; k < 5; k++) { for (int j = -4; j < 5; j++) { for (int i = -4; i < 5; i++) { mainWorld = viewInvert * Matrix.CreateTranslation(i * 2.5f, j * 2.5f, k * 2.5f); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.View = mainView; effect.World = mainWorld; effect.Projection = mainProjection; } mesh.Draw(); } } } } base.Draw(gameTime); } } }
■今回は色加算なのでこの3行が必要になります。
graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true;
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
ポリゴンのソートをするのがめんどくさいのでデプスをfalseにしておきます。
graphics.GraphicsDevice.RenderState.DepthBufferEnable = false;