コード例 #1
0
        static void PrepareObjectQueries(MyOcclusionQueryID queryID, List<MyElement> cullObjectListForDraw, List<MyOcclusionQueryIssue> renderOcclusionQueries, ref int occludedItemsStats)
        {
            if (queryID != MyOcclusionQueryID.MAIN_RENDER)
                return;

            if (!Settings.EnableHWOcclusionQueries)
                return;

            if (!m_currentSetup.EnableOcclusionQueries)
                return;

            int c = 0;
            while (c < cullObjectListForDraw.Count)
            {
                MyCullableRenderObject cullableRenderObject = (MyCullableRenderObject)cullObjectListForDraw[c];

                bool isVisibleFromQuery = false;
                MyOcclusionQueryIssue query = cullableRenderObject.GetQuery(queryID);
                if (query.OcclusionQueryIssued)
                {
                    isVisibleFromQuery = query.OcclusionQueryVisible;

                    bool isComplete = query.OcclusionQuery.IsComplete;

                    if (isComplete)
                    {
                        query.OcclusionQueryIssued = false;

                        isVisibleFromQuery = query.OcclusionQuery.PixelCount > 0;

                        //Holy ATI 
                        if (query.OcclusionQuery.PixelCount < 0)
                        {
                            isVisibleFromQuery = true;
                        }

                        query.OcclusionQueryVisible = isVisibleFromQuery;


                        //if (m_renderCounter % OCCLUSION_INTERVAL == cullableRenderObject.RenderCounter)
                        if (!query.OcclusionQueryVisible)
                        {
                            renderOcclusionQueries.Add(query);
                        }
                    }

                    if (!isVisibleFromQuery)
                    {
                        occludedItemsStats += cullableRenderObject.EntitiesContained;
                        cullObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }
                }
                else
                {
                    if (query.OcclusionQueryVisible && (m_renderCounter % OCCLUSION_INTERVAL == cullableRenderObject.RenderCounter || ShowHWOcclusionQueries))
                    {
                        renderOcclusionQueries.Add(cullableRenderObject.GetQuery(queryID));
                    }

                    if (!query.OcclusionQueryVisible)
                    {
                        renderOcclusionQueries.Add(cullableRenderObject.GetQuery(queryID));

                        occludedItemsStats += cullableRenderObject.EntitiesContained;
                        cullObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }
                }

                c++;
            }
        }
コード例 #2
0
 public MyOcclusionQueryIssue GetQuery(MyOcclusionQueryID id)
 {
     return m_queries[(int)id];
 }
コード例 #3
0
        internal static void PrepareEntitiesForLargeDraw(ref BoundingFrustumD frustum, Vector3D cameraPosition, MyOcclusionQueryID queryID, List<MyElement> renderObjectListForDraw, ref int occludedItemsStats)
        {
            GetRenderProfiler().StartProfilingBlock("PrepareEntitiesForDrawFr()");

            if (queryID != MyOcclusionQueryID.MAIN_RENDER)
            {             
                return;
            }

            renderObjectListForDraw.Clear();

            GetRenderProfiler().StartProfilingBlock("m_prunningStructure.OverlapAllFrustum");
            m_farObjectsPrunningStructure.OverlapAllFrustum(ref frustum, renderObjectListForDraw);

            //AssertRenderObjects(renderObjectListForDraw);
            GetRenderProfiler().EndProfilingBlock();
          
            GetRenderProfiler().StartProfilingBlock("Get from cullobjects - part 2");

            int c = 0;

            if (queryID == MyOcclusionQueryID.MAIN_RENDER)
            {
                //int ii = 0;
                while (c < renderObjectListForDraw.Count)
                {
                    MyRenderLight renderLight = renderObjectListForDraw[c] as MyRenderLight;
                    if (renderLight != null && ((renderLight.LightOn || renderLight.GlareOn)))
                    {
                        continue;
                    }

                    MyRenderObject ro = renderObjectListForDraw[c] as MyRenderObject;

                    if (ro.NearFlag)
                    {
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }


                    if (!ro.SkipIfTooSmall)
                    {
                        c++;
                        continue;
                    }

                    Vector3D entityPosition = ro.WorldVolume.Center;

                    Vector3D.Distance(ref cameraPosition, ref entityPosition, out ro.Distance);

                    float cullRatio = MyRenderConstants.DISTANCE_CULL_RATIO;

                    if (ro.WorldVolume.Radius < ro.Distance / cullRatio)
                    {
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }
                    c++;
                }
            }

            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().EndProfilingBlock();
        }
