|
| 1 | +using System.Collections.Generic; |
| 2 | +using UnityEditor.Experimental.Rendering; |
| 3 | +using UnityEditor; |
| 4 | + |
| 5 | +public class LegacyShadersToLowEndUpgrader : MaterialUpgrader |
| 6 | +{ |
| 7 | + private struct UpgradeParams |
| 8 | + { |
| 9 | + public float blendMode; |
| 10 | + public float specularSource; |
| 11 | + public float glosinessSource; |
| 12 | + public float reflectionSource; |
| 13 | + } |
| 14 | + |
| 15 | + private static class SupportedUpgradeParams |
| 16 | + { |
| 17 | + static public UpgradeParams diffuseOpaque = new UpgradeParams() |
| 18 | + { |
| 19 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque, |
| 20 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular, |
| 21 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha, |
| 22 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 23 | + }; |
| 24 | + |
| 25 | + static public UpgradeParams specularOpaque = new UpgradeParams() |
| 26 | + { |
| 27 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque, |
| 28 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor, |
| 29 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha, |
| 30 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 31 | + }; |
| 32 | + |
| 33 | + static public UpgradeParams diffuseAlpha = new UpgradeParams() |
| 34 | + { |
| 35 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha, |
| 36 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular, |
| 37 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha, |
| 38 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 39 | + }; |
| 40 | + |
| 41 | + static public UpgradeParams specularAlpha = new UpgradeParams() |
| 42 | + { |
| 43 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha, |
| 44 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor, |
| 45 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha, |
| 46 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 47 | + }; |
| 48 | + |
| 49 | + static public UpgradeParams diffuseAlphaCutout = new UpgradeParams() |
| 50 | + { |
| 51 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout, |
| 52 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular, |
| 53 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha, |
| 54 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 55 | + }; |
| 56 | + |
| 57 | + static public UpgradeParams specularAlphaCutout = new UpgradeParams() |
| 58 | + { |
| 59 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout, |
| 60 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor, |
| 61 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha, |
| 62 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection |
| 63 | + }; |
| 64 | + |
| 65 | + static public UpgradeParams diffuseCubemap = new UpgradeParams() |
| 66 | + { |
| 67 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque, |
| 68 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular, |
| 69 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha, |
| 70 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap |
| 71 | + }; |
| 72 | + |
| 73 | + static public UpgradeParams specularCubemap = new UpgradeParams() |
| 74 | + { |
| 75 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque, |
| 76 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor, |
| 77 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha, |
| 78 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap |
| 79 | + }; |
| 80 | + |
| 81 | + static public UpgradeParams specularCubemapAlpha = new UpgradeParams() |
| 82 | + { |
| 83 | + blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha, |
| 84 | + specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor, |
| 85 | + glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha, |
| 86 | + reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap |
| 87 | + }; |
| 88 | + } |
| 89 | + |
| 90 | + [MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Selection", false, 3)] |
| 91 | + public static void UpgradeMaterialsToLDSelection() |
| 92 | + { |
| 93 | + List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>(); |
| 94 | + GetUpgraders(ref materialUpgraders); |
| 95 | + |
| 96 | + MaterialUpgrader.UpgradeSelection(materialUpgraders, "Upgrade to LD Materials"); |
| 97 | + } |
| 98 | + |
| 99 | + [MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Project", false, 4)] |
| 100 | + public static void UpgradeMaterialsToLDProject() |
| 101 | + { |
| 102 | + List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>(); |
| 103 | + GetUpgraders(ref materialUpgraders); |
| 104 | + |
| 105 | + MaterialUpgrader.UpgradeProjectFolder(materialUpgraders, "Upgrade to LD Materials"); |
| 106 | + } |
| 107 | + |
| 108 | + private static void GetUpgraders(ref List<MaterialUpgrader> materialUpgraders) |
| 109 | + { |
| 110 | + ///////////////////////////////////// |
| 111 | + // Legacy Shaders upgraders / |
| 112 | + ///////////////////////////////////// |
| 113 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Diffuse", SupportedUpgradeParams.diffuseOpaque)); |
| 114 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Specular", SupportedUpgradeParams.specularOpaque)); |
| 115 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque)); |
| 116 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Bumped Specular", SupportedUpgradeParams.specularOpaque)); |
| 117 | + |
| 118 | + // TODO: option to use environment map as texture or use reflection probe |
| 119 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Reflective/Bumped Diffuse", SupportedUpgradeParams.diffuseCubemap)); |
| 120 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Reflective/Bumped Specular", SupportedUpgradeParams.specularOpaque)); |
| 121 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Reflective/Diffuse", SupportedUpgradeParams.diffuseCubemap)); |
| 122 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Reflective/Specular", SupportedUpgradeParams.specularOpaque)); |
| 123 | + |
| 124 | + // Self-Illum upgrade still not supported |
| 125 | + //materialUpgraders.Add(new LegacyShaderToLowEndUpgrader("Legacy Shaders/Self-Illum/Bumped Specular")); |
| 126 | + |
| 127 | + // Alpha Blended |
| 128 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Diffuse", SupportedUpgradeParams.diffuseAlpha)); |
| 129 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Specular", SupportedUpgradeParams.specularCubemap)); |
| 130 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Bumped Diffuse", SupportedUpgradeParams.diffuseAlpha)); |
| 131 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Bumped Specular", SupportedUpgradeParams.specularCubemap)); |
| 132 | + |
| 133 | + // Cutout |
| 134 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse", SupportedUpgradeParams.diffuseAlphaCutout)); |
| 135 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Cutout/Specular", SupportedUpgradeParams.specularAlphaCutout)); |
| 136 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse", SupportedUpgradeParams.diffuseAlphaCutout)); |
| 137 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular", SupportedUpgradeParams.specularAlphaCutout)); |
| 138 | + |
| 139 | + ///////////////////////////////////// |
| 140 | + // Reflective Shader Upgraders / |
| 141 | + ///////////////////////////////////// |
| 142 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Reflective/Diffuse Reflection Spec", SupportedUpgradeParams.specularCubemap)); |
| 143 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Reflective/Diffuse Reflection Spec Transp", SupportedUpgradeParams.specularCubemapAlpha)); |
| 144 | + |
| 145 | + ///////////////////////////////////// |
| 146 | + // Mobile Upgraders / |
| 147 | + ///////////////////////////////////// |
| 148 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/Diffuse", SupportedUpgradeParams.diffuseOpaque)); |
| 149 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/Bumped Specular", SupportedUpgradeParams.specularOpaque)); |
| 150 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/Bumped Specular(1 Directional Light)", SupportedUpgradeParams.specularOpaque)); |
| 151 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque)); |
| 152 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/Unlit (Supports Lightmap)", SupportedUpgradeParams.diffuseOpaque)); |
| 153 | + materialUpgraders.Add(new LegacyShadersToLowEndUpgrader("Mobile/VertexLit", SupportedUpgradeParams.specularOpaque)); |
| 154 | + } |
| 155 | + |
| 156 | + LegacyShadersToLowEndUpgrader(string oldShaderName, UpgradeParams upgraderParams) |
| 157 | + { |
| 158 | + RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile"); |
| 159 | + SetNewFloatProperty("_Mode", upgraderParams.blendMode); |
| 160 | + SetNewFloatProperty("_SpecSource", upgraderParams.specularSource); |
| 161 | + SetNewFloatProperty("_GlossinessSource", upgraderParams.glosinessSource); |
| 162 | + SetNewFloatProperty("_ReflectionSource", upgraderParams.reflectionSource); |
| 163 | + } |
| 164 | +} |
0 commit comments