CreateEffect() public method

public CreateEffect ( ) : BasicEffect
return Microsoft.Xna.Framework.Graphics.BasicEffect
Beispiel #1
0
        public void Build(RTSRenderer renderer, string image, Vector3 radii, Vector3 heights)
        {
            fx = renderer.CreateEffect();

            fx.FogEnabled         = false;
            fx.VertexColorEnabled = false;
            fx.LightingEnabled    = false;
            fx.TextureEnabled     = true;

            if (image == null || !File.Exists(image))
            {
                Texture = renderer.CreateTexture2D(3, 3, SurfaceFormat.Color, false);
                Texture.SetData(new Color[] {
                    Color.White, Color.Transparent, Color.White,
                    Color.Transparent, Color.Transparent, Color.Transparent,
                    Color.White, Color.Transparent, Color.White
                });
            }
            else
            {
                Texture = renderer.LoadTexture2D(image);
            }
            fx.Texture = Texture;

            VertexPositionTexture[] verts = new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(1f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(1f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 1f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 1f))
            };
            int[] inds = new int[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            };
            for (int i = 0; i < 4; i++)
            {
                verts[i].Position     *= new Vector3(radii.X, heights.X, radii.X);
                verts[i + 4].Position *= new Vector3(radii.Y, heights.Y, radii.Y);
                verts[i + 8].Position *= new Vector3(radii.Z, heights.Z, radii.Z);
            }

            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);
        }
        public void Build(RTSRenderer renderer, string image, Vector3 radii, Vector3 heights)
        {
            fx = renderer.CreateEffect();

            fx.FogEnabled = false;
            fx.VertexColorEnabled = false;
            fx.LightingEnabled = false;
            fx.TextureEnabled = true;

            if(image == null || !File.Exists(image)) {
                Texture = renderer.CreateTexture2D(3, 3, SurfaceFormat.Color, false);
                Texture.SetData(new Color[] {
                    Color.White, Color.Transparent, Color.White,
                    Color.Transparent, Color.Transparent, Color.Transparent,
                    Color.White, Color.Transparent, Color.White
                });
            }
            else {
                Texture = renderer.LoadTexture2D(image);
            }
            fx.Texture = Texture;

            VertexPositionTexture[] verts = new VertexPositionTexture[] {
                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0.5f, 0)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(1f, 0)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(1f, 0.5f)),

                new VertexPositionTexture(new Vector3(-1, 1f, -1), new Vector2(0, 0.5f)),
                new VertexPositionTexture(new Vector3(1, 1f, -1), new Vector2(0.5f, 0.5f)),
                new VertexPositionTexture(new Vector3(-1, 1f, 1), new Vector2(0, 1f)),
                new VertexPositionTexture(new Vector3(1, 1f, 1), new Vector2(0.5f, 1f))
            };
            int[] inds = new int[] {
                0, 1, 2, 2, 1, 3,
                4, 5, 6, 6, 5, 7,
                8, 9, 10, 10, 9, 11
            };
            for(int i = 0; i < 4; i++) {
                verts[i].Position *= new Vector3(radii.X, heights.X, radii.X);
                verts[i + 4].Position *= new Vector3(radii.Y, heights.Y, radii.Y);
                verts[i + 8].Position *= new Vector3(radii.Z, heights.Z, radii.Z);
            }

            vb = renderer.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, verts.Length, BufferUsage.WriteOnly);
            vb.SetData(verts);
            ib = renderer.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, inds.Length, BufferUsage.WriteOnly);
            ib.SetData(inds);
        }
