示例#1
0
        // This method defines the way in which renderers are initialized
        private void UpdateRenderers()
        {
            if (renderersDirty)
            {
                ClearRenderers();

                // Find all renderers which should be controlled with this Highlighter component
                List <Renderer> renderers = new List <Renderer>();
                GrabRenderers(tr, renderers);

                // Cache found renderers
                for (int i = 0, imax = renderers.Count; i < imax; i++)
                {
                    GameObject          rg       = renderers[i].gameObject;
                    HighlighterRenderer renderer = rg.GetComponent <HighlighterRenderer>();
                    if (renderer == null)
                    {
                        renderer = rg.AddComponent <HighlighterRenderer>();
                    }
                    renderer.SetState(true);

                    renderer.Initialize(opaqueMaterial, transparentShader, cachedSeeThrough);
                    highlightableRenderers.Add(renderer);
                }

                renderersDirty = false;
            }
        }
示例#2
0
 // Clear cached renderers
 private void ClearRenderers()
 {
     for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
     {
         HighlighterRenderer renderer = highlightableRenderers[i];
         renderer.isAlive = false;
     }
     highlightableRenderers.Clear();
 }
示例#3
0
        //
        private void FillBufferInternal(CommandBuffer buffer)
        {
            // Set cachedOverlay if changed
            bool overlayToUse = mode == HighlighterMode.Overlay || mode == HighlighterMode.Occluder;

            if (cachedOverlay != overlayToUse)
            {
                cachedOverlay = overlayToUse;

                opaqueMaterial.SetKeyword(keywordOverlay, cachedOverlay);
                for (int i = 0; i < highlightableRenderers.Count; i++)
                {
                    highlightableRenderers[i].SetOverlay(cachedOverlay);
                }
            }

            // Set cachedColor if changed
            Color colorToUse = mode != HighlighterMode.Occluder ? color : occluderColor;

            if (cachedColor != colorToUse)
            {
                cachedColor = colorToUse;

                // Apply color
                opaqueMaterial.SetColor(ShaderPropertyID._HighlightingColor, cachedColor);
                for (int i = 0; i < highlightableRenderers.Count; i++)
                {
                    highlightableRenderers[i].SetColor(cachedColor);
                }
            }

            // Fill CommandBuffer with this highlighter rendering commands
            for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
            {
                // To avoid null-reference exceptions when cached renderer has been removed but SetDirty() wasn't been called
                HighlighterRenderer renderer = highlightableRenderers[i];
                if (renderer == null)
                {
                    highlightableRenderers.RemoveAt(i);
                }
                else if (!renderer.IsValid())
                {
                    highlightableRenderers.RemoveAt(i);
                    renderer.isAlive = false;
                }
                else
                {
                    // Check if renderer is visible for the currently rendering camera.
                    // (Last camera called OnWillRenderObject on HighlighterRenderer instance is the same camera for which we're currently filling CommandBuffer)
                    if (HighlightingBase.GetVisible(renderer) || forceRender)
                    {
                        renderer.FillBuffer(buffer);
                    }
                }
            }
        }
示例#4
0
        //
        private void FillBufferInternal(CommandBuffer buffer, Mode m, bool depthAvailable)
        {
            UpdateRenderers();

            bool isHighlighter = once || flashing || (transitionValue > 0f);
            bool isOccluder    = occluder && (seeThrough || !depthAvailable);

            // Update mode
            mode = Mode.None;
            if (isHighlighter)
            {
                mode = seeThrough ? Mode.HighlighterSeeThrough : Mode.Highlighter;
            }
            else if (isOccluder)
            {
                mode = seeThrough ? Mode.OccluderSeeThrough : Mode.Occluder;
            }

            if (mode == Mode.None || mode != m)
            {
                return;
            }

            if (isHighlighter)
            {
                // ZTest = (seeThrough ? Always : LEqual), StencilRef = 1
                UpdateShaderParams(seeThrough, true);
            }
            else if (isOccluder)
            {
                // ZTest = LEqual, StencilRef = seeThrough ? 1 : 0
                UpdateShaderParams(false, seeThrough);
            }
            UpdateColors();

            // Fill CommandBuffer with this highlighter rendering commands
            for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
            {
                // To avoid null-reference exceptions when cached renderer has been removed but ReinitMaterials wasn't been called
                HighlighterRenderer renderer = highlightableRenderers[i];
                if (renderer == null)
                {
                    highlightableRenderers.RemoveAt(i);
                }
                // Try to fill buffer
                else if (!renderer.FillBuffer(buffer))
                {
                    highlightableRenderers.RemoveAt(i);
                    renderer.SetState(false);
                }
            }
        }