コード例 #4
0
        internal static void PrepareEntitiesForDraw(ref BoundingFrustumD frustum, Vector3D cameraPosition, MyOcclusionQueryID queryID, List<MyElement> renderObjectListForDraw, List<MyRenderLight> renderLightsForDraw, List<MyElement> cullObjectListForDraw, List<MyElement> manualCullObjectListForDraw, List<MyOcclusionQueryIssue> renderOcclusionQueries, ref int occludedItemsStats)
        {
            GetRenderProfiler().StartProfilingBlock("PrepareEntitiesForDrawFr()");

            if (queryID != MyOcclusionQueryID.MAIN_RENDER)
            {
                m_shadowPrunningStructure.OverlapAllFrustum(ref frustum, renderObjectListForDraw);

                GetRenderProfiler().StartProfilingBlock("m_manualCullingStructure.OverlapAllFrustum");
                m_manualCullingStructure.OverlapAllFrustum(ref frustum, manualCullObjectListForDraw);
                GetRenderProfiler().EndProfilingBlock();

                GetRenderProfiler().StartProfilingBlock("Get from manual cullobjects");
                foreach (MyCullableRenderObject cullableObject in manualCullObjectListForDraw)
                {
                    cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);
                }
                GetRenderProfiler().EndProfilingBlock();

                foreach (var nearObject in m_nearObjects)
                {
                    renderObjectListForDraw.Add(nearObject);
                }

                GetRenderProfiler().EndProfilingBlock();
                return;
            }

            GetRenderProfiler().StartProfilingBlock("m_cullingStructure.OverlapAllFrustum");
            m_cullingStructure.OverlapAllFrustum(ref frustum, cullObjectListForDraw);
            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().StartProfilingBlock("m_manualCullingStructure.OverlapAllFrustum");
            m_manualCullingStructure.OverlapAllFrustum(ref frustum, manualCullObjectListForDraw);
            GetRenderProfiler().EndProfilingBlock();

            
            if (renderOcclusionQueries != null)
            {
                //Process only big cull object for queries
                renderOcclusionQueries.Clear();

                GetRenderProfiler().StartProfilingBlock("PrepareObjectQueries");
                PrepareObjectQueries(queryID, cullObjectListForDraw, renderOcclusionQueries, ref occludedItemsStats);
                GetRenderProfiler().EndProfilingBlock();

                GetRenderProfiler().StartProfilingBlock("PrepareObjectQueries 2");
                PrepareObjectQueries(queryID, manualCullObjectListForDraw, renderOcclusionQueries, ref occludedItemsStats);
                GetRenderProfiler().EndProfilingBlock();
            }

            renderObjectListForDraw.Clear();
            renderLightsForDraw.Clear();

            GetRenderProfiler().StartProfilingBlock("m_prunningStructure.OverlapAllFrustum");
            m_prunningStructure.OverlapAllFrustum(ref frustum, renderObjectListForDraw);

            //AssertRenderObjects(renderObjectListForDraw);
            GetRenderProfiler().EndProfilingBlock();


            GetRenderProfiler().StartProfilingBlock("Get from cullobjects - part 1");

            foreach (MyCullableRenderObject cullableObject in cullObjectListForDraw)
            {
                if (frustum.Contains(cullableObject.WorldAABB) == VRageMath.ContainmentType.Contains)
                {
                    cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);
                }
                else
                {
                    cullableObject.CulledObjects.OverlapAllFrustum(ref frustum, renderObjectListForDraw, false);
                }
            }

            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().StartProfilingBlock("Get from manual cullobjects");

            foreach (MyCullableRenderObject cullableObject in manualCullObjectListForDraw)
            {
                cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);
                MyRenderProxy.VisibleObjectsWrite.Add(cullableObject.ID);
            }

            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().StartProfilingBlock("Get from cullobjects - part 2");

            int c = 0;

            if (queryID == MyOcclusionQueryID.MAIN_RENDER)
            {
                //int ii = 0;
                while (c < renderObjectListForDraw.Count)
                {
                    MyRenderLight renderLight = renderObjectListForDraw[c] as MyRenderLight;
                    if (renderLight != null && ((renderLight.LightOn || renderLight.GlareOn)))
                    {
                        renderLightsForDraw.Add(renderLight);
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }

                    MyRenderObject ro = renderObjectListForDraw[c] as MyRenderObject;

                    if (ro.NearFlag)
                    {
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }


                    if (!ro.SkipIfTooSmall)
                    {
                        c++;
                        continue;
                    }

            
                    Vector3D entityPosition = ro.WorldVolume.Center;

                    Vector3D.Distance(ref cameraPosition, ref entityPosition, out ro.Distance);
                    
                    float cullRatio = MyRenderConstants.DISTANCE_CULL_RATIO;

                    if (ro.WorldVolume.Radius < ro.Distance / cullRatio)
                    {
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    }
                    

                    c++;
                }


                MyLights.UpdateLightsForEffect(m_renderLightsForDraw);
            }

            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().EndProfilingBlock();
        }