Beispiel #3
0
        public void Hook(RTSRenderer renderer, GameState s, int ti)
        {
            ImageWidth  = s.CGrid.numCells.X;
            ImageHeight = s.CGrid.numCells.Y;
            Terrain     = renderer.CreateRenderTarget2D(ImageWidth, ImageHeight, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, RenderTargetUsage.DiscardContents);
            TeamIndex   = ti;
            Team        = s.teams[TeamIndex];

            Vector3 center = new Vector3(s.CGrid.size.X * 0.5f, 0, s.CGrid.size.Y * 0.5f);

            float h = Grey.Vox.Region.HEIGHT + Camera.INITIAL_HIGH_SETTINGS.MaxDistance;

            mV  = Matrix.CreateLookAt(center + Vector3.Up * (h + 1f), center, -Vector3.UnitZ);
            mP  = Matrix.CreateOrthographic(s.CGrid.size.X, s.CGrid.size.Y, 0, h + 2f);
            mVP = mV * mP;

            fxCamera = renderer.CreateEffect();
            fxCamera.LightingEnabled    = false;
            fxCamera.FogEnabled         = false;
            fxCamera.TextureEnabled     = false;
            fxCamera.VertexColorEnabled = true;
            fxCamera.View       = mV;
            fxCamera.Projection = mP;
            fxCamera.World      = Matrix.Identity;

            mapPlanes = new Plane[6];
            float off = s.CGrid.size.Length() * 0.25f;

            mapPlanes[0] = new Plane(Vector3.UnitX, off);
            mapPlanes[1] = new Plane(Vector3.UnitY, 0);
            mapPlanes[2] = new Plane(Vector3.UnitZ, off);
            mapPlanes[3] = new Plane(-Vector3.UnitX, s.CGrid.size.X + off);
            mapPlanes[4] = new Plane(-Vector3.UnitY, h + 2f);
            mapPlanes[5] = new Plane(-Vector3.UnitZ, s.CGrid.size.Y + off);

            refreshFOW           = true;
            s.CGrid.OnFOWChange += (x, y, p, f) => {
                refreshFOW = refreshFOW | (p == ti);
            };

            TeamMap   = renderer.CreateTexture2D(s.CGrid.numCells.X, s.CGrid.numCells.Y, SurfaceFormat.Color, false);
            qSeen     = new Queue <SeenEntity>();
            tbScanner = new TimeBudget(SCAN_BINS);
            float r = (float)s.CGrid.numCells.X / SCAN_BINS;

            for (int i = 0; i < SCAN_BINS - 1; i++)
            {
                tbScanner.AddTask(new ScanTask((int)(r * i), (int)(r * (i + 1)), s.CGrid, Team, qSeen));
            }
            tbScanner.AddTask(new ScanTask((int)(r * (SCAN_BINS - 1)), s.CGrid.numCells.X, s.CGrid, Team, qSeen));
        }
Beispiel #4
0
        public void Hook(RTSRenderer renderer, GameState s, int ti)
        {
            ImageWidth = s.CGrid.numCells.X;
            ImageHeight = s.CGrid.numCells.Y;
            Terrain = renderer.CreateRenderTarget2D(ImageWidth, ImageHeight, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, RenderTargetUsage.DiscardContents);
            TeamIndex = ti;
            Team = s.teams[TeamIndex];

            Vector3 center = new Vector3(s.CGrid.size.X * 0.5f, 0, s.CGrid.size.Y * 0.5f);

            float h = Grey.Vox.Region.HEIGHT + Camera.INITIAL_HIGH_SETTINGS.MaxDistance;
            mV = Matrix.CreateLookAt(center + Vector3.Up * (h + 1f), center, -Vector3.UnitZ);
            mP = Matrix.CreateOrthographic(s.CGrid.size.X, s.CGrid.size.Y, 0, h + 2f);
            mVP = mV * mP;

            fxCamera = renderer.CreateEffect();
            fxCamera.LightingEnabled = false;
            fxCamera.FogEnabled = false;
            fxCamera.TextureEnabled = false;
            fxCamera.VertexColorEnabled = true;
            fxCamera.View = mV;
            fxCamera.Projection = mP;
            fxCamera.World = Matrix.Identity;

            mapPlanes = new Plane[6];
            float off = s.CGrid.size.Length() * 0.25f;
            mapPlanes[0] = new Plane(Vector3.UnitX, off);
            mapPlanes[1] = new Plane(Vector3.UnitY, 0);
            mapPlanes[2] = new Plane(Vector3.UnitZ, off);
            mapPlanes[3] = new Plane(-Vector3.UnitX, s.CGrid.size.X + off);
            mapPlanes[4] = new Plane(-Vector3.UnitY, h + 2f);
            mapPlanes[5] = new Plane(-Vector3.UnitZ, s.CGrid.size.Y + off);

            refreshFOW = true;
            s.CGrid.OnFOWChange += (x, y, p, f) => {
                refreshFOW = refreshFOW | (p == ti);
            };

            TeamMap = renderer.CreateTexture2D(s.CGrid.numCells.X, s.CGrid.numCells.Y, SurfaceFormat.Color, false);
            qSeen = new Queue<SeenEntity>();
            tbScanner = new TimeBudget(SCAN_BINS);
            float r = (float)s.CGrid.numCells.X / SCAN_BINS;
            for(int i = 0; i < SCAN_BINS - 1; i++) {
                tbScanner.AddTask(new ScanTask((int)(r * i), (int)(r * (i + 1)), s.CGrid, Team, qSeen));
            }
            tbScanner.AddTask(new ScanTask((int)(r * (SCAN_BINS - 1)), s.CGrid.numCells.X, s.CGrid, Team, qSeen));
        }