Ejemplo n.º 1
0
        //
        private void OnDisable()
        {
            HighlightingBase.RemoveHighlighter(this);

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

            // Reset highlighting parameters to default values
            materialsIsDirty = true;
            currentState     = 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;
             */
        }
Ejemplo n.º 2
0
        //
        protected virtual void OnEnable()
        {
            hb = target as HighlightingBase;

            LoadPresets();
            presetIndex = FindCurrentPreset();
        }
Ejemplo n.º 3
0
        protected virtual void OnEnable()
        {
            hb = target as HighlightingBase;
//			hb.CheckInstance();
            LoadPresets();
//			presetIndex = FindCurrentPreset();
        }
Ejemplo n.º 4
0
        //
        protected virtual void OnRenderImage(RenderTexture src, RenderTexture dst)
        {
            bool oddEven = true;

            for (int i = 0; i < renderers.Count; i++)
            {
                HighlightingBase renderer = renderers[i];
                if (oddEven)
                {
                    renderer.Blit(src, dst);
                }
                else
                {
                    renderer.Blit(dst, src);
                }

                oddEven = !oddEven;
            }

            // Additional blit because final result should be in dst RenderTexture
            if (oddEven)
            {
                Graphics.Blit(src, dst);
            }
        }
Ejemplo n.º 5
0
		// 
		protected virtual void OnEnable()
		{
			hb = target as HighlightingBase;
			hb.CheckInstance();

			LoadPresets();
			presetIndex = FindCurrentPreset();
		}
	// 
	protected virtual void OnEnable()
	{
		hb = target as HighlightingBase;
		hb.CheckInstance();

		gradObj = new SerializedObject(hb);
		gradProp = gradObj.FindProperty("gradient");
		hb.UpdateGradient();
	}
Ejemplo n.º 7
0
        //
        public virtual void Register(HighlightingBase renderer)
        {
            if (!renderers.Contains(renderer))
            {
                renderers.Add(renderer);
            }

            enabled = renderers.Count > 0;
        }
Ejemplo n.º 8
0
        //
        private void OnEnable()
        {
            if (!CheckInstance())
            {
                return;
            }

            HighlightingBase.AddHighlighter(this);
        }
Ejemplo n.º 9
0
        public virtual void Register(HighlightingBase renderer)
        {
            if (!renderers.Contains(renderer))
            {
                renderers.Add(renderer);
            }

            enabled = renderers.Count > 0;
        }
Ejemplo n.º 10
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);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        //
        public virtual void Unregister(HighlightingBase renderer)
        {
            int index = renderers.IndexOf(renderer);
            if (index != -1)
            {
                renderers.RemoveAt(index);
            }

            enabled = renderers.Count > 0;
        }
Ejemplo n.º 12
0
        public virtual void Unregister(HighlightingBase renderer)
        {
            int index = renderers.IndexOf(renderer);

            if (index != -1)
            {
                renderers.RemoveAt(index);
            }

            enabled = renderers.Count > 0;
        }
        // Called once (before OnPreRender) for each camera if the object is visible
        void OnWillRenderObject()
        {
            Camera cam = Camera.current;

            // Another camera may intercept rendering and send it's own OnWillRenderObject events (i.e. water rendering),
            // so we're caching currently rendering camera only if it has HighlighterBase component
            if (HighlightingBase.IsHighlightingCamera(cam))
            {
                // VR Camera renders twice per frame (once for each eye), but OnWillRenderObject is called once so we have to cache reference to the camera
                lastCamera = cam;
            }
        }
Ejemplo n.º 14
0
 // Called once (before OnPreRender) for each camera if the object is visible.
 // The function is called during the culling process just before rendering each culled object.
 void OnWillRenderObject()
 {
     HighlightingBase.SetVisible(this);
 }
Ejemplo n.º 15
0
		/// <summary>
		/// Render highlighting to the highlightingBuffer using frameBuffer.depthBuffer.
		/// </summary>
		/// <param name="frameBuffer">Frame buffer RenderTexture, depthBuffer of which will be used to occlude highlighting.</param>
		public void RenderHighlighting(RenderTexture frameBuffer)
		{
			// Release highlightingBuffer if it wasn't released already
			if (highlightingBuffer != null)
			{
				RenderTexture.ReleaseTemporary(highlightingBuffer);
				highlightingBuffer = null;
			}

			if (!isSupported || !enabled || !go.activeInHierarchy) { return; }

			int aa = QualitySettings.antiAliasing;
			if (aa == 0) { aa = 1; }

			bool depthAvailable = true;
			// Check if frameBuffer.depthBuffer is not available, contains garbage (when MSAA is enabled) or doesn't have stencil bits (when depth is 16 or 0)
			if (frameBuffer == null || frameBuffer.depth < 24) { depthAvailable = false; }

			// Reset aa value to 1 in case mainCam is in DeferredLighting Rendering Path
			if (refCam.actualRenderingPath == RenderingPath.DeferredLighting) { aa = 1; }
			// In case MSAA is enabled in forward/vertex lit rendeirng paths - depth buffer contains garbage
			else if (aa > 1) { depthAvailable = false; }

			// Check if framebuffer depth data availability has changed
			if (isDepthAvailable != depthAvailable)
			{
				isDepthAvailable = depthAvailable;
				// Update ZWrite value for all highlighting shaders correspondingly (isDepthAvailable ? ZWrite Off : ZWrite On)
				Highlighter.SetZWrite(isDepthAvailable ? 0f : 1f);
				if (isDepthAvailable)
				{
					Debug.LogWarning("HighlightingSystem : Framebuffer depth data is available back again and will be used to occlude highlighting. Highlighting occluders disabled.");
				}
				else
				{
					Debug.LogWarning("HighlightingSystem : Framebuffer depth data is not available and can't be used to occlude highlighting. Highlighting occluders enabled.");
				}
			}

			// Set global depth offset properties for highlighting shaders to the values which has this HighlightingBase component
			Highlighter.SetOffsetFactor(offsetFactor);
			Highlighter.SetOffsetUnits(offsetUnits);

			// Set this component as currently active HighlightingBase before enabling Highlighters
			current = this;

			// Turn on highlighting shaders on all highlighter components
			int count = 0;
			for (int i = 0; i < highlighters.Count; i++)
			{
				if (highlighters[i].Highlight()) { count++; }
			}

			// Do nothing in case no Highlighters is currently visible
			if (count == 0)
			{
				current = null;
				return;
			}

			// If frameBuffer.depthBuffer is not available
			int w = Screen.width;
			int h = Screen.height;
			int depth = 24;			// because stencil will be rendered to the highlightingBuffer.depthBuffer

			// If frameBuffer.depthBuffer is available
			if (isDepthAvailable)
			{
				w = frameBuffer.width;
				h = frameBuffer.height;
				depth = 0;			// because stencil will be rendered to frameBuffer.depthBuffer
			}

			// Setup highlightingBuffer RenderTexture
			highlightingBuffer = RenderTexture.GetTemporary(w, h, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, aa);
			if (!highlightingBuffer.IsCreated())
			{
				highlightingBuffer.filterMode = FilterMode.Point;
				highlightingBuffer.useMipMap = false;
				highlightingBuffer.wrapMode = TextureWrapMode.Clamp;
			}

			// Clear highlightingBuffer colorBuffer and clear depthBuffer only in case frameBuffer depth data is not available
			RenderTexture.active = highlightingBuffer;
			GL.Clear((isDepthAvailable ? false : true), true, Color.clear);

			// Use depth data from frameBuffer in case it is available. Use highlightingBuffer.depthBuffer otherwise
			RenderBuffer depthBuffer = isDepthAvailable ? frameBuffer.depthBuffer : highlightingBuffer.depthBuffer;
			
			if (!shaderCameraGO)
			{
				shaderCameraGO = new GameObject("HighlightingCamera");
				shaderCameraGO.hideFlags = HideFlags.HideAndDontSave;
				shaderCamera = shaderCameraGO.AddComponent<Camera>();
				shaderCamera.enabled = false;
			}
			
			shaderCamera.CopyFrom(refCam);
			//shaderCamera.projectionMatrix = mainCam.projectionMatrix;		// Uncomment this line if you have problems using Highlighting System with custom projection matrix on your camera
			shaderCamera.cullingMask = layerMask;
			shaderCamera.rect = new Rect(0f, 0f, 1f, 1f);
			shaderCamera.renderingPath = RenderingPath.Forward;
			shaderCamera.depthTextureMode = DepthTextureMode.None;
			shaderCamera.hdr = false;
			shaderCamera.useOcclusionCulling = false;
			shaderCamera.backgroundColor = new Color(0, 0, 0, 0);
			shaderCamera.clearFlags = CameraClearFlags.Nothing;
			shaderCamera.SetTargetBuffers(highlightingBuffer.colorBuffer, depthBuffer);

			// Get rid of "Tiled GPU Perf warning" if we're not in debug mode
			#if !DEBUG_ENABLED
			frameBuffer.MarkRestoreExpected();
			#endif
			shaderCamera.Render();

			// Extinguish all highlighters
			for (int i = 0; i < highlighters.Count; i++)
			{
				highlighters[i].Extinguish();
			}

			// Highlighting buffer rendering finished. Reset currently active HighlightingBase
			current = null;

			// Create two buffers for blurring the image
			int width = highlightingBuffer.width / _downsampleFactor;
			int height = highlightingBuffer.height / _downsampleFactor;
			RenderTexture buffer = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			RenderTexture buffer2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			if (!buffer.IsCreated())
			{
				buffer.useMipMap = false;
				buffer.wrapMode = TextureWrapMode.Clamp;
			}
			if (!buffer2.IsCreated())
			{
				buffer2.useMipMap = false;
				buffer2.wrapMode = TextureWrapMode.Clamp;
			}
			
			// Copy highlighting buffer to the smaller texture
			Graphics.Blit(highlightingBuffer, buffer, blitMaterial);
			
			// Blur the small texture
			bool oddEven = true;
			for (int i = 0; i < iterations; i++)
			{
				if (oddEven) { FourTapCone(buffer, buffer2, i); }
				else { FourTapCone(buffer2, buffer, i); }
				oddEven = !oddEven;
			}
			
			// Upscale blurred texture and cut stencil from it
			Graphics.SetRenderTarget(highlightingBuffer.colorBuffer, depthBuffer);
			cutMaterial.SetTexture(ShaderPropertyID._MainTex, oddEven ? buffer : buffer2);
			DoubleBlit(cutMaterial, 0, cutMaterial, 1);

			// Cleanup
			RenderTexture.ReleaseTemporary(buffer);
			RenderTexture.ReleaseTemporary(buffer2);
		}
 //
 protected virtual void OnEnable()
 {
     hb = target as HighlightingBase;
     hb.CheckInstance();
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Render highlighting to the highlightingBuffer using frameBuffer.depthBuffer.
        /// </summary>
        /// <param name="frameBuffer">Frame buffer RenderTexture, depthBuffer of which will be used to occlude highlighting.</param>
        public void RenderHighlighting(RenderTexture frameBuffer)
        {
            // Release highlightingBuffer if it wasn't released already
            if (highlightingBuffer != null)
            {
                RenderTexture.ReleaseTemporary(highlightingBuffer);
                highlightingBuffer = null;
            }

            if (!isSupported || !enabled || !go.activeInHierarchy)
            {
                return;
            }

            int aa = QualitySettings.antiAliasing;

            if (aa == 0)
            {
                aa = 1;
            }

            bool depthAvailable = true;

            // Check if frameBuffer.depthBuffer is not available, contains garbage (when MSAA is enabled) or doesn't have stencil bits (when depth is 16 or 0)
            if (frameBuffer == null || frameBuffer.depth < 24)
            {
                depthAvailable = false;
            }

            // Reset aa value to 1 in case mainCam is in DeferredLighting Rendering Path
            if (refCam.actualRenderingPath == RenderingPath.DeferredLighting)
            {
                aa = 1;
            }
            // In case MSAA is enabled in forward/vertex lit rendeirng paths - depth buffer contains garbage
            else if (aa > 1)
            {
                depthAvailable = false;
            }

            // Check if framebuffer depth data availability has changed
            if (isDepthAvailable != depthAvailable)
            {
                isDepthAvailable = depthAvailable;
                // Update ZWrite value for all highlighting shaders correspondingly (isDepthAvailable ? ZWrite Off : ZWrite On)
                Highlighter.SetZWrite(isDepthAvailable ? 0f : 1f);
                if (isDepthAvailable)
                {
                    Debug.LogWarning("HighlightingSystem : Framebuffer depth data is available back again and will be used to occlude highlighting. Highlighting occluders disabled.");
                }
                else
                {
                    Debug.LogWarning("HighlightingSystem : Framebuffer depth data is not available and can't be used to occlude highlighting. Highlighting occluders enabled.");
                }
            }

            // Set global depth offset properties for highlighting shaders to the values which has this HighlightingBase component
            Highlighter.SetOffsetFactor(offsetFactor);
            Highlighter.SetOffsetUnits(offsetUnits);

            // Set this component as currently active HighlightingBase before enabling Highlighters
            current = this;

            // Turn on highlighting shaders on all highlighter components
            int count = 0;

            for (int i = 0; i < highlighters.Count; i++)
            {
                if (highlighters[i].Highlight())
                {
                    count++;
                }
            }

            // Do nothing in case no Highlighters is currently visible
            if (count == 0)
            {
                current = null;
                return;
            }

            // If frameBuffer.depthBuffer is not available
            int w     = Screen.width;
            int h     = Screen.height;
            int depth = 24;                             // because stencil will be rendered to the highlightingBuffer.depthBuffer

            // If frameBuffer.depthBuffer is available
            if (isDepthAvailable)
            {
                w     = frameBuffer.width;
                h     = frameBuffer.height;
                depth = 0;                                      // because stencil will be rendered to frameBuffer.depthBuffer
            }

            // Setup highlightingBuffer RenderTexture
            highlightingBuffer = RenderTexture.GetTemporary(w, h, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, aa);
            if (!highlightingBuffer.IsCreated())
            {
                highlightingBuffer.filterMode = FilterMode.Point;
                highlightingBuffer.useMipMap  = false;
                highlightingBuffer.wrapMode   = TextureWrapMode.Clamp;
            }

            // Clear highlightingBuffer colorBuffer and clear depthBuffer only in case frameBuffer depth data is not available
            RenderTexture.active = highlightingBuffer;
            GL.Clear((isDepthAvailable ? false : true), true, Color.clear);

            // Use depth data from frameBuffer in case it is available. Use highlightingBuffer.depthBuffer otherwise
            RenderBuffer depthBuffer = isDepthAvailable ? frameBuffer.depthBuffer : highlightingBuffer.depthBuffer;

            if (!shaderCameraGO)
            {
                shaderCameraGO           = new GameObject("HighlightingCamera");
                shaderCameraGO.hideFlags = HideFlags.HideAndDontSave;
                shaderCamera             = shaderCameraGO.AddComponent <Camera>();
                shaderCamera.enabled     = false;
            }

            shaderCamera.CopyFrom(refCam);
            //shaderCamera.projectionMatrix = mainCam.projectionMatrix;		// Uncomment this line if you have problems using Highlighting System with custom projection matrix on your camera
            shaderCamera.cullingMask         = layerMask;
            shaderCamera.rect                = new Rect(0f, 0f, 1f, 1f);
            shaderCamera.renderingPath       = RenderingPath.Forward;
            shaderCamera.depthTextureMode    = DepthTextureMode.None;
            shaderCamera.allowHDR            = false;
            shaderCamera.useOcclusionCulling = false;
            shaderCamera.backgroundColor     = new Color(0, 0, 0, 0);
            shaderCamera.clearFlags          = CameraClearFlags.Nothing;
            shaderCamera.SetTargetBuffers(highlightingBuffer.colorBuffer, depthBuffer);

            // Get rid of "Tiled GPU Perf warning" if we're not in debug mode
                        #if !DEBUG_ENABLED
            frameBuffer.MarkRestoreExpected();
                        #endif
            shaderCamera.Render();

            // Extinguish all highlighters
            for (int i = 0; i < highlighters.Count; i++)
            {
                highlighters[i].Extinguish();
            }

            // Highlighting buffer rendering finished. Reset currently active HighlightingBase
            current = null;

            // Create two buffers for blurring the image
            int           width   = highlightingBuffer.width / _downsampleFactor;
            int           height  = highlightingBuffer.height / _downsampleFactor;
            RenderTexture buffer  = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
            RenderTexture buffer2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
            if (!buffer.IsCreated())
            {
                buffer.useMipMap = false;
                buffer.wrapMode  = TextureWrapMode.Clamp;
            }
            if (!buffer2.IsCreated())
            {
                buffer2.useMipMap = false;
                buffer2.wrapMode  = TextureWrapMode.Clamp;
            }

            // Copy highlighting buffer to the smaller texture
            Graphics.Blit(highlightingBuffer, buffer, blitMaterial);

            // Blur the small texture
            bool oddEven = true;
            for (int i = 0; i < iterations; i++)
            {
                if (oddEven)
                {
                    FourTapCone(buffer, buffer2, i);
                }
                else
                {
                    FourTapCone(buffer2, buffer, i);
                }
                oddEven = !oddEven;
            }

            // Upscale blurred texture and cut stencil from it
            Graphics.SetRenderTarget(highlightingBuffer.colorBuffer, depthBuffer);
            cutMaterial.SetTexture(ShaderPropertyID._MainTex, oddEven ? buffer : buffer2);
            DoubleBlit(cutMaterial, 0, cutMaterial, 1);

            // Cleanup
            RenderTexture.ReleaseTemporary(buffer);
            RenderTexture.ReleaseTemporary(buffer2);
        }