public static void CreateShaderVariants()
    {
        var shaderVariantPath = "Assets/Shaders/ShaderVariants/";
        var shaderPath        = "Assets/Shaders/";

        if (Directory.Exists(shaderVariantPath))
        {
            Directory.Delete(shaderVariantPath, true);
        }
        var shaderList        = UnityEditorHelper.GetAllObjects <Shader>("shader", shaderPath);
        var matList           = UnityEditorHelper.GetAllObjects <Material>("mat");
        var shaderVariantDict = new Dictionary <string, HashSet <ShaderVariant> >();

        foreach (var mat in matList)
        {
            if (!mat)
            {
                continue;
            }
            var shader = mat.shader;
            if (shaderList.Contains(shader))
            {
                var shaderVariantCollectionName = $"{Path.GetFileNameWithoutExtension(shader.name)}_ShaderVariants";
                var shaderVariantCollectionPath = $"{shaderVariantPath}{shaderVariantCollectionName}.shadervariants";
                if (!shaderVariantDict.TryGetValue(shaderVariantCollectionPath, out var hashSet))
                {
                    shaderVariantDict[shaderVariantCollectionPath] = new HashSet <ShaderVariant>();
                }
                var shaderVariant = new ShaderVariant
                {
                    shader   = shader,
                    keywords = mat.shaderKeywords
                };
                shaderVariantDict[shaderVariantCollectionPath].Add(shaderVariant);
            }
        }
        foreach (var shaderVariantCollection in shaderVariantDict)
        {
            var path = shaderVariantCollection.Key;
            if (File.Exists(path))
            {
                AssetDatabase.DeleteAsset(path);
                AssetDatabase.Refresh();
            }
            var dir = path.Replace(Path.GetFileName(path), "");
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            AssetDatabase.CreateAsset(new ShaderVariantCollection(), path);
            var shaderVariantCollectionAsset = AssetDatabase.LoadAssetAtPath <ShaderVariantCollection>(path);
            foreach (var shaderVariant in shaderVariantCollection.Value)
            {
                shaderVariantCollectionAsset.Add(shaderVariant);
            }
            EditorUtility.SetDirty(shaderVariantCollectionAsset);
            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
        }
    }
        public static RawData GetShaderVariantEntries(Shader shader)
        {
            if (shader == null)
            {
                return(null);
            }
            int[]    types    = null;
            String[] keywords = null;
            object[] args     = new object[] { shader, new ShaderVariantCollection(), types, keywords };
            ShaderUtils.GetShaderVariantEntriesMethod.Invoke(null, args);
            types    = args[2] as int[];
            keywords = args[3] as String[];
            var result = new RawData();

            for (int i = 0; i < keywords.Length; ++i)
            {
                var keyword = keywords[i];
                var sv      = new ShaderVariant(shader, ( PassType )types[i], keyword.Split(' '));
                List <ShaderVariant> variants;
                if (!result.TryGetValue(shader, out variants))
                {
                    variants = new List <ShaderVariant>();
                    result.Add(shader, variants);
                }
                variants.Add(sv);
            }
            return(result);
        }
        public static ShaderVariant Factory(bool transparent, Material _material)
        {
            ShaderVariant sv = transparent ? (ShaderVariant) new TransparentShaderVariant() : (ShaderVariant) new OpaqueShaderVariant();

            sv.material = _material;
            return(sv);
        }
Exemplo n.º 4
0
        public void BuildShaderVariant(ShaderVariant variant, Water water, WindWaves windWaves, WaterQualityLevel qualityLevel)
        {
            OnValidate(windWaves);

            ResolveFinalSettings(qualityLevel);

            variant.SetWaterKeyword("_WAVES_FFT_SLOPE", enabled && renderedMaps == MapType.Slope);
            variant.SetUnityKeyword("_WAVES_ALIGN", (!water.Volume.Boundless && water.Volume.HasRenderableAdditiveVolumes && flattenMode == FlattenMode.Auto) || flattenMode == FlattenMode.ForcedOn);
            variant.SetUnityKeyword("_WAVES_FFT", enabled && (renderedMaps & MapType.Displacement) != 0);
        }
Exemplo n.º 5
0
        private void CompileVariant(Pipeline pipe, JBooth.BetterShaders.OptionOverrides overrides, string path)
        {
            var variant = new ShaderVariant();

            variant.Pipe = pipe;

            CompileVariant(overrides, path, variant);

            variants.Add(variant);
        }
Exemplo n.º 6
0
        public void BuildShaderVariant(ShaderVariant variant, Water water, WaterQualityLevel qualityLevel)
        {
            CreateObjects();
            ResolveFinalSettings(qualityLevel);

            waterWavesFFT.BuildShaderVariant(variant, water, this, qualityLevel);
            waterWavesGerstner.BuildShaderVariant(variant, water, this, qualityLevel);

            variant.SetWaterKeyword("_INCLUDE_SLOPE_VARIANCE", dynamicSmoothness.Enabled);
        }
    public void Start()
    {
        mInputController  = FindObjectOfType <InputController>();
        pointerController = FindObjectOfType <PointerController>();
        deleteTool        = FindObjectOfType <DeleteToolOld>();

        m_MeshRenderer = GetComponent <MeshRenderer>();
        m_Mat          = m_MeshRenderer.material;
        shaderVariant  = ShaderVariant.Factory(transparent, m_Mat);
    }
    public void CacheShadersFromPackage(string cahced_package_name)
    {
        //IL_002d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0032: Expected O, but got Unknown
        //IL_00ac: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b8: Unknown result type (might be due to invalid IL or missing references)
        //IL_00be: Unknown result type (might be due to invalid IL or missing references)
        PackageObject cachedPackage = GetCachedPackage(cahced_package_name);

        if (cachedPackage != null)
        {
            AssetBundle val = cachedPackage.obj as AssetBundle;
            if (val != null)
            {
                Shader[] array = val.LoadAllAssets <Shader>();
                ShaderVariantCollection val2 = new ShaderVariantCollection();
                int i = 0;
                for (int num = array.Length; i < num; i++)
                {
                    if (!array[i].get_isSupported())
                    {
                        Log.Error("no support shader : " + array[i].get_name());
                    }
                    string name = array[i].get_name();
                    shaderCaches.Add(name, array[i]);
                    if (name.StartsWith("EeL") || name.Contains("effect"))
                    {
                        ShaderVariant val3 = default(ShaderVariant);
                        val3.shader = array[i];
                        val2.Add(val3);
                    }
                }
                if (!val2.get_isWarmedUp())
                {
                    val2.WarmUp();
                }
            }
        }
    }
Exemplo n.º 9
0
        private void CompileVariant(JBooth.BetterShaders.OptionOverrides overrides, string path, ShaderVariant variant)
        {
            var pipeline = (JBooth.BetterShaders.ShaderBuilder.RenderPipeline)variant.Pipe;

            if (path.EndsWith("surfshader"))
            {
                variant.Code = JBooth.BetterShaders.BetterShaderImporterEditor.BuildExportShader(pipeline, overrides, path);
            }
            else if (path.EndsWith("stackedshader"))
            {
                variant.Code = JBooth.BetterShaders.StackedShaderImporterEditor.BuildExportShader(pipeline, overrides, path);
            }

            variant.Code = variant.Code.Replace("\n\r", "\n");
            variant.Code = variant.Code.Replace("\r\n", "\n");
        }
Exemplo n.º 10
0
 public bool Contains(ShaderVariant variant) =>
 this.ContainsInternal(variant.shader, variant.passType, variant.keywords);
Exemplo n.º 11
0
 public bool Contains(ShaderVariant variant)
 {
     return(ContainsInternal(variant.shader, variant.passType, variant.keywords));
 }
Exemplo n.º 12
0
 public bool Remove(ShaderVariant variant)
 {
     return(RemoveInternal(variant.shader, variant.passType, variant.keywords));
 }
Exemplo n.º 13
0
 public bool Add(ShaderVariant variant)
 {
     return(AddInternal(variant.shader, variant.passType, variant.keywords));
 }
Exemplo n.º 14
0
 public bool Remove(ShaderVariant variant)
 {
     return this.RemoveInternal(variant.shader, variant.passType, variant.keywords);
 }
Exemplo n.º 15
0
 public bool Contains(ShaderVariant variant)
 {
     return this.ContainsInternal(variant.shader, variant.passType, variant.keywords);
 }
Exemplo n.º 16
0
 public bool Add(ShaderVariant variant)
 {
     return this.AddInternal(variant.shader, variant.passType, variant.keywords);
 }
Exemplo n.º 17
0
 public bool Add(ShaderVariant variant) =>
 this.AddInternal(variant.shader, variant.passType, variant.keywords);
Exemplo n.º 18
0
 public bool Remove(ShaderVariant variant) =>
 this.RemoveInternal(variant.shader, variant.passType, variant.keywords);
Exemplo n.º 19
0
        public void BuildShaderVariant(ShaderVariant variant, Water water, WaterQualityLevel qualityLevel)
        {
            OnValidate();

            variant.SetWaterKeyword("_WATER_FOAM_WS", enabled && overlays == null && CheckPreresquisites());
        }
        public void OnProcessShader(
            Shader shader,
            ShaderSnippetData snippet,
            IList <ShaderCompilerData> data)
        {
            List <ShaderVariantCollection> keepShaders = null;

            foreach (var guid in AssetDatabase.FindAssets("t:ShaderStripper"))
            {
                string         path     = AssetDatabase.GUIDToAssetPath(guid);
                ShaderStripper stripper = AssetDatabase.LoadAssetAtPath <ShaderStripper>(path);
                if (stripper != null)
                {
                    if (!stripper.enabled)
                    {
                        return;
                    }
                    keepShaders = stripper.keepShaders;
                }
            }

            Debug.Assert(keepShaders != null);
            if (keepShaders.Count == 0)
            {
                return;
            }
            for (int i = data.Count - 1; i >= 0; --i)
            {
                ShaderCompilerData variant  = data[i];
                List <string>      keywords = new List <string>();
                var variantKeywords         = variant.shaderKeywordSet.GetShaderKeywords();
                foreach (ShaderKeyword keyword in variantKeywords)
                {
                    string k = keyword.GetKeywordName();
                    keywords.Add(k);
                }

                bool match = false;
                try
                {
                    ShaderVariant currentVariant = new ShaderVariant();
                    currentVariant.shader   = shader;
                    currentVariant.passType = snippet.passType;
                    currentVariant.keywords = keywords.ToArray();

                    foreach (ShaderVariantCollection collection in keepShaders)
                    {
                        if (collection.Contains(currentVariant))
                        {
                            match = true;
                            break;
                        }
                    }
                }
                catch (System.ArgumentException)
                {
                    // not valid, continue...
                }

                Debug.LogFormat(
                    "{0} shader {1} pass {2} keywords {3}",
                    match ? "Keep" : "Strip",
                    shader.name,
                    snippet.passType,
                    string.Join(" ", keywords));

                if (!match)
                {
                    data.RemoveAt(i);
                }
            }
        }
Exemplo n.º 21
0
 public void BuildShaderVariant(ShaderVariant variant, Water water, WaterQualityLevel qualityLevel)
 {
     variant.SetWaterKeyword("_PLANAR_REFLECTIONS", enabled && (!highQuality || !qualityLevel.allowHighQualityReflections));
     variant.SetWaterKeyword("_PLANAR_REFLECTIONS_HQ", enabled && highQuality && qualityLevel.allowHighQualityReflections);
 }
Exemplo n.º 22
0
 public void BuildShaderVariant(ShaderVariant variant, Water water, WindWaves windWaves, WaterQualityLevel qualityLevel)
 {
     variant.SetUnityKeyword("_WAVES_GERSTNER", enabled);
 }
Exemplo n.º 23
0
 public void BuildShaderVariant(ShaderVariant variant, Water water, WaterQualityLevel qualityLevel)
 {
     variant.SetWaterKeyword("_WATER_OVERLAYS", enabled);
 }