Пример #1
0
        private void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (m_Camera == null)
            {
                return;
            }

            // Calculate Frustum origins and rays for mask camera.
            Matrix4x4 frustumOrigins;
            Matrix4x4 frustumRays;

            LOSHelper.CalculateViewVectors(m_Camera, out frustumRays, out frustumOrigins);

            // Push parameters which are identical for all LOS sources.
            Materials.Mask.SetMatrix(ShaderID.FrustumRays, frustumRays);
            Materials.Mask.SetMatrix(ShaderID.FrustumOrigins, frustumOrigins);
            Materials.Mask.SetMatrix(ShaderID.WorldToCameraMatrix, m_Camera.worldToCameraMatrix);

            // Store original skybox.
            Material originalSkybox = RenderSettings.skybox;

            // Set-up skybox material which clears render texture to farplane depth.
            RenderSettings.skybox = Materials.SkyBox;

            // Create Mask Render Texture.
            RenderTexture maskRenderTexture = CreateMaskRenderTexture();

            // Get list with all LOS sources.
            List <LOSSource> losSources = LOSManager.Instance.LOSSources;

            // Iterate over all LOS sources.
            for (int i = 0; i < losSources.Count; i++)
            {
                RenderSourceToMask(losSources[i], ref maskRenderTexture);
            }

            // Revert original skybox.
            RenderSettings.skybox = originalSkybox;

            // Get unmodified screen buffer.
            Materials.Combine.SetTexture(ShaderID.PreEffectTex, m_BufferStorage.BufferTexture);

            // Set-up material.
            Materials.Combine.SetTexture(ShaderID.MaskTex, maskRenderTexture);

            // Check if Stencil Mask component is used.
            bool isStencilMaskEnabled = (m_StencilMask != null) && (m_StencilMask.enabled == true);

            if (isStencilMaskEnabled)
            {
                // Set Stencil Mask texture.
                Materials.Combine.SetTexture(ShaderID.StencilMaskTex, m_StencilMask.MaskTexture);
            }

            // Render final effect.
            Graphics.Blit(source, destination, Materials.Combine, isStencilMaskEnabled ? 1 : 0);

            RenderTexture.ReleaseTemporary(maskRenderTexture);
        }
Пример #2
0
        private void RenderWorldPosition(RenderTexture source, RenderTexture destination)
        {
            // Calculate Frustum origins and rays for mask camera.
            Matrix4x4 frustumOrigins;
            Matrix4x4 frustumRays;

            LOSHelper.CalculateViewVectors(m_Camera, out frustumRays, out frustumOrigins);

            // Push parameters which are identical for all LOS sources.
            Materials.Debug.SetMatrix(ShaderID.FrustumRays, frustumRays);
            Materials.Debug.SetMatrix(ShaderID.FrustumOrigins, frustumOrigins);

            Materials.Debug.SetPass(2);

            LOSMask.IndexedGraphicsBlit(destination);
        }