Example #1
0
 public void RenameShader(string oldName, string newName, MaterialFinalizer finalizer = null)
 {
     m_OldShader = oldName;
     m_NewShader = newName;
     m_Finalizer = finalizer;
 }
 public StandardsTerrainToHDTerrainLitUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
 {
     RenameShader(sourceShaderName, destShaderName, finalizer);
 }
 public HDLitToBetterLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
 {
     RenameShader(sourceShaderName, destShaderName, finalizer);
 }
        public UnlitsToHDUnlitUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
        {
            RenameShader(sourceShaderName, destShaderName, finalizer);

            if (sourceShaderName == Unlit_Color)
            {
                RenameColor("_Color", "_UnlitColor");
            }
            else             // all other unlit have a texture
            {
                RenameTexture("_MainTex", "_UnlitColorMap");
            }

            if (sourceShaderName == Unlit_Cutout)
            {
                RenameFloat("_Cutoff", "_AlphaCutoff");
                SetFloat("_AlphaCutoffEnable", 1f);
            }
            else
            {
                SetFloat("_AlphaCutoffEnable", 0f);
            }


            SetFloat("_SurfaceType", (sourceShaderName == Unlit_Transparent)? 1f : 0f);
        }
Example #5
0
        public StandardToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer)
        {
            RenameShader(sourceShaderName, destShaderName, finalizer);

            RenameTexture("_MainTex", "_BaseColorMap");
            RenameColor("_Color", "_BaseColor");
            RenameFloat("_Glossiness", "_Smoothness");
            RenameTexture("_BumpMap", "_NormalMap");
            RenameFloat("_BumpScale", "_NormalScale");
            RenameColor("_EmissionColor", "_EmissiveColor");
            RenameFloat("_DetailNormalMapScale", "_DetailNormalScale");
            RenameFloat("_Cutoff", "_AlphaCutoff");
            RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);

            // the HD renderloop packs detail albedo and detail normals into a single texture.
            // mapping the detail normal map, if any, to the detail map, should do the right thing if
            // there is no detail albedo.
            RenameTexture("_DetailNormalMap", "_DetailMap");

            // Metallic uses [Gamma] attribute in standard shader but not in Lit.
            // @Seb: Should we convert?
            RenameFloat("_Metallic", "_Metallic");

            //@TODO: Seb. Why do we multiply color by intensity
            //       in shader when we can just store a color?
            // builtinData.emissiveColor * builtinData.emissiveIntensity
        }
        public StandardsToHDLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
        {
            RenameShader(sourceShaderName, destShaderName, finalizer);

            RenameTexture("_MainTex", "_BaseColorMap");
            RenameColor("_Color", "_BaseColor");
            RenameFloat("_Glossiness", "_Smoothness");
            RenameTexture("_BumpMap", "_NormalMap");
            RenameFloat("_BumpScale", "_NormalScale");
            RenameTexture("_ParallaxMap", "_HeightMap");
            RenameTexture("_EmissionMap", "_EmissiveColorMap");
            RenameTexture("_DetailAlbedoMap", "_DetailMap");
            RenameFloat("_UVSec", "_UVDetail");
            SetFloat("_LinkDetailsWithBase", 0);
            RenameFloat("_DetailNormalMapScale", "_DetailNormalScale");
            RenameFloat("_Cutoff", "_AlphaCutoff");
            RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);


            if (sourceShaderName == Standard)
            {
                SetFloat("_MaterialID", 1f);
            }

            if (sourceShaderName == Standard_Spec)
            {
                SetFloat("_MaterialID", 4f);

                RenameColor("_SpecColor", "_SpecularColor");
                RenameTexture("_SpecGlossMap", "_SpecularColorMap");
            }
        }
        /// <summary>
        /// Postprocesses materials while you are importing a SpeedTree 8 asset. Call from OnPostprocessSpeedTree in a MaterialPostprocessor.
        /// </summary>
        /// <param name="speedtree">The GameObject Unity creates from this imported SpeedTree.</param>
        /// <param name="stImporter">The asset importer used to import this SpeedTree asset.</param>
        /// <param name="finalizer">Render pipeline-specific material finalizer.</param>
        public static void PostprocessSpeedTree8Materials(GameObject speedtree, SpeedTreeImporter stImporter, MaterialFinalizer finalizer = null)
        {
            LODGroup lg = speedtree.GetComponent <LODGroup>();

            LOD[] lods = lg.GetLODs();
            for (int l = 0; l < lods.Length; l++)
            {
                LOD  lod         = lods[l];
                bool isBillboard = stImporter.hasBillboard && (l == lods.Length - 1);
                int  wq          = Mathf.Min(stImporter.windQualities[l], stImporter.bestWindQuality);
                foreach (Renderer r in lod.renderers)
                {
                    // Override default motion vector generation mode pending
                    // proper motion vector integration in SRPs.
                    r.motionVectorGenerationMode = MotionVectorGenerationMode.Camera;
                    foreach (Material m in r.sharedMaterials)
                    {
                        float cutoff = stImporter.alphaTestRef;
                        ImportNewSpeedTree8Material(m, wq, isBillboard);
                        if (finalizer != null)
                        {
                            finalizer(m);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Creates a material upgrader that handles the property renames that HD and Universal have in common when upgrading
 /// from the built-in SpeedTree 8 shader.
 /// </summary>
 /// <param name="sourceShaderName">Original SpeedTree8 shader name.</param>
 /// <param name="destShaderName">New SpeedTree 8 shader name.</param>
 /// <param name="finalizer">A delegate that postprocesses the material for the render pipeline in use.</param>
 public SpeedTree8MaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
 {
     RenameShader(sourceShaderName, destShaderName, finalizer);
     RenameFloat("_WindQuality", "_WINDQUALITY");
     RenameFloat("_TwoSided", "_CullMode"); // Currently only used in HD. Update this once URP per-material cullmode is enabled via shadergraph.
 }
 /// <summary>
 /// Creates a material upgrader that handles the property renames that HD and Universal have in common when upgrading
 /// from the built-in SpeedTree 8 shader.
 /// </summary>
 /// <param name="sourceShaderName">Original SpeedTree8 shader name.</param>
 /// <param name="destShaderName">New SpeedTree 8 shader name.</param>
 /// <param name="finalizer">A delegate that postprocesses the material for the render pipeline in use.</param>
 public SpeedTree8MaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
 {
     RenameShader(sourceShaderName, destShaderName, finalizer);
     RenameFloat("_WindQuality", "_WINDQUALITY");
     RenameFloat("_BillboardKwToggle", "EFFECT_BILLBOARD");
     RenameKeywordToFloat("EFFECT_EXTRA_TEX", "EFFECT_EXTRA_TEX", 1, 0);
     RenameKeywordToFloat("EFFECT_SUBSURFACE", "_SubsurfaceKwToggle", 1, 0);
     RenameKeywordToFloat("EFFECT_BUMP", "_NormalMapKwToggle", 1, 0);
     RenameKeywordToFloat("EFFECT_HUE_VARIATION", "_HueVariationKwToggle", 1, 0);
 }
Example #10
0
        public HDLitToURPLitMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer = null)
        {
            if (sourceShaderName == null)
            {
                throw new ArgumentNullException("oldShaderName");
            }

            RenameShader(sourceShaderName, destShaderName, finalizer);

            RenameTexture("_BaseColorMap", "_BaseMap");
            //RenameColor("_Color", "_BaseColor");
            //RenameFloat("_Glossiness", "_Smoothness");
            RenameTexture("_NormalMap", "_BumpMap");
            RenameTexture("_MaskMap", "_MetallicGlossMap");
            RenameFloat("_NormalScale", "_BumpScale");
            //RenameTexture("_ParallaxMap", "_HeightMap");
            RenameTexture("_EmissiveColorMap", "_EmissionMap");
            RenameColor("_EmissiveColor", "_EmissionColor");
            //RenameTexture("_DetailAlbedoMap", "_DetailMap");
            //RenameFloat("_UVSec", "_UVDetail");
            //SetFloat("_LinkDetailsWithBase", 0);
            //RenameFloat("_DetailNormalMapScale", "_DetailNormalScale");
            RenameFloat("_AlphaCutoff", "_Cutoff");

            //RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);

            //if (sourceShaderName == Lit)
            //{
            //    SetFloat("_MaterialID", 1f);
            //}

            //if (sourceShaderName == Standard_Spec)
            //{
            //    SetFloat("_MaterialID", 4f);

            //    RenameColor("_SpecColor", "_SpecularColor");
            //    RenameTexture("_SpecGlossMap", "_SpecularColorMap");
            //}
        }