示例#5
0
        static public void SetVisible(HighlighterRenderer renderer)
        {
            // Another camera may intercept rendering and send it's own OnWillRenderObject events (i.e. water rendering).
            // Also, VR Camera with Multi Pass Stereo Rendering Method renders twice per frame (once for each eye),
            // but OnWillRenderObject is called once so we have to check.
            if (Camera.current != currentCamera)
            {
                return;
            }

            // Add to the list of renderers visible for the current Highlighting renderer
            visibleRenderers.Add(renderer);
        }
示例#6
0
        // This method defines how renderers are initialized
        private void UpdateRenderers()
        {
            if (isDirty)
            {
                isDirty = false;

                ClearRenderers();

                // Find all renderers which should be highlighted with this HighlighterCore component instance
                GrabRenderers(tr);

                // Cache found renderers
                for (int i = 0, imax = sRendererData.Count; i < imax; i++)
                {
                    RendererData rendererData = sRendererData[i];
                    GameObject   rg           = rendererData.renderer.gameObject;

                    HighlighterRenderer renderer = rg.GetComponent <HighlighterRenderer>();
                    if (renderer == null)
                    {
                        renderer = rg.AddComponent <HighlighterRenderer>();
                    }
                    renderer.isAlive = true;

                    renderer.Initialize(opaqueMaterial, transparentShader, rendererData.submeshIndices);
                    renderer.SetOverlay(cachedOverlay);
                    renderer.SetColor(cachedColor);
                    highlightableRenderers.Add(renderer);
                }

                // Release RendererData instances
                for (int i = 0; i < sRendererData.Count; i++)
                {
                    ReleaseRendererDataInstance(sRendererData[i]);
                }
                sRendererData.Clear();
            }
        }
示例#7
0
 static public bool GetVisible(HighlighterRenderer renderer)
 {
     return(visibleRenderers.Contains(renderer));
 }
示例#8
0
        //
        private void FillBufferInternal(CommandBuffer buffer, Mode m)
        {
            UpdateRenderers();

            // Update mode
            mode = Mode.None;
            // Highlighter
            if (once || flashing || (transitionValue > 0f))
            {
                mode = seeThrough ? Mode.HighlighterSeeThrough : Mode.Highlighter;
            }
            // Occluder
            else if (occluder && seeThrough)
            {
                mode = Mode.OccluderSeeThrough;
            }

            if (mode == Mode.None || mode != m)
            {
                return;
            }

            // Update shader property if changed
            if (cachedSeeThrough != seeThrough)
            {
                cachedSeeThrough = seeThrough;

                if (cachedSeeThrough)
                {
                    _opaqueMaterial.EnableKeyword(keywordSeeThrough);
                }
                else
                {
                    _opaqueMaterial.DisableKeyword(keywordSeeThrough);
                }

                for (int i = 0; i < highlightableRenderers.Count; i++)
                {
                    highlightableRenderers[i].SetSeeThroughForTransparent(seeThrough);
                }
            }

            UpdateColors();

            // Fill CommandBuffer with this highlighter rendering commands
            for (int i = highlightableRenderers.Count - 1; i >= 0; i--)
            {
                // To avoid null-reference exceptions when cached renderer has been removed but ReinitMaterials wasn't been called
                HighlighterRenderer renderer = highlightableRenderers[i];
                if (renderer == null)
                {
                    highlightableRenderers.RemoveAt(i);
                }
                // Try to fill buffer
                else if (!renderer.FillBuffer(buffer, forceRender))
                {
                    highlightableRenderers.RemoveAt(i);
                    renderer.SetState(false);
                }
            }
        }