Beispiel #1
0
 internal override void Draw(SpriteBatch sb, DebugStrings ds, int order, StereoEye stereoEye)
 {
     if (order == _order)
     {
         Draw(sb, ds, stereoEye);
     }
 }
 internal override void Draw(SpriteBatch sb, DebugStrings ds, int order, StereoEye stereoEye)
 {
     foreach (VisibleObject obj in collection)
     {
         obj.Draw(sb, ds, order, stereoEye);
     }
 }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        internal void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            if (spriteCount == 0)
            {
                return;
            }

            if (dirty)
            {
                //	realloc buffers in necessary
                if (vertices.Count > capacity * VertexPerSprite)
                {
                    var newCapacity = MathUtil.IntDivRoundUp(vertices.Count / VertexPerSprite, 64) * 64;

                    ReallocGpuBuffers(newCapacity);
                }

                vertexBuffer.SetData(vertices.ToArray());

                framesBuffer.SetData(framesData);

                dirty = false;
            }


            rs.Device.PixelShaderConstants[1] = framesBuffer;
            rs.Device.SetupVertexInput(vertexBuffer, null);


            foreach (var group in groups)
            {
                rs.Device.PixelShaderResources[0] = group.Texture.Srv;
                rs.Device.Draw(group.SpriteCount * VertexPerSprite, group.StartSprite * VertexPerSprite);
            }
        }
        public override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            int w = Game.GraphicsDevice.DisplayBounds.Width;
            int h = Game.GraphicsDevice.DisplayBounds.Height;

            var sb   = Game.GetService <SpriteBatch>();
            var rand = new Random();

            // Game.GraphicsDevice.ClearBackbuffer(Color4.Black);
            Game.GraphicsDevice.ClearBackbuffer(Color4.White);

            sb.Begin();

            foreach (var cell in Field)
            {
                var coord = new Vector2();
                cell.cartCoord(out coord);
                var xTopLeft = w / 2 + coord.X - hexW / 2;
                var yTopLeft = h / 2 + coord.Y - hexH / 2;
                sb.Draw(hex, xTopLeft, yTopLeft, hexW, hexH, (cell.mark == cellStatus.OPENED) ? new Color(132, 204, 129) : new Color(75, 70, 105));
                switch (cell.mark)
                {
                case cellStatus.FLAG:
                    sb.Draw(flag, xTopLeft + 0.2f * hexW, yTopLeft + 0.2f * hexH, hexW * 0.6f, hexH * 0.6f, Color.White);
                    break;

                case cellStatus.QUESTION:
                    sb.Draw(question, xTopLeft, yTopLeft, hexW, hexH, Color.White);
                    break;

                case cellStatus.OPENED:
                    // if (cell.bombNeighboursCount > 0) font.DrawString(sb, cell.bombNeighboursCount.ToString(), xTopLeft + 0.5f * (hexW - font.MeasureString(cell.bombNeighboursCount.ToString()).Width), yTopLeft + 0.5f * (hexH + font.AverageCapitalLetterHeight), Color.Black);
                    if (cell.bombNeighboursCount > 0)
                    {
                        font.DrawString(sb, cell.bombNeighboursCount.ToString(), xTopLeft + 0.5f * (hexW - font.MeasureString(cell.bombNeighboursCount.ToString()).Width), yTopLeft + 0.5f * (hexH + 10), Color.Black);
                    }
                    break;
                }
                if (status != gameStatus.CONTINUES && cell.hasBomb)
                {
                    sb.Draw(bomb, xTopLeft + 0.2f * hexW, yTopLeft + 0.2f * hexH, hexW * 0.6f, hexH * 0.6f, Color.White);
                }
            }

            if (status != gameStatus.CONTINUES)
            {
                if (status == gameStatus.LOST)
                {
                    sb.Draw(loser, (w - loserWidth) / 2, (h - loserHeight) / 2, loserWidth, loserHeight, Color.White);
                }
                else
                {
                    sb.Draw(winner, (w - winnerWidth) / 2, (h - winnerHeight) / 2, winnerWidth, winnerHeight, Color.White);
                }
            }

            sb.End();

            base.Draw(gameTime, stereoEye);
        }
 internal override void Draw(SpriteBatch sb, DebugStrings ds, StereoEye stereoEye)
 {
     for (int i = 0; i < 7; i++)
     {
         Draw(sb, ds, i, stereoEye);
     }
 }
Beispiel #6
0
        public List <int> DragSelect(Point topLeft, Point bottomRight, StereoEye eye)
        {
            List <int> selectedIndices = new List <int>();
            Vector2    topLeftProj     = PixelsToProj(topLeft);
            Vector2    bottomRightProj = PixelsToProj(bottomRight);

            var cam        = Game.GetService <GreatCircleCamera>();
            var viewMatrix = cam.GetViewMatrix(eye);
            var projMatrix = cam.GetProjectionMatrix(eye);

            Graph graph        = this.GetGraph();
            int   currentIndex = 0;

            foreach (SpatialNode node in graph.Nodes)
            {
                Vector4 posWorld = new Vector4(node.Position, 1.0f);
                Vector4 posView  = Vector4.Transform(posWorld, viewMatrix);
                Vector4 posProj  = Vector4.Transform(posView, projMatrix);
                posProj /= posProj.W;
                if
                (posProj.X >= topLeftProj.X && posProj.X <= bottomRightProj.X &&
                 posProj.Y >= bottomRightProj.Y && posProj.Y <= topLeftProj.Y
                )
                {
                    selectedIndices.Add(currentIndex);
                }
                ++currentIndex;
            }
            return(selectedIndices);
        }
Beispiel #7
0
        internal override void Draw(SpriteBatch sb, DebugStrings ds, StereoEye stereoEye)
        {
            float currentX = X + Config.OffsetX;
            float currentY = Y + Config.OffsetY;

            float offsetScale = 0;

            if (stereoEye == StereoEye.Left)
            {
                offsetScale = -Config.offsetScale;
            }
            if (stereoEye == StereoEye.Right)
            {
                offsetScale = Config.offsetScale;
            }

            sb.Draw(Texture, currentX - offsetScale, currentY, Config.HEX_SIZE, Config.HEX_SIZE, ((Team)Parent).Color);
            float x        = ((Team)Parent).TeamId % 2 == 0 ? currentX + 230 * Config.HEX_SIZE / 1000 : currentX + 50 * Config.HEX_SIZE / 1000;
            float y        = currentY + 380 * Config.HEX_SIZE / 1000;
            int   starSize = Config.HEX_SIZE / 3;

            for (int i = 0; i < _healths; i++)
            {
                sb.Draw(_health, x - offsetScale, y + Config.HEX_SIZE / 3, starSize, starSize, ((Team)Parent).Color);
                x += starSize * 55 / 100 + 1;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            base.Draw(gameTime, stereoEye);

            //	Draw stuff here :
            GetService <UserInterface>().Draw(gameTime, stereoEye);
        }
Beispiel #9
0
        public override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            SpriteBatch sb = Game.GetService <SpriteBatch>();

            sb.Begin();
            GameCollection.Draw(sb, Game.GetService <DebugStrings>(), stereoEye);
            if (weHaveAWinner)
            {
                float offsetScale = 0;
                if (stereoEye == StereoEye.Left)
                {
                    offsetScale = -Config.offsetScale * 1.5f;
                }
                if (stereoEye == StereoEye.Right)
                {
                    offsetScale = Config.offsetScale * 1.5f;
                }

                int y = (int)Game.GraphicsDevice.DisplayBounds.Height / 2;
                int x = (int)Game.GraphicsDevice.DisplayBounds.Width / 2;
                sb.Draw(winner, x - 450 - offsetScale, y - 114, 900, 228, GameCollection.Winner.Color);
            }
            sb.End();
            base.Draw(gameTime, stereoEye);
        }
