Skip to content

Commit a44f6c5

Browse files
committed
Changed the upgrader to apply conversion parameters in the AssignNewShadertoMaterial callback so when changing the shader in the material UI it also upgrade properly.
1 parent f763714 commit a44f6c5

4 files changed

Lines changed: 92 additions & 135 deletions

File tree

Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs

Lines changed: 29 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,6 @@
44

55
public class LegacyShadersToLowEndUpgrader
66
{
7-
private static class SupportedUpgradeParams
8-
{
9-
static public UpgradeParams diffuseOpaque = new UpgradeParams()
10-
{
11-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
12-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
13-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
14-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
15-
};
16-
17-
static public UpgradeParams specularOpaque = new UpgradeParams()
18-
{
19-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
20-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
21-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
22-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
23-
};
24-
25-
static public UpgradeParams diffuseAlpha = new UpgradeParams()
26-
{
27-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
28-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
29-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
30-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
31-
};
32-
33-
static public UpgradeParams specularAlpha = new UpgradeParams()
34-
{
35-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
36-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
37-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
38-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
39-
};
40-
41-
static public UpgradeParams diffuseAlphaCutout = new UpgradeParams()
42-
{
43-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout,
44-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
45-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
46-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
47-
};
48-
49-
static public UpgradeParams specularAlphaCutout = new UpgradeParams()
50-
{
51-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout,
52-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
53-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
54-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
55-
};
56-
57-
static public UpgradeParams diffuseCubemap = new UpgradeParams()
58-
{
59-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
60-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
61-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
62-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
63-
};
64-
65-
static public UpgradeParams specularCubemap = new UpgradeParams()
66-
{
67-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
68-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
69-
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
70-
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
71-
};
72-
73-
static public UpgradeParams diffuseCubemapAlpha = new UpgradeParams()
74-
{
75-
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
76-
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
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-
907
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Project", false, 3)]
918
public static void UpgradeMaterialsToLDProject()
929
{
@@ -111,51 +28,51 @@ private static void GetUpgraders(ref List<MaterialUpgrader> materialUpgraders)
11128
/////////////////////////////////////
11229
// Legacy Shaders upgraders /
11330
/////////////////////////////////////
114-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Diffuse", SupportedUpgradeParams.diffuseOpaque));
115-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Specular", SupportedUpgradeParams.specularOpaque));
116-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
117-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Specular", SupportedUpgradeParams.specularOpaque));
31+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Lmegacy Shaders/Diffuse"));
32+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Specular"));
33+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Diffuse"));
34+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Specular"));
11835

11936
// TODO: option to use environment map as texture or use reflection probe
120-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Diffuse", SupportedUpgradeParams.diffuseCubemap));
121-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Specular", SupportedUpgradeParams.specularOpaque));
122-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Diffuse", SupportedUpgradeParams.diffuseCubemap));
123-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Specular", SupportedUpgradeParams.specularOpaque));
37+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Diffuse"));
38+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Specular"));
39+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Diffuse"));
40+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Specular"));
12441

12542
// Self-Illum upgrader
126-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Diffuse", SupportedUpgradeParams.diffuseOpaque));
127-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
128-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Specular", SupportedUpgradeParams.specularOpaque));
129-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Specular", SupportedUpgradeParams.specularOpaque));
43+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Diffuse"));
44+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Diffuse"));
45+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Specular"));
46+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Specular"));
13047

13148
// Alpha Blended
132-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Diffuse", SupportedUpgradeParams.diffuseAlpha));
133-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Specular", SupportedUpgradeParams.specularAlpha));
134-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Diffuse", SupportedUpgradeParams.diffuseAlpha));
135-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Specular", SupportedUpgradeParams.specularAlpha));
49+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Diffuse"));
50+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Specular"));
51+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Diffuse"));
52+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Specular"));
13653

13754
// Cutout
138-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
139-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Specular", SupportedUpgradeParams.specularAlphaCutout));
140-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
141-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular", SupportedUpgradeParams.specularAlphaCutout));
55+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse"));
56+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Specular"));
57+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse"));
58+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular"));
14259

14360
/////////////////////////////////////
14461
// Reflective Shader Upgraders /
14562
/////////////////////////////////////
146-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Transperant", SupportedUpgradeParams.diffuseCubemapAlpha));
147-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec", SupportedUpgradeParams.specularCubemap));
148-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec Transp", SupportedUpgradeParams.specularCubemapAlpha));
63+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Transperant"));
64+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec"));
65+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec Transp"));
14966

15067
/////////////////////////////////////
15168
// Mobile Upgraders /
15269
/////////////////////////////////////
153-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Diffuse", SupportedUpgradeParams.diffuseOpaque));
154-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular", SupportedUpgradeParams.specularOpaque));
155-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular(1 Directional Light)", SupportedUpgradeParams.specularOpaque));
156-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
157-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Unlit (Supports Lightmap)", SupportedUpgradeParams.diffuseOpaque));
158-
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/VertexLit", SupportedUpgradeParams.specularOpaque));
70+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Diffuse"));
71+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular"));
72+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular(1 Directional Light)"));
73+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Diffuse"));
74+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Unlit (Supports Lightmap)"));
75+
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/VertexLit"));
15976

16077
/////////////////////////////////////
16178
// Particles /

Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public enum ReflectionSource
5151
ReflectionProbe
5252
}
5353

54+
public struct UpgradeParams
55+
{
56+
public BlendMode blendMode;
57+
public SpecularSource specularSource;
58+
public GlossinessSource glosinessSource;
59+
public ReflectionSource reflectionSource;
60+
}
61+
5462
private static class Styles
5563
{
5664
public static GUIContent[] albedoGlosinessLabels =
@@ -164,6 +172,14 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad
164172
float shininess = material.GetFloat("_Shininess");
165173
material.SetFloat("_Shininess", Mathf.Clamp(shininess, kMinShininessValue, 1.0f));
166174

175+
string oldShaderName = oldShader.name;
176+
string[] shaderStrings = oldShaderName.Split('/');
177+
178+
if (shaderStrings[0].Equals("Legacy Shaders") || shaderStrings[0].Equals("Mobile") || shaderStrings[0].Equals("Reflective"))
179+
{
180+
ConvertFromLegacy(material, oldShaderName);
181+
}
182+
167183
UpdateMaterialKeywords(material);
168184
}
169185

@@ -362,4 +378,47 @@ private void SetKeyword(Material material, string keyword, bool enable)
362378
else
363379
material.DisableKeyword(keyword);
364380
}
381+
382+
private void ConvertFromLegacy(Material material, string oldShaderName)
383+
{
384+
UpgradeParams shaderUpgradeParams;
385+
386+
if (oldShaderName.Contains("Transp"))
387+
{
388+
shaderUpgradeParams.blendMode = BlendMode.Alpha;
389+
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
390+
}
391+
else if (oldShaderName.Contains("Cutout"))
392+
{
393+
shaderUpgradeParams.blendMode = BlendMode.Cutout;
394+
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
395+
}
396+
else
397+
{
398+
shaderUpgradeParams.blendMode = BlendMode.Opaque;
399+
shaderUpgradeParams.glosinessSource = GlossinessSource.BaseAlpha;
400+
}
401+
402+
if (oldShaderName.Contains("Spec"))
403+
shaderUpgradeParams.specularSource = SpecularSource.SpecularTextureAndColor;
404+
else
405+
shaderUpgradeParams.specularSource = SpecularSource.NoSpecular;
406+
407+
if (oldShaderName.Contains("Reflective"))
408+
shaderUpgradeParams.reflectionSource = ReflectionSource.Cubemap;
409+
else
410+
shaderUpgradeParams.reflectionSource = ReflectionSource.NoReflection;
411+
412+
material.SetFloat("_Mode", (float)shaderUpgradeParams.blendMode);
413+
material.SetFloat("_SpecSource", (float)shaderUpgradeParams.specularSource);
414+
material.SetFloat("_GlossinessSource", (float)shaderUpgradeParams.glosinessSource);
415+
material.SetFloat("_ReflectionSource", (float)shaderUpgradeParams.reflectionSource);
416+
417+
if (oldShaderName.Contains("Self-Illumin"))
418+
{
419+
material.SetTexture("_EmissionMap", material.GetTexture("_MainTex"));
420+
material.SetTexture("_MainTex", null);
421+
material.SetColor("_EmissionColor", Color.white);
422+
}
423+
}
365424
}

Assets/LowEndMobilePipeline/Editor/LowendUpgraders.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
using UnityEditor.Experimental.Rendering;
22
using UnityEngine;
33

4-
public struct UpgradeParams
5-
{
6-
public float blendMode;
7-
public float specularSource;
8-
public float glosinessSource;
9-
public float reflectionSource;
10-
}
11-
124
public class LegacyBlinnPhongUpgrader : MaterialUpgrader
135
{
14-
public LegacyBlinnPhongUpgrader(string oldShaderName, UpgradeParams upgraderParams)
6+
public LegacyBlinnPhongUpgrader(string oldShaderName)
157
{
168
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
17-
SetNewFloatProperty("_Mode", upgraderParams.blendMode);
18-
SetNewFloatProperty("_SpecSource", upgraderParams.specularSource);
19-
SetNewFloatProperty("_GlossinessSource", upgraderParams.glosinessSource);
20-
SetNewFloatProperty("_ReflectionSource", upgraderParams.reflectionSource);
21-
22-
if (oldShaderName.Contains("Legacy Shaders/Self-Illumin"))
23-
{
24-
RenameTexture("_MainTex", "_EmissionMap");
25-
RemoveTexture("_MainTex");
26-
SetNewColorProperty("_EmissionColor", Color.white);
27-
}
289
}
2910
}
3011

@@ -58,6 +39,6 @@ public class TerrainUpgrader : MaterialUpgrader
5839
public TerrainUpgrader(string oldShaderName)
5940
{
6041
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
61-
SetNewFloatProperty("_Shininess", 1.0f);
42+
SetFloat("_Shininess", 1.0f);
6243
}
6344
}

Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public void RemoveTexture(string name)
104104
m_TexturesToRemove.Add(name);
105105
}
106106

107-
public void SetNewFloatProperty(string propertyName, float value)
107+
public void SetFloat(string propertyName, float value)
108108
{
109109
m_FloatPropertiesToSet[propertyName] = value;
110110
}
111111

112-
public void SetNewColorProperty(string propertyName, Color value)
112+
public void SetColor(string propertyName, Color value)
113113
{
114114
m_ColorPropertiesToSet[propertyName] = value;
115115
}

0 commit comments

Comments
 (0)