Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
        //
        protected virtual void RebuildCommandBuffer()
        {
            renderBuffer.Clear();

            RenderTargetIdentifier depthID = isDepthAvailable ? cameraTargetID : highlightingBufferID;

            // Prepare and clear render target
            renderBuffer.SetRenderTarget(highlightingBufferID, depthID);
            renderBuffer.ClearRenderTarget(!isDepthAvailable, true, colorClear);

            // Fill buffer with highlighters rendering commands
            Highlighter.FillBuffer(renderBuffer, isDepthAvailable);

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

            int width  = highlightingBuffer.width / _downsampleFactor;
            int height = highlightingBuffer.height / _downsampleFactor;

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

            renderBuffer.Blit(highlightingBufferID, blur1ID);

            // Blur the small texture
            bool oddEven = true;

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

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

                oddEven = !oddEven;
            }

            // 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);
        }
Exemplo n.º 3
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);
        }