Beispiel #10
0
 public override void Draw(GameTime gameTime, StereoEye stereoEye)
 {
     SpriteBatch sb = Game.GetService<SpriteBatch>();
     sb.Begin();
     gameCollection.Draw(sb, Game.GetService<DebugStrings>(), stereoEye);
     sb.End();
     base.Draw(gameTime, stereoEye);
 }
Beispiel #11
0
        /// <summary>
        /// Draws sprite laters and all sublayers.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        public void DrawSprites(GameTime gameTime, StereoEye stereoEye, RenderTargetSurface surface, IEnumerable <SpriteLayer> layers)
        {
            device.ResetStates();
            //device.RestoreBackbuffer();
            device.SetTargets(null, surface);

            DrawSpritesRecursive(gameTime, stereoEye, surface, layers, Matrix.Identity, new Color4(1f, 1f, 1f, 1f));
        }
Beispiel #12
0
 internal override void Draw(Fusion.Graphics.SpriteBatch sb, Fusion.Graphics.DebugStrings ds, StereoEye stereoEye)
 {
     float offsetScale = 0;
     if (stereoEye == StereoEye.Left)
         offsetScale = -Config.offsetScale;
     if (stereoEye == StereoEye.Right)
         offsetScale = Config.offsetScale;
     sb.Draw(Texture, Cell.X - offsetScale, Cell.Y, Config.HEX_SIZE, Config.HEX_SIZE, Team.Color);
 }
Beispiel #13
0
        public override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            SpriteBatch sb = Game.GetService <SpriteBatch>();

            sb.Begin();
            gameCollection.Draw(sb, Game.GetService <DebugStrings>(), stereoEye);
            sb.End();
            base.Draw(gameTime, stereoEye);
        }
Beispiel #14
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            GraphicsDevice.ClearBackbuffer(Color.CornflowerBlue, 1, 0);

            sceneDrawer.EvaluateScene(frame, AnimationMode.Repeat);
            sceneDrawer.Draw(gameTime, stereoEye);

            base.Draw(gameTime, stereoEye);
        }
Beispiel #15
0
        /// <summary>
        /// Called when the game determines it is time to draw a frame.
        /// In stereo mode this method will be called twice to render left and right parts of stereo image.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected virtual void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            //GIS.Draw(gameTime, stereoEye);

            RenderSystem.Draw(gameTime, stereoEye);

            GraphicsDevice.ResetStates();
            GraphicsDevice.RestoreBackbuffer();
        }
Beispiel #16
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            var cam = GetService <Camera>();

            GraphicsDevice.ClearBackbuffer(new Color(50, 70, 100, 255), 1, 0);

            constData.World      = Matrix.Identity;
            constData.ViewProj   = cam.GetViewMatrix(stereoEye) * cam.GetProjectionMatrix(stereoEye);
            constData.ViewPos    = new Vector4(cam.GetCameraMatrix(stereoEye).TranslationVector, 1);
            constData.World      = Matrix.Identity;
            constData.LodDist    = new Vector4(minLOD, maxLOD, minDistance, maxDistance);
            constData.ScaleSharp = new Vector4(textureScale, blendSharpness, 0, 0);

            GraphicsDevice.PipelineState           = factory[wireframe ? (int)RenderFlags.Wireframe : 0];
            GraphicsDevice.PixelShaderSamplers[0]  = SamplerState.LinearPointWrap;
            GraphicsDevice.DomainShaderSamplers[0] = SamplerState.LinearPointWrap;

            GraphicsDevice.PixelShaderConstants[0]  = constBuffer;
            GraphicsDevice.VertexShaderConstants[0] = constBuffer;
            GraphicsDevice.HullShaderConstants[0]   = constBuffer;
            GraphicsDevice.DomainShaderConstants[0] = constBuffer;


            for (int i = 0; i < scene.Nodes.Count; i++)
            {
                int meshId = scene.Nodes[i].MeshIndex;

                if (meshId < 0)
                {
                    continue;
                }

                constData.World = worldMatricies[i];
                constBuffer.SetData(constData);

                GraphicsDevice.SetupVertexInput(vertexBuffers[meshId], indexBuffers[meshId]);

                foreach (var subset in scene.Meshes[meshId].Subsets)
                {
                    GraphicsDevice.PixelShaderResources[0] = textures[3];
                    GraphicsDevice.PixelShaderResources[1] = textures[4];
                    GraphicsDevice.PixelShaderResources[2] = textures[1];
                    GraphicsDevice.PixelShaderResources[3] = textures[2];

                    GraphicsDevice.DomainShaderResources[0] = textures[3];
                    GraphicsDevice.DomainShaderResources[1] = textures[4];
                    GraphicsDevice.DomainShaderResources[2] = textures[1];
                    GraphicsDevice.DomainShaderResources[3] = textures[2];

                    GraphicsDevice.DrawIndexed(subset.PrimitiveCount * 3, subset.StartPrimitive * 3, 0);
                }
            }


            base.Draw(gameTime, stereoEye);
        }
 private void SetupMaterial(Material m, Camera camera)
 {
     m.SetVector(_cameraPositionId, camera.transform.position);
     m.SetMatrix(_viewMatrixId, camera.worldToCameraMatrix.transpose);
     if (_forceEyeMode != _setForceEyeMode)
     {
         Helper.SetupStereoEyeModeMaterial(m, _forceEyeMode);
         _setForceEyeMode = _forceEyeMode;
     }
 }
Beispiel #18
0
            public override Context Prepare(GameTime gameTime, StereoEye stereoEye)
            {
                var cam = Game.GetService <Camera>();

                return(new Context()
                {
                    View = cam.GetViewMatrix(stereoEye),
                    Projection = cam.GetProjectionMatrix(stereoEye),
                    ViewPosition = cam.GetCameraPosition4(stereoEye)
                });
            }
Beispiel #19
0
        /// <summary>
        /// Draw stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            //	Clear back buffer :
            GraphicsDevice.ClearBackbuffer(new Color4(0, 0, 0, 1));

            //	Update constant buffer and bound it to pipeline:
            cbData.Transform = Matrix.OrthoRH(4, 3, -2, 2);
            cbData.Time      = 0.001f * (float)gameTime.Total.TotalMilliseconds;
            cb.SetData(cbData);

            GraphicsDevice.VertexShaderConstants[0] = cb;
            GraphicsDevice.PixelShaderConstants[0]  = cb;

            //	Fill vertex buffer :
            var v0 = new Vertex {
                Position = new Vector3(-1.0f, -1.0f, 0), Color = Color.Red, TexCoord = new Vector2(0, 1)
            };
            var v1 = new Vertex {
                Position = new Vector3(1.0f, 1.0f, 0), Color = Color.White, TexCoord = new Vector2(1, 0)
            };
            var v2 = new Vertex {
                Position = new Vector3(-1.0f, 1.0f, 0), Color = Color.Blue, TexCoord = new Vector2(0, 0)
            };
            var v3 = new Vertex {
                Position = new Vector3(-1.0f, -1.0f, 0), Color = Color.Red, TexCoord = new Vector2(0, 1)
            };
            var v4 = new Vertex {
                Position = new Vector3(1.0f, -1.0f, 0), Color = Color.Lime, TexCoord = new Vector2(1, 1)
            };
            var v5 = new Vertex {
                Position = new Vector3(1.0f, 1.0f, 0), Color = Color.White, TexCoord = new Vector2(1, 0)
            };                                                                                                                                    //*/

            var data = new Vertex[] { v0, v1, v2, v3, v4, v5 };

            vb.SetData(data, 0, 6);

            //	Set required ubershader :

            //	Set device states :
            GraphicsDevice.PipelineState          = factory[0];
            GraphicsDevice.PixelShaderSamplers[0] = SamplerState.LinearWrap;

            //	Setup texture :
            GraphicsDevice.PixelShaderResources[0]  = tex;
            GraphicsDevice.VertexShaderResources[1] = instDataGpu;

            //	Setup vertex data and draw :
            GraphicsDevice.SetupVertexInput(vb, null);

            GraphicsDevice.DrawInstanced(6, InstanceCount, 0, 0);

            base.Draw(gameTime, stereoEye);
        }
Beispiel #20
0
        /// <summary>
        ///
        /// </summary>
        ///
        public override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            if (!vertexDataAccum.Any())
            {
                return;
            }

            if (Config.SuppressDebugRender)
            {
                vertexDataAccum.Clear();
            }

            var dev = Game.GraphicsDevice;


            if (RenderTarget != null)
            {
                if (DepthStencil == null)
                {
                    throw new InvalidOperationException("Both RenderTarget and DepthStencil must be set.");
                }
                dev.SetTargets(DepthStencil, RenderTarget);
            }


            constData.Transform = View * Projection;
            constBuffer.SetData(constData);

            dev.SetupVertexInput(vertexBuffer, null);
            dev.VertexShaderConstants[0] = constBuffer;
            dev.PipelineState            = factory[0];


            int numDPs = MathUtil.IntDivUp(vertexDataAccum.Count, vertexBufferSize);

            for (int i = 0; i < numDPs; i++)
            {
                int numVerts = i < numDPs - 1 ? vertexBufferSize : vertexDataAccum.Count % vertexBufferSize;

                if (numVerts == 0)
                {
                    break;
                }

                vertexDataAccum.CopyTo(i * vertexBufferSize, vertexArray, 0, numVerts);

                vertexBuffer.SetData(vertexArray, 0, numVerts);

                dev.Draw(numVerts, 0);
            }

            vertexDataAccum.Clear();
        }
Beispiel #21
0
 internal bool OnGameDraw(GameTime gameTime, StereoEye stereoEye)
 {
     if (GameDraw != null)
     {
         GameDraw(this, new DrawEventArgs()
         {
             GameTime = gameTime, StereoEye = stereoEye
         });
         return(true);
     }
     return(false);
 }
Beispiel #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="frame"></param>
        internal void DrawInternal(GameTime gameTime, StereoEye stereoEye, SpriteBatch sb, Color colorMul)
        {
            var vp = Game.GraphicsDevice.DisplayBounds;

            sb.ColorMultiplier = colorMul * this.OverallColor;

            if (IsDrawable && MathUtil.IsRectInsideRect(vp, GlobalRectangle))
            {
                if (ClippingMode == ClippingMode.None)
                {
                    DrawFrameBorders(sb);

                    Draw(gameTime, stereoEye, sb);

                    foreach (var child in Children)
                    {
                        child.DrawInternal(gameTime, stereoEye, sb, sb.ColorMultiplier);
                    }
                }
                else
                {
                    Rectangle clipRect = new Rectangle(0, 0, 0, 0);

                    if (ClippingMode == ClippingMode.ClipByFrame)
                    {
                        clipRect = GlobalRectangle;
                    }
                    if (ClippingMode == ClippingMode.ClipByBorder)
                    {
                        clipRect = GetBorderedRectangle();
                    }
                    if (ClippingMode == ClippingMode.ClipByPadding)
                    {
                        clipRect = GetPaddedRectangle();
                    }

                    DrawFrameBorders(sb);

                    sb.Restart(SpriteBlend.AlphaBlend, null, null, null, clipRect);

                    Draw(gameTime, stereoEye, sb);

                    foreach (var child in Children)
                    {
                        child.DrawInternal(gameTime, stereoEye, sb, sb.ColorMultiplier);
                    }

                    sb.Restart();
                }
            }

            sb.ColorMultiplier = colorMul;
        }
 protected override void Draw(Fusion.GameTime gameTime, StereoEye stereoEye)
 {
     base.Draw(gameTime, stereoEye);
     if (DateTime.Now > nextSnapshotTime)
     {
         Bitmap bmp;
         backBufferToBitmap(out bmp);
         bmp.Save(Wheel.Current(), ImageFormat.Png);
         bmp.Dispose();
         nextSnapshotTime = nextSnapshotTime.Add(snapshotPeriod);
         Wheel.Next();
     }
 }
Beispiel #24
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            base.Draw(gameTime, stereoEye);

            var sb = GetService <SpriteBatch>();

            sb.Begin();

            sb.End();


            //	Draw stuff here :
        }
Beispiel #25
0
        /// <summary>
        /// Draws frame stuff.
        /// </summary>
        /// <param name="gameTime"></param>
        protected virtual void Draw(GameTime gameTime, StereoEye stereoEye, SpriteBatch sb)
        {
            DrawFrameImage(sb);
            DrawFrameText(sb);

            if (UserDraw != null)
            {
                UserDraw(this, new DrawEventArgs()
                {
                    GameTime = gameTime, StereoEye = stereoEye, SpriteBatch = sb
                });
            }
        }
Beispiel #26
0
            public override Context Prepare(GameTime gameTime, StereoEye stereoEye)
            {
                var cam = Game.GetService <Camera>();

                CopyBoneTransformsTo(boneTransforms);
                constBufferBones.SetData(boneTransforms);

                return(new Context()
                {
                    View = cam.GetViewMatrix(stereoEye),
                    Projection = cam.GetProjectionMatrix(stereoEye),
                    ViewPosition = cam.GetCameraPosition4(stereoEye)
                });
            }
Beispiel #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            var sb = GetService <SpriteBatch>();
            var tp = GetService <TexturePump>();
            var w  = GraphicsDevice.DisplayBounds.Width;
            var h  = GraphicsDevice.DisplayBounds.Height;

            int imgWidth  = 128;
            int imgHeight = 128;

            int cols = w / imgWidth;
            int rows = h / imgHeight;

            offset = Math.Max(0, offset);
            offset = Math.Min(offset, cols * imgWidth);

            sb.Begin();

            for (int i = 0; i < images.Length; i++)
            {
                int x = (i / rows) * imgWidth - offset * 10;
                int y = (i % rows) * imgHeight;

                if (x < -128 || x > w)
                {
                    continue;
                }

                Texture2D tex;
                var       status = tp.Load(images[i], out tex);

                if (status == TexturePumpStatus.Loading)
                {
                    sb.Draw(texLoading, x, y, imgWidth, imgHeight, Color.Blue);
                }
                if (status == TexturePumpStatus.Failed)
                {
                    sb.Draw(texFailed, x, y, imgWidth, imgHeight, Color.Red);
                }
                if (status == TexturePumpStatus.Ready)
                {
                    sb.Draw(tex, x + 2, y + 2, imgWidth - 4, imgHeight - 4, Color.White);
                }
            }

            sb.End();

            base.Draw(gameTime, stereoEye);
        }
Beispiel #28
0
        /// <summary>
        /// Draws entire interface
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            if (Config.SkipUserInterface)
            {
                return;
            }

            var sb = Game.GetService <SpriteBatch>();
            var ds = Game.GetService <DebugStrings>();
            var vp = Game.GraphicsDevice.DisplayBounds;

            int load = 0;


            Game.GraphicsDevice.ResetStates();
            Game.GraphicsDevice.RestoreBackbuffer();

            if (RootFrame != null)
            {
                var list = Frame.BFSList(RootFrame);
                foreach (var f in list)
                {
                    if (f.OnGameDraw(gameTime, stereoEye))
                    {
                        Game.GraphicsDevice.ResetStates();
                        Game.GraphicsDevice.RestoreBackbuffer();
                    }
                }
            }


            sb.Begin();

            if (RootFrame != null)
            {
                RootFrame.DrawInternal(gameTime, stereoEye, sb, Color.White);
            }

            sb.ColorMultiplier = Color.White;

            sb.End();

            if (Config.ShowProfilingInfo)
            {
                ds.Add("Viewport         : {0} {1}", vp.Width, vp.Height);
                ds.Add("UI update time   : {0}", uiUpdateProfiling);
                ds.Add("SpriteBatch load : {0}", load);
            }
        }
Beispiel #29
0
        internal override void Draw(SpriteBatch sb, Fusion.Graphics.DebugStrings ds, StereoEye stereoEye)
        {
            float offsetScale = 0;

            if (stereoEye == StereoEye.Left)
            {
                offsetScale = -Config.offsetScale;
            }
            if (stereoEye == StereoEye.Right)
            {
                offsetScale = Config.offsetScale;
            }

            sb.Draw(Texture, Cell.X - offsetScale, Cell.Y, Config.HEX_SIZE, Config.HEX_SIZE, ((Team)Parent).Color);
        }
Beispiel #30
0
        void InputDevice_KeyDown(object sender, Fusion.Input.InputDevice.KeyEventArgs e)
        {
            if (Game.InputDevice.IsKeyDown(Keys.LeftButton))
            {
                if (ParticleList.Count > 0)
                {
                    var cam = Game.GetService <OrbitCamera>();

                    StereoEye stereoEye = Fusion.Graphics.StereoEye.Mono;

                    var viewMtx = cam.GetViewMatrix(stereoEye);
                    var projMtx = cam.GetProjectionMatrix(stereoEye);


                    var inp = Game.InputDevice;

                    int w = Game.GraphicsDevice.DisplayBounds.Width;
                    int h = Game.GraphicsDevice.DisplayBounds.Height;

                    param.MouseX = 2.0f * (float)inp.MousePosition.X / (float)w - 1.0f;
                    param.MouseY = -2.0f * (float)inp.MousePosition.Y / (float)h + 1.0f;

                    simulationBufferSrc.GetData(injectionBufferCPU);
                    foreach (var part in injectionBufferCPU)
                    {
                        var worldPos = new Vector4(part.Position, 1);
                        var viewPos  = Vector4.Transform(worldPos, viewMtx);
                        var projPos  = Vector4.Transform(viewPos, projMtx);
                        projPos /= projPos.W;
                        if ((Math.Abs(projPos.X /*/ projPos.Z */ - param.MouseX) < 0.02f) && (Math.Abs(projPos.Y /*/ projPos.Z */ - param.MouseY) < 0.02f))
                        {
                            Console.WriteLine(part.Size0 + " Size");
                            break;
                        }
                    }
                }
            }

            if (Game.InputDevice.IsKeyDown(Keys.Q))
            {
                Pause();
            }

            if (Game.InputDevice.IsKeyDown(Keys.B))
            {
                AddMaxParticles();
            }
        }
Beispiel #31
0
 /// <summary>
 /// Gets camera matrix for given stereo eye.
 /// </summary>
 /// <param name="stereoEye"></param>
 /// <returns></returns>
 public Matrix GetCameraMatrix(StereoEye stereoEye)
 {
     if (stereoEye == StereoEye.Mono)
     {
         return(cameraMatrix);
     }
     if (stereoEye == StereoEye.Left)
     {
         return(cameraMatrixL);
     }
     if (stereoEye == StereoEye.Right)
     {
         return(cameraMatrixR);
     }
     throw new ArgumentException("stereoEye");
 }
Beispiel #32
0
 /// <summary>
 /// Returns camera position as Vector4
 /// </summary>
 /// <param name="stereoEye"></param>
 /// <returns></returns>
 public Vector4 GetCameraPosition4(StereoEye stereoEye)
 {
     if (stereoEye == StereoEye.Mono)
     {
         return(new Vector4(cameraMatrix.TranslationVector, 1));
     }
     if (stereoEye == StereoEye.Left)
     {
         return(new Vector4(cameraMatrixL.TranslationVector, 1));
     }
     if (stereoEye == StereoEye.Right)
     {
         return(new Vector4(cameraMatrixR.TranslationVector, 1));
     }
     throw new ArgumentException("stereoEye");
 }
Beispiel #33
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            var sb		=	GetService<SpriteBatch>();
            var tp		=	GetService<TexturePump>();
            var w		=	GraphicsDevice.DisplayBounds.Width;
            var h		=	GraphicsDevice.DisplayBounds.Height;

            int imgWidth	= 128;
            int imgHeight	= 128;

            int cols	=	w / imgWidth;
            int rows	=	h / imgHeight;

            offset		=	Math.Max( 0, offset );
            offset		=	Math.Min( offset, cols * imgWidth );

            sb.Begin();

                for (int i = 0; i < images.Length; i++) {

                    int x = ( i / rows ) * imgWidth - offset * 10;
                    int y = ( i % rows ) * imgHeight;

                    if (x<-128 || x>w) {
                        continue;
                    }

                    Texture2D	tex;
                    var status	=	tp.Load(images[i], out tex);

                    if (status == TexturePumpStatus.Loading) {
                        sb.Draw( texLoading, x, y, imgWidth, imgHeight, Color.Blue );
                    }
                    if (status == TexturePumpStatus.Failed) {
                        sb.Draw( texFailed, x, y, imgWidth, imgHeight, Color.Red );
                    }
                    if (status == TexturePumpStatus.Ready) {
                        sb.Draw( tex, x+2, y+2, imgWidth-4, imgHeight-4, Color.White );
                    }
                }

            sb.End();

            base.Draw( gameTime, stereoEye );
        }
Beispiel #34
0
        /// <summary>
        /// Draw stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            //	Clear back buffer :
            GraphicsDevice.ClearBackbuffer( new Color4(0,0,0,0) );

            //	Fill vertex buffer :
            var v0	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v1	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };
            var v2	=	new Vertex{ Position = new Vector3( -1.0f,  1.0f, 0 ), Color = Color.Blue,  TexCoord = new Vector2(0,0) };
            var v3	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v4	=	new Vertex{ Position = new Vector3(  1.0f, -1.0f, 0 ), Color = Color.Lime,  TexCoord = new Vector2(1,1) };
            var v5	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };//*/

            var data = new Vertex[]{ v0, v1, v2, v3, v4, v5 };

            vertexBuffer.SetData( data, 0, 6 );

            var tex = texture;

            UberFlags flags = UberFlags.NONE;
            if (InputDevice.IsKeyDown(Keys.D1) ) flags |= UberFlags.USE_TEXTURE;
            if (InputDevice.IsKeyDown(Keys.D2) ) flags |= UberFlags.USE_VERTEX_COLOR;
            if (InputDevice.IsKeyDown(Keys.D3) ) tex = textureSRgb;

            //	Update constant buffer and bound it to pipeline:
            cbData.Transform	=	Matrix.OrthoRH( 4, 3, -2, 2 );
            constBuffer.SetData(cbData);

            GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
            GraphicsDevice.PixelShaderConstants[0]	= constBuffer;

            //	Setup device state :
            GraphicsDevice.PipelineState			= factory[ (int)flags ];
            GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap ;

            //	Setup texture :
            GraphicsDevice.PixelShaderResources[0]	= tex ;

            //	Setup vertex data and draw :
            GraphicsDevice.SetupVertexInput( vertexBuffer, null );
            GraphicsDevice.Draw( 6, 0 );

            base.Draw( gameTime, stereoEye );
        }
Beispiel #35
0
        public List<int> DragSelect(Point topLeft, Point bottomRight, StereoEye eye )
        {
            List<int> selectedIndices = new List<int>();
            Vector2 topLeftProj		= PixelsToProj(topLeft);
            Vector2 bottomRightProj	= PixelsToProj(bottomRight);

            var cam = Game.GetService<GreatCircleCamera>();
            var viewMatrix = cam.GetViewMatrix(eye);
            var projMatrix = cam.GetProjectionMatrix(eye);

            Graph graph = this.GetGraph();
            int currentIndex = 0;
            foreach (SpatialNode node in graph.Nodes)
            {
                Vector4 posWorld = new Vector4(node.Position, 1.0f);
                Vector4 posView = Vector4.Transform(posWorld, viewMatrix);
                Vector4 posProj = Vector4.Transform(posView, projMatrix);
                posProj /= posProj.W;
                if
                (	posProj.X >= topLeftProj.X && posProj.X <= bottomRightProj.X &&
                    posProj.Y >= bottomRightProj.Y && posProj.Y <= topLeftProj.Y
                )
                {
                    selectedIndices.Add(currentIndex);
                }
                ++currentIndex;
            }
            return selectedIndices;
        }
Beispiel #36
0
        public bool ClickNode(Point cursor, StereoEye eye, float threshold, out int nodeIndex )
        {
            nodeIndex = 0;

            var cam = Game.GetService<GreatCircleCamera>();
            var viewMatrix = cam.GetViewMatrix( eye );
            var projMatrix = cam.GetProjectionMatrix( eye );
            Graph graph = this.GetGraph();

            Vector2 cursorProj = PixelsToProj(cursor);
            bool nearestFound = false;

            float minZ = 99999;
            int currentIndex = 0;
            foreach (SpatialNode node in graph.Nodes)
            {
                Vector4 posWorld = new Vector4(node.Position - ((SpatialNode)graph.Nodes[referenceNodeIndex]).Position, 1.0f);
                Vector4 posView = Vector4.Transform(posWorld, viewMatrix);
                Vector4 posProj = Vector4.Transform(posView, projMatrix);
                posProj /= posProj.W;
                Vector2 diff = new Vector2(posProj.X - cursorProj.X, posProj.Y - cursorProj.Y);
                if (diff.Length() < threshold)
                {
                    nearestFound = true;
                    if (minZ > posProj.Z)
                    {
                        minZ = posProj.Z;
                        nodeIndex = currentIndex;
                    }
                }
                ++currentIndex;
            }
            return nearestFound;
        }
Beispiel #37
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		internal void Draw ( GameTime gameTime, StereoEye stereoEye )
		{
			Counters.Reset();

			Gis.Update(gameTime);
			//GIS.Draw(gameTime, StereoEye.Mono);

			RenderLayer[] layersToDraw;

			lock (viewLayers) {
				layersToDraw = viewLayers
					.OrderBy( c1 => c1.Order )
					.Where( c2 => c2.Visible )
					.ToArray();
			}

			foreach ( var viewLayer in layersToDraw ) {
				viewLayer.Render( gameTime, stereoEye );
			}

			if (ShowCounters) {
				Counters.PrintCounters();
			}
		}
Beispiel #38
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="camera"></param>
		/// <param name="depthBuffer"></param>
		/// <param name="hdrTarget"></param>
		/// <param name="diffuse"></param>
		/// <param name="specular"></param>
		/// <param name="normals"></param>
		internal void RenderGBuffer ( StereoEye stereoEye, Camera camera, HdrFrame frame, RenderWorld viewLayer )
		{		
			using ( new PixEvent("RenderGBuffer") ) {
				if (surfaceShader==null) {	
					return;
				}

				if (rs.SkipSceneRendering) {
					return;
				}

				var device		=	Game.GraphicsDevice;

				var view			=	camera.GetViewMatrix( stereoEye );
				var projection		=	camera.GetProjectionMatrix( stereoEye );
				var viewPosition	=	camera.GetCameraPosition4( stereoEye );

				var cbData		=	new CBMeshInstanceData();

				var hdr			=	frame.HdrBuffer.Surface;
				var depth		=	frame.DepthBuffer.Surface;
				var diffuse		=	frame.DiffuseBuffer.Surface;
				var specular	=	frame.SpecularBuffer.Surface;
				var normals		=	frame.NormalMapBuffer.Surface;
				var scattering	=	frame.ScatteringBuffer.Surface;

				device.ResetStates();

				device.SetTargets( depth, hdr, diffuse, specular, normals, scattering );
				device.PixelShaderSamplers[0]	= SamplerState.AnisotropicWrap ;

				var instances	=	viewLayer.Instances;

				//#warning INSTANSING!
				foreach ( var instance in instances ) {

					if (!instance.Visible) {
						continue;
					}

					cbData.View			=	view;
					cbData.Projection	=	projection;
					cbData.World		=	instance.World;
					cbData.ViewPos		=	viewPosition;
					
					constBuffer.SetData( cbData );

					device.PixelShaderConstants[0]	= constBuffer ;
					device.VertexShaderConstants[0]	= constBuffer ;

					device.SetupVertexInput( instance.vb, instance.ib );

					if (instance.IsSkinned) {
						constBufferBones.SetData( instance.BoneTransforms );
						device.VertexShaderConstants[3]	= constBufferBones ;
					}

					try {

						foreach ( var sg in instance.ShadingGroups ) {

							device.PipelineState	=	instance.IsSkinned ? sg.Material.GBufferSkinned : sg.Material.GBufferRigid;

							device.PixelShaderConstants[1]	= sg.Material.ConstantBufferParameters;
							device.PixelShaderConstants[2]	= sg.Material.ConstantBufferUVModifiers;
							device.VertexShaderConstants[1]	= sg.Material.ConstantBufferParameters;
							device.VertexShaderConstants[2]	= sg.Material.ConstantBufferUVModifiers;

							sg.Material.SetTextures( device );

							device.DrawIndexed( sg.IndicesCount, sg.StartIndex, 0 );

							rs.Counters.SceneDIPs++;
						}
					} catch ( UbershaderException e ) {
						Log.Warning( e.Message );					
						ExceptionDialog.Show( e );
					}
				}
			}
		}
Beispiel #39
0
        /// <summary>
        /// Draw stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            //	Clear back buffer :
            GraphicsDevice.ClearBackbuffer( new Color4(0,0,0,1) );

            //	Update constant buffer and bound it to pipeline:
            cbData.Transform	=	Matrix.OrthoRH( 4, 3, -2, 2 );
            cbData.Time = 0.001f * (float)gameTime.Total.TotalMilliseconds;
            cb.SetData( cbData );

            GraphicsDevice.VertexShaderConstants[0]	= cb ;
            GraphicsDevice.PixelShaderConstants[0]	= cb ;

            //	Fill vertex buffer :
            var v0	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v1	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };
            var v2	=	new Vertex{ Position = new Vector3( -1.0f,  1.0f, 0 ), Color = Color.Blue,  TexCoord = new Vector2(0,0) };
            var v3	=	new Vertex{ Position = new Vector3( -1.0f, -1.0f, 0 ), Color = Color.Red,   TexCoord = new Vector2(0,1) };
            var v4	=	new Vertex{ Position = new Vector3(  1.0f, -1.0f, 0 ), Color = Color.Lime,  TexCoord = new Vector2(1,1) };
            var v5	=	new Vertex{ Position = new Vector3(  1.0f,  1.0f, 0 ), Color = Color.White, TexCoord = new Vector2(1,0) };//*/

            var data = new Vertex[]{ v0, v1, v2, v3, v4, v5 };

            vb.SetData( data, 0, 6 );

            //	Set required ubershader :

            //	Set device states :
            GraphicsDevice.PipelineState		= factory[0];
            GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearWrap ;

            //	Setup texture :
            GraphicsDevice.PixelShaderResources[0]	= tex ;
            GraphicsDevice.VertexShaderResources[1]	= instDataGpu ;

            //	Setup vertex data and draw :
            GraphicsDevice.SetupVertexInput( vb, null );

            GraphicsDevice.DrawInstanced( 6, InstanceCount, 0, 0 );

            base.Draw( gameTime, stereoEye );
        }
Beispiel #40
0
        /// <summary>
        /// DrawGatheredStrings
        /// </summary>
        public override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            var x = 8;
            int y = 8;

            if (Config.SuppressDebugString) {
                linesAccum.Clear();
                return;
            }

            if (!linesDraw.Any()) {
                return;
            }

            var sb = Game.GetService<SpriteBatch>();

            sb.Begin();

                int w = linesDraw.Max( line => line.text.Length ) * 8 + 16;
                int h = linesDraw.Count * 8 + 16;

                maxWidth	=	Math.Max( w, maxWidth );

                sb.Draw( sb.TextureWhite, new Rectangle(0,0, maxWidth, h), Config.BackgroundColor );

                foreach ( var line in linesDraw ) {
                    //font.DrawString( rs.SpriteBatch, line.text, x, y, line.color );
                    sb.DrawDebugString( x+1, y+1, line.text, Color.Black );
                    sb.DrawDebugString( x+0, y+0, line.text, line.color );
                    y += 8;
                }

            sb.End();
        }
Beispiel #41
0
        /// <summary>
        /// 
        /// </summary>
        /// 
        public override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            if (!vertexDataAccum.Any()) {
                return;
            }

            if (Config.SuppressDebugRender) {
                vertexDataAccum.Clear();
            }

            var dev = Game.GraphicsDevice;

            if (RenderTarget!=null) {
                if (DepthStencil==null) {
                    throw new InvalidOperationException("Both RenderTarget and DepthStencil must be set.");
                }
                dev.SetTargets( DepthStencil, RenderTarget );
            }

            constData.Transform = View * Projection;
            constBuffer.SetData(constData);

            dev.SetupVertexInput( vertexBuffer, null );
            dev.VertexShaderConstants[0]	=	constBuffer ;
            dev.PipelineState				=	factory[0];

            int numDPs = MathUtil.IntDivUp(vertexDataAccum.Count, vertexBufferSize);

            for (int i = 0; i < numDPs; i++) {

                int numVerts = i < numDPs - 1 ? vertexBufferSize : vertexDataAccum.Count % vertexBufferSize;

                if (numVerts == 0) {
                    break;
                }

                vertexDataAccum.CopyTo(i * vertexBufferSize, vertexArray, 0, numVerts);

                vertexBuffer.SetData(vertexArray, 0, numVerts);

                dev.Draw( numVerts, 0);

            }

            vertexDataAccum.Clear();
        }
Beispiel #42
0
 internal override void Draw(SpriteBatch sb, DebugStrings ds, int order, StereoEye stereoEye)
 {
     if (order == _order)
         Draw(sb, ds, stereoEye);
 }
Beispiel #43
0
 internal override void Draw(SpriteBatch sb, DebugStrings ds, StereoEye stereoEye)
 {
 }
Beispiel #44
0
		/// <summary>
		/// Gets projection matrix for given stereo eye.
		/// </summary>
		/// <param name="stereoEye"></param>
		/// <returns></returns>
		public Matrix GetProjectionMatrix ( StereoEye stereoEye )
		{
			if (stereoEye==StereoEye.Mono) return projMatrix;
			if (stereoEye==StereoEye.Left) return projMatrixL;
			if (stereoEye==StereoEye.Right) return projMatrixR;
			throw new ArgumentException("stereoEye");
		}
Beispiel #45
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw( GameTime gameTime, StereoEye stereoEye )
        {
            GraphicsDevice.ClearBackbuffer( Color.CornflowerBlue, 1, 0 );

            var vp		=	GraphicsDevice.DisplayBounds;
            var cam		=	GetService<Camera>();
            var sr		=	GetService<SceneRenderer>();
            var lr		=	GetService<LightRenderer>();
            var sb		=	GetService<SpriteBatch>();
            var sky		=	GetService<Sky>();
            var hdr		=	GetService<HdrFilter>();
            var flt		=	GetService<Filter>();
            var hbao	=	GetService<SsaoFilter>();

            GraphicsDevice.Clear( hdrTarget.Surface, Color.Black );

            lr.ClearGBuffer();

            var view		=	cam.GetViewMatrix( stereoEye );
            var proj		=	cam.GetProjectionMatrix( stereoEye );
            var viewMono	=	cam.GetViewMatrix( StereoEye.Mono );
            var projMono	=	cam.GetProjectionMatrix( StereoEye.Mono );

            //	render shadows once and
            //	reuse the on next subframe:
            if (gameTime.SubframeID==0) {
                lr.RenderShadows( viewMono, projMono, sr );
            }

            //	render G-buffer :
            sr.RenderGBuffer ( view, proj, lr.DepthBuffer, hdrTarget, lr.DiffuseBuffer, lr.SpecularBuffer, lr.NormalMapBuffer );

            //	render sky :
            sky.Render( gameTime, lr.DepthBuffer.Surface, hdrTarget.Surface, view, proj );

            hbao.Render( view, proj, lr.DepthBuffer, lr.NormalMapBuffer );

            //	render lighting :
            lr.RenderLighting( view, proj, hdrTarget.Surface, hbao.OcclusionMap );

            //	perform HDR filter :
            hdr.Render( gameTime, ldrTarget.Surface, hdrTarget );

            //	perform FXAA :
            flt.Fxaa( GraphicsDevice.BackbufferColor.Surface, ldrTarget );

            GraphicsDevice.ResetStates();
            GraphicsDevice.RestoreBackbuffer();

            /*sb.Begin( BlendState.Opaque, SamplerState.LinearClamp );

                int w = vp.Width  / 2;
                int h = vp.Height / 2;

                if ( InputDevice.IsKeyDown( Keys.T ) ) {

                    sb.Draw( hdrTarget			,	0, 0, w, h, Color.White );
                    sb.Draw( lr.DiffuseBuffer	,	w, 0, w, h, Color.White );
                    sb.Draw( lr.SpecularBuffer	,	0, h, w, h, Color.White );
                    sb.Draw( lr.NormalMapBuffer	,	w, h, w, h, Color.White );

                    sb.Draw( lr.CSMColor,  0,  0,400,100, Color.White );
                    sb.Draw( lr.SpotColor, 0,100,400,400, Color.White );

                } else {

                    sb.Draw( hdrTarget,	0, 0, vp.Width, vp.Height, Color.White );

                }

            sb.End();*/

            base.Draw( gameTime, stereoEye );
        }
Beispiel #46
0
		/// <summary>
		/// Performs luminance measurement, tonemapping, applies bloom.
		/// </summary>
		/// <param name="target">LDR target.</param>
		/// <param name="hdrImage">HDR source image.</param>
		public void Render ( StereoEye stereoEye, Camera camera, ShaderResource depthBuffer, ShaderResource wsNormals )
		{
			var view		=	camera.GetViewMatrix( stereoEye );
			var projection	=	camera.GetProjectionMatrix( stereoEye );

			
			var device	=	Game.GraphicsDevice;
			var filter	=	Game.RenderSystem.Filter;

			if (!Enabled) {
				device.Clear( occlusionMap0.Surface, Color4.White );
				return;
			}

			using (new PixEvent("SSAO Render")) {
				filter.StretchRect( downsampledDepth.Surface, depthBuffer );
				filter.StretchRect( downsampledNormals.Surface, wsNormals );

				using (new PixEvent("SSAO Pass")) {

					//
					//	Setup parameters :
					//
					var paramsData	=	new Params();
					paramsData.ProjMatrix	=	projection;
					paramsData.View			=	view;
					paramsData.ViewProj		=	view * projection;
					paramsData.InvViewProj	=	Matrix.Invert( view * projection );
					paramsData.InvProj = Matrix.Invert(projection);
					//paramsData.TraceStep	=	Config.TraceStep;
					//paramsData.DecayRate	=	Config.DecayRate;
					paramsData.MaxSampleRadius	= MaxSamplingRadius;
					paramsData.MaxDepthJump		= MaxDepthJump;

					paramsCB.SetData( paramsData );
					sampleDirectionsCB.SetData(sampleDirectionData);

					device.PixelShaderConstants[0]	=	paramsCB;
					device.PixelShaderConstants[1]  =   sampleDirectionsCB;

					//
					//	Measure and adapt :
					//
					device.SetTargets( null, occlusionMap0 );

					device.PixelShaderResources[0]	=	downsampledDepth;
					device.PixelShaderResources[1]	=	downsampledNormals;
					device.PixelShaderResources[2]	=	randomDir;
					device.PixelShaderSamplers[0]	=	SamplerState.LinearClamp;

					Flags sampleNumFlag = getSampleNumFlag();

					device.PipelineState = factory[getFlags()];
			
					device.Draw( 3, 0 );
			
					device.ResetStates();
				}

				using (new PixEvent("Bilateral Filter")) {
					if (BlurSigma!=0) {
						filter.GaussBlurBilateral( occlusionMap0, occlusionMap1, downsampledDepth, downsampledNormals, BlurSigma, Sharpness, 0 );
					}
				}
			}
		}
Beispiel #47
0
 /// <summary>
 /// Gets vector of camera position
 /// </summary>
 /// <param name="eye"></param>
 /// <returns></returns>
 public Vector3 GetCameraPosition( StereoEye eye )
 {
     return GetCameraMatrix(eye).TranslationVector;
 }
Beispiel #48
0
 /// <summary>
 /// Gets vector of camera position
 /// </summary>
 /// <param name="eye"></param>
 /// <returns></returns>
 public Vector4 GetCameraPosition4( StereoEye eye )
 {
     return new Vector4( GetCameraMatrix(eye).TranslationVector, 1 );
 }
		/// <summary>
		/// Performs good-old StretchRect to destination buffer with blending.
		/// </summary>
		/// <param name="dst"></param>
		/// <param name="src"></param>
		/// <param name="filter"></param>
		/// <param name="rect"></param>
		public void RenderSsao ( RenderTargetSurface ssaoDst, StereoEye stereoEye, Camera camera, DepthStencil2D depthSource, RenderTarget2D normalsSource )
		{
			SetDefaultRenderStates();

			using( new PixEvent("SSAO") ) {

				var ssaoParams = new SsaoParams();

				ssaoParams.View					=	camera.GetViewMatrix( stereoEye );	
				ssaoParams.Projection			=	camera.GetProjectionMatrix( stereoEye );	
				ssaoParams.InverseProjection	=	Matrix.Invert( ssaoParams.Projection );	
				paramsCB.SetData( ssaoParams );


				SetViewport( ssaoDst );
				device.SetTargets( null, ssaoDst );

				device.PipelineState			=	factory[ (int)(ShaderFlags.SSAO) ];

				device.VertexShaderResources[0] =	depthSource;
				device.PixelShaderResources[0]	=	depthSource;
				device.PixelShaderSamplers[0]	=	SamplerState.PointClamp;

				device.PixelShaderConstants[0]	=	paramsCB;
				device.PixelShaderConstants[1]	=	randomDirsCB;

				device.Draw( 3, 0 );
			}
			device.ResetStates();
		}
Beispiel #50
0
 /// <summary>
 /// Returns matrix with camera view
 /// </summary>
 /// <param name="eye"></param>
 /// <returns></returns>
 public Matrix GetViewMatrix( StereoEye eye )
 {
     if (eye==StereoEye.Mono) return ViewMatrix;
     if (eye==StereoEye.Left) return ViewMatrixL;
     if (eye==StereoEye.Right) return ViewMatrixR;
     throw new ArgumentException("eye");
 }
Beispiel #51
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            base.Draw(gameTime, stereoEye);

            //		time += gameTime.Elapsed.Milliseconds;

            var cam = GetService<GreatCircleCamera>();
            var dr = GetService<DebugRender>();
            var pSys = GetService<GraphSystem>();
            dr.View = cam.GetViewMatrix(stereoEye);
            dr.Projection = cam.GetProjectionMatrix(stereoEye);

            //		dr.DrawGrid(20);
            var ds = GetService<DebugStrings>();
            if (isSelected)
            {
                ds.Add(Color.Orange, "Selected node # " + selectedNodeIndex);
                pSys.Select(selectedNodeIndex);
            }
            else
            {
                //ds.Add(Color.Orange, "No selection");
                pSys.Deselect();
            }
            DrawNames();
        }
Beispiel #52
0
		/// <summary>
		/// Draw stuff here
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw ( GameTime gameTime, StereoEye stereoEye )
		{
			var sb = GetService<SpriteBatch>();
			var rand = new Random();

			var data = Enumerable.Range(0,64*64)
						.Select( i => rand.NextColor() )
						.ToArray();

			dynamicTexture.SetData(0, null, data, 0, 64*64 );


			GraphicsDevice.SetTargets( dsMS.Surface, rtMS.Surface );
			GraphicsDevice.Clear( dsMS.Surface );
			GraphicsDevice.Clear( rtMS.Surface, Color4.Black );
			

			sb.Begin(SpriteBlend.AlphaBlend,null,null, Matrix.OrthoRH(256,256,-1,1));
				sb.DrawSprite( texture, 0,0,256, angle, Color.White );
			sb.End();

			GraphicsDevice.Resolve( rtMS, rt );


			GraphicsDevice.RestoreBackbuffer();


			int w  = GraphicsDevice.DisplayBounds.Width;
			int h  = GraphicsDevice.DisplayBounds.Height;

			//	begin sprite gathering/accumulation :
			sb.Begin();

				if (InputDevice.IsKeyDown(Keys.T)) {
					sb.Draw( texture2, 0,          0, 256, 256, Color.White	);
					sb.Draw( texture , 256+128*0,  0, 128, 128, Color.Red	);
					sb.Draw( texture2, 256+128*1,  0, 128, 128, Color.Lime	);
					sb.Draw( texture , 256+128*2,  0, 128, 128, Color.Blue	);
				} else {
					sb.Draw( rt, 0,          0, 256, 256, Color.White	);
					sb.Draw( rt, 256+128*0,  0, 128, 128, Color.Red	);
					sb.Draw( rt, 256+128*1,  0, 128, 128, Color.Lime	);
					sb.Draw( rt, 256+128*2,  0, 128, 128, Color.Blue	);
				}

			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.PointClamp);
				sb.DrawSprite( texture, 576,192,128, angle, Color.White );


			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.LinearClamp);
				sb.DrawSprite( texture, 704,192,128, angle, Color.White );


			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.PointClamp);
				sb.DrawSprite( texture2, 576,192+128,128, angle, Color.White );


			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.LinearClamp);
				sb.DrawSprite( texture2, 704,192+128,128, angle, Color.White );


			sb.Restart();

				for (int i=0; i<numSprites; i++) {
					//sb.DrawSprite( sb.TextureWhite, r.Next(w), r.Next(h), 7, r.NextFloat(0,360), r.NextColor() ); 
					sb.Draw( sb.TextureWhite, r.Next(w), r.Next(h), 7, 7, r.NextColor() ); 
				}

				var h1 = font1.LineHeight;
				var h2 = font2.LineHeight;

				font1.DrawString( sb, "Lenna Soderberg",      64, 256 + h1,      Color.White  );
				font2.DrawString( sb, "Text (tracking = 0)",  64, 256 + h1+h2,   Color.Red );
				font2.DrawString( sb, "Text (tracking = 2)",  64, 256 + h1+h2*2, Color.Lime, 2 );
				font2.DrawString( sb, "Text (tracking = 4)", 64, 256 + h1+h2*3, Color.Lime, 4 );

				font2.DrawString( sb, string.Format("{1} sprites -> FPS = {0}", gameTime.Fps, numSprites), 64, 256 + h1+h2*4, Color.White );


			sb.Restart( SpriteBlend.Additive );
				sb.Draw( sb.TextureWhite,   256, 128, 128, 128, Color.Gray	);
				sb.Draw( texture, 256, 128, 128, 128, Color.Gray	);


			sb.Restart( SpriteBlend.AlphaBlend );
				sb.Draw( sb.TextureWhite, 256+128, 128, 128, 128, new Color(240,225,160,255)	);


			sb.Restart( SpriteBlend.NegMultiply );
				sb.Draw( texture, 256+128, 128, 128, 128, Color.White	);


			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.AnisotropicWrap);
				sb.DrawBeam( texture2, new Vector2(350,540), new Vector2(750,415), Color.Yellow, Color.LightYellow, 80, 5.5f, offset );

			sb.Restart(SpriteBlend.AlphaBlend, SamplerState.PointClamp);
				sb.Draw( dynamicTexture, 0,0,256,256,new Color(255,255,255,64) );

				sb.Draw( sb.TextureBlack,	0,0,8,8, Color.White);
				sb.Draw( sb.TextureBlue,	8,0,8,8, Color.White);
				sb.Draw( sb.TextureGreen, 	16,0,8,8, Color.White);
				sb.Draw( sb.TextureRed,		24,0,8,8, Color.White);
				sb.Draw( sb.TextureWhite,	32,0,8,8, Color.White);

			sb.Restart();

				/*var name = atlas.SubImageNames[ ((int)atlasId) % atlas.SubImageNames.Length ];
				var ar = atlas.GetSubImageRectangle( name );

				sb.Draw( atlas.Texture, new Rectangle(10,400, ar.Width, ar.Height), ar, Color.White );
				sb.DrawDebugString( 10, 392, name, Color.White );

				atlasId += gameTime.ElapsedSec * 2;*/

			sb.End();

			base.Draw( gameTime, stereoEye );
		}
Beispiel #53
0
		/// <summary>
		/// Draws game
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw ( GameTime gameTime, StereoEye stereoEye )
		{
			base.Draw( gameTime, stereoEye );

			//	Draw stuff here :
		}
Beispiel #54
0
		/// <summary>
		/// Returns camera position as Vector4
		/// </summary>
		/// <param name="stereoEye"></param>
		/// <returns></returns>
		public Vector4 GetCameraPosition4 ( StereoEye stereoEye )
		{
			if (stereoEye==StereoEye.Mono)  return new Vector4(cameraMatrix .TranslationVector, 1);
			if (stereoEye==StereoEye.Left)  return new Vector4(cameraMatrixL.TranslationVector, 1);
			if (stereoEye==StereoEye.Right) return new Vector4(cameraMatrixR.TranslationVector, 1);
			throw new ArgumentException("stereoEye");
		}
Beispiel #55
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		protected override void Draw (GameTime gameTime, StereoEye stereoEye)
		{
			CBData cbData = new CBData();

			var cam = GetService<Camera>();

			GraphicsDevice.ClearBackbuffer(Color.CornflowerBlue, 1, 0);


			foreach ( var e in space.Entities ) {
				Box box = e as Box;
				if ( box != null ) // this won't create any graphics for an entity that isn't a box
				{
					if ( box.IsDynamic ) // draw only dynamic boxes
					{
						// fill world matrix
						Fusion.Mathematics.Matrix matrix = new Fusion.Mathematics.Matrix(box.WorldTransform.M11, box.WorldTransform.M12, box.WorldTransform.M13, box.WorldTransform.M14,
																									box.WorldTransform.M21, box.WorldTransform.M22, box.WorldTransform.M23, box.WorldTransform.M24,
																									box.WorldTransform.M31, box.WorldTransform.M32, box.WorldTransform.M33, box.WorldTransform.M34,
																									box.WorldTransform.M41, box.WorldTransform.M42, box.WorldTransform.M43, box.WorldTransform.M44);
						cbData.Projection = cam.GetProjectionMatrix(stereoEye);
						cbData.View = cam.GetViewMatrix(stereoEye);
						cbData.World = matrix;
						cbData.ViewPos = new Vector4Fusion(cam.GetCameraMatrix(stereoEye).TranslationVector, 1);
						Color c = (Color) box.Tag;
						cbData.Color =  c.ToVector4();

						constBuffer.SetData(cbData);
						
						GraphicsDevice.PipelineState = factory[0];

						GraphicsDevice.PixelShaderConstants[0] = constBuffer;
						GraphicsDevice.VertexShaderConstants[0] = constBuffer;
						GraphicsDevice.PixelShaderSamplers[0] = SamplerState.AnisotropicWrap;
						GraphicsDevice.PixelShaderResources[0] = texture;

						// setup data and draw box
						GraphicsDevice.SetupVertexInput(vb, ib);
						GraphicsDevice.DrawIndexed( 36, 0, 0);
					}
				}
			}

			base.Draw(gameTime, stereoEye);
		}
Beispiel #56
0
 public override void Draw(GameTime gameTime, StereoEye stereoEye)
 {
     //Console.WriteLine(gameTime.ElapsedSec);
     GameCollection.Draw(Game.GetService<SpriteBatch>(), Game.GetService<DebugStrings>());
     base.Draw(gameTime, stereoEye);
 }
Beispiel #57
0
		/// <summary>
		/// Gets camera matrix for given stereo eye.
		/// </summary>
		/// <param name="stereoEye"></param>
		/// <returns></returns>
		public Matrix GetCameraMatrix ( StereoEye stereoEye )
		{
			if (stereoEye==StereoEye.Mono) return cameraMatrix;
			if (stereoEye==StereoEye.Left) return cameraMatrixL;
			if (stereoEye==StereoEye.Right) return cameraMatrixR;
			throw new ArgumentException("stereoEye");
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Render ( GameTime gameTime, Camera camera, StereoEye stereoEye, HdrFrame viewFrame )
		{
			var view		=	camera.GetViewMatrix( stereoEye );
			var projection	=	camera.GetProjectionMatrix( stereoEye );

			var colorTarget	=	viewFrame.HdrBuffer.Surface;
			var depthTarget	=	viewFrame.DepthBuffer.Surface;

			var viewport	=	new Viewport( 0, 0, colorTarget.Width, colorTarget.Height );

			RenderGeneric( "Particles", gameTime, camera, viewport, view, projection, colorTarget, null, viewFrame.DepthBuffer, Flags.DRAW );
		}
Beispiel #59
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gameTime"></param>
 /// <param name="stereoEye"></param>
 public override void Draw( GameTime gameTime, StereoEye stereoEye )
 {
 }
Beispiel #60
0
        /// <summary>
        /// Draws game
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="stereoEye"></param>
        protected override void Draw(GameTime gameTime, StereoEye stereoEye)
        {
            base.Draw(gameTime, stereoEye);

            //		time += gameTime.Elapsed.Milliseconds;

            var cam = GetService<GreatCircleCamera>();
            var dr = GetService<DebugRender>();
            var pSys = GetService<GraphSystem>();

            dr.View = cam.GetViewMatrix(stereoEye);
            dr.Projection = cam.GetProjectionMatrix(stereoEye);
            var ds = GetService<DebugStrings>();
            if (isSelected)
            {
                selectedDoctor = doctorToPatients.Keys.First(x => x.id == selectedNodeIndex );
                pSys.Select(selectedNodeIndex);
                //вывод в панель пациентов и врача
                mainPanel.Children.ElementAt( 0 ).Text = "Id # " + selectedNodeIndex;
            }
            else
            {

                //ds.Add(Color.Orange, "No selection");
                //pSys.Deselect();
            }
            if(selectedDoctor!=null)
                printInfoDoctor(selectedDoctor.fio + ": " + selectedDoctor.category);
            var offsetY = this.GraphicsDevice.DisplayBounds.Height*95/100;
            // TODO:
            //            foreach (var level in mainPanel.listLevel)
            //		    {
            //                printInfo(level.ToString(), (200 - level.ToString().Count() * 5) / 2, offsetY);
            //		        offsetY -= 90;
            //		    }
        }