internal void Render()
        {
            var foliageComponents = MyFoliageComponents.ActiveComponents;

            if (foliageComponents.Count <= 0)
            {
                return;
            }

            ViewProjection = MyRender11.Environment.Matrices.ViewProjectionAt0;
            Viewport       = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            PerFrame();
            Begin();

            var viewFrustum = new BoundingFrustumD(MyRender11.Environment.Matrices.ViewProjectionD);

            foreach (var foliageComponent in foliageComponents)
            {
                var  renderableComponent       = foliageComponent.Owner.GetRenderable();
                bool removeDitheringInProgress = renderableComponent.m_objectDithering > 0 && renderableComponent.m_objectDithering < 2;
                if (!removeDitheringInProgress && foliageComponent.Owner.CalculateCameraDistance() < MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance())
                {
                    if (viewFrustum.Contains(foliageComponent.Owner.Aabb) != ContainmentType.Disjoint)
                    {
                        foliageComponent.Render(this);
                    }
                }
            }

            End();
        }
示例#2
0
        internal static void Render()
        {
            m_instance.ViewProjection = MyEnvironment.ViewProjectionAt0;
            m_instance.Viewport       = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            //m_instance.DepthBuffer = MyRender.MainGbuffer.DepthBuffer.DepthStencil;
            //m_instance.RTs = MyRender.MainGbuffer.GbufferTargets;

            m_instance.PerFrame();
            m_instance.Begin();

            var viewFrustum = new BoundingFrustumD(MyEnvironment.ViewProjectionD);

            foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll())
            {
                if (f.m_owner.CalculateCameraDistance() < MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance() &&
                    viewFrustum.Contains(f.m_owner.Aabb) != VRageMath.ContainmentType.Disjoint)
                {
                    f.Render(m_instance);
                }
            }

            m_instance.End();
        }
示例#3
0
 //  Checks if specified bounding sphere is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding sphere.
 //  Don't use BoundingSphere.Transform. Instead transform sphere center manualy and then create new sphere.
 public static bool IsInFrustum(ref BoundingSphereD boundingSphere)
 {
     VRageMath.ContainmentType result;
     m_boundingFrustum.Contains(ref boundingSphere, out result);
     return(result != VRageMath.ContainmentType.Disjoint);
 }
示例#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();
        }
        internal void Render()
        {
            var foliageComponents = MyFoliageComponents.ActiveComponents;
            if (foliageComponents.Count <= 0)
                return;

            ViewProjection = MyRender11.Environment.ViewProjectionAt0;
            Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            PerFrame();
            Begin();

            var viewFrustum = new BoundingFrustumD(MyRender11.Environment.ViewProjectionD);

            foreach (var foliageComponent in foliageComponents)
            {
                var renderableComponent = foliageComponent.Owner.GetRenderable();
                bool removeDitheringInProgress = renderableComponent.m_objectDithering > 0 && renderableComponent.m_objectDithering < 2;
                if (!removeDitheringInProgress && foliageComponent.Owner.CalculateCameraDistance() < MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance())
                {
                    if (viewFrustum.Contains(foliageComponent.Owner.Aabb) != ContainmentType.Disjoint)
                        foliageComponent.Render(this);
                }
            }

            End();
        }
