Пример #1
0
        //
        private void OnDisable()
        {
            HighlighterManager.Remove(this);

            // Clear cached renderers
            if (highlightableRenderers != null)
            {
                highlightableRenderers.Clear();
            }

            // Reset highlighting parameters to default values
            renderersDirty   = true;
            highlighted      = false;
            currentColor     = Color.clear;
            transitionActive = false;
            transitionValue  = 0f;
            once             = false;
            flashing         = false;
            constantly       = false;
            occluder         = false;
            seeThrough       = false;

            /*
             * // Reset custom parameters of the highlighting
             * onceColor = Color.red;
             * flashingColorMin = new Color(0f, 1f, 1f, 0f);
             * flashingColorMax = new Color(0f, 1f, 1f, 1f);
             * flashingFreq = 2f;
             * constantColor = Color.yellow;
             */
        }
Пример #2
0
        //
        private void OnEnable()
        {
            if (!CheckInstance())
            {
                return;
            }

            HighlighterManager.Add(this);
        }
Пример #3
0
 //
 protected virtual void FillBuffer(CommandBuffer buffer, int renderQueue)
 {
     HashSet <Highlighter> .Enumerator e;
     e = HighlighterManager.GetEnumerator();
     while (e.MoveNext())
     {
         Highlighter highlighter = e.Current;
         highlighter.FillBuffer(renderBuffer, renderQueue);
     }
 }
Пример #4
0
        protected virtual bool HighlightersChanged()
        {
            bool changed = false;

            HashSet <Highlighter> .Enumerator e = HighlighterManager.GetEnumerator();
            while (e.MoveNext())
            {
                Highlighter highlighter = e.Current;
                changed |= highlighter.UpdateHighlighting(isDepthAvailable);
            }

            return(changed);
        }
Пример #5
0
        //
        protected virtual void RebuildCommandBuffer()
        {
            renderBuffer.Clear();

            int aa = GetAA();

            RenderTargetIdentifier depthID = isDepthAvailable ? cameraTargetID : highlightingBufferID;

            // Prepare and clear render target
            renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBuffer, -1, -1, isDepthAvailable ? 0 : 24, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB, aa);
            renderBuffer.SetRenderTarget(highlightingBufferID, depthID);
            renderBuffer.ClearRenderTarget(!isDepthAvailable, true, colorClear);

            // Fill buffer with highlighters rendering commands
            HashSet <Highlighter> .Enumerator e;
            e = HighlighterManager.GetEnumerator();
            while (e.MoveNext())
            {
                Highlighter highlighter = e.Current;
                highlighter.FillBuffer(ref renderBuffer, false);
            }
            e = HighlighterManager.GetEnumerator();
            while (e.MoveNext())
            {
                Highlighter highlighter = e.Current;
                highlighter.FillBuffer(ref renderBuffer, true);
            }

            // Create two buffers for blurring the image
            RenderTargetIdentifier blur1ID = new RenderTargetIdentifier(ShaderPropertyID._HighlightingBlur1);
            RenderTargetIdentifier blur2ID = new RenderTargetIdentifier(ShaderPropertyID._HighlightingBlur2);

            int width  = cam.pixelWidth / _downsampleFactor;
            int height = cam.pixelHeight / _downsampleFactor;

            renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur1, width, height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
            renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur2, width, height, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

            Vector4 v;

            v = new Vector4(1f / (float)cam.pixelWidth, 1f / (float)cam.pixelHeight, 0f, 0f);
            renderBuffer.SetGlobalVector(ShaderPropertyID._HighlightingBufferTexelSize, v);
            renderBuffer.SetGlobalVector(ShaderPropertyID._HighlightingBlurredTexelSize, v * _downsampleFactor);

            renderBuffer.Blit(highlightingBufferID, blur1ID);

            // Blur the small texture
            bool oddEven = true;

            for (int i = 0; i < _iterations; i++)
            {
                float off = _blurMinSpread + i * _blurSpread;
                renderBuffer.SetGlobalFloat(ShaderPropertyID._HighlightingBlurOffset, off);

                if (oddEven)
                {
                    renderBuffer.Blit(blur1ID, blur2ID, blurMaterial);
                }
                else
                {
                    renderBuffer.Blit(blur2ID, blur1ID, blurMaterial);
                }

                oddEven = !oddEven;
            }

            v = new Vector4(-1f / (float)cam.pixelWidth, 1f / (float)cam.pixelHeight, 0f, 0f);
            renderBuffer.SetGlobalVector(ShaderPropertyID._HighlightingBufferTexelSize, v);

            // Upscale blurred texture and cut stencil from it
            renderBuffer.SetGlobalTexture(ShaderPropertyID._HighlightingBlurred, oddEven ? blur1ID : blur2ID);
            renderBuffer.SetRenderTarget(highlightingBufferID, depthID);
            renderBuffer.DrawMesh(quad, identityMatrix, cutMaterial);

            // Cleanup
            renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur1);
            renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur2);
        }