GetPassName() private method

private GetPassName ( int pass ) : string
pass int
return string
コード例 #1
0
ファイル: Material.cs プロジェクト: clarte53/armine
        public static Material FromUnity(Scene scene, UnityEngine.Material unity_material)
        {
            if (shadersProperties == null)
            {
                TextAsset properties = Resources.Load <TextAsset>(Constants.shaderDatabase);

                if (properties != null && properties.bytes.Length > 0)
                {
                    shadersProperties = (Dictionary <int, string[]>)Module.Import.Binary.serializer.Deserialize(properties.bytes);
                }
            }

            if (shadersProperties != null)
            {
                // Create new material
                Material material = new Material();

                // Save material options
                material.name                    = unity_material.name;
                material.shader                  = unity_material.shader.name;
                material.renderQueue             = unity_material.renderQueue;
                material.hideFlags               = unity_material.hideFlags;
                material.globalIlluminationFlags = unity_material.globalIlluminationFlags;
                material.keywords                = unity_material.shaderKeywords;
                material.passes                  = new bool[unity_material.passCount];

                // Save material enabled passes
                for (int i = 0; i < material.passes.Length; i++)
                {
#if UNITY_5_6_OR_NEWER
                    material.passes[i] = unity_material.GetShaderPassEnabled(unity_material.GetPassName(i));
#else
                    material.passes[i] = true;
#endif
                }

                // Save material properties
                // Range properties in Unity are f****d-up. It can be either int or float values, and their is no way to know wich one it is.
                // However, if we restore them using the wrong type, we get no errors but they are (obviously) ignored...
                // Therefore, we will save range as both int and float to be conservative.
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.RANGE, ref material.ints, (m, p) => m.GetInt(p));
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.RANGE, ref material.floats, (m, p) => m.GetFloat(p));
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.FLOAT, ref material.floats, (m, p) => m.GetFloat(p));
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.VECTOR, ref material.vectors, (m, p) => m.GetVector(p));
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.COLOR, ref material.colors, (m, p) => m.GetColor(p));
                FromUnityMaterialProperties(unity_material, Shaders.PropertyType.TEXTURE, ref material.textures, (m, p) =>
                {
                    UnityEngine.Texture unity_tex = m.GetTexture(p);

                    int index = (unity_tex != null && unity_tex is Texture2D ? scene.GetUnityTextureIndex((Texture2D)unity_tex) : -1);

                    return(index >= 0 ? new TextureParams((uint)index, m.GetTextureOffset(p), m.GetTextureScale(p)) : null);
                });

                return(material);
            }

            return(null);
        }
コード例 #2
0
ファイル: Material.cs プロジェクト: clarte53/armine
        public UnityEngine.Material ToUnity(Scene scene, Utils.Progress progress = null)
        {
            if (unityMaterial == null)
            {
                // Get the material shader
                Shader unity_shader = GetUnityShader(shader);

                if (unity_shader != null)
                {
                    // Create a new material with the selected shader
                    unityMaterial = new UnityEngine.Material(unity_shader);

                    // Set material options
                    unityMaterial.name                    = name;
                    unityMaterial.renderQueue             = renderQueue;
                    unityMaterial.hideFlags               = hideFlags;
                    unityMaterial.globalIlluminationFlags = globalIlluminationFlags;
                    unityMaterial.shaderKeywords          = keywords;

                    // Activate required shader passes
                    if (passes != null)
                    {
                        for (int i = 0; i < passes.Length; i++)
                        {
#if UNITY_5_6_OR_NEWER
                            unityMaterial.SetShaderPassEnabled(unityMaterial.GetPassName(i), passes[i]);
#endif
                        }
                    }

                    // Set material properties
                    ToUnityMaterialProperties <int, int>(unityMaterial, ints, (m, p, v) => m.SetInt(p, v));
                    ToUnityMaterialProperties <float, float>(unityMaterial, floats, (m, p, v) => m.SetFloat(p, v));
                    ToUnityMaterialProperties <Vector3, Vector3>(unityMaterial, vectors, (m, p, v) => m.SetVector(p, v));
                    ToUnityMaterialProperties <Color, Color>(unityMaterial, colors, (m, p, v) => m.SetColor(p, v));
                    ToUnityMaterialProperties <TextureParams, UnityEngine.Texture>(unityMaterial, textures, (m, p, v) =>
                    {
                        m.SetTexture(p, scene.textures[v.index].ToUnity(progress));
                        m.SetTextureOffset(p, v.offset);
                        m.SetTextureScale(p, v.scale);
                    });

                    // Set materials missing properties / keywords if material is imported from assimp
                    if ((keywords == null || keywords.Length <= 0) && shader == Constants.defaultAssimpShader)
                    {
                        CLARTE.Shaders.Standard.Utility.MaterialChanged(unityMaterial);
                    }
                }

                if (progress != null)
                {
                    progress.Update(1);
                }
            }

            return(unityMaterial);
        }