コード例 #5
0
        internal static void PrepareEntitiesForDraw(ref BoundingBoxD box, MyOcclusionQueryID queryID, List<MyElement> renderObjectListForDraw, List<MyRenderLight> renderLightsForDraw, List<MyOcclusionQueryIssue> renderOcclusionQueries, ref int occludedItemsStats)
        {
            GetRenderProfiler().StartProfilingBlock("PrepareEntitiesForDraw()");

            //Process only big cull object for queries
            renderOcclusionQueries.Clear();

            m_cullingStructure.OverlapAllBoundingBox(ref box, m_cullObjectListForDraw);

            PrepareObjectQueries(queryID, m_cullObjectListForDraw, renderOcclusionQueries, ref occludedItemsStats);

            renderObjectListForDraw.Clear();

            GetRenderProfiler().StartProfilingBlock("m_prunningStructure.OverlapAllBoundingBox");
            m_prunningStructure.OverlapAllBoundingBox(ref box, renderObjectListForDraw);

            foreach (MyCullableRenderObject cullableObject in m_cullObjectListForDraw)
            {
                cullableObject.CulledObjects.OverlapAllBoundingBox(ref box, renderObjectListForDraw, 0, false);
            }

            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().EndProfilingBlock();
        }
コード例 #6
0
        internal static void PrepareEntitiesForDraw(ref BoundingFrustum frustum, Vector3 cameraPosition, float cameraZoomDivider, MyOcclusionQueryID queryID, List<MyElement> renderObjectListForDraw, List<MyElement> cullObjectListForDraw, List<MyOcclusionQueryIssue> renderOcclusionQueries, ref int occludedItemsStats)
        {
            m_renderProfiler.StartProfilingBlock("PrepareEntitiesForDrawFr()");
                 
            if (queryID != MyOcclusionQueryID.MAIN_RENDER)
            {
                m_shadowPrunningStructure.OverlapAllFrustum(ref frustum, renderObjectListForDraw);
                m_renderProfiler.EndProfilingBlock();
                return;
            }      

            m_renderProfiler.StartProfilingBlock("m_cullingStructure.OverlapAllFrustum");
            m_cullingStructure.OverlapAllFrustum(ref frustum, cullObjectListForDraw);
            m_renderProfiler.EndProfilingBlock();

            if (renderOcclusionQueries != null)
            {
                //Process only big cull object for queries
                renderOcclusionQueries.Clear();

                m_renderProfiler.StartProfilingBlock("PrepareObjectQueries");
                PrepareObjectQueries(queryID, cullObjectListForDraw, renderOcclusionQueries, ref occludedItemsStats);
                m_renderProfiler.EndProfilingBlock();
            }

            renderObjectListForDraw.Clear();

            m_renderProfiler.StartProfilingBlock("m_prunningStructure.OverlapAllFrustum");
            m_prunningStructure.OverlapAllFrustum(ref frustum, renderObjectListForDraw);
            //AssertRenderObjects(renderObjectListForDraw);
            m_renderProfiler.EndProfilingBlock();


            m_renderProfiler.StartProfilingBlock("Get from cullobjects - part 1");

            //int i = 1;

            if (queryID == MyOcclusionQueryID.MAIN_RENDER)
            {
                foreach (MyCullableRenderObject cullableObject in cullObjectListForDraw)
                {
                    if (frustum.Contains(cullableObject.GetWorldSpaceAABB()) == MinerWarsMath.ContainmentType.Contains)
                    {
                        cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);
                    }
                    else
                    {
                        cullableObject.CulledObjects.OverlapAllFrustum(ref frustum, renderObjectListForDraw, false);
                      //  i++;
                    } 




                    //AssertRenderObjects(renderObjectListForDraw);
                    //BoundingBox aabb = new BoundingBox(new Vector3(float.MinValue), new Vector3(float.MaxValue));
                    //cullableObject.CulledObjects.OverlapAllBoundingBox(ref aabb, renderObjectListForDraw, false);
                    //cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);                
                }
            }
            else
            {
                foreach (MyCullableRenderObject cullableObject in cullObjectListForDraw)
                {
                    if (frustum.Contains(cullableObject.GetWorldSpaceAABB()) == MinerWarsMath.ContainmentType.Contains)
                    {
                        cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);
                    }
                    else
                    {
                        cullableObject.CulledObjects.OverlapAllFrustum(ref frustum, renderObjectListForDraw, false);
                    }

                    //cullableObject.CulledObjects.OverlapAllFrustum(ref frustum, renderObjectListForDraw, false);
                    //cullableObject.CulledObjects.GetAll(renderObjectListForDraw, false);                
                }
            }

            m_renderProfiler.EndProfilingBlock();

            m_renderProfiler.StartProfilingBlock("Get from cullobjects - part 2");
                
            int c = 0;

            if (queryID == MyOcclusionQueryID.MAIN_RENDER)
            {
                //int ii = 0;
                while (c < renderObjectListForDraw.Count)
                {
                    MyRenderObject ro = renderObjectListForDraw[c] as MyRenderObject;
                    if (!ro.SkipIfTooSmall)
                    {
                        c++;
                        continue;
                    }
                          
                    Vector3 entityPosition = ro.Entity.GetPosition();
                    
                    Vector3.Distance(ref cameraPosition, ref entityPosition, out ro.Distance);
                    ro.Distance = MyCamera.GetDistanceWithFOV(ro.Distance);

                    float cullRatio = ro.Entity is MyStaticAsteroid ? 75 : MyRenderConstants.DISTANCE_CULL_RATIO;

                    if (ro.Entity is MinerWars.AppCode.Game.Entities.SubObjects.MyPrefabLargeWeapon ||
                        ro.Entity is MinerWars.AppCode.Game.Entities.Weapons.MyLargeShipBarrelBase ||
                        ro.Entity is MinerWars.AppCode.Game.Entities.Weapons.MyLargeShipGunBase)
                    {
                        cullRatio = 250;
                    }

                    if (ro.Entity.WorldVolume.Radius < ro.Distance / cullRatio)
                    {
                        renderObjectListForDraw.RemoveAtFast(c);
                        continue;
                    } 


                                      
                    //float f = ro.Distance / (2 * (float)Math.Tan(Math.PI * MyCamera.FieldOfView));

                    //if (f > ro.Entity.LocalVolume.Radius * 100)
                    //{
                    //    renderObjectListForDraw.RemoveAtFast(c);
                    //    continue;
                    //}

                    c++;
                }
            }

            m_renderProfiler.EndProfilingBlock();

            m_renderProfiler.EndProfilingBlock();
        }
コード例 #7
0
 public MyOcclusionQueryIssue GetQuery(MyOcclusionQueryID id)
 {
     return(m_queries[(int)id]);
 }