Beispiel #1
0
        /// <summary>
        /// Cull test for spot lights
        /// </summary>
        /// <param name="volume">Volume</param>
        /// <param name="viewerPosition">Viewer position</param>
        private void CullSpotLights(ICullingVolume volume, Vector3 viewerPosition)
        {
            var sLights = this.spotLights.FindAll(l =>
            {
                if (l.Enabled && volume.Contains(l.BoundingSphere) != ContainmentType.Disjoint)
                {
                    float d = Vector3.Distance(viewerPosition, l.Position);

                    return((l.Radius / d) >= (1f / GameEnvironment.LODDistanceLow));
                }

                return(false);
            });

            if (sLights.Count > 0)
            {
                sLights.Sort((l1, l2) =>
                {
                    float d1 = Vector3.Distance(viewerPosition, l1.Position);
                    float d2 = Vector3.Distance(viewerPosition, l2.Position);

                    float f1 = l1.Radius / d1 == 0 ? 1 : d1;
                    float f2 = l2.Radius / d2 == 0 ? 1 : d2;

                    return(f1.CompareTo(f2));
                });

                this.visibleLights.AddRange(sLights);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the node list suitable for foliage planting
        /// </summary>
        /// <param name="volume">Culling volume</param>
        /// <param name="sph">Foliagle bounding sphere</param>
        /// <returns>Returns a node list</returns>
        private IEnumerable <QuadTreeNode> GetFoliageNodes(ICullingVolume volume, BoundingSphere sph)
        {
            var nodes = this.foliageQuadtree.GetNodesInVolume(ref sph);

            if (nodes?.Any() == true)
            {
                return(nodes.Where(n => volume.Contains(n.BoundingBox) != ContainmentType.Disjoint));
            }

            return(new QuadTreeNode[] { });
        }
Beispiel #3
0
        /// <summary>
        /// Performs culling test
        /// </summary>
        /// <param name="volume">Culling volume</param>
        /// <param name="distance">If the object is inside the volume, returns the distance</param>
        /// <returns>Returns true if the object is outside of the frustum</returns>
        public override bool Cull(ICullingVolume volume, out float distance)
        {
            bool cull;

            distance = float.MaxValue;

            if (this.HasVolumes)
            {
                if (this.coarseBoundingSphere.HasValue)
                {
                    cull = volume.Contains(this.coarseBoundingSphere.Value) == ContainmentType.Disjoint;
                }
                else if (this.SphericVolume)
                {
                    cull = volume.Contains(this.GetBoundingSphere()) == ContainmentType.Disjoint;
                }
                else
                {
                    cull = volume.Contains(this.GetBoundingBox()) == ContainmentType.Disjoint;
                }
            }
            else
            {
                cull = false;
            }

            if (!cull)
            {
                var eyePosition = volume.Position;

                distance = Vector3.DistanceSquared(this.Manipulator.Position, eyePosition);

                this.LevelOfDetail = GameEnvironment.GetLOD(
                    eyePosition,
                    this.coarseBoundingSphere,
                    this.Manipulator.LocalTransform,
                    this.Manipulator.AveragingScale);
            }

            return(cull);
        }
        /// <summary>
        /// Performs a culling test against the specified frustum
        /// </summary>
        /// <param name="volume">Culling volume</param>
        /// <param name="distance">If the object is inside the volume, returns the distance</param>
        /// <returns>Returns true if the emitter is outside of the frustum</returns>
        public bool Cull(ICullingVolume volume, out float distance)
        {
            distance = float.MaxValue;

            var bbox = this.GetBoundingBox();

            var inside = volume.Contains(bbox) != ContainmentType.Disjoint;

            if (inside)
            {
                distance = Vector3.DistanceSquared(volume.Position, this.Position);
            }

            return(this.Culled = !inside);
        }
Beispiel #5
0
        /// <summary>
        /// Performs culling test
        /// </summary>
        /// <param name="volume">Culling volume</param>
        /// <param name="distance">If the object is inside the volume, returns the distance</param>
        /// <returns>Returns true if the object is outside of the frustum</returns>
        public override bool Cull(ICullingVolume volume, out float distance)
        {
            distance = float.MaxValue;

            if (groundPickingQuadtree == null)
            {
                return(false);
            }

            bool cull = volume.Contains(groundPickingQuadtree.BoundingBox) == ContainmentType.Disjoint;

            if (!cull)
            {
                distance = 0;
            }

            return(cull);
        }