示例#6
0
        static ContainmentType ContainsAdv(this MyOrientedBoundingBoxD obb, BoundingFrustumD frust, HashSet <Vector3D> internalPoints, out bool noCorners)
        {
            var points = new Vector3D[8];

            obb.GetCorners(points, 0);
            int inside = 0;

            for (int i = 0; i < points.Length; i++)
            {
                if (frust.Contains(points[i]) != ContainmentType.Disjoint)
                {
                    inside++;
                    internalPoints.Add(points[i]);
                }
            }
            noCorners = false;
            switch (inside)
            {
            case (8):
                return(ContainmentType.Contains);

            default:
                if (internalPoints.Count != 0 || frust.Contains(obb.GetAABB()) != ContainmentType.Disjoint)
                {
                    noCorners = true;
                    var res   = new HashSet <Vector3D>();
                    var lines = frust.GetLines();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        var from = obb.Contains(ref lines[i].From);
                        var to   = obb.Contains(ref lines[i].To);
                        if (from && to)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].To);
                        }
                        else if (from)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].GetPoint(obb.Intersects(ref lines[i]).Value));
                        }
                        else if (to)
                        {
                            res.Add(lines[i].To);
                            var back = lines[i].Reverse();
                            res.Add(back.GetPoint(obb.Intersects(ref back).Value));
                        }
                        else
                        {
                            var first  = obb.Intersects(ref lines[i]);
                            var back   = lines[i].Reverse();
                            var second = obb.Intersects(ref back);
                            if (first != null)
                            {
                                res.Add(lines[i].GetPoint(first.Value));
                            }
                            if (second != null)
                            {
                                res.Add(back.GetPoint(second.Value));
                            }
                        }
                    }
                    lines = obb.GetLines();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        var from = frust.Contains(lines[i].From) != ContainmentType.Disjoint;
                        var to   = frust.Contains(lines[i].To) != ContainmentType.Disjoint;
                        if (from && to)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].To);
                        }
                        else if (from)
                        {
                            res.Add(lines[i].From);
                            res.Add(lines[i].GetPoint(frust.Intersects(lines[i].ToRay()).Value));
                        }
                        else if (to)
                        {
                            res.Add(lines[i].To);
                            res.Add(lines[i].Reverse().GetPoint(frust.Intersects(lines[i].ToReversedRay()).Value));
                        }
                        else
                        {
                            var first  = frust.Intersects(lines[i].ToRay());
                            var second = frust.Intersects(lines[i].ToReversedRay());
                            if (first != null)
                            {
                                res.Add(lines[i].GetPoint(first.Value));
                            }
                            if (second != null)
                            {
                                res.Add(lines[i].Reverse().GetPoint(second.Value));
                            }
                        }
                    }

                    foreach (var r in res)
                    {
                        internalPoints.Add(r);
                    }
                    if (internalPoints.Count > 0)
                    {
                        return(ContainmentType.Intersects);
                    }
                }
                return(ContainmentType.Disjoint);
            }
        }
        internal static void Render()
        {
            m_instance.ViewProjection = MyEnvironment.ViewProjectionAt0;
            m_instance.Viewport = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);
            //m_instance.DepthBuffer = MyRender.MainGbuffer.DepthBuffer.DepthStencil;
            //m_instance.RTs = MyRender.MainGbuffer.GbufferTargets;

            m_instance.PerFrame();
            m_instance.Begin();

            var viewFrustum = new BoundingFrustumD(MyEnvironment.ViewProjectionD);
			var foliageComponents = MyComponentFactory<MyFoliageComponent>.GetAll();
            foreach(var foliageComponent in foliageComponents)
            {
				if (foliageComponent.m_owner.CalculateCameraDistance() < MyRender11.RenderSettings.FoliageDetails.GrassDrawDistance()
					&& viewFrustum.Contains(foliageComponent.m_owner.Aabb) != VRageMath.ContainmentType.Disjoint)
                {
					foliageComponent.Render(m_instance);
                }
            }

            m_instance.End();
        }
示例#8
0
 //  Checks if specified bounding box is in actual bounding frustum
 //  IMPORTANT: If you observe bad result of this test, check how you transform your bounding box.
 //  Don't use BoundingBox.Transform. Instead transform box manualy and then create new box.
 public bool IsInFrustum(ref BoundingBoxD boundingBox)
 {
     VRageMath.ContainmentType result;
     BoundingFrustum.Contains(ref boundingBox, out result);
     return(result != VRageMath.ContainmentType.Disjoint);
 }