public override void ProcessSystem() { var camera = EntityWorld.GetActiveCamera(); var viewRect = camera.GetViewRect(1.0f); var device = _batch.GraphicsDevice; Vertex3CTN vtx = new Vertex3CTN(); vtx.Color = Color.White; vtx.Normal = Vector3.Forward; var origSampleState = _batch.GraphicsDevice.SamplerStates[0]; device.SamplerStates[0] = SamplerState.LinearWrap; device.BlendState = BlendState.Additive; device.RasterizerState = RasterizerState.CullNone; vtx.Position = new Vector3(viewRect.Left, viewRect.Top, 0); vtx.TextureCoords = _dustTexture.GetUV(viewRect.Left, viewRect.Top); _quad[0] = vtx; vtx.Position = new Vector3(viewRect.Left, viewRect.Bottom, 0); vtx.TextureCoords = _dustTexture.GetUV(viewRect.Left, viewRect.Bottom); _quad[1] = vtx; vtx.Position = new Vector3(viewRect.Right, viewRect.Top, 0); vtx.TextureCoords = _dustTexture.GetUV(viewRect.Right, viewRect.Top); _quad[2] = vtx; vtx.Position = new Vector3(viewRect.Right, viewRect.Bottom, 0); vtx.TextureCoords = _dustTexture.GetUV(viewRect.Right, viewRect.Bottom); _quad[3] = vtx; Matrix matrix = Matrix.Identity; _batch.Begin(effect: camera.SpriteBatchBasicEffect); _batch.DrawVertices(_dustTexture, _quad, _quadIndices, ref matrix); _batch.End(); _batch.GraphicsDevice.SamplerStates[0] = origSampleState; }
public void Draw(SpriteComponent sprite, ref Matrix transform, Color[] colors, Vector3[] normals) { Vertex3CTN vtx = new Vertex3CTN(); if (colors == null) throw new ArgumentException(nameof(colors)); if(normals == null) throw new ArgumentException(nameof(normals)); var tex = sprite.Texture; Vector2 texCoordLT = tex.GetUV(sprite.TextureRect.Left, sprite.TextureRect.Top); Vector2 texCoordBR = tex.GetUV(sprite.TextureRect.Right, sprite.TextureRect.Bottom); vtx.Position = Vector3.Zero; vtx.TextureCoords = texCoordLT; vtx.Color = colors[0]; vtx.Normal = normals[0]; _quadVertices[0] = vtx; vtx.Position = new Vector3(0, sprite.TextureRect.Height, 0); vtx.TextureCoords = new Vector2(texCoordLT.X, texCoordBR.Y); vtx.Color = colors[1]; vtx.Normal = normals[1]; _quadVertices[1] = vtx; vtx.Position = new Vector3(sprite.TextureRect.Width, 0, 0); vtx.TextureCoords = new Vector2(texCoordBR.X, texCoordLT.Y); vtx.Color = colors[2]; vtx.Normal = normals[2]; _quadVertices[2] = vtx; vtx.Position = new Vector3(sprite.TextureRect.Width, sprite.TextureRect.Height, 0); vtx.TextureCoords = texCoordBR; vtx.Color = colors[3]; vtx.Normal = normals[3]; _quadVertices[3] = vtx; DrawVertices(tex, _quadVertices, _quadIndices, ref transform); }
public void DrawVertices(Texture2D texture, Vertex3CTN[] vertices, int[] indices, ref Matrix transform) { if (_texture == null) _texture = texture; if (_texture != texture) { RenderImpl(texture); _vertexCount = 0; _indexCount = 0; _texture = texture; } EnsureSpace(indices.Length, vertices.Length); int baseIndex = _vertexCount; for (int i = 0; i < vertices.Length; i++) { var vtx = vertices[i]; Vector3.Transform(ref vtx.Position, ref transform, out vtx.Position); if (Math.Abs(vtx.Position.Z) > float.Epsilon) throw new InvalidProgramException(); _vertices[_vertexCount++] = vtx; } for(int i = 0; i < indices.Length; i++) { _indices[_indexCount++] = indices[i] + baseIndex; } }