教科書をXNAゲームプログラミング で勉強してるけど、こいつ3.0対応で、4.0でかなり勝手が変わってる。
ある程度は参考になるけど、実質は Memeplexes見たほうが良さそう。
ということで、勉強中。
で、両方のハイブリッドを作る俺。頂点を作成しとく。
BasicEffect effect; VertexPositionColor[] vertexes = new [] { new VertexPositionColor( new Vector3(0, 0.5F, 0), new Color(0xFF, 0, 0, 0xFF)), new VertexPositionColor( new Vector3(0.5F, -0.5F, 0), new Color(0xFF, 0, 0, 0x80)), new VertexPositionColor( new Vector3(-0.5F, -0.5F, 0), new Color(0xFF, 0, 0, 0x00)), new VertexPositionColor( new Vector3(0, -0.5F, 0), new Color(0, 0, 0xFF, 0xFF)), new VertexPositionColor( new Vector3(-0.5F, 0.5F, 0), new Color(0, 0, 0xFF, 0x80)), new VertexPositionColor( new Vector3(0.5F, 0.5F, 0), new Color(0, 0, 0xFF, 0x0)), };
で、必要なBasicEffectの初期化
this.effect = new BasicEffect(this.GraphicsDevice); this.effect.VertexColorEnabled = true; this.effect.View = Matrix.CreateLookAt( new Vector3(0, 0, 3), new Vector3(0, 0, 0), Vector3.Transform( Vector3.Up, Matrix.CreateRotationZ(0))); this.effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), this.GraphicsDevice.Viewport.AspectRatio, 1, 100);
Dispose は割愛するとして、作画直前に AlphaBlend を設定する。
this.GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (var pass in this.effect.CurrentTechnique.Passes) { pass.Apply(); this.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.TriangleList, this.vertexes, 0, 2); }
Additive と AlphaBlend では結果が異なってて、Additive の場合はRGB値を足し算してくらしいので、白に対しては何を足しても白になる。逆にAlpaBlendは逆の動作なのかなーと。
普通にテクスチャ貼るときに、GraphicsDevice.DepthStencilStateプロパティをDepthStencilState.Noneで設定すると深度バッファ無効になって後ろのテクスチャも表示されるようになるそうな。
これヴェールの一部とか、透ける布の表現難しそうな、、、、。