示例#1
0
        //         public void BeginUpdate()
        //         { }

        public void UpdateMode(OutlineModes mode, HashSet <OutlineTarget> targets)
        {
            CommandBufferGroupItem commandBuffer = GetCommandBufferItem(mode);

            commandBuffer.BeginUpdate();
            foreach (OutlineTarget ot in targets)
            {
                Renderer[] otRenderers = null;
                if (ot.AffectChildren)
                {
                    otRenderers = ot.gameObject.GetComponentsInChildren <Renderer>();
                }
                else
                {
                    otRenderers = ot.GetComponents <Renderer>();
                }

                if (ot.ExcludeParticleSystems)
                {
                    otRenderers = PurgeParticleSystemRenderers(otRenderers);
                }
                commandBuffer.AddRenderingSteps(otRenderers, ot.OutlineColor, ot.Thickness, drawSilhouettesShader);
            }
            commandBuffer.EndUpdate();
        }
示例#2
0
 public CommandBufferGroupItem(OutlineModes outlineMode, Camera cam)
 {
     mode               = outlineMode;
     attachedCamera     = cam;
     tmpRenderTextureID = Shader.PropertyToID("_SilhouetteTempRT" + mode.ToString());
     RenderTextureID    = Shader.PropertyToID("_SilhouetteRT" + mode.ToString());
     ClearOnUpdate      = true;
 }
示例#3
0
        public static Color32 EncodeToCommandBufferKey(Color32 color, OutlineModes mode)
        {
            Color32 res = color;

            res.a = (byte)mode;

            return(res);
        }
示例#4
0
        //         public void EndUpdate()
        //         {
        //             for ( int i = 0; i < Items.Length; i++ )
        //                 if ( !Items[i].Used )
        //                     Items[i].Clear();
        //         }

        public void Clear(OutlineModes mode)
        {
            int idx = (int)mode;

            if (buffers[idx] != null)
            {
                buffers[idx].Clear();
            }
        }
示例#5
0
        public CommandBufferGroupItem GetCommandBufferItem(OutlineModes mode)
        {
            int idx = (int)mode;

            if (buffers[idx] == null)
            {
                buffers[idx] = new CommandBufferGroupItem(mode, cam);
            }

            return(buffers[idx]);
        }
示例#6
0
        public static CommandBufferKey DecodeCommandBufferKey(Color32 key)
        {
            OutlineModes mode = GetMode(key.a);

            key.a = 255;
            return(new CommandBufferKey()
            {
                Mode = mode,
                OutlineColor = key
            });
        }
示例#7
0
        public static OutlineInfo Decode(Color32 hash)
        {
            OutlineModes mode             = GetMode(hash.a);
            byte         outlineThickness = (byte)(hash.a - (byte)mode);

            hash.a = 255; // (byte)mode;

            return(new OutlineInfo()
            {
                Mode = mode,
                OutlineThickness = outlineThickness,
                OutlineColor = hash
            });
        }
示例#8
0
        public RenderTexture GetSilhouettesRT(OutlineModes mode)
        {
            int idx = (int)mode;

            if (silhouettesRT[idx])
            {
                if ((silhouettesRT[idx].width != myCamera.pixelWidth) || (silhouettesRT[idx].height != myCamera.pixelHeight))
                {
                    ReleaseSilhouettesRT(mode);
                    silhouettesRT[idx] = null;
                }
            }

            if (!silhouettesRT[idx])
            {
                RenderTexture rt = new RenderTexture(myCamera.pixelWidth, myCamera.pixelHeight, RenderTextureSettings.Depth, RenderTextureSettings.Format, RenderTextureReadWrite.Default);
                rt.useMipMap    = false;
                rt.antiAliasing = 1;
                rt.Create();
                silhouettesRT[idx] = rt;
            }

            return(silhouettesRT[idx]);
        }
 public OutlineTargetListKey(OutlineTarget target, bool useOldMode = false, bool useOldThickness = false)
 {
     Mode      = useOldMode ? target.OldMode : target.Mode;
     Thickness = useOldThickness ? target.OldThickness : target.Thickness;
 }
示例#10
0
        private void ApplyOutline(RenderTexture source, RenderTexture destination, OutlineModes mode, int thickness, Vector2 minUV, Vector2 maxUV)
        {
            // RenderTexture silhouettesTex = Shader.GetGlobalTexture( silhouetteRTID ) as RenderTexture;
            // RenderTexture silhouettesTex = Shader.GetGlobalTexture( silhouetteRTID ) as RenderTexture;
            // Shader.GetGlobalTexture( CommandBuffers.GetCommandBufferItem( /*OutlineModes.FastSolid*/mode ).RenderTextureID ) as RenderTexture;
            RenderTexture silhouettesTex = GetSilhouettesRT(mode);

            if (!silhouettesTex)
            {
                return;
            }

            int modeInt = (int)mode;

            outlineMaterials[modeInt].SetInt("_Thickness", thickness);
            outlineMaterials[modeInt].SetVector("_MinUV", minUV);
            outlineMaterials[modeInt].SetVector("_MaxUV", maxUV);

            switch (mode)
            {
            case OutlineModes.FastSolid:
                // [_Maintexture]: source image
                // [tempRT1]: silhouettes
                outlineMaterials[modeInt].SetTexture("_SecondTex", silhouettesTex);
                Graphics.Blit(source, destination, outlineMaterials[modeInt], 0 /*(int)OutlineShaderPasses.FastSolid*/);
                break;

            case OutlineModes.FastGlow:
                // [_Maintexture]: source image
                // [tempRT1]: silhouettes
                outlineMaterials[modeInt].SetTexture("_SecondTex", silhouettesTex);
                Graphics.Blit(source, destination, outlineMaterials[modeInt], 0 /*(int)OutlineShaderPasses.FastGlow*/);
                break;

            case OutlineModes.AccurateSolid:
                RenderTexture tmpAS = RenderTexture.GetTemporary(source.width, source.height, RenderTextureSettings.Depth, RenderTextureSettings.Format, RenderTextureReadWrite.Default, 1);

                // PASS 0 of OutlineMat shader
                // [SOURCE] tempRT1: white silhouettes (_Maintexture)
                // [DESTINATION] tempRT2: horizontal blur
                Graphics.Blit(silhouettesTex, tmpAS, outlineMaterials[modeInt], 0 /*(int)OutlineShaderPasses.HorizontalAccurateSolid*/);
                //Graphics.Blit( tmpAS, destination );

                // PASS 1 of OutlineMat shader
                // [SOURCE] source: original complete image (_MainTexture)
                // [OutlineMat._SecondTexture] tempRT2: horizontal blurred image from first pass (_SecondTexture)
                // [DESTINATION] destination
                outlineMaterials[modeInt].SetTexture("_SecondTex", tmpAS);
                Graphics.Blit(source, destination, outlineMaterials[modeInt], 1 /*(int)OutlineShaderPasses.VerticalAndBlendAccurateSolid*/);

                RenderTexture.ReleaseTemporary(tmpAS);
                break;

            case OutlineModes.AccurateGlow:
                RenderTexture tmpAG = RenderTexture.GetTemporary(source.width, source.height, RenderTextureSettings.Depth, RenderTextureSettings.Format, RenderTextureReadWrite.Default, 1);

                // PASS 0 of OutlineMat shader
                // [SOURCE] tempRT1: white silhouettes (_Maintexture)
                // [DESTINATION] tempRT2: horizontal blur
                Graphics.Blit(silhouettesTex, tmpAG, outlineMaterials[modeInt], 0 /*(int)OutlineShaderPasses.HorizontalAccurateGlow*/);
                //Graphics.Blit( tmpAG, destination );
                //return;

                // PASS 1 of OutlineMat shader
                // [SOURCE] source: original complete image (_MainTexture)
                // [OutlineMat._SecondTexture] tempRT2: horizontal blurred image from first pass (_SecondTexture)
                // [DESTINATION] destination
                outlineMaterials[modeInt].SetTexture("_SecondTex", tmpAG);
                Graphics.Blit(source, destination, outlineMaterials[modeInt], 1 /*(int)OutlineShaderPasses.VerticalAndBlendAccurateGlow*/);
                //HIGH HIGH HIGH TODO: Tiled GPU perf. warning: RenderTexture color surface (1269x605) was not cleared/discarded. See TiledGPUPerformanceWarning.ColorSurface label in Profiler for info
                // UnityEngine.Graphics:Blit( Texture, RenderTexture, Material, Int32 )
                // Cromos.OutlinePostEffect:ApplyOutline( RenderTexture, RenderTexture, OutlineModes, Int32, Vector2, Vector2 )( at Assets / Cromos / Highlighter / Outliner / OutlinePostEffect.cs:477 )
                // Cromos.OutlinePostEffect:OnRenderImage( RenderTexture, RenderTexture )( at Assets / Cromos / Highlighter / Outliner / OutlinePostEffect.cs:251 )

                RenderTexture.ReleaseTemporary(tmpAG);
                break;

            default:
                Debug.LogError("unknown outline mode", Instance);
                //Debug.LogError( "unknown outline mode" );
                break;
            }
        }
示例#11
0
 private void CreateOutlineShaderAndMaterial(OutlineModes mode)
 {
     CreateOutlineShaderAndMaterial((int)mode);
 }
示例#12
0
 public void ReleaseSilhouettesRT(OutlineModes mode)
 {
     ReleaseSilhouettesRT((int)mode);
 }
示例#13
0
        //HIGH: nella scena Outline Modes, anche se cancello tutti i cubi, il numero di Render Texture rimane eccessivo (dovrebbe essere 3 senza alcun effetto di post)


        /// <summary>
        /// all the outline magics happens here. Just don't touch this method please
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if ((!IsSupported) || (OutlineTarget.All.Count == 0))
            {
                Graphics.Blit(source, destination);
                return;
            }

            //             try
            //             {
            if (!materialsInitialized)
            {
                InitSilhouetteShaderAndMaterial();
            }

            //attachedCamera.cullingMask = originalCullinkgMask;

            // DEBUG: uncomment to see silhouette texture from command buffer
            //RenderTexture silhouettesTex = Shader.GetGlobalTexture( CommandBuffers.GetCommandBufferItem( OutlineModes.FastSolid ).RenderTextureID ) as RenderTexture;
            //#if UNITY_EDITOR
            if (debugView)
            {
                Graphics.Blit(GetSilhouettesRT(OutlineModes.FastSolid), destination);
                return;
            }
            //#endif

            if (OutlineTarget.All != null)
            {
                if (OutlineTarget.All.Count > 0)
                {
                    int           numberOfSteps = OutlineTarget.All.Count;
                    RenderTexture src           = source;
                    RenderTexture dst           = destination;
                    RenderTexture tmpRT         = null;
                    bool          multiBlit     = numberOfSteps > 1;
                    if (multiBlit)
                    {
                        tmpRT = RenderTexture.GetTemporary(source.width, source.height, RenderTextureSettings.Depth, RenderTextureSettings.Format, RenderTextureReadWrite.Default, 1);
                    }

                    float deltaX = (float)OutlineTarget.MaxThickness / (float)myCamera.pixelWidth;
                    float deltaY = (float)OutlineTarget.MaxThickness / (float)myCamera.pixelHeight;

                    int counter = 0;
                    foreach (KeyValuePair <OutlineTargetListKey, HashSet <OutlineTarget> > pair in OutlineTarget.All)
                    {
                        OutlineModes            mode      = pair.Key.Mode;
                        int                     thickness = pair.Key.Thickness;
                        HashSet <OutlineTarget> targets   = pair.Value;

                        if (multiBlit)
                        {
                            UpdateMultiBlitSrcDest(numberOfSteps, counter, source, destination, ref src, ref dst, tmpRT);
                        }

                        Vector2 minUV = Vector2.positiveInfinity;
                        Vector2 maxUV = Vector2.negativeInfinity;

                        foreach (OutlineTarget ot in targets)
                        {
                            minUV.x = Mathf.Min(minUV.x, ot.MinUV.x);
                            minUV.y = Mathf.Min(minUV.y, ot.MinUV.y);

                            maxUV.x = Mathf.Max(maxUV.x, ot.MaxUV.x);
                            maxUV.y = Mathf.Max(maxUV.y, ot.MaxUV.y);
                        }
                        minUV.x -= deltaX;
                        minUV.y -= deltaY;
                        maxUV.x += deltaX;
                        maxUV.y += deltaY;

#if UNITY_EDITOR
                        UVs[(int)mode].min = minUV;
                        UVs[(int)mode].max = maxUV;
#endif

                        ApplyOutline(src, dst, mode, thickness, minUV, maxUV);
                        counter++;
                    }

                    if (tmpRT)
                    {
                        RenderTexture.ReleaseTemporary(tmpRT);
                    }

                    return;
                }
            }
            //             }
            //             catch ( System.Exception ex )
            //             {
            //                 Debug.LogException( ex, this );
            //             }

            Graphics.Blit(source, destination);
        }
示例#14
0
 public OutlineInfo(OutlineModes mode, int thickness, Color color)
 {
     Mode             = mode;
     OutlineThickness = (byte)thickness;
     OutlineColor     = color;
 }
示例#15
0
 public OutlineTargetListKey(OutlineModes mode, int thickness)
 {
     Mode      = mode;
     Thickness = thickness;
 }
示例#16
0
 public int CountByMode(OutlineModes mode)
 {
     return(modeCounter[(int)mode]);
 }
示例#17
0
 private void ReleaseOutlineShaderAndMaterial(OutlineModes mode)
 {
     ReleaseOutlineShaderAndMaterial((int)mode);
 }