// protected virtual void RebuildCommandBuffer() { renderBuffer.Clear(); renderBuffer.BeginSample(profileHighlightingSystem); // Prepare and clear render target renderBuffer.SetRenderTarget(highlightingBufferID); renderBuffer.ClearRenderTarget(true, true, colorClear); // Fill buffer with highlighters rendering commands HighlighterCore.FillBuffer(renderBuffer); RenderTextureDescriptor desc = cachedDescriptor; desc.width = highlightingBuffer.width / _downsampleFactor; desc.height = highlightingBuffer.height / _downsampleFactor; desc.depthBufferBits = 0; // Create two buffers for blurring the image renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur1, desc, FilterMode.Bilinear); renderBuffer.GetTemporaryRT(ShaderPropertyID._HighlightingBlur2, desc, FilterMode.Bilinear); 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.Blit(oddEven ? blur1ID : blur2ID, highlightingBufferID, cutMaterial); // Cleanup renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur1); renderBuffer.ReleaseTemporaryRT(ShaderPropertyID._HighlightingBlur2); renderBuffer.EndSample(profileHighlightingSystem); }
// Recursively follows hierarchy of objects from t, searches for Renderers and adds them to the list. // Breaks if another Highlighter component found private void GrabRenderers(Transform t) { GameObject g = t.gameObject; // Find all Renderers on the current GameObject g, filter them and add to the sRendererData list g.GetComponents <Renderer>(sRenderers); for (int i = 0, imax = sRenderers.Count; i < imax; i++) { Renderer renderer = sRenderers[i]; if (rendererFilterToUse(renderer, sSubmeshIndices)) { RendererData rendererData = GetRendererDataInstance(); rendererData.renderer = renderer; List <int> submeshIndices = rendererData.submeshIndices; submeshIndices.Clear(); submeshIndices.AddRange(sSubmeshIndices); sRendererData.Add(rendererData); } sSubmeshIndices.Clear(); } sRenderers.Clear(); // Return if transform t doesn't have any children int childCount = t.childCount; if (childCount == 0) { return; } // Recursively cache renderers on all child GameObjects for (int i = 0; i < childCount; i++) { Transform childTransform = t.GetChild(i); // Do not cache Renderers of this childTransform in case it has it's own Highlighter component HighlighterCore h = childTransform.GetComponent <HighlighterCore>(); if (h != null) { continue; } GrabRenderers(childTransform); } }