浏览代码

Changes to lowend upgraders after material upgrader callback.

/vr_sandbox
Felipe Lira 8 年前
当前提交
6c22422b
共有 8 个文件被更改,包括 594 次插入478 次删除
  1. 136
      Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs
  2. 576
      Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs
  3. 264
      Assets/LowEndMobilePipeline/Editor/LowendUpgraders.cs
  4. 43
      Assets/LowEndMobilePipeline/Editor/StandardToLowEndMaterialUpgrader.cs
  5. 2
      Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs
  6. 2
      Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs
  7. 37
      Assets/LowEndMobilePipeline/Editor/UpgradeCommon.cs
  8. 12
      Assets/LowEndMobilePipeline/Editor/UpgradeCommon.cs.meta

136
Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs


using System.Collections.Generic;
using UnityEditor.Experimental.Rendering;
using UnityEditor;
public class LegacyShadersToLowEndUpgrader
namespace UnityEditor.Experimental.Rendering.LowendMobile
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Project", false, 3)]
public static void UpgradeMaterialsToLDProject()
public class LegacyShadersToLowEndUpgrader
List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
GetUpgraders(ref materialUpgraders);
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Project", false, 3)]
public static void UpgradeMaterialsToLDProject()
{
List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
GetUpgraders(ref materialUpgraders);
MaterialUpgrader.UpgradeProjectFolder(materialUpgraders, "Upgrade to LD Materials");
}
MaterialUpgrader.UpgradeProjectFolder(materialUpgraders, "Upgrade to LD Materials");
}
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Selection", false, 4)]
public static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
GetUpgraders(ref materialUpgraders);
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Selection", false, 4)]
public static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
GetUpgraders(ref materialUpgraders);
MaterialUpgrader.UpgradeSelection(materialUpgraders, "Upgrade to LD Materials");
}
MaterialUpgrader.UpgradeSelection(materialUpgraders, "Upgrade to LD Materials");
}
// TODO: Replace this logic with AssignNewShaderToMaterial
private static void GetUpgraders(ref List<MaterialUpgrader> materialUpgraders)
{
/////////////////////////////////////
// Legacy Shaders upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Lmegacy Shaders/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Specular"));
private static void GetUpgraders(ref List<MaterialUpgrader> materialUpgraders)
{
/////////////////////////////////////
// Legacy Shaders upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Specular", SupportedUpgradeParams.specularOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Bumped Specular", SupportedUpgradeParams.specularOpaque));
// TODO: option to use environment map as texture or use reflection probe
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Specular"));
// TODO: option to use environment map as texture or use reflection probe
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Diffuse", SupportedUpgradeParams.diffuseCubemap));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Bumped Specular", SupportedUpgradeParams.specularOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Diffuse", SupportedUpgradeParams.diffuseCubemap));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Reflective/Specular", SupportedUpgradeParams.specularOpaque));
// Self-Illum upgrader
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Specular"));
// Self-Illum upgrader
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Specular", SupportedUpgradeParams.specularOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Self-Illumin/Bumped Specular", SupportedUpgradeParams.specularOpaque));
// Alpha Blended
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Specular"));
// Alpha Blended
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Diffuse", SupportedUpgradeParams.diffuseAlpha));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Specular", SupportedUpgradeParams.specularAlpha));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Diffuse", SupportedUpgradeParams.diffuseAlpha));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Bumped Specular", SupportedUpgradeParams.specularAlpha));
// Cutout
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular"));
// Cutout
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Specular", SupportedUpgradeParams.specularAlphaCutout));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular", SupportedUpgradeParams.specularAlphaCutout));
/////////////////////////////////////
// Reflective Shader Upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Transperant"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec Transp"));
/////////////////////////////////////
// Reflective Shader Upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Transperant", SupportedUpgradeParams.diffuseCubemapAlpha));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec", SupportedUpgradeParams.specularCubemap));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec Transp", SupportedUpgradeParams.specularCubemapAlpha));
/////////////////////////////////////
// Mobile Upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular(1 Directional Light)"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Diffuse"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Unlit (Supports Lightmap)"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/VertexLit"));
/////////////////////////////////////
// Mobile Upgraders /
/////////////////////////////////////
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular", SupportedUpgradeParams.specularOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Specular(1 Directional Light)", SupportedUpgradeParams.specularOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/Unlit (Supports Lightmap)", SupportedUpgradeParams.diffuseOpaque));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Mobile/VertexLit", SupportedUpgradeParams.specularOpaque));
/////////////////////////////////////
// Particles /
/////////////////////////////////////
materialUpgraders.Add(new ParticlesAdditiveUpgrader("Particles/Additive"));
materialUpgraders.Add(new ParticlesAdditiveUpgrader("Mobile/Particles/Additive"));
materialUpgraders.Add(new ParticlesMultiplyUpgrader("Particles/Multiply"));
materialUpgraders.Add(new ParticlesMultiplyUpgrader("Mobile/Particles/Multiply"));
/////////////////////////////////////
// Particles /
/////////////////////////////////////
materialUpgraders.Add(new ParticlesAdditiveUpgrader("Particles/Additive"));
materialUpgraders.Add(new ParticlesAdditiveUpgrader("Mobile/Particles/Additive"));
materialUpgraders.Add(new ParticlesMultiplyUpgrader("Particles/Multiply"));
materialUpgraders.Add(new ParticlesMultiplyUpgrader("Mobile/Particles/Multiply"));
}
}
}

576
Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs


using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor.Experimental.Rendering.LowendMobile;
{
private const float kMinShininessValue = 0.01f;
private MaterialProperty blendModeProp = null;
private MaterialProperty albedoMapProp = null;
private MaterialProperty albedoColorProp = null;
private MaterialProperty alphaCutoffProp = null;
private MaterialProperty specularSourceProp = null;
private MaterialProperty glossinessSourceProp = null;
private MaterialProperty reflectionSourceProp = null;
private MaterialProperty specularGlossMapProp = null;
private MaterialProperty specularColorProp = null;
private MaterialProperty shininessProp = null;
private MaterialProperty bumpMapProp = null;
private MaterialProperty emissionMapProp = null;
private MaterialProperty emissionColorProp = null;
private MaterialProperty reflectionMapProp = null;
private MaterialProperty reflectionColorProp = null;
private MaterialEditor m_MaterialEditor = null;
public enum BlendMode
{
Opaque,
Cutout,
Alpha
}
public enum SpecularSource
{
SpecularTextureAndColor,
BaseTexture,
NoSpecular
}
public enum GlossinessSource
BaseAlpha,
SpecularAlpha
}
public enum ReflectionSource
{
NoReflection,
Cubemap,
ReflectionProbe
}
private const float kMinShininessValue = 0.01f;
private MaterialProperty blendModeProp = null;
private MaterialProperty albedoMapProp = null;
private MaterialProperty albedoColorProp = null;
private MaterialProperty alphaCutoffProp = null;
private MaterialProperty specularSourceProp = null;
private MaterialProperty glossinessSourceProp = null;
private MaterialProperty reflectionSourceProp = null;
private MaterialProperty specularGlossMapProp = null;
private MaterialProperty specularColorProp = null;
private MaterialProperty shininessProp = null;
private MaterialProperty bumpMapProp = null;
private MaterialProperty emissionMapProp = null;
private MaterialProperty emissionColorProp = null;
private MaterialProperty reflectionMapProp = null;
private MaterialProperty reflectionColorProp = null;
public struct UpgradeParams
{
public BlendMode blendMode;
public SpecularSource specularSource;
public GlossinessSource glosinessSource;
public ReflectionSource reflectionSource;
}
private MaterialEditor m_MaterialEditor = null;
private static class Styles
{
public static GUIContent[] albedoGlosinessLabels =
private static class Styles
new GUIContent("Base (RGB) Glossiness (A)", "Base Color (RGB) and Glossiness (A)"),
new GUIContent("Base (RGB)", "Base Color (RGB)")
};
public static GUIContent[] albedoGlosinessLabels =
{
new GUIContent("Base (RGB) Glossiness (A)", "Base Color (RGB) and Glossiness (A)"),
new GUIContent("Base (RGB)", "Base Color (RGB)")
};
public static GUIContent albedoAlphaLabel = new GUIContent("Base (RGB) Alpha (A)",
"Base Color (RGB) and Transparency (A)");
public static GUIContent albedoAlphaLabel = new GUIContent("Base (RGB) Alpha (A)",
"Base Color (RGB) and Transparency (A)");
public static GUIContent[] specularGlossMapLabels =
{
new GUIContent("Specular Color (RGB)", "Specular Color (RGB)"),
new GUIContent("Specular Color (RGB) Glossiness (A)", "Specular Color (RGB) Glossiness (A)")
};
public static GUIContent[] specularGlossMapLabels =
{
new GUIContent("Specular Color (RGB)", "Specular Color (RGB)"),
new GUIContent("Specular Color (RGB) Glossiness (A)", "Specular Color (RGB) Glossiness (A)")
};
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent emissionMapLabel = new GUIContent("Emission Map", "Emission Map");
public static GUIContent reflectionMapLabel = new GUIContent("Reflection Source", "Reflection Source Map");
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent emissionMapLabel = new GUIContent("Emission Map", "Emission Map");
public static GUIContent reflectionMapLabel = new GUIContent("Reflection Source", "Reflection Source Map");
public static GUIContent alphaCutoutWarning =
new GUIContent(
"This material has alpha cutout enabled. Alpha cutout has severe performance impact on mobile!");
public static GUIContent alphaCutoutWarning =
new GUIContent(
"This material has alpha cutout enabled. Alpha cutout has severe performance impact on mobile!");
public static GUIStyle warningStyle = new GUIStyle();
public static readonly string[] blendNames = Enum.GetNames(typeof(BlendMode));
public static readonly string[] specSourceNames = Enum.GetNames(typeof(SpecularSource));
public static readonly string[] glossinessSourceNames = Enum.GetNames(typeof(GlossinessSource));
public static readonly string[] speculaSourceNames = Enum.GetNames(typeof(ReflectionSource));
public static GUIStyle warningStyle = new GUIStyle();
public static readonly string[] blendNames = Enum.GetNames(typeof(UpgradeBlendMode));
public static readonly string[] specSourceNames = Enum.GetNames(typeof(SpecularSource));
public static readonly string[] glossinessSourceNames = Enum.GetNames(typeof(GlossinessSource));
public static readonly string[] speculaSourceNames = Enum.GetNames(typeof(ReflectionSource));
public static string renderingModeLabel = "Rendering Mode";
public static string specularSourceLabel = "Specular Color Source";
public static string glossinessSourceLable = "Glossiness Source";
public static string glossinessSource = "Glossiness Source";
public static string albedoColorLabel = "Base Color";
public static string albedoMapAlphaLabel = "Base(RGB) Alpha(A)";
public static string albedoMapGlossinessLabel = "Base(RGB) Glossiness (A)";
public static string alphaCutoffLabel = "Alpha Cutoff";
public static string shininessLabel = "Shininess";
public static string normalMapLabel = "Normal map";
public static string emissionColorLabel = "Emission Color";
public static string reflectionSourceLabel = "Reflection Source";
}
public static string renderingModeLabel = "Rendering Mode";
public static string specularSourceLabel = "Specular Color Source";
public static string glossinessSourceLable = "Glossiness Source";
public static string glossinessSource = "Glossiness Source";
public static string albedoColorLabel = "Base Color";
public static string albedoMapAlphaLabel = "Base(RGB) Alpha(A)";
public static string albedoMapGlossinessLabel = "Base(RGB) Glossiness (A)";
public static string alphaCutoffLabel = "Alpha Cutoff";
public static string shininessLabel = "Shininess";
public static string normalMapLabel = "Normal map";
public static string emissionColorLabel = "Emission Color";
public static string reflectionSourceLabel = "Reflection Source";
}
private void FindMaterialProperties(MaterialProperty[] properties)
{
blendModeProp = FindProperty("_Mode", properties);
albedoMapProp = FindProperty("_MainTex", properties);
albedoColorProp = FindProperty("_Color", properties);
private void FindMaterialProperties(MaterialProperty[] properties)
{
blendModeProp = FindProperty("_Mode", properties);
albedoMapProp = FindProperty("_MainTex", properties);
albedoColorProp = FindProperty("_Color", properties);
alphaCutoffProp = FindProperty("_Cutoff", properties);
specularSourceProp = FindProperty("_SpecSource", properties);
glossinessSourceProp = FindProperty("_GlossinessSource", properties);
specularGlossMapProp = FindProperty("_SpecGlossMap", properties);
specularColorProp = FindProperty("_SpecColor", properties);
shininessProp = FindProperty("_Shininess", properties);
bumpMapProp = FindProperty("_BumpMap", properties);
emissionMapProp = FindProperty("_EmissionMap", properties);
emissionColorProp = FindProperty("_EmissionColor", properties);
reflectionMapProp = FindProperty("_Cube", properties);
reflectionColorProp = FindProperty("_ReflectColor", properties);
reflectionSourceProp = FindProperty("_ReflectionSource", properties);
}
alphaCutoffProp = FindProperty("_Cutoff", properties);
specularSourceProp = FindProperty("_SpecSource", properties);
glossinessSourceProp = FindProperty("_GlossinessSource", properties);
specularGlossMapProp = FindProperty("_SpecGlossMap", properties);
specularColorProp = FindProperty("_SpecColor", properties);
shininessProp = FindProperty("_Shininess", properties);
bumpMapProp = FindProperty("_BumpMap", properties);
emissionMapProp = FindProperty("_EmissionMap", properties);
emissionColorProp = FindProperty("_EmissionColor", properties);
reflectionMapProp = FindProperty("_Cube", properties);
reflectionColorProp = FindProperty("_ReflectColor", properties);
reflectionSourceProp = FindProperty("_ReflectionSource", properties);
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
Material material = materialEditor.target as Material;
m_MaterialEditor = materialEditor;
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
Material material = materialEditor.target as Material;
m_MaterialEditor = materialEditor;
FindMaterialProperties(properties);
FindMaterialProperties(properties);
EditorGUI.BeginChangeCheck();
DoBlendMode();
EditorGUI.BeginChangeCheck();
DoBlendMode();
EditorGUILayout.Space();
DoSpecular();
EditorGUILayout.Space();
DoSpecular();
EditorGUILayout.Space();
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMapProp);
EditorGUILayout.Space();
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMapProp);
EditorGUILayout.Space();
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionMapLabel, emissionMapProp, emissionColorProp);
EditorGUILayout.Space();
m_MaterialEditor.TexturePropertySingleLine(Styles.emissionMapLabel, emissionMapProp, emissionColorProp);
EditorGUILayout.Space();
DoReflection();
EditorGUILayout.Space();
DoReflection();
if (EditorGUI.EndChangeCheck())
UpdateMaterialKeywords(material);
if (EditorGUI.EndChangeCheck())
LegacyBlinnPhongUpgrader.UpdateMaterialKeywords(material);
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
materialEditor.RenderQueueField();
materialEditor.RenderQueueField();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
if ((BlendMode)blendModeProp.floatValue == BlendMode.Cutout)
{
Styles.warningStyle.normal.textColor = Color.yellow;
EditorGUILayout.LabelField(Styles.alphaCutoutWarning, Styles.warningStyle);
if ((UpgradeBlendMode) blendModeProp.floatValue == UpgradeBlendMode.Cutout)
{
Styles.warningStyle.normal.textColor = Color.yellow;
EditorGUILayout.LabelField(Styles.alphaCutoutWarning, Styles.warningStyle);
}
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
{
base.AssignNewShaderToMaterial(material, oldShader, newShader);
// Shininess value cannot be zero since it will produce undefined values for cases where pow(0, 0).
float shininess = material.GetFloat("_Shininess");
material.SetFloat("_Shininess", Mathf.Clamp(shininess, kMinShininessValue, 1.0f));
string oldShaderName = oldShader.name;
string[] shaderStrings = oldShaderName.Split('/');
if (shaderStrings[0].Equals("Legacy Shaders") || shaderStrings[0].Equals("Mobile") || shaderStrings[0].Equals("Reflective"))
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
ConvertFromLegacy(material, oldShaderName);
}
UpdateMaterialKeywords(material);
}
private void DoBlendMode()
{
int modeValue = (int)blendModeProp.floatValue;
EditorGUI.BeginChangeCheck();
modeValue = EditorGUILayout.Popup(Styles.renderingModeLabel, modeValue, Styles.blendNames);
if (EditorGUI.EndChangeCheck())
blendModeProp.floatValue = modeValue;
BlendMode mode = (BlendMode)blendModeProp.floatValue;
base.AssignNewShaderToMaterial(material, oldShader, newShader);
EditorGUILayout.Space();
// Shininess value cannot be zero since it will produce undefined values for cases where pow(0, 0).
float shininess = material.GetFloat("_Shininess");
material.SetFloat("_Shininess", Mathf.Clamp(shininess, kMinShininessValue, 1.0f));
if (mode == BlendMode.Opaque)
{
int glossSource = (int)glossinessSourceProp.floatValue;
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMapProp, albedoColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMapProp, albedoColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);
if (mode == BlendMode.Cutout)
m_MaterialEditor.RangeProperty(alphaCutoffProp, "Cutoff");
}
}
string oldShaderName = oldShader.name;
string[] shaderStrings = oldShaderName.Split('/');
private void DoSpecular()
{
EditorGUILayout.Space();
if (shaderStrings[0].Equals("Legacy Shaders") || shaderStrings[0].Equals("Mobile") ||
shaderStrings[0].Equals("Reflective"))
{
ConvertFromLegacy(material, oldShaderName);
}
int source = (int)specularSourceProp.floatValue;
EditorGUI.BeginChangeCheck();
source = EditorGUILayout.Popup(Styles.specularSourceLabel, source, Styles.specSourceNames);
if (EditorGUI.EndChangeCheck())
{
specularSourceProp.floatValue = source;
if (source == (int)SpecularSource.BaseTexture)
glossinessSourceProp.floatValue = (float)GlossinessSource.BaseAlpha;
LegacyBlinnPhongUpgrader.UpdateMaterialKeywords(material);
SpecularSource specSource = (SpecularSource)specularSourceProp.floatValue;
if (specSource != SpecularSource.NoSpecular)
private void DoBlendMode()
int glossinessSource = (int)glossinessSourceProp.floatValue;
int modeValue = (int) blendModeProp.floatValue;
glossinessSource = EditorGUILayout.Popup(Styles.glossinessSourceLable, glossinessSource,
Styles.glossinessSourceNames);
modeValue = EditorGUILayout.Popup(Styles.renderingModeLabel, modeValue, Styles.blendNames);
glossinessSourceProp.floatValue = (float)glossinessSource;
}
blendModeProp.floatValue = modeValue;
int glossSource = (int)glossinessSourceProp.floatValue;
if (specSource == SpecularSource.SpecularTextureAndColor)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.specularGlossMapLabels[glossSource], specularGlossMapProp, specularColorProp);
UpgradeBlendMode mode = (UpgradeBlendMode) blendModeProp.floatValue;
EditorGUILayout.Space();
if (mode == UpgradeBlendMode.Opaque)
{
int glossSource = (int) glossinessSourceProp.floatValue;
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMapProp,
albedoColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMapProp, albedoColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);
if (mode == UpgradeBlendMode.Cutout)
m_MaterialEditor.RangeProperty(alphaCutoffProp, "Cutoff");
}
if (specSource != SpecularSource.NoSpecular)
private void DoSpecular()
EditorGUILayout.Space();
int source = (int) specularSourceProp.floatValue;
float shininess = EditorGUILayout.Slider(Styles.shininessLabel, shininessProp.floatValue, kMinShininessValue, 1.0f);
source = EditorGUILayout.Popup(Styles.specularSourceLabel, source, Styles.specSourceNames);
shininessProp.floatValue = shininess;
}
}
private void DoReflection()
{
EditorGUILayout.Space();
int source = (int) reflectionSourceProp.floatValue;
EditorGUI.BeginChangeCheck();
source = EditorGUILayout.Popup(Styles.reflectionSourceLabel, source, Styles.speculaSourceNames);
if (EditorGUI.EndChangeCheck())
reflectionSourceProp.floatValue = (float) source;
EditorGUILayout.Space();
ReflectionSource reflectionSource = (ReflectionSource) reflectionSourceProp.floatValue;
if (reflectionSource == ReflectionSource.Cubemap)
m_MaterialEditor.TexturePropertySingleLine(Styles.reflectionMapLabel, reflectionMapProp, reflectionColorProp);
}
private void UpdateMaterialKeywords(Material material)
{
UpdateMaterialBlendMode(material);
UpdateMaterialSpecularSource(material);
UpdateMaterialReflectionSource(material);
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
SetKeyword(material, "_CUBEMAP_REFLECTION", material.GetTexture("_Cube"));
SetKeyword(material, "_EMISSION_MAP", material.GetTexture("_EmissionMap"));
}
{
specularSourceProp.floatValue = source;
if (source == (int) SpecularSource.BaseTexture)
glossinessSourceProp.floatValue = (float) GlossinessSource.BaseAlpha;
}
private void UpdateMaterialBlendMode(Material material)
{
BlendMode mode = (BlendMode) material.GetFloat("_Mode");
switch (mode)
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = -1;
break;
SpecularSource specSource = (SpecularSource) specularSourceProp.floatValue;
if (specSource != SpecularSource.NoSpecular)
{
int glossinessSource = (int) glossinessSourceProp.floatValue;
EditorGUI.BeginChangeCheck();
glossinessSource = EditorGUILayout.Popup(Styles.glossinessSourceLable, glossinessSource,
Styles.glossinessSourceNames);
if (EditorGUI.EndChangeCheck())
glossinessSourceProp.floatValue = (float) glossinessSource;
}
case BlendMode.Cutout:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", true);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = (int)RenderQueue.AlphaTest;
break;
int glossSource = (int) glossinessSourceProp.floatValue;
if (specSource == SpecularSource.SpecularTextureAndColor)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.specularGlossMapLabels[glossSource],
specularGlossMapProp, specularColorProp);
}
case BlendMode.Alpha:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", true);
material.renderQueue = (int) RenderQueue.Transparent;
break;
if (specSource != SpecularSource.NoSpecular)
{
EditorGUI.BeginChangeCheck();
float shininess = EditorGUILayout.Slider(Styles.shininessLabel, shininessProp.floatValue,
kMinShininessValue, 1.0f);
if (EditorGUI.EndChangeCheck())
shininessProp.floatValue = shininess;
}
}
private void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource) material.GetFloat("_SpecSource");
if (specSource == SpecularSource.NoSpecular)
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else if (specSource == SpecularSource.BaseTexture)
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", true);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else if (specSource == SpecularSource.SpecularTextureAndColor && material.GetTexture("_SpecGlossMap"))
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", true);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else
private void DoReflection()
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", true);
}
EditorGUILayout.Space();
GlossinessSource glossSource = (GlossinessSource) material.GetFloat("_GlossinessSource");
if (glossSource == GlossinessSource.BaseAlpha)
SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", true);
else
SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
}
int source = (int) reflectionSourceProp.floatValue;
EditorGUI.BeginChangeCheck();
source = EditorGUILayout.Popup(Styles.reflectionSourceLabel, source, Styles.speculaSourceNames);
if (EditorGUI.EndChangeCheck())
reflectionSourceProp.floatValue = (float) source;
private void UpdateMaterialReflectionSource(Material material)
{
ReflectionSource reflectionSource = (ReflectionSource) material.GetFloat("_ReflectionSource");
if (reflectionSource == ReflectionSource.NoReflection)
{
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
}
else if (reflectionSource == ReflectionSource.Cubemap && material.GetTexture("_Cube"))
{
SetKeyword(material, "_CUBEMAP_REFLECTION", true);
}
else if (reflectionSource == ReflectionSource.ReflectionProbe)
{
Debug.LogWarning("Reflection probe not implemented yet");
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
}
else
{
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
EditorGUILayout.Space();
ReflectionSource reflectionSource = (ReflectionSource) reflectionSourceProp.floatValue;
if (reflectionSource == ReflectionSource.Cubemap)
m_MaterialEditor.TexturePropertySingleLine(Styles.reflectionMapLabel, reflectionMapProp,
reflectionColorProp);
}
private void SetKeyword(Material material, string keyword, bool enable)
{
if (enable)
material.EnableKeyword(keyword);
else
material.DisableKeyword(keyword);
}
private void ConvertFromLegacy(Material material, string oldShaderName)
{
UpgradeParams shaderUpgradeParams;
if (oldShaderName.Contains("Transp"))
{
shaderUpgradeParams.blendMode = BlendMode.Alpha;
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
}
else if (oldShaderName.Contains("Cutout"))
private void ConvertFromLegacy(Material material, string oldShaderName)
shaderUpgradeParams.blendMode = BlendMode.Cutout;
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
}
else
{
shaderUpgradeParams.blendMode = BlendMode.Opaque;
shaderUpgradeParams.glosinessSource = GlossinessSource.BaseAlpha;
}
UpgradeParams shaderUpgradeParams;
if (oldShaderName.Contains("Spec"))
shaderUpgradeParams.specularSource = SpecularSource.SpecularTextureAndColor;
else
shaderUpgradeParams.specularSource = SpecularSource.NoSpecular;
if (oldShaderName.Contains("Transp"))
{
shaderUpgradeParams.blendMode = UpgradeBlendMode.Alpha;
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
}
else if (oldShaderName.Contains("Cutout"))
{
shaderUpgradeParams.blendMode = UpgradeBlendMode.Cutout;
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
}
else
{
shaderUpgradeParams.blendMode = UpgradeBlendMode.Opaque;
shaderUpgradeParams.glosinessSource = GlossinessSource.BaseAlpha;
}
if (oldShaderName.Contains("Reflective"))
shaderUpgradeParams.reflectionSource = ReflectionSource.Cubemap;
else
shaderUpgradeParams.reflectionSource = ReflectionSource.NoReflection;
if (oldShaderName.Contains("Spec"))
shaderUpgradeParams.specularSource = SpecularSource.SpecularTextureAndColor;
else
shaderUpgradeParams.specularSource = SpecularSource.NoSpecular;
material.SetFloat("_Mode", (float)shaderUpgradeParams.blendMode);
material.SetFloat("_SpecSource", (float)shaderUpgradeParams.specularSource);
material.SetFloat("_GlossinessSource", (float)shaderUpgradeParams.glosinessSource);
material.SetFloat("_ReflectionSource", (float)shaderUpgradeParams.reflectionSource);
if (oldShaderName.Contains("Reflective"))
shaderUpgradeParams.reflectionSource = ReflectionSource.Cubemap;
else
shaderUpgradeParams.reflectionSource = ReflectionSource.NoReflection;
if (oldShaderName.Contains("Self-Illumin"))
{
material.SetTexture("_EmissionMap", material.GetTexture("_MainTex"));
material.SetTexture("_MainTex", null);
material.SetColor("_EmissionColor", Color.white);
material.SetFloat("_Mode", (float) shaderUpgradeParams.blendMode);
material.SetFloat("_SpecSource", (float) shaderUpgradeParams.specularSource);
material.SetFloat("_GlossinessSource", (float) shaderUpgradeParams.glosinessSource);
material.SetFloat("_ReflectionSource", (float) shaderUpgradeParams.reflectionSource);
if (oldShaderName.Contains("Self-Illumin"))
{
material.SetTexture("_EmissionMap", material.GetTexture("_MainTex"));
material.SetTexture("_MainTex", null);
material.SetColor("_EmissionColor", Color.white);
}
}

264
Assets/LowEndMobilePipeline/Editor/LowendUpgraders.cs


using UnityEditor.Experimental.Rendering;
using UnityEngine;
using UnityEngine;
using UnityEngine.Rendering;
public class LegacyBlinnPhongUpgrader : MaterialUpgrader
namespace UnityEditor.Experimental.Rendering.LowendMobile
public LegacyBlinnPhongUpgrader(string oldShaderName)
public static class SupportedUpgradeParams
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
static public UpgradeParams diffuseOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams specularOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams diffuseAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams specularAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams diffuseAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams specularAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
reflectionSource = ReflectionSource.NoReflection
};
static public UpgradeParams diffuseCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.Cubemap
};
static public UpgradeParams specularCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.Cubemap
};
static public UpgradeParams diffuseCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.Cubemap
};
static public UpgradeParams specularCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
reflectionSource = ReflectionSource.Cubemap
};
}
public class ParticlesMultiplyUpgrader : MaterialUpgrader
{
public ParticlesMultiplyUpgrader(string oldShaderName)
public class LegacyBlinnPhongUpgrader : MaterialUpgrader
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/Particles/Multiply");
public LegacyBlinnPhongUpgrader(string oldShaderName, UpgradeParams upgradeParams)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR", UpdateMaterialKeywords);
SetFloat("_Mode", (float)upgradeParams.blendMode);
SetFloat("_SpecSource", (float)upgradeParams.specularSource);
SetFloat("_GlossinessSource", (float)upgradeParams.glosinessSource);
SetFloat("_ReflectionSource", (float)upgradeParams.reflectionSource);
if (oldShaderName.Contains("Legacy Shaders/Self-Illumin"))
{
RenameTexture("_MainTex", "_EmissionMap");
RemoveTexture("_MainTex");
SetColor("_EmissionColor", Color.white);
}
}
public static void UpdateMaterialKeywords(Material material)
{
UpdateMaterialBlendMode(material);
UpdateMaterialSpecularSource(material);
UpdateMaterialReflectionSource(material);
SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
SetKeyword(material, "_SPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
SetKeyword(material, "_CUBEMAP_REFLECTION", material.GetTexture("_Cube"));
SetKeyword(material, "_EMISSION_MAP", material.GetTexture("_EmissionMap"));
}
private static void UpdateMaterialBlendMode(Material material)
{
UpgradeBlendMode mode = (UpgradeBlendMode)material.GetFloat("_Mode");
switch (mode)
{
case UpgradeBlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = -1;
break;
case UpgradeBlendMode.Cutout:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", true);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = (int)RenderQueue.AlphaTest;
break;
case UpgradeBlendMode.Alpha:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", true);
material.renderQueue = (int)RenderQueue.Transparent;
break;
}
}
private static void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource");
if (specSource == SpecularSource.NoSpecular)
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else if (specSource == SpecularSource.BaseTexture)
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", true);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else if (specSource == SpecularSource.SpecularTextureAndColor && material.GetTexture("_SpecGlossMap"))
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", true);
SetKeyword(material, "_SPECULAR_COLOR", false);
}
else
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);
SetKeyword(material, "_SPECULAR_MAP", false);
SetKeyword(material, "_SPECULAR_COLOR", true);
}
GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource");
if (glossSource == GlossinessSource.BaseAlpha)
SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", true);
else
SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
}
private static void UpdateMaterialReflectionSource(Material material)
{
ReflectionSource reflectionSource = (ReflectionSource)material.GetFloat("_ReflectionSource");
if (reflectionSource == ReflectionSource.NoReflection)
{
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
}
else if (reflectionSource == ReflectionSource.Cubemap && material.GetTexture("_Cube"))
{
SetKeyword(material, "_CUBEMAP_REFLECTION", true);
}
else if (reflectionSource == ReflectionSource.ReflectionProbe)
{
Debug.LogWarning("Reflection probe not implemented yet");
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
}
else
{
SetKeyword(material, "_CUBEMAP_REFLECTION", false);
}
}
private static void SetKeyword(Material material, string keyword, bool enable)
{
if (enable)
material.EnableKeyword(keyword);
else
material.DisableKeyword(keyword);
}
}
public class ParticlesAdditiveUpgrader : MaterialUpgrader
{
public ParticlesAdditiveUpgrader(string oldShaderName)
public class ParticlesMultiplyUpgrader : MaterialUpgrader
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/Particles/Additive");
public ParticlesMultiplyUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/Particles/Multiply");
}
}
public class ParticlesAdditiveUpgrader : MaterialUpgrader
{
public ParticlesAdditiveUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/Particles/Additive");
}
}
public class StandardUpgrader : MaterialUpgrader
{
public StandardUpgrader(string oldShaderName)
public class StandardUpgrader : MaterialUpgrader
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
RenameFloat("_Glossiness", "_Shininess");
public StandardUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
RenameFloat("_Glossiness", "_Shininess");
}
}
public class TerrainUpgrader : MaterialUpgrader
{
public TerrainUpgrader(string oldShaderName)
public class TerrainUpgrader : MaterialUpgrader
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
SetFloat("_Shininess", 1.0f);
public TerrainUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
SetFloat("_Shininess", 1.0f);
}
}
}

43
Assets/LowEndMobilePipeline/Editor/StandardToLowEndMaterialUpgrader.cs


using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
public class StandardToLowEndMaterialUpgrader
namespace UnityEditor.Experimental.Rendering.LowendMobile
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Project Folder", false, 1)]
private static void UpgradeMaterialsToLDProject()
public class StandardToLowEndMaterialUpgrader
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Project Folder", false, 1)]
private static void UpgradeMaterialsToLDProject()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to LD Materials");
}
MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to LD Materials");
}
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Selection", false, 2)]
private static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Selection", false, 2)]
private static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to LD Materials");
}
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to LD Materials");
}
private static void GetUpgraders(ref List<MaterialUpgrader> upgraders)
{
upgraders.Add(new StandardUpgrader("Standard (Specular setup)"));
upgraders.Add(new StandardUpgrader("Standard"));
upgraders.Add(new TerrainUpgrader("TerrainSurface"));
private static void GetUpgraders(ref List<MaterialUpgrader> upgraders)
{
upgraders.Add(new StandardUpgrader("Standard (Specular setup)"));
upgraders.Add(new StandardUpgrader("Standard"));
upgraders.Add(new TerrainUpgrader("TerrainSurface"));
}
}
}

2
Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs


using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.LowendMobile

2
Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs


dstMaterial.SetFloat(t.property, srcMaterial.IsKeywordEnabled(t.keyword) ? t.setVal : t.unsetVal);
}
public void RenameShader(string oldName, string newName, MaterialFinalizer finalizer)
public void RenameShader(string oldName, string newName, MaterialFinalizer finalizer = null)
{
m_OldShader = oldName;
m_NewShader = newName;

37
Assets/LowEndMobilePipeline/Editor/UpgradeCommon.cs


namespace UnityEditor.Experimental.Rendering.LowendMobile
{
public enum UpgradeBlendMode
{
Opaque,
Cutout,
Alpha
}
public enum SpecularSource
{
SpecularTextureAndColor,
BaseTexture,
NoSpecular
}
public enum GlossinessSource
{
BaseAlpha,
SpecularAlpha
}
public enum ReflectionSource
{
NoReflection,
Cubemap,
ReflectionProbe
}
public struct UpgradeParams
{
public UpgradeBlendMode blendMode;
public SpecularSource specularSource;
public GlossinessSource glosinessSource;
public ReflectionSource reflectionSource;
}
}

12
Assets/LowEndMobilePipeline/Editor/UpgradeCommon.cs.meta


fileFormatVersion: 2
guid: 8fe5351dffe46e648adb2abd7a167ce7
timeCreated: 1490691870
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存