Ejemplo n.º 1
0
 private void OnDisable()
 {
     if (current != this)
     {
         return;
     }
     current = null;
     if (!Application.isPlaying)
     {
         DestroyImmediate(texCopyMat);
         if (decalAlbedoAtlas)
         {
             DestroyImmediate(decalAlbedoAtlas);
         }
         if (decalNormalAtlas)
         {
             DestroyImmediate(decalNormalAtlas);
         }
         if (decalSpecularAtlas)
         {
             DestroyImmediate(decalSpecularAtlas);
         }
     }
     else
     {
         Destroy(texCopyMat);
         if (decalAlbedoAtlas)
         {
             Destroy(decalAlbedoAtlas);
         }
         if (decalNormalAtlas)
         {
             Destroy(decalNormalAtlas);
         }
         if (decalSpecularAtlas)
         {
             Destroy(decalSpecularAtlas);
         }
     }
     foreach (var i in allAlbedoComponent)
     {
         i.Dispose();
     }
     foreach (var i in allNormalComponent)
     {
         i.Dispose();
     }
     foreach (var i in allSpecularComponent)
     {
         i.Dispose();
     }
 }
Ejemplo n.º 2
0
        private void OnEnable()
        {
            if (current)
            {
                enabled = false;
                return;
            }
            current    = this;
            elements   = int3(allAlbedoTextures.Count, allNormalTextures.Count, allSpecularTextures.Count);
            texCopyMat = new Material(Shader.Find("Hidden/DecalCopy"));
            foreach (var i in allAlbedoComponent)
            {
                i.Init();
            }
            foreach (var i in allNormalComponent)
            {
                i.Init();
            }
            foreach (var i in allSpecularComponent)
            {
                i.Init();
            }
            int depthSlice = allAlbedoTextures.Count + allAlbedoComponent.Count;

            if (depthSlice > 0)
            {
                decalAlbedoAtlas = new RenderTexture(new RenderTextureDescriptor
                {
                    width             = albedoSize,
                    height            = albedoSize,
                    volumeDepth       = depthSlice,
                    dimension         = TextureDimension.Tex2DArray,
                    enableRandomWrite = true,
                    colorFormat       = RenderTextureFormat.ARGB32,
                    msaaSamples       = 1,
                });
                decalAlbedoAtlas.wrapMode = TextureWrapMode.Repeat;
                decalAlbedoAtlas.Create();
            }
            depthSlice = allNormalTextures.Count + allNormalComponent.Count;
            if (depthSlice > 0)
            {
                decalNormalAtlas = new RenderTexture(new RenderTextureDescriptor
                {
                    width             = normalSize,
                    height            = normalSize,
                    volumeDepth       = depthSlice,
                    dimension         = TextureDimension.Tex2DArray,
                    enableRandomWrite = true,
                    colorFormat       = RenderTextureFormat.RGHalf,
                    msaaSamples       = 1
                });
                decalNormalAtlas.wrapMode = TextureWrapMode.Repeat;
                decalNormalAtlas.Create();
            }
            depthSlice = allSpecularTextures.Count + allSpecularComponent.Count;
            if (depthSlice > 0)
            {
                decalSpecularAtlas = new RenderTexture(new RenderTextureDescriptor
                {
                    width             = specularSize,
                    height            = specularSize,
                    volumeDepth       = depthSlice,
                    dimension         = TextureDimension.Tex2DArray,
                    enableRandomWrite = true,
                    colorFormat       = RenderTextureFormat.ARGB32,
                    msaaSamples       = 1
                });
                decalSpecularAtlas.wrapMode = TextureWrapMode.Repeat;
                decalSpecularAtlas.Create();
            }
            if (!Application.isPlaying)
            {
                LoadTexturesInEditor();
            }
            else
            {
                StartCoroutine(LoadTextures());
            }
        }