Exemple #1
0
        public LineHelper(Vector3 start, Vector3 end, short time, LineHelperManager lineHelperManager)
        {
            if (!GameSettings.d_drawlines)
            {
                return;
            }

            _start = start;
            _end   = end;

            Verts = new VertexPositionColor[2];
            //Verts[0].Position = _start;
            //Verts[1].Position = _end;

            //Verts[0].Color = new Color(Color.Red, 0.5f);
            //Verts[1].Color = new Color(Color.Green, 0.5f);
            Verts[0] = lineHelperManager.GetVertexPositionColor(_start, new Color(Color.Red, 0.5f));
            Verts[1] = lineHelperManager.GetVertexPositionColor(_end, new Color(Color.Green, 0.5f));
            Timer    = time;
        }
Exemple #2
0
        public void Draw()
        {
            if (samplePositions.Count <= 0)
            {
                return;
            }
            LineHelperManager.AddLineStartEnd(startPosition, startPosition + startNormal, 1);
            //LineHelperManager.AddLineStartEnd(startPosition, startPosition + reflectVector * 10, 1, Color.AliceBlue, Color.Aqua);

            for (int index = 0; index < samplePositions.Count - 1; index++)
            {
                Vector3 v0 = samplePositions[index];
                Vector3 v1 = samplePositions[index + 1];
                LineHelperManager.AddLineStartEnd(v0, v1, 1, Color.Yellow, Color.Red);

                LineHelperManager.AddLineStartEnd(v0, sampleTests[index], 1, Color.Blue, Color.Violet);
            }

            //if(samplePositions.Count>0)
            //LineHelperManager.AddLineStartEnd(samplePositions[samplePositions.Count-1], sampleTests[samplePositions.Count - 1], 1, Color.Blue, Color.Violet);
        }
Exemple #3
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);
        }
Exemple #4
0
        private void TiledLighting(BoundingFrustum frustum, List <PointLight> pointLights, int cols, int rows)
        {
            if (TiledList == null || TiledList.Length != cols * rows)
            {
                TiledList       = new int[cols * rows][];
                TiledListLength = new float[cols * rows];

                for (var index = 0; index < TiledList.Length; index++)
                {
                    TiledList[index] = new int[MAXLIGHTSPERTILE];
                }
            }

            if (_tileFrustum == null)
            {
                _tileFrustum = new BoundingFrustumEx(frustum.Matrix);
            }

            Vector3[] mainfrustumCorners = frustum.GetCorners();

            for (float col = 0; col < cols; col++)
            {
                for (float row = 0; row < rows; row++)
                {
                    //top left
                    _tileFrustumCorners[0] = mainfrustumCorners[0]
                                             + (mainfrustumCorners[1] - mainfrustumCorners[0]) * col / cols
                                             + (mainfrustumCorners[3] - mainfrustumCorners[0]) * row / rows;

                    //top right
                    _tileFrustumCorners[1] = mainfrustumCorners[0]
                                             + (mainfrustumCorners[1] - mainfrustumCorners[0]) * (col + 1) / cols
                                             + (mainfrustumCorners[3] - mainfrustumCorners[0]) * row / rows;


                    //bot right
                    _tileFrustumCorners[2] = mainfrustumCorners[0]
                                             + (mainfrustumCorners[1] - mainfrustumCorners[0]) * (col + 1) / cols
                                             + (mainfrustumCorners[2] - mainfrustumCorners[1]) * (row + 1) / rows;

                    //bot left
                    _tileFrustumCorners[3] = mainfrustumCorners[0]
                                             + (mainfrustumCorners[1] - mainfrustumCorners[0]) * (col) / cols
                                             + (mainfrustumCorners[2] - mainfrustumCorners[1]) * (row + 1) / rows;

                    _tileFrustumCorners[4] = mainfrustumCorners[4]
                                             + (mainfrustumCorners[5] - mainfrustumCorners[4]) * col / cols
                                             + (mainfrustumCorners[7] - mainfrustumCorners[4]) * row / rows;

                    _tileFrustumCorners[5] = mainfrustumCorners[4]
                                             + (mainfrustumCorners[5] - mainfrustumCorners[4]) * (col + 1) / cols
                                             + (mainfrustumCorners[7] - mainfrustumCorners[4]) * row / rows;


                    _tileFrustumCorners[6] = mainfrustumCorners[4]
                                             + (mainfrustumCorners[5] - mainfrustumCorners[4]) * (col + 1) / cols
                                             + (mainfrustumCorners[6] - mainfrustumCorners[5]) * (row + 1) / rows;

                    _tileFrustumCorners[7] = mainfrustumCorners[4]
                                             + (mainfrustumCorners[5] - mainfrustumCorners[4]) * (col) / cols
                                             + (mainfrustumCorners[6] - mainfrustumCorners[5]) * (row + 1) / rows;

                    _tileFrustum.SetCorners(ref _tileFrustumCorners);
                    _tileFrustum.CreatePlanesFromCorners();

                    //Now we are ready to frustum cull... phew

                    int index = (int)(row * cols + col);

                    int numberOfLightsInTile = 0;

                    for (var i = 0; i < pointLights.Count; i++)
                    {
                        var             pointLight      = pointLights[i];
                        ContainmentType containmentType = _tileFrustum.Contains(pointLight.BoundingSphere);

                        if (containmentType == ContainmentType.Intersects ||
                            containmentType == ContainmentType.Contains)
                        {
                            TiledList[index][numberOfLightsInTile] = i;
                            numberOfLightsInTile++;
                        }

                        if (numberOfLightsInTile >= MAXLIGHTSPERTILE)
                        {
                            break;
                        }
                    }

                    TiledListLength[index] = numberOfLightsInTile;

#if SHOWTILES
                    LineHelperManager.AddFrustum(_tileFrustum, 1, numberOfLightsInTile > 1 ? Color.Red : numberOfLightsInTile > 0 ? Color.Blue : Color.Green);
#endif
                }
            }

            //Note: This needs a custom monogame version, since the default doesn't like to pass int[];
            _tiledListLengthParam.SetValue(TiledListLength);
        }
Exemple #5
0
        public LineHelper(Vector3 start, Vector3 end, short time, Color starColor, Color endColor, LineHelperManager lineHelperManager)
        {
            if (!GameSettings.d_drawlines)
            {
                return;
            }

            _start = start;
            _end   = end;

            Verts = new VertexPositionColor[2];
            //Verts[0].Position = _start;
            //Verts[1].Position = _end;

            //Verts[0].Color = starColor;
            //Verts[1].Color = endColor;
            Verts[0] = lineHelperManager.GetVertexPositionColor(_start, starColor);
            Verts[1] = lineHelperManager.GetVertexPositionColor(_end, endColor);

            Timer = time;
        }