public void Draw() { Memory.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; Memory.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; Memory.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Memory.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; using (AlphaTestEffect ate = new AlphaTestEffect(Memory.graphics.GraphicsDevice) { Projection = projectionMatrix, View = viewMatrix, World = worldMatrix }) using (BasicEffect effect = new BasicEffect(Memory.graphics.GraphicsDevice) { TextureEnabled = true }) { for (int n = 0; n < (modelGroups?.Count ?? 0); n++) { foreach (Model b in modelGroups[n]) { GeometryVertexPosition vpt = GetVertexBuffer(b); if (n == 3 && skyRotators[Memory.Encounters.Scenario] != 0) { CreateRotation(vpt); } if (vpt == null) { continue; } int localVertexIndex = 0; for (int i = 0; i < vpt.GeometryInfoSupplier.Length; i++) { ate.Texture = (Texture2D)textures[vpt.GeometryInfoSupplier[i].clut]; //provide texture per-face foreach (EffectPass pass in ate.CurrentTechnique.Passes) { pass.Apply(); if (vpt.GeometryInfoSupplier[i].bQuad) { Memory.graphics.GraphicsDevice.DrawUserPrimitives(primitiveType: PrimitiveType.TriangleList, vertexData: vpt.VertexPositionTexture, vertexOffset: localVertexIndex, primitiveCount: 2); localVertexIndex += 6; } else { Memory.graphics.GraphicsDevice.DrawUserPrimitives(primitiveType: PrimitiveType.TriangleList, vertexData: vpt.VertexPositionTexture, vertexOffset: localVertexIndex, primitiveCount: 1); localVertexIndex += 3; } } } } } } }
/// <summary> /// Moves sky /// </summary> /// <param name="vpt"></param> private void CreateRotation(GeometryVertexPosition vpt) { localRotator += (short)skyRotators[Memory.Encounters.Scenario] / 4096f * Memory.gameTime.ElapsedGameTime.Milliseconds; if (localRotator <= 0) { return; } for (int i = 0; i < vpt.VertexPositionTexture.Length; i++) { vpt.VertexPositionTexture[i].Position = Vector3.Transform(vpt.VertexPositionTexture[i].Position, Matrix.CreateRotationY(MathHelper.ToRadians(localRotator))); } }
public void Draw() { Memory.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; Memory.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; Memory.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default; Memory.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; //Memory.graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone; using (AlphaTestEffect ate = new AlphaTestEffect(Memory.graphics.GraphicsDevice) { Projection = projectionMatrix, View = viewMatrix, World = worldMatrix, }) using (BasicEffect effect = new BasicEffect(Memory.graphics.GraphicsDevice) { TextureEnabled = true, }) { //var models = (from modelgroup in modelGroups // where (modelgroup?.Count ?? 0) > 0 // from model in modelgroup // where model.quads != null && model.triangles != null && model.vertices != null // select model); int[] order = new int[] { 3, 0, 1, 2 }; foreach (int n in order.Where(x => x < (modelGroups?.Count ?? 0))) { foreach (Model b in modelGroups[n]) { GeometryVertexPosition vpt = GetVertexBuffer(b); if (n == 3 && skyRotators[Memory.Encounters.Scenario] != 0) { CreateRotation(vpt); } if (vpt == null) { continue; } int localVertexIndex = 0; foreach (GeometryInfoSupplier gis in vpt.GeometryInfoSupplier.Where(x => !x.GPU.HasFlag(GPU.v2_add))) { Memory.graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend; process(gis); } //BlendState bs = new BlendState //{ // //ColorWriteChannels = ColorWriteChannels.Blue | ColorWriteChannels.Green | ColorWriteChannels.Red, // ColorSourceBlend = Blend.One, // AlphaSourceBlend = Blend.One, // ColorDestinationBlend = Blend.InverseSourceColor, // AlphaDestinationBlend = Blend.One, // ColorBlendFunction = BlendFunction.Max //}; foreach (GeometryInfoSupplier gis in vpt.GeometryInfoSupplier.Where(x => x.GPU.HasFlag(GPU.v2_add))) { Memory.graphics.GraphicsDevice.BlendState = Memory.blendState_Add;//bs; process(gis); } // bs?.Dispose(); void process(GeometryInfoSupplier gis) { ate.Texture = (Texture2D)textures[gis.clut]; //provide texture per-face foreach (EffectPass pass in ate.CurrentTechnique.Passes) { pass.Apply(); if (gis.bQuad) { Memory.graphics.GraphicsDevice.DrawUserPrimitives(primitiveType: PrimitiveType.TriangleList, vertexData: vpt.VertexPositionTexture, vertexOffset: localVertexIndex, primitiveCount: 2); localVertexIndex += 6; } else { Memory.graphics.GraphicsDevice.DrawUserPrimitives(primitiveType: PrimitiveType.TriangleList, vertexData: vpt.VertexPositionTexture, vertexOffset: localVertexIndex, primitiveCount: 1); localVertexIndex += 3; } } } } } } }