Exemple #1
0
        /// <summary>
        /// Checks to see if object is inside the view frustum of any of the LOS cameras.
        /// Ideally should be called in OnWillRenderObject, but it's to late to disable renderer..
        /// Early outs when visible to one camera.
        /// </summary>
        private static bool CustomCull(Bounds meshBounds, int layerMask)
        {
            // Get list of sources.
            List <LOSSource> losSources = LOSManager.Instance.LOSSources;

            for (int i = 0; i < losSources.Count; ++i)
            {
                LOSSource losSource = losSources[i];
                if (LOSHelper.CheckBoundsVisibility(losSource, meshBounds, layerMask))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Checks to see if object is inside the view frustum of any of the LOS cameras.
        /// Ideally should be called in OnWillRenderObject, but it's to late to disable renderer..
        /// Early outs when visible to one camera.
        /// </summary>
        private void UpdateVisibleSources()
        {
            Bounds meshBounds = gameObject.GetComponent <Renderer>().bounds;

            // Get list of sources.
            List <LOSSource> losSources = LOSManager.Instance.LOSSources;

            for (int i = 0; i < losSources.Count; ++i)
            {
                LOSSource losSource = losSources[i];

                bool isVisible = LOSHelper.CheckBoundsVisibility(losSource, meshBounds, m_RaycastLayerMask.value);

                UpdateList(losSource, isVisible);
            }
        }
Exemple #3
0
        /// <summary>
        /// Updates mask for specific LOS source.
        /// </summary>
        private void RenderSourceToMask(LOSSource losSource, ref RenderTexture maskRenderTexture)
        {
            Camera sourceCamera = losSource.SourceCamera;

            if (sourceCamera == null)
            {
                return;
            }

            // Set "skybox" material farplane.
            Materials.SkyBox.SetVector(ShaderID.FarPlane, new Vector4(sourceCamera.farClipPlane, sourceCamera.farClipPlane, sourceCamera.farClipPlane, sourceCamera.farClipPlane));

            // Source depth texture resolution.
            int sourceBufferWidth  = CalculateRTSize(losSource.RenderTargetWidth, m_QualityLevel);
            int sourceBufferHeight = CalculateRTSize(losSource.RenderTargetHeight, m_QualityLevel);

            // Create temporary rendertexture for rendering linear depth.
            RenderTexture sourceBuffer = RenderTexture.GetTemporary(sourceBufferWidth, sourceBufferHeight, 16, RenderTextureFormat.RGFloat);

            sourceBuffer.filterMode = FilterMode.Trilinear;
            sourceBuffer.wrapMode   = TextureWrapMode.Clamp;

            // Set camera render target.
            sourceCamera.targetTexture = sourceBuffer;

            // Render depth from source Camera.
            sourceCamera.RenderWithShader(Shaders.Depth, null);

            //Push LOS source specific parameters.
            Materials.Mask.SetTexture(ShaderID.SourceDepthTex, sourceBuffer);
            Materials.Mask.SetMatrix(ShaderID.SourceWorldProj, sourceCamera.projectionMatrix * sourceCamera.worldToCameraMatrix);
            Materials.Mask.SetVector(ShaderID.SourceInfo, losSource.SourceInfo);
            Materials.Mask.SetVector(ShaderID.Settings, new Vector4(losSource.DistanceFade, losSource.EdgeFade, losSource.MinVariance, losSource.BackfacesFade));
            Materials.Mask.SetVector(ShaderID.Flags, new Vector4(PixelOperation.Clamp == losSource.OutOfBoundArea ? 0.0f : 1.0f, PixelOperation.Exclude == losSource.OutOfBoundArea ? -1.0f : 1.0f, losSource.MaskInvert ? 1.0f : 0.0f, losSource.ExcludeBackfaces ? 1.0f : 0.0f));
            Materials.Mask.SetColor(ShaderID.ColorMask, losSource.MaskColor * losSource.MaskIntensity);

            // Set Correct material pass.
            Materials.Mask.SetPass(0);

            // Render Mask.
            IndexedGraphicsBlit(maskRenderTexture);

            // Release linear depth render texture.
            RenderTexture.ReleaseTemporary(sourceBuffer);
        }
Exemple #4
0
        /// <summary>
        /// Checks if the mesh bounds are visible to the LOS Source
        /// </summary>
        public static bool CheckBoundsVisibility(LOSSource losSource, Bounds meshBounds, int layerMask)
        {
            Camera currentCamera = losSource.SourceCamera;

            if (losSource.IsVisible && currentCamera != null)
            {
                Plane[] cameraPlanes = losSource.FrustumPlanes;

                if (GeometryUtility.TestPlanesAABB(cameraPlanes, meshBounds))
                {
                    if (LOSHelper.CheckRayCast(currentCamera, meshBounds, losSource.SourceInfo.w, layerMask))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public void RemoveLOSSource(LOSSource source)
        {
            Debug.Assert(m_LOSSources.Contains(source), "LOSSource not found in list, can't remove");

            m_LOSSources.Remove(source);
        }
        public void AddLOSSource(LOSSource source)
        {
            Debug.Assert(!m_LOSSources.Contains(source), "LOSSource already in list, can't add");

            m_LOSSources.Add(source);
        }
Exemple #7
0
        /// <summary>
        /// Checks to see if object is inside the view frustum of any of the LOS cameras.
        /// Ideally should be called in OnWillRenderObject, but it's to late to disable renderer..
        /// Early outs when visible to one camera.
        /// </summary>

        /* private static bool culler(GameObject _self, Bounds meshBounds, int layerMask)
         * {
         *   // Get list of sources.
         *   List<LOSSource> losSources = LOSManager.Instance.LOSSources;
         *
         *   for (int i = 0; i < losSources.Count; ++i)
         *   {
         *       LOSSource losSource = losSources[i];
         *
         *       if (LOSHelper.CheckBoundsVisibility(losSource, meshBounds, layerMask) && losSources[i].transform.root.name != "player")
         *       {
         *           if (losSources[i].transform.parent.GetComponent<IA>() != null)
         *           {
         *               losSources[i].transform.parent.GetComponent<IA>().detectView(true);
         *           }
         *
         *           return true;
         *       }
         *       else if(!LOSHelper.CheckBoundsVisibility(losSource, meshBounds, layerMask) && losSources[i].transform.root.name != "player")
         *       {
         *           if (losSources[i].transform.parent.GetComponent<IA>()!=null) {
         *               losSources[i].transform.parent.GetComponent<IA>().detectView(false);
         *           }
         *       }
         *   }
         *
         *   return false;
         * }*/

        private static bool CustomCull(Transform _target, LOSSource losSource, GameObject objMesh, int layerMask)
        {
            //Debug.Log("Target: "+_target.GetComponent<SimpleIA>().typeNPC + " losSource: "+ losSource+" objMesh: "+objMesh.transform.parent.GetComponent<BodyChange>());

            /* if (objMesh.tag == "Player" && LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent<Renderer>().bounds, layerMask)) {
             *   Debug.Log("veo: "+objMesh.transform.parent.gameObject.name + " " + objMesh.transform.parent.gameObject.activeSelf);
             *   _target.GetComponent<SimpleIA>().setTarget(objMesh.transform);
             *   _target.GetComponent<SimpleIA>().setDetectado(true);
             *   return true;
             * }
             * else if(objMesh.tag == "Player" && !LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent<Renderer>().bounds, layerMask)
             *   &&  _target.GetComponent<SimpleIA>().getDetectado())
             * {
             *   Debug.Log("no veo: " + objMesh.transform.parent.gameObject.name + " " + objMesh.transform.parent.gameObject.activeSelf);
             *   if (!_target.GetComponent<SimpleIA>().ActionRangeAlerta())
             *   {
             *       _target.GetComponent<SimpleIA>().setDetectado(false);
             *       _target.GetComponent<SimpleIA>().setState(2);
             *
             *   }
             *   else
             *   {
             *       // Debug.Log(" alerta in but not focus " + objMesh.transform.parent.gameObject.name);
             *
             *   }
             *   return false;
             * }*/


            if (objMesh.tag == "Player" && LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent <Renderer>().bounds, layerMask) &&
                objMesh.transform.parent.gameObject.activeSelf && !_target.GetComponent <SimpleIA>().getDetectado())
            {
                // Debug.Log("te veo "+ objMesh.transform.parent.gameObject.name+" activo "+ objMesh.transform.parent.gameObject.activeSelf);
                _target.GetComponent <SimpleIA>().setTarget(objMesh.transform);
                _target.GetComponent <SimpleIA>().setDetectado(true);

                return(true);
            }
            else if (objMesh.tag == "Player" && !LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent <Renderer>().bounds, layerMask) &&
                     _target.GetComponent <SimpleIA>().getDetectado() && objMesh.transform.parent.gameObject.activeSelf)
            {
                // Debug.Log(" fuera de foco " + _target.GetComponent<SimpleIA>().ActionRangeAlerta());

                //verifico con rango alerta
                if (!_target.GetComponent <SimpleIA>().ActionRangeAlerta())
                {
                    _target.GetComponent <SimpleIA>().setDetectado(false);
                    _target.GetComponent <SimpleIA>().setState(2);
                }
                else
                {
                    // Debug.Log(" alerta in but not focus " + objMesh.transform.parent.gameObject.name);
                }

                return(true);
            }
            else if (objMesh.tag == "Player" && LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent <Renderer>().bounds, layerMask) && !objMesh.transform.parent.gameObject.activeSelf)
            {
                //Debug.Log("No te veo " + objMesh.transform.parent.gameObject.name);
                //verifico con rango alerta

                _target.GetComponent <SimpleIA>().setDetectado(false);
                _target.GetComponent <SimpleIA>().setState(2);

                // return true;
            }
            else if (objMesh.tag == "NPC" && _target.GetComponent <SimpleIA>().typeNPC == SimpleIA.TypeNPC.clero && objMesh.transform.parent.GetComponent <BodyChange>().dominate&& !_target.GetComponent <BodyChange>().dominate&&
                     LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent <Renderer>().bounds, layerMask) && objMesh.transform.parent.GetComponent <SimpleIA>().typeNPC == SimpleIA.TypeNPC.normal)
            {
                // Debug.Log("veo impostor " + _target.GetComponent<SimpleIA>().typeNPC+ "//"+objMesh.transform.parent.GetComponent<SimpleIA>().typeNPC);
                _target.GetComponent <SimpleIA>().setTarget(objMesh.transform);
                _target.GetComponent <SimpleIA>().setDetectado(true);

                //  return true;
            }
            else if (objMesh.tag == "NPC" && _target.GetComponent <SimpleIA>().typeNPC == SimpleIA.TypeNPC.clero && objMesh.transform.parent.GetComponent <BodyChange>().dominate&& !_target.GetComponent <BodyChange>().dominate&&
                     !LOSHelper.CheckBoundsVisibility(losSource, objMesh.GetComponent <Renderer>().bounds, layerMask) && _target.GetComponent <SimpleIA>().getDetectado())
            {
                // Debug.Log("no veo impostor"+ objMesh.transform.parent.name+" "+ _target.name);
                _target.GetComponent <SimpleIA>().setDetectado(false);
                _target.GetComponent <SimpleIA>().setState(2);
                //return true;
            }


            return(false);
        }
        /// <summary>
        /// Updates mask for specific LOS source.
        /// </summary>
        private void RenderSourceToMask(LOSSource losSource, ref RenderTexture maskRenderTexture)
        {
            Camera sourceCamera = losSource.SourceCamera;

            if (sourceCamera == null) return;

            // Set "skybox" material farplane.
            Materials.SkyBox.SetFloat(ShaderID.FarPlane, sourceCamera.farClipPlane);

            // Source depth texture resolution.
            int sourceBufferWidth = CalculateRTSize(losSource.RenderTargetWidth, m_QualityLevel);
            int sourceBufferHeight = CalculateRTSize(losSource.RenderTargetHeight, m_QualityLevel);

            // Create temporary rendertexture for rendering linear depth.
            RenderTexture sourceBuffer = RenderTexture.GetTemporary(sourceBufferWidth, sourceBufferHeight, 16, RenderTextureFormat.RGFloat);
            sourceBuffer.filterMode = FilterMode.Trilinear;
            sourceBuffer.wrapMode = TextureWrapMode.Clamp;

            // Set camera render target.
            sourceCamera.targetTexture = sourceBuffer;

            // Render depth from source Camera.
            sourceCamera.RenderWithShader(Shaders.Depth, null);

            // Blur buffer if needed.
            if (losSource.Blur && !m_DisableBlur)
                BlurTexture(sourceBuffer, Materials.Blur, losSource.BlurIterations, losSource.BlurSize);

            //Push LOS source specific parameters.
            Materials.Mask.SetTexture(ShaderID.SourceDepthTex, sourceBuffer);
            Materials.Mask.SetMatrix(ShaderID.SourceWorldProj, sourceCamera.projectionMatrix * sourceCamera.worldToCameraMatrix);
            Materials.Mask.SetVector(ShaderID.SourceInfo, losSource.SourceInfo);
            Materials.Mask.SetVector(ShaderID.Settings, new Vector4(losSource.DistanceFade, losSource.EdgeFade, losSource.MinVariance, losSource.MaskInvert ? 1.0f : 0.0f));
            Materials.Mask.SetVector(ShaderID.Flags, new Vector4(PixelOperation.Clamp == losSource.OutOfBoundArea ? 0.0f : 1.0f, PixelOperation.Exclude == losSource.OutOfBoundArea ? -1.0f : 1.0f, 0, 0));
            Materials.Mask.SetColor(ShaderID.ColorMask, losSource.MaskColor * losSource.MaskIntensity);

            // Set Correct material pass.
            Materials.Mask.SetPass(m_Camera.orthographic ? 1 : 0);

            // Render Mask.
            IndexedGraphicsBlit(maskRenderTexture);

            // Release linear depth render texture.
            RenderTexture.ReleaseTemporary(sourceBuffer);
        }
        public void AddLOSSource(LOSSource source)
        {
            Assert.Test(!m_LOSSources.Contains(source), "LOSSource already in list, can't add");

            m_LOSSources.Add(source);
        }
        public void RemoveLOSSource(LOSSource source)
        {
            Assert.Test(m_LOSSources.Contains(source), "LOSSource not found in list, can't remove");

            m_LOSSources.Remove(source);
        }