浏览代码

Changed the upgrader to apply conversion parameters in the AssignNewShadertoMaterial callback so when changing the shader in the material UI it also upgrade properly.

/vr_sandbox
Felipe Lira 8 年前
当前提交
15fae8de
共有 4 个文件被更改,包括 92 次插入135 次删除
  1. 141
      Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs
  2. 59
      Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs
  3. 23
      Assets/LowEndMobilePipeline/Editor/LowendUpgraders.cs
  4. 4
      Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs

141
Assets/LowEndMobilePipeline/Editor/LegacyShadersToLowEndUpgrader.cs


public class LegacyShadersToLowEndUpgrader
{
private static class SupportedUpgradeParams
{
static public UpgradeParams diffuseOpaque = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams specularOpaque = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams diffuseAlpha = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams specularAlpha = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams diffuseAlphaCutout = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams specularAlphaCutout = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Cutout,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.SpecularAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.NoReflection
};
static public UpgradeParams diffuseCubemap = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
};
static public UpgradeParams specularCubemap = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Opaque,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
};
static public UpgradeParams diffuseCubemapAlpha = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.NoSpecular,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
};
static public UpgradeParams specularCubemapAlpha = new UpgradeParams()
{
blendMode = (float)LowendMobilePipelineMaterialEditor.BlendMode.Alpha,
specularSource = (float)LowendMobilePipelineMaterialEditor.SpecularSource.SpecularTextureAndColor,
glosinessSource = (float)LowendMobilePipelineMaterialEditor.GlossinessSource.BaseAlpha,
reflectionSource = (float)LowendMobilePipelineMaterialEditor.ReflectionSource.Cubemap
};
}
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Legacy Materials to LowEndMobile - Project", false, 3)]
public static void UpgradeMaterialsToLDProject()
{

/////////////////////////////////////
// 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));
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"));
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));
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"));
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));
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"));
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));
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"));
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));
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"));
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));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Transperant"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec"));
materialUpgraders.Add(new LegacyBlinnPhongUpgrader("Reflective/Diffuse Reflection Spec Transp"));
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));
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"));
/////////////////////////////////////
// Particles /

59
Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs


ReflectionProbe
}
public struct UpgradeParams
{
public BlendMode blendMode;
public SpecularSource specularSource;
public GlossinessSource glosinessSource;
public ReflectionSource reflectionSource;
}
private static class Styles
{
public static GUIContent[] albedoGlosinessLabels =

// 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"))
{
ConvertFromLegacy(material, oldShaderName);
}
UpdateMaterialKeywords(material);
}

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"))
{
shaderUpgradeParams.blendMode = BlendMode.Cutout;
shaderUpgradeParams.glosinessSource = GlossinessSource.SpecularAlpha;
}
else
{
shaderUpgradeParams.blendMode = BlendMode.Opaque;
shaderUpgradeParams.glosinessSource = GlossinessSource.BaseAlpha;
}
if (oldShaderName.Contains("Spec"))
shaderUpgradeParams.specularSource = SpecularSource.SpecularTextureAndColor;
else
shaderUpgradeParams.specularSource = SpecularSource.NoSpecular;
if (oldShaderName.Contains("Reflective"))
shaderUpgradeParams.reflectionSource = ReflectionSource.Cubemap;
else
shaderUpgradeParams.reflectionSource = ReflectionSource.NoReflection;
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);
}
}
}

23
Assets/LowEndMobilePipeline/Editor/LowendUpgraders.cs


using UnityEditor.Experimental.Rendering;
using UnityEngine;
public struct UpgradeParams
{
public float blendMode;
public float specularSource;
public float glosinessSource;
public float reflectionSource;
}
public LegacyBlinnPhongUpgrader(string oldShaderName, UpgradeParams upgraderParams)
public LegacyBlinnPhongUpgrader(string oldShaderName)
SetNewFloatProperty("_Mode", upgraderParams.blendMode);
SetNewFloatProperty("_SpecSource", upgraderParams.specularSource);
SetNewFloatProperty("_GlossinessSource", upgraderParams.glosinessSource);
SetNewFloatProperty("_ReflectionSource", upgraderParams.reflectionSource);
if (oldShaderName.Contains("Legacy Shaders/Self-Illumin"))
{
RenameTexture("_MainTex", "_EmissionMap");
RemoveTexture("_MainTex");
SetNewColorProperty("_EmissionColor", Color.white);
}
}
}

public TerrainUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, "ScriptableRenderPipeline/LowEndMobile/NonPBR");
SetNewFloatProperty("_Shininess", 1.0f);
SetFloat("_Shininess", 1.0f);
}
}

4
Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs


m_TexturesToRemove.Add(name);
}
public void SetNewFloatProperty(string propertyName, float value)
public void SetFloat(string propertyName, float value)
public void SetNewColorProperty(string propertyName, Color value)
public void SetColor(string propertyName, Color value)
{
m_ColorPropertiesToSet[propertyName] = value;
}

正在加载...
取消
保存