Example #1
0
        public static MaterialManager GetInstance(NTexture texture, string shaderName)
        {
            NTexture rootTexture = texture.root;

            if (rootTexture.materialManagers == null)
            {
                rootTexture.materialManagers = new Dictionary <string, MaterialManager>();
            }

            MaterialManager mm;

            if (!rootTexture.materialManagers.TryGetValue(shaderName, out mm))
            {
                mm = new MaterialManager(rootTexture);
                rootTexture.materialManagers.Add(shaderName, mm);
            }

            if (mm.sharedMaterial == null)
            {
                Shader shader = ShaderConfig.Get(shaderName);
                if (shader == null)
                {
                    Debug.LogWarning("FairyGUI: shader not found: " + shaderName);
                    shader = Shader.Find("Transparent/Diffuse");
                }
                mm.sharedMaterial             = new Material(shader);
                mm.sharedMaterial.mainTexture = rootTexture.nativeTexture;
                if (rootTexture.alphaTexture != null)
                {
                    mm.sharedMaterial.SetTexture("_AlphaTex", rootTexture.alphaTexture);
                }
            }

            return(mm);
        }
        public NMaterial CreateMaterial()
        {
            Shader shader = ShaderConfig.Get(shaderName);

            if (shader == null)
            {
                Debug.LogWarning("FairyGUI: shader not found: " + shaderName);
                shader = Shader.Find("UI/Default");
            }
            NMaterial mat = new NMaterial(shader);

            mat.mainTexture = texture.nativeTexture;
            if (texture.alphaTexture != null)
            {
                mat.EnableKeyword("COMBINED");
                mat.SetTexture("_AlphaTex", texture.alphaTexture);
            }

            shader.hideFlags = DisplayOptions.hideFlags;
            mat.hideFlags    = DisplayOptions.hideFlags;

            return(mat);
        }
Example #3
0
        public Material GetContextMaterial(UpdateContext context)
        {
            if (!context.clipped)
            {
                return(sharedMaterial);
            }

            Material mat;

            if (context.clipInfo.soft)
            {
                if (context.workCount != _softUpdateSeq)
                {
                    _softUpdateSeq = context.workCount;
                    _softClipId    = context.clipInfo.clipId;
                    _softNextIndex = 0;
                }
                else if (_softClipId != context.clipInfo.clipId)
                {
                    _softNextIndex++;
                    _softClipId = context.clipInfo.clipId;
                }

                if (_softClippedMaterials == null)
                {
                    _softClippedMaterials = new List <Material>();
                }

                if (_softNextIndex < _softClippedMaterials.Count)
                {
                    mat = _softClippedMaterials[_softNextIndex];
                }
                else
                {
                    Shader shader = ShaderConfig.Get(sharedMaterial.shader.name + ShaderConfig.softClipShaderSuffix);
                    if (shader == null)
                    {
                        Debug.LogWarning("FairyGUI: " + sharedMaterial.shader.name + " doesn't have a soft clipped shader version for clipping");
                        shader = sharedMaterial.shader;
                    }

                    mat             = new Material(shader);
                    mat.mainTexture = sharedMaterial.mainTexture;
                    if (_owner.alphaTexture != null)
                    {
                        mat.SetTexture("_AlphaTex", _owner.alphaTexture);
                    }
                    _softClippedMaterials.Add(mat);
                }

                mat.mainTextureOffset = context.clipInfo.offset;
                mat.mainTextureScale  = context.clipInfo.scale;
                mat.SetVector("_ClipSharpness", context.clipInfo.softness);
            }
            else
            {
                if (context.workCount != _updateSeq)
                {
                    _updateSeq = context.workCount;
                    _clipId    = context.clipInfo.clipId;
                    _nextIndex = 0;
                }
                else if (_clipId != context.clipInfo.clipId)
                {
                    _nextIndex++;
                    _clipId = context.clipInfo.clipId;
                }

                if (_clippedMaterials == null)
                {
                    _clippedMaterials = new List <Material>();
                }

                if (_nextIndex < _clippedMaterials.Count)
                {
                    mat = _clippedMaterials[_nextIndex];
                }
                else
                {
                    Shader shader = ShaderConfig.Get(sharedMaterial.shader.name + ShaderConfig.alphaClipShaderSuffix);
                    if (shader == null)
                    {
                        Debug.LogWarning("FairyGUI: " + sharedMaterial.shader.name + " doesn't have a clipped shader version for clipping");
                        shader = sharedMaterial.shader;
                    }

                    mat             = new Material(shader);
                    mat.mainTexture = sharedMaterial.mainTexture;
                    if (_owner.alphaTexture != null)
                    {
                        mat.SetTexture("_AlphaTex", _owner.alphaTexture);
                    }
                    _clippedMaterials.Add(mat);
                }

                mat.mainTextureOffset = context.clipInfo.offset;
                mat.mainTextureScale  = context.clipInfo.scale;
            }

            return(mat);
        }