Esempio n. 1
0
        public void DrawGizmo(Matrix staticViewProjection, EditorLogic.EditorSendData editorData)
        {
            if (editorData.SelectedObjectId == 0)
            {
                return;
            }



            Vector3 position = editorData.SelectedObjectPosition;

            EditorLogic.GizmoModes gizmoMode = editorData.GizmoMode;
            Matrix rotation = (GameStats.e_LocalTransformation || gizmoMode == EditorLogic.GizmoModes.Scale) ? editorData.SelectedObject.RotationMatrix : Matrix.Identity;

            //Z
            DrawArrow(position, rotation, 0, 0, 0, GetHoveredId() == 1 ? 1 : 0.5f, Color.Blue, staticViewProjection, gizmoMode);             //z 1
            DrawArrow(position, rotation, -Math.PI / 2, 0, 0, GetHoveredId() == 2 ? 1 : 0.5f, Color.Green, staticViewProjection, gizmoMode); //y 2
            DrawArrow(position, rotation, 0, Math.PI / 2, 0, GetHoveredId() == 3 ? 1 : 0.5f, Color.Red, staticViewProjection, gizmoMode);    //x 3

            DrawArrow(position, rotation, Math.PI, 0, 0, GetHoveredId() == 1 ? 1 : 0.5f, Color.Blue, staticViewProjection, gizmoMode);       //z 1
            DrawArrow(position, rotation, Math.PI / 2, 0, 0, GetHoveredId() == 2 ? 1 : 0.5f, Color.Green, staticViewProjection, gizmoMode);  //y 2
            DrawArrow(position, rotation, 0, -Math.PI / 2, 0, GetHoveredId() == 3 ? 1 : 0.5f, Color.Red, staticViewProjection, gizmoMode);   //x 3
            //DrawArrowRound(position, rotation, Math.PI, 0, 0, GetHoveredId() == 1 ? 1 : 0.5f, Color.Blue, staticViewProjection); //z 1
            //DrawArrowRound(position, rotation,-Math.PI / 2, 0, 0, GetHoveredId() == 2 ? 1 : 0.5f, Color.Green, staticViewProjection); //y 2
            //DrawArrowRound(position, rotation,0, Math.PI / 2, 0, GetHoveredId() == 3 ? 1 : 0.5f, Color.Red, staticViewProjection); //x 3
        }
Esempio n. 2
0
        public void DrawGizmos(Matrix staticViewProjection, EditorLogic.EditorSendData editorData, Assets assets)
        {
            if (editorData.SelectedObjectId == 0)
            {
                return;
            }

            _graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            _graphicsDevice.DepthStencilState = DepthStencilState.None;
            _graphicsDevice.BlendState        = BlendState.Opaque;

            Vector3 position = editorData.SelectedObjectPosition;

            Matrix rotation = (GameStats.e_LocalTransformation || editorData.GizmoMode == EditorLogic.GizmoModes.Scale) ? editorData.SelectedObject.RotationMatrix : Matrix.Identity;

            //Z
            DrawArrow(position, rotation, 0, 0, 0, 0.5f, new Color(1, 0, 0), staticViewProjection, assets);
            DrawArrow(position, rotation, -Math.PI / 2, 0, 0, 0.5f, new Color(2, 0, 0), staticViewProjection, assets);
            DrawArrow(position, rotation, 0, Math.PI / 2, 0, 0.5f, new Color(3, 0, 0), staticViewProjection, assets);

            DrawArrow(position, rotation, Math.PI, 0, 0, 0.5f, new Color(1, 0, 0), staticViewProjection, assets);
            DrawArrow(position, rotation, Math.PI / 2, 0, 0, 0.5f, new Color(2, 0, 0), staticViewProjection, assets);
            DrawArrow(position, rotation, 0, -Math.PI / 2, 0, 0.5f, new Color(3, 0, 0), staticViewProjection, assets);
        }
Esempio n. 3
0
        public void DrawIds(MeshMaterialLibrary meshMat, List <Decal> decals, List <PointLight> pointLights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix viewProjection, Matrix view, EditorLogic.EditorSendData editorData)
        {
            _graphicsDevice.SetRenderTarget(_idRenderTarget2D);
            _graphicsDevice.BlendState = BlendState.Opaque;

            _graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            _graphicsDevice.DepthStencilState = DepthStencilState.Default;

            meshMat.Draw(MeshMaterialLibrary.RenderType.IdRender, viewProjection);

            //Now onto the billboards
            DrawBillboards(decals, pointLights, dirLights, envSample, debug, viewProjection, view);

            //Now onto the gizmos
            DrawGizmos(viewProjection, editorData, _assets);

            Rectangle sourceRectangle =
                new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);

            Color[] retrievedColor = new Color[1];

            try
            {
                if (sourceRectangle.X >= 0 && sourceRectangle.Y >= 0 && sourceRectangle.X < _idRenderTarget2D.Width - 2 && sourceRectangle.Y < _idRenderTarget2D.Height - 2)
                {
                    _idRenderTarget2D.GetData(0, sourceRectangle, retrievedColor, 0, 1);
                }
            }
            catch
            {
                //nothing
            }

            HoveredId = IdGenerator.GetIdFromColor(retrievedColor[0]);
        }
Esempio n. 4
0
        public void Draw(MeshMaterialLibrary meshMat, List <Decal> decals, List <PointLight> pointLights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix viewProjection, Matrix view, EditorLogic.EditorSendData editorData, bool mouseMoved)
        {
            if (editorData.GizmoTransformationMode)
            {
                _graphicsDevice.SetRenderTarget(_idRenderTarget2D);
                _graphicsDevice.Clear(Color.Black);
                return;
            }

            if (mouseMoved)
            {
                DrawIds(meshMat, decals, pointLights, dirLights, envSample, debug, viewProjection, view, editorData);
            }

            if (GameSettings.e_drawoutlines)
            {
                DrawOutlines(meshMat, viewProjection, mouseMoved, HoveredId, editorData, mouseMoved);
            }
        }
Esempio n. 5
0
        public void DrawOutlines(MeshMaterialLibrary meshMat, Matrix viewProjection, bool drawAll, int hoveredId, EditorLogic.EditorSendData editorData, bool mouseMoved)
        {
            _graphicsDevice.SetRenderTarget(_idRenderTarget2D);

            if (!mouseMoved)
            {
                _graphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);
            }
            else
            {
                _graphicsDevice.Clear(Color.Black);
            }
            _graphicsDevice.BlendState        = BlendState.Opaque;
            _graphicsDevice.DepthStencilState = DepthStencilState.Default;
            _graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;

            int selectedId = editorData.SelectedObjectId;

            //Selected entity
            if (selectedId != 0)
            {
                //UPdate the size of our outlines!

                if (!drawAll)
                {
                    meshMat.Draw(MeshMaterialLibrary.RenderType.IdOutline, viewProjection, false, false,
                                 false, selectedId);
                }

                Shaders.IdRenderEffectParameterColorId.SetValue(_selectedColor);
                meshMat.Draw(MeshMaterialLibrary.RenderType.IdOutline, viewProjection, false, false,
                             outlined: true, outlineId: selectedId);
            }

            if (selectedId != hoveredId && hoveredId != 0 && mouseMoved)
            {
                if (!drawAll)
                {
                    meshMat.Draw(MeshMaterialLibrary.RenderType.IdOutline, viewProjection, false, false, false, hoveredId);
                }

                Shaders.IdRenderEffectParameterColorId.SetValue(_hoveredColor);
                meshMat.Draw(MeshMaterialLibrary.RenderType.IdOutline, viewProjection, false, false, outlined: true, outlineId: hoveredId);
            }
        }
Esempio n. 6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        //  RENDER FUNCTIONS
        ////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region MAIN DRAW FUNCTIONS
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        //  MAIN DRAW FUNCTIONS
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Main Draw function of the game
        /// </summary>
        /// <param name="camera">view point of the renderer</param>
        /// <param name="meshMaterialLibrary">a class that has stored all our mesh data</param>
        /// <param name="entities">entities and their properties</param>
        /// <param name="pointLights"></param>
        /// <param name="directionalLights"></param>
        /// <param name="editorData">The data passed from our editor logic</param>
        /// <param name="gameTime"></param>
        /// <returns></returns>
        public void Draw(Camera camera, MeshMaterialLibrary meshMaterialLibrary, List <BasicEntity> entities, List <PointLightSource> pointLights, List <DirectionalLightSource> directionalLights, EditorLogic.EditorSendData editorData, GameTime gameTime)
        {
            //Reset the stat counter, so we can count stats/information for this frame only
            ResetStats();

            //Update the mesh data for changes in physics etc.
            meshMaterialLibrary.FrustumCullingStartFrame(entities);

            //Check if we changed some drastic stuff for which we need to reload some elements
            CheckRenderChanges(directionalLights);

            //Render ShadowMaps
            //DrawShadowMaps(meshMaterialLibrary, entities, pointLights, directionalLights, camera);

            //Update our view projection matrices if the camera moved
            UpdateViewProjection(camera, meshMaterialLibrary, entities);

            GS.BeginMark("DrawTextureBuffer", Color.Red);
            //Draw our meshes to the G Buffer
            DrawTextureBuffer(meshMaterialLibrary);

            GS.EndMark("DrawTextureBuffer");

            FixSeams();

            GS.BeginMark("DrawMeshes", Color.Blue);
            DrawObjects(meshMaterialLibrary);
            GS.EndMark("DrawMeshes");
            //Draw the final rendered image, change the output based on user input to show individual buffers/rendertargets
            RenderMode();

            //Draw (debug) lines
            LineHelperManager.Draw(_graphicsDevice, _staticViewProjection);

            //Set up the frustum culling for the next frame
            meshMaterialLibrary.FrustumCullingFinalizeFrame(entities);
        }
Esempio n. 7
0
        public void DrawBillboards(List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData sendData)
        {
            _graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            _graphicsDevice.SetVertexBuffer(_billboardBuffer.VBuffer);
            _graphicsDevice.Indices = (_billboardBuffer.IBuffer);

            Shaders.BillboardEffect.CurrentTechnique = Shaders.BillboardEffectTechnique_Billboard;

            Shaders.BillboardEffectParameter_IdColor.SetValue(Color.Gray.ToVector3());

            //Decals

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconDecal);
            for (int index = 0; index < decals.Count; index++)
            {
                var decal = decals[index];
                DrawBillboard(decal, staticViewProjection, view, sendData);
            }

            //Lights

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconLight);
            for (int index = 0; index < lights.Count; index++)
            {
                var light = lights[index];
                DrawBillboard(light, staticViewProjection, view, sendData);
            }

            //DirectionalLights
            for (var index = 0; index < dirLights.Count; index++)
            {
                DirectionalLight light = dirLights[index];
                DrawBillboard(light, staticViewProjection, view, sendData);

                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position, light.Direction * 10, 1, Color.Black, light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitX * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitY * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position + Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);
                HelperGeometryManager.GetInstance()
                .AddLineStartDir(light.Position - Vector3.UnitZ * 10, light.Direction * 10, 1, Color.Black,
                                 light.Color);

                if (light.CastShadows)
                {
                    BoundingFrustum boundingFrustumShadow = new BoundingFrustum(light.LightViewProjection);

                    HelperGeometryManager.GetInstance().CreateBoundingBoxLines(boundingFrustumShadow);
                }
            }

            //EnvMap

            Shaders.BillboardEffectParameter_Texture.SetValue(_assets.IconEnvmap);

            DrawBillboard(envSample, staticViewProjection, view, sendData);

            //Dbg
            for (int index = 0; index < debug.Count; index++)
            {
                var dbgEntity = debug[index];
                DrawBillboard(dbgEntity, staticViewProjection, view, sendData);
            }
        }
Esempio n. 8
0
        public void DrawEditorElements(MeshMaterialLibrary meshMaterialLibrary, List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData editorData)
        {
            _graphicsDevice.SetRenderTarget(null);
            _graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            _graphicsDevice.DepthStencilState = DepthStencilState.Default;
            _graphicsDevice.BlendState        = BlendState.Opaque;

            DrawGizmo(staticViewProjection, editorData);
            DrawBillboards(decals, lights, dirLights, envSample, debug, staticViewProjection, view, editorData);
        }
Esempio n. 9
0
 public void DrawIds(MeshMaterialLibrary meshMaterialLibrary, List <Decal> decals, List <PointLight> lights, List <DirectionalLight> dirLights, EnvironmentSample envSample, List <DebugEntity> debug, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData editorData)
 {
     _idAndOutlineRenderer.Draw(meshMaterialLibrary, decals, lights, dirLights, envSample, debug, staticViewProjection, view, editorData, _mouseMovement);
 }
Esempio n. 10
0
        private void DrawBillboard(TransformableObject billboardObject, Matrix staticViewProjection, Matrix view, EditorLogic.EditorSendData sendData)
        {
            Matrix world = Matrix.CreateTranslation(billboardObject.Position);

            Shaders.BillboardEffectParameter_WorldViewProj.SetValue(world * staticViewProjection);
            Shaders.BillboardEffectParameter_WorldView.SetValue(world * view);

            if (billboardObject.Id == GetHoveredId())
            {
                Shaders.BillboardEffectParameter_IdColor.SetValue(Color.White.ToVector3());
            }
            if (billboardObject.Id == sendData.SelectedObjectId)
            {
                Shaders.BillboardEffectParameter_IdColor.SetValue(Color.Gold.ToVector3());
            }

            Shaders.BillboardEffect.CurrentTechnique.Passes[0].Apply();

            _graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2);

            if (billboardObject.Id == GetHoveredId() || billboardObject.Id == sendData.SelectedObjectId)
            {
                Shaders.BillboardEffectParameter_IdColor.SetValue(Color.Gray.ToVector3());
            }
        }