Exemplo n.º 1
0
        void DrawDominateLights()
        {
            List <DominateLight> lights = null;

            LightingManager.GetLights <DominateLight>(out lights);

            if (lights != null)
            {
                for (int i = 0; i < lights.Count; i++)
                {
                    DominateLight light = lights[i];

                    if (light.Enabled)
                    {
                        quadRenderer.BindBuffer();

                        dominateLightEffect.Parameters["Colour"].SetValue(light.Colour);
                        dominateLightEffect.Parameters["Intensity"].SetValue(light.Intensity);
                        dominateLightEffect.Parameters["Direction"].SetValue(light.Direction);
                        dominateLightEffect.Parameters["SpecPow"].SetValue(light.SpecularPower);

                        dominateLightEffect.Parameters["NormalMap"].SetValue(normalTarget);

                        dominateLightEffect.CurrentTechnique.Passes[0].Apply();

                        Common.Device.BlendState = blendBlack;

                        quadRenderer.Draw();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Render()
        {
            QuadRenderer.Begin();
            float alpha = (10 - timer) / 10;

            QuadRenderer.DrawFullScreenGradient(new Color4(38f / 255, 38f / 255, 39f / 255, alpha), new Color4(70f / 255, 69f / 255, 70f / 255, alpha));

            Color4 color = new Color4(1, 1, 1, alpha);

            QuadRenderer.Draw(StartupLayer.logo, new Vector2(Display.Width / 2 - StartupLayer.logo.Width / 2, Display.Height / 2 - StartupLayer.logo.Height / 2 - 20 * alpha), color);

            QuadRenderer.End();
        }
Exemplo n.º 3
0
        public void Draw()
        {
            if (!initialized)
            {
                return;
            }
#if DEBUG
            //bool wasDirty = surface.IsDirty;
#endif
            if (surface.IsDirty)
            {
                DataRectangle rect = mappableSurface.Map(SharpDX.DXGI.MapFlags.Write);
                surface.CopyTo(rect.DataPointer, rect.Pitch, 4, false, false);
                mappableSurface.Unmap();
                Display.context.CopyResource(mappableTexture, webTex.Tex);
            }
            QuadRenderer.Draw(webTex, position, new Color4(1, 1, 1, 1));
#if DEBUG
            //FontRenderer.Draw(FontManager.Get("default"), "Dirty:"+wasDirty, new Vector2(position.X, position.Y), Color.White);
#endif
        }
Exemplo n.º 4
0
        private void UpdateBrush()
        {
            if (updateBrush)
            {
                Display.context.OutputMerger.SetTargets(brushRenderTarget);
                Display.context.ClearRenderTargetView(brushRenderTarget, Color.Transparent);

                QuadRenderer.Begin();
                Display.context.OutputMerger.BlendState = DeviceStates.blendStateDrawing;

                int    quality = 85;
                Color4 color   = new Color4(1, 1, 1, 1);
                color.Alpha = 0.012f;

                float size = 1;
                for (int i = 1; i <= quality; i++)
                {
                    size = ((100.0f - CurrentBrushSoftness) / 100) + ((float)i / quality) * (CurrentBrushSoftness / 100);
                    QuadRenderer.Draw(DefaultBrush, new Vector2(256 * (1 - size)), new Vector2(size), color);
                }

                QuadRenderer.End();

                Display.context.OutputMerger.SetTargets(Display.depthStencil, Display.renderTarget);
                GraphicsManager.Reset();

                CurrentBrush.ressource = new ShaderResourceView(Display.device, brushTexture);

                Display.context.CopyResource(brushTexture, brushTextureReadable);

                Surface surf = brushTextureReadable.QueryInterface <Surface>();

                DataStream    streamN;
                DataRectangle rect = surf.Map(SharpDX.DXGI.MapFlags.Read, out streamN);
                streamN.Position = 0;

                byte[] textureData = new byte[512 * 512 * 4];
                streamN.ReadRange(textureData, 0, textureData.Length);

                surf.Unmap();

                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                    512, 512,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb
                    );

                System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(
                    new System.Drawing.Rectangle(0, 0, 512, 512),
                    System.Drawing.Imaging.ImageLockMode.WriteOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppArgb
                    );

                IntPtr safePtr = bmpData.Scan0;
                System.Runtime.InteropServices.Marshal.Copy(textureData, 0, safePtr, textureData.Length);
                bmp.UnlockBits(bmpData);

                form.brushPreview.Image    = bmp;
                form.brushPreview.SizeMode = PictureBoxSizeMode.Zoom;


                updateBrush = false;
            }
        }
Exemplo n.º 5
0
        protected override void WinUpdate()
        {
            if (ForegroundGame.Map == null)
            {
                return;
            }

            UpdateBrush();

            Point pnt = new Point(InputHelper.mouseX, InputHelper.mouseY);

            bool canZoom = true;

            float realWheel = InputHelper.wheelDelta - deltaWheel;

            deltaWheel = InputHelper.wheelDelta;

            camera.ZoomLevel -= realWheel;
            if (camera.ZoomLevel < camera.minZoom)
            {
                camera.ZoomLevel = camera.minZoom;
                canZoom          = false;
            }
            else if (camera.ZoomLevel > 50)
            {
                camera.ZoomLevel = 50;
            }

            bool freezeDestination = false;

            if (updateWaterShader && !InputHelper.leftDown)
            {
                TerrainWater.Initialize();
                updateWaterShader = false;
            }

            //------------------------------------------------------------------------------------------------ SELECTION STUFF
            if ((currentTool == Tool.OBJECT_EDIT || currentTool == Tool.DECAL_EDIT) && InputHelper.altDown)
            {
                freezeDestination = true;
            }
            else if (currentTool != Tool.NOTHING && InputHelper.altDown && InputHelper.rightDown)
            {
                if (!LastRightClick)
                {
                    clickPos          = deltaPos = pnt;
                    lastBrushSize     = CurrentBrushSize;
                    lastBrushSoftness = CurrentBrushSoftness;
                }
                float dx   = pnt.X - deltaPos.X;
                float dy   = pnt.Y - deltaPos.Y;
                float dist = 1;

                if (destination != new Vector3(0, -99999, 0))
                {
                    dist  = Vector3.Distance(destination, camera.eyePosition);
                    dist /= ClientSize.Width / 2;
                }

                CurrentBrushSize = lastBrushSize + (dx * dist);

                if (CurrentBrushSize < 1)
                {
                    CurrentBrushSize = 1;
                }
                else if (CurrentBrushSize > 200)
                {
                    CurrentBrushSize = 200;
                }
                form.brushSize.Value = (int)CurrentBrushSize;

                CurrentBrushSoftness = lastBrushSoftness - (dy * dist);
                if (CurrentBrushSoftness < 0)
                {
                    CurrentBrushSoftness = 0;
                }
                else if (CurrentBrushSoftness > 100)
                {
                    CurrentBrushSoftness = 100;
                }
                form.brushSoftness.Value = (int)CurrentBrushSoftness;

                ChangeBrushProperties(CurrentBrushSize, CurrentBrushSoftness, CurrentBrushIntensity);
                freezeDestination = true;
            }
            else
            {
                CameraInputs(pnt);
            }

            Ray ray = CameraHelper.RayFromScreen(pnt.X, pnt.Y);

            if (!freezeDestination)
            {
                destination = ForegroundGame.Map.Pick(ray, false);
            }
            Vector2 size    = new Vector2(CurrentBrushSize / 512);
            Vector2 textPos = new Vector2(destination.X, destination.Z) + new Vector2(-256 + 256 * (1 - size.X));

            //------------------------------------------------------------------------------------------------ MODIFICATION AND TOOLS AND STUFF

            if (InputHelper.leftDown)
            {
                if (currentTool == Tool.PATHFINDING)
                {
                    #region Pathfinding
                    int roundedSize = (int)Math.Ceiling(CurrentBrushSize / 2);
                    int destX       = (int)Math.Round(destination.X, MidpointRounding.ToEven);
                    int destY       = (int)Math.Round(destination.Z, MidpointRounding.ToEven);

                    int width = (int)Math.Ceiling((float)Terrain.info.width / 2);

                    for (int x = -roundedSize; x < roundedSize; x++)
                    {
                        for (int y = -roundedSize; y < roundedSize; y++)
                        {
                            float power = (Vector2.Distance(Vector2.Zero, new Vector2(x, y)) / CurrentBrushSize) / 0.5f;

                            float limit = 1 - (CurrentBrushSoftness / 100);
                            power = (power - limit) / (1 - limit);
                            power = 1 - GameUtils.Clamp(power, 0, 1);

                            if (power > 0 && Terrain.InsideMap(destX + x, destY + y))
                            {
                                Point2D point = new Point2D((int)((destX + x) / 2), (int)((destY + y) / 2));//ForegroundGame.Map_Space.WorldToSpace(new Vector3());
                                Terrain.info.accessibilityArray[point.X + point.Y * width] = (byte)(CurrentBrushColor.Green == 0 ? 0 : 1);
                            }
                        }
                    }
                    #endregion
                }
                else if (currentTool == Tool.TEXTURE)
                {
                    #region Texture
                    Color4 colorAlphad = CurrentBrushColor;
                    colorAlphad.Alpha = CurrentBrushIntensity / 100;

                    Display.context.OutputMerger.SetTargets(drawableRenderTarget);
                    Display.context.ClearRenderTargetView(drawableRenderTarget, Color.Black);

                    QuadRenderer.Begin();
                    Display.context.OutputMerger.BlendState = DeviceStates.blendStateDrawing;
                    QuadRenderer.Draw(Terrain.info.TextureMap, new Vector2(0), Color.White);

                    QuadRenderer.Draw(CurrentBrush, textPos, size, colorAlphad);

                    QuadRenderer.End();

                    Display.context.OutputMerger.SetTargets(Display.depthStencil, Display.renderTarget);
                    GraphicsManager.Reset();

                    Texture2DDescription descHM = new Texture2DDescription()
                    {
                        ArraySize         = 1,
                        BindFlags         = BindFlags.ShaderResource,
                        CpuAccessFlags    = CpuAccessFlags.None,
                        Format            = Format.R8G8B8A8_UNorm,
                        Width             = Terrain.info.width,
                        Height            = Terrain.info.height,
                        MipLevels         = 1,
                        OptionFlags       = ResourceOptionFlags.None,
                        SampleDescription = new SampleDescription(1, 0),
                        Usage             = ResourceUsage.Default,
                    };

                    Terrain.info.TextureMap.Tex.Dispose();
                    Terrain.info.TextureMap.ressource.Dispose();
                    Terrain.info.TextureMap.Tex = new Texture2D(Display.device, descHM);
                    Display.context.CopyResource(drawableTexture, Terrain.info.TextureMap.Tex);
                    Terrain.info.TextureMap.RecreateSRV();
                    modifiedTextureMap = true;
                    #endregion
                }
                else if (currentTool == Tool.COLOR)
                {
                    #region Color
                    Color4 colorAlphad = CurrentBrushColor;
                    colorAlphad.Alpha = CurrentBrushIntensity / 100;

                    Display.context.OutputMerger.SetTargets(drawableRenderTarget);
                    Display.context.ClearRenderTargetView(drawableRenderTarget, Color.Black);

                    QuadRenderer.Begin();
                    Display.context.OutputMerger.BlendState = DeviceStates.blendStateDrawing;
                    QuadRenderer.Draw(Terrain.info.ColorMap, new Vector2(0), Color.White);

                    QuadRenderer.Draw(CurrentBrush, textPos, size, colorAlphad);

                    QuadRenderer.End();

                    Display.context.OutputMerger.SetTargets(Display.depthStencil, Display.renderTarget);
                    GraphicsManager.Reset();

                    Texture2DDescription descHM = new Texture2DDescription()
                    {
                        ArraySize         = 1,
                        BindFlags         = BindFlags.ShaderResource,
                        CpuAccessFlags    = CpuAccessFlags.None,
                        Format            = Format.R8G8B8A8_UNorm,
                        Width             = Terrain.info.width,
                        Height            = Terrain.info.height,
                        MipLevels         = 1,
                        OptionFlags       = ResourceOptionFlags.None,
                        SampleDescription = new SampleDescription(1, 0),
                        Usage             = ResourceUsage.Default,
                    };

                    Terrain.info.ColorMap.Tex.Dispose();
                    Terrain.info.ColorMap.Tex = new Texture2D(Display.device, descHM);
                    Display.context.CopyResource(drawableTexture, Terrain.info.ColorMap.Tex);
                    Terrain.info.ColorMap.RecreateSRV();
                    modifiedColorMap = true;
                    #endregion
                }
                else if (currentTool == Tool.LANDSCAPE_DOWN || currentTool == Tool.LANDSCAPE_UP || currentTool == Tool.LANDSCAPE_SET || currentTool == Tool.LANDSCAPE_SMOOTH)
                {
                    #region Terraforming

                    if (!LastClick && currentTool == Tool.LANDSCAPE_SET && !form.customSetValue.Checked)
                    {
                        form.levelTo.Value = (decimal)destination.Y;
                    }

                    int destX = (int)Math.Round(destination.X, MidpointRounding.ToEven);
                    int destY = (int)Math.Round(destination.Z, MidpointRounding.ToEven);


                    int roundedSize = (int)Math.Ceiling(CurrentBrushSize / 2);

                    if (currentTool == Tool.LANDSCAPE_SMOOTH)
                    {
                        listForSmoothing = new List <float[]>(roundedSize * roundedSize * 2 * 2);
                    }

                    for (int x = -roundedSize; x < roundedSize; x++)
                    {
                        for (int y = -roundedSize; y < roundedSize; y++)
                        {
                            float power = (Vector2.Distance(Vector2.Zero, new Vector2(x, y)) / CurrentBrushSize) / 0.5f;

                            float limit = 1 - (CurrentBrushSoftness / 100);
                            power = (power - limit) / (1 - limit);
                            power = 1 - GameUtils.Clamp(power, 0, 1);

                            if (power > 0 && Terrain.InsideMap(destX + x, destY + y))
                            {
                                float height = Terrain.vertices[destX + x + (destY + y) * Terrain.info.width].Position.Y;

                                switch (currentTool)
                                {
                                case Tool.LANDSCAPE_UP:
                                    height += CurrentBrushIntensity / 100 * power;
                                    Terrain.ChangeHeight(destX + x, destY + y, height);
                                    break;

                                case Tool.LANDSCAPE_DOWN:
                                    height -= CurrentBrushIntensity / 100 * power;
                                    Terrain.ChangeHeight(destX + x, destY + y, height);
                                    break;

                                case Tool.LANDSCAPE_SET:
                                    Terrain.ChangeHeight(destX + x, destY + y, GameUtils.Lerp(height, HeightLevelSetBrush, power));
                                    break;

                                case Tool.LANDSCAPE_SMOOTH:
                                    listForSmoothing.Add(new float[] { destX + x, destY + y, CurrentBrushIntensity / 100 * power });
                                    break;
                                }
                            }
                        }
                    }
                    if (currentTool == Tool.LANDSCAPE_SMOOTH)
                    {
                        Terrain.SmoothHeight(listForSmoothing);
                    }


                    DataStream stream;
                    Display.context.MapSubresource(Terrain.vertexBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out stream);
                    stream.WriteRange(Terrain.vertices);
                    Display.context.UnmapSubresource(Terrain.vertexBuffer, 0);

                    updateWaterShader = true;
                    #endregion
                }
            }


            LastClick       = InputHelper.leftDown;
            LastMiddleClick = InputHelper.middleDown;
            LastRightClick  = InputHelper.rightDown;
        }
Exemplo n.º 6
0
        public void Render2D()
        {
            Vector2 pos;
            float   length = 0;
            Vector2 pos2D;

            for (int i = 0; i < list.Count; i++)
            {
                InteractiveObject2D obj = list[i];

                CameraHelper.Convert3DPointTo2D(obj.entity.IntObj3D.Position, out pos);
                obj.position.X = (int)pos.X;
                obj.position.Y = (int)pos.Y;
                if (!StrategicMode)
                {
                    length         = Vector3.Distance(SceneManager.Camera.eyePosition, obj.entity.IntObj3D.Position);
                    obj.rect.Width = obj.rect.Height = (int)(16 * (obj.bracketSize * 120 / length));
                    obj.rect.X     = (int)(pos.X - (float)obj.rect.Height / 2);
                    obj.rect.Y     = (int)(pos.Y - (float)obj.rect.Height / 2);
                }
                else
                {
                    obj.rect.Width = obj.rect.Height = 16;
                    obj.rect.X     = (int)pos.X - 7;
                    obj.rect.Y     = (int)pos.Y - 7;
                }
                obj.onScreen = obj.rect.Right > 0 && obj.rect.Bottom > 0 && obj.rect.Left < Display.Width && obj.rect.Top < Display.Height;
                if (!obj.onScreen)
                {
                    continue;
                }

                //DEBUG SELECTION RECTANGLE
                //QuadRenderer.Draw(Resources.GetEmptyTexture(), new SharpDX.Rectangle(obj.rect.X, obj.rect.Y, obj.rect.Width, obj.rect.Height), new Color4(0, 1, 1, 0.2f));


                if (!StrategicMode)
                {
                    // DRAW PROGRESS BARS

                    /*if (obj.progress != -1) {
                     *  //if (obj.side != Main.network.me.id) continue;
                     *  float size = obj.bracketSize * 1000 / length;
                     *  Vector2 posBar = new Vector2(pos.X - size, pos.Y + 5 + size);
                     *  Vector2 sizeBar = new Vector2(size * 2, 2);
                     *  Vector2 progressBar = new Vector2(size * 2 * ((float)obj.progress / 10000), 2)*0.25f;
                     *  QuadRenderer.Draw(Resources.GetEmptyTexture(), posBar - new Vector2(1, 1), (sizeBar + new Vector2(2, 2))*0.25f, Color.Black);
                     *
                     *  QuadRenderer.Draw(Resources.GetEmptyTexture(), posBar, progressBar, Color.Cyan);
                     *  posBar.Y += 2;
                     *  FontRenderer.Draw("default", obj.progress_text, posBar + new Vector2(1, 1), Color.Black);
                     *  FontRenderer.Draw("default", obj.progress_text, posBar, Color.White);
                     * }*/
                    if (obj.selected || obj.focused)
                    {
                        SharpDX.Rectangle rect = new SharpDX.Rectangle(obj.rect.X, obj.rect.Y + obj.rect.Height, obj.rect.Width, 3);
                        QuadRenderer.Draw(Resources.GetEmptyTexture(), rect, Color.Black);

                        rect.Right = (int)(rect.Right * ((float)obj.entity.Health / obj.entity.HealthMax));
                        QuadRenderer.Draw(Resources.GetEmptyTexture(), rect, Color.LightGreen);
                    }
                }
                else
                {
                    // DRAW STRATEGIC ICON OUTLINES
                    pos2D.X = pos.X - 7;
                    pos2D.Y = pos.Y - 7;

                    if (obj.iconId != -1 && !obj.selected && !obj.focused)
                    {
                        QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 32, 16, 16), Color.Black);
                    }
                }
            }

            if (!StrategicMode)
            {
                return;
            }

            // STRATEGIC ICONS with over the outlines
            //------------------------------------------

            foreach (InteractiveObject2D obj in list)
            {
                if (!obj.onScreen || obj.iconId == -1)
                {
                    continue;
                }
                pos2D.X = obj.position.X - 7;
                pos2D.Y = obj.position.Y - 7;

                Color4 color = Color.LimeGreen;//Main.network.players.GetColor(obj.side);
                QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 0, 16, 16), color);
            }

            // SELECTED UNITS HAVE TO BE RENDERED ON TOP
            //------------------------------------------

            foreach (InteractiveObject2D obj in list)
            {
                if (!obj.onScreen || obj.iconId == -1 || (!obj.selected && !obj.focused))
                {
                    continue;
                }
                pos2D.X = obj.position.X - 7;
                pos2D.Y = obj.position.Y - 7;
                Color4 color = Color.Black;
                if (obj.selected)
                {
                    color = Color.White;
                }
                else if (obj.focused)
                {
                    color = Color.LimeGreen; //Main.network.players.GetColor(obj.side);
                }
                QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 32, 16, 16), color);
            }
            foreach (InteractiveObject2D obj in list)
            {
                if (!obj.onScreen || obj.iconId == -1 || (!obj.selected && !obj.focused))
                {
                    continue;
                }
                pos2D.X = obj.position.X - 7;
                pos2D.Y = obj.position.Y - 7;

                Color4 color = Color.LimeGreen; //Main.network.players.GetColor(obj.side);
                QuadRenderer.Draw(ForegroundGame.startegicIcons, new SharpDX.Rectangle((int)pos2D.X, (int)pos2D.Y, 16, 16), new SharpDX.Rectangle(obj.iconId, 0, 16, 16), color);
            }
        }
 /// <summary>
 /// Clear GBuffer.
 /// </summary>
 private void ClearGBuffer()
 {
     graphicsDevice.BlendState = BlendState.Opaque;
     clearBufferEffect.Techniques[0].Passes[0].Apply();
     quadRenderer.Draw(graphicsDevice);
 }