Skip to content

Commit f4d4900

Browse files
committed
Added ReflectionCubemap support to lowend mobile. Added Material upgraders to most of legacy shaders.
1 parent 3f15b01 commit f4d4900

8 files changed

Lines changed: 284 additions & 52 deletions

Assets/LowEndMobilePipeline/Editor/LegacyMobileToLowendMobileUpgrader.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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+
}

Assets/LowEndMobilePipeline/Editor/LegacyMobileToLowendMobileUpgrader.cs.meta renamed to Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ public class LowendMobilePipelineMaterialEditor : MaterialEditor
1010
private MaterialProperty alphaCutoffProp = null;
1111
private MaterialProperty specularSourceProp = null;
1212
private MaterialProperty glossinessSourceProp = null;
13+
private MaterialProperty reflectionSourceProp = null;
1314
private MaterialProperty specularGlossMapProp = null;
1415
private MaterialProperty specularColorProp = null;
1516
private MaterialProperty shininessProp = null;
1617
private MaterialProperty bumpMapProp = null;
1718
private MaterialProperty emissionMapProp = null;
1819
private MaterialProperty emissionColorProp = null;
20+
private MaterialProperty reflectionMapProp = null;
21+
private MaterialProperty reflectionColorProp = null;
1922

2023
public enum BlendMode
2124
{
@@ -37,6 +40,13 @@ public enum GlossinessSource
3740
SpecularAlpha
3841
}
3942

43+
public enum ReflectionSource
44+
{
45+
NoReflection,
46+
Cubemap,
47+
ReflectionProbe
48+
}
49+
4050
private void Awake()
4151
{
4252
Material material = target as Material;
@@ -65,6 +75,7 @@ private static class Styles
6575

6676
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
6777
public static GUIContent emissionMapLabel = new GUIContent("Emission Map", "Emission Map");
78+
public static GUIContent reflectionMapLabel = new GUIContent("Reflection Source", "Reflection Source Map");
6879

6980
public static GUIContent alphaCutoutWarning =
7081
new GUIContent(
@@ -74,6 +85,7 @@ private static class Styles
7485
public static readonly string[] blendNames = Enum.GetNames(typeof(BlendMode));
7586
public static readonly string[] specSourceNames = Enum.GetNames(typeof(SpecularSource));
7687
public static readonly string[] glossinessSourceNames = Enum.GetNames(typeof(GlossinessSource));
88+
public static readonly string[] speculaSourceNames = Enum.GetNames(typeof(ReflectionSource));
7789

7890
public static string renderingModeLabel = "Rendering Mode";
7991
public static string specularSourceLabel = "Specular Color Source";
@@ -86,6 +98,7 @@ private static class Styles
8698
public static string shininessLabel = "Shininess";
8799
public static string normalMapLabel = "Normal map";
88100
public static string emissionColorLabel = "Emission Color";
101+
public static string reflectionSourceLabel = "Reflection Source";
89102
}
90103

91104
private void FindMaterialProperties(Material material)
@@ -104,6 +117,9 @@ private void FindMaterialProperties(Material material)
104117
bumpMapProp = GetMaterialProperty(mats, "_BumpMap");
105118
emissionMapProp = GetMaterialProperty(mats, "_EmissionMap");
106119
emissionColorProp = GetMaterialProperty(mats, "_EmissionColor");
120+
reflectionMapProp = GetMaterialProperty(mats, "_Cube");
121+
reflectionColorProp = GetMaterialProperty(mats, "_ReflectColor");
122+
reflectionSourceProp = GetMaterialProperty(mats, "_ReflectionSource");
107123
}
108124

109125
public override void OnInspectorGUI()
@@ -127,6 +143,9 @@ public override void OnInspectorGUI()
127143
EditorGUILayout.Space();
128144
TexturePropertySingleLine(Styles.emissionMapLabel, emissionMapProp, emissionColorProp);
129145

146+
EditorGUILayout.Space();
147+
DoReflection();
148+
130149
if (EditorGUI.EndChangeCheck())
131150
UpdateMaterialKeywords(material);
132151

@@ -205,12 +224,30 @@ private void DoSpecular()
205224
}
206225
}
207226

227+
private void DoReflection()
228+
{
229+
EditorGUILayout.Space();
230+
231+
int source = (int) reflectionSourceProp.floatValue;
232+
EditorGUI.BeginChangeCheck();
233+
source = EditorGUILayout.Popup(Styles.reflectionSourceLabel, source, Styles.speculaSourceNames);
234+
if (EditorGUI.EndChangeCheck())
235+
reflectionSourceProp.floatValue = (float) source;
236+
237+
EditorGUILayout.Space();
238+
ReflectionSource reflectionSource = (ReflectionSource) reflectionSourceProp.floatValue;
239+
if (reflectionSource == ReflectionSource.Cubemap)
240+
TexturePropertySingleLine(Styles.reflectionMapLabel, reflectionMapProp, reflectionColorProp);
241+
}
242+
208243
private void UpdateMaterialKeywords(Material material)
209244
{
210245
UpdateMaterialBlendMode(material);
211246
UpdateMaterialSpecularSource(material);
247+
UpdateMaterialReflectionSource(material);
212248
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
213249
SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
250+
SetKeyword(material, "_CUBEMAP_REFLECTION", material.GetTexture("_Cube"));
214251
}
215252

216253
private void UpdateMaterialBlendMode(Material material)
@@ -282,6 +319,28 @@ private void UpdateMaterialSpecularSource(Material material)
282319
SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
283320
}
284321

322+
private void UpdateMaterialReflectionSource(Material material)
323+
{
324+
ReflectionSource reflectionSource = (ReflectionSource) reflectionSourceProp.floatValue;
325+
if (reflectionSource == ReflectionSource.NoReflection)
326+
{
327+
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
328+
}
329+
else if (reflectionSource == ReflectionSource.Cubemap && material.GetTexture("_Cube"))
330+
{
331+
SetKeyword(material, "_CUBEMAP_REFLECTION", true);
332+
}
333+
else if (reflectionSource == ReflectionSource.ReflectionProbe)
334+
{
335+
Debug.LogWarning("Reflection probe not implemented yet");
336+
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
337+
}
338+
else
339+
{
340+
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
341+
}
342+
}
343+
285344
private void SetKeyword(Material material, string keyword, bool enable)
286345
{
287346
if (enable)

Assets/LowEndMobilePipeline/Editor/StandardToLowEndMaterialUpgrader.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@
44

55
public class StandardToLowEndMaterialUpgrader : MaterialUpgrader
66
{
7-
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Selection")]
7+
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Selection", false, 1)]
88
private static void UpgradeMaterialsToLDProject()
99
{
1010
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
11-
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard (Specular setup)"));
12-
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard"));
13-
upgraders.Add(new StandardToLowEndMaterialUpgrader("TerrainSurface"));
11+
GetUpgraders(ref upgraders);
1412

1513
MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to LD Materials");
1614
}
1715

18-
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Project Folder")]
16+
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Project Folder", false, 2)]
1917
private static void UpgradeMaterialsToLDSelection()
2018
{
2119
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
20+
GetUpgraders(ref upgraders);
21+
22+
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to LD Materials");
23+
}
24+
25+
private static void GetUpgraders(ref List<MaterialUpgrader> upgraders)
26+
{
2227
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard (Specular setup)"));
2328
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard"));
2429
upgraders.Add(new StandardToLowEndMaterialUpgrader("TerrainSurface"));
25-
26-
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to LD Materials");
2730
}
2831

2932
StandardToLowEndMaterialUpgrader(string oldShaderName)
3033
{
3134
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile");
35+
RenameFloat("_Glossiness", "_Shininess");
3236
}
3337
}

0 commit comments

Comments
 (0)