浏览代码

cleanup some common code

/system-shock-transitional-shader
Paul Melamed 7 年前
当前提交
7a08434c
共有 3 个文件被更改,包括 39 次插入109 次删除
  1. 29
      ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs
  2. 60
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitTransitionalMaterialUpgrader.cs
  3. 59
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitTransitionalMaterialUpgrader.cs

29
ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs


dstMaterial.SetFloat(t.property, srcMaterial.IsKeywordEnabled(t.keyword) ? t.setVal : t.unsetVal);
}
public void CommonRename()
{
RenameTexture("_MainTex", "_BaseColorMap");
RenameColor("_Color", "_BaseColor");
RenameFloat("_Glossiness", "_Smoothness");
RenameTexture("_BumpMap", "_NormalMap");
RenameFloat("_BumpScale", "_NormalScale");
RenameTexture("_EmissionMap", "_EmissiveColorMap");
RenameColor("_EmissionColor", "_EmissiveColor");
RenameFloat("_Cutoff", "_AlphaCutoff");
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);
RenameTexture("_ParallaxMap", "_HeightMap");
RenameTexture("_DetailAlbedoMap", "_DetailMapLegacy");
RenameTexture("_DetailMask", "_DetailMaskMapLegacy");
RenameVector("_DetailAlbedoMap_ST", "_DetailMap_ST");
}
public void CommonConvert(Material srcMaterial, Material dstMaterial)
{
if (srcMaterial.GetTexture("_ParallaxMap") != null)
{
dstMaterial.SetFloat("_DisplacementMode", 2.0f);
dstMaterial.SetFloat("_DisplacementLockObjectScale", 0.0f);
dstMaterial.SetFloat("_DepthOffsetEnable", 1.0f);
}
dstMaterial.SetFloat("_EmissiveIntensity", 3.141f); // same as lights
}
public void RenameShader(string oldName, string newName, MaterialFinalizer finalizer = null)
{
m_OldShader = oldName;

60
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitTransitionalMaterialUpgrader.cs


public StandardSpecularToHDLitTransitionalMaterialUpgrader() : this("Standard (Specular setup)", "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass) { }
public StandardSpecularToHDLitTransitionalMaterialUpgrader(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer)
{
// Anything reasonable that can be done here?
//RenameFloat("_SpecColor", ...);
{
RenameTexture("_MainTex", "_BaseColorMap");
RenameColor("_Color", "_BaseColor");
RenameFloat("_Glossiness", "_Smoothness");
RenameTexture("_BumpMap", "_NormalMap");
RenameFloat("_BumpScale", "_NormalScale");
RenameTexture("_EmissionMap", "_EmissiveColorMap");
RenameColor("_EmissionColor", "_EmissiveColor");
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale");
RenameFloat("_Cutoff", "_AlphaCutoff");
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);
CommonRename();
RenameTexture("_ParallaxMap", "_HeightMap");
// the HD renderloop packs detail albedo and detail normals into a single texture.
// mapping the detail normal map, if any, to the detail map, should do the right thing if
// there is no detail albedo.
RenameTexture("_DetailAlbedoMap", "_DetailMapLegacy");
RenameTexture("_DetailMask", "_DetailMaskMapLegacy");
RenameVector("_DetailAlbedoMap_ST", "_DetailMap_ST");
if (srcMaterial.GetTexture("_ParallaxMap") != null)
{
dstMaterial.SetFloat("_DisplacementMode", 2.0f);
dstMaterial.SetFloat("_DisplacementLockObjectScale", 0.0f);
dstMaterial.SetFloat("_DepthOffsetEnable", 1.0f);
}
dstMaterial.SetFloat("_EmissiveIntensity", 3.141f); // same as lights
CommonConvert(srcMaterial, dstMaterial);
}
[Test]
public void UpgradeMaterial()
{
var newShader = Shader.Find("HDRenderPipeline/Lit");
var mat = new Material(Shader.Find("Standard (Specular setup)"));
var albedo = new Texture2D(1, 1);
var normals = new Texture2D(1, 1);
var baseScale = new Vector2(1, 1);
var color = Color.red;
mat.mainTexture = albedo;
mat.SetTexture("_BumpMap", normals);
mat.color = color;
mat.SetTextureScale("_MainTex", baseScale);
MaterialUpgrader.Upgrade(mat, this, MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties);
Assert.AreEqual(newShader, mat.shader);
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap"));
Assert.AreEqual(color, mat.GetColor("_BaseColor"));
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap"));
Assert.AreEqual(normals, mat.GetTexture("_NormalMap"));
Assert.IsTrue(mat.IsKeywordEnabled("_NORMALMAP"));
}
}
}
}

59
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitTransitionalMaterialUpgrader.cs


namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public class StandardToHDLitTransitionalMaterialUpgrader : MaterialUpgrader
{
{
CommonRename();
RenameTexture("_MainTex", "_BaseColorMap");
RenameColor("_Color", "_BaseColor");
RenameFloat("_Glossiness", "_Smoothness");
RenameTexture("_BumpMap", "_NormalMap");
RenameFloat("_BumpScale", "_NormalScale");
RenameTexture("_EmissionMap", "_EmissiveColorMap");
RenameColor("_EmissionColor", "_EmissiveColor");
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale");
RenameFloat("_Cutoff", "_AlphaCutoff");
RenameKeywordToFloat("_ALPHATEST_ON", "_AlphaCutoffEnable", 1f, 0f);
RenameTexture("_ParallaxMap", "_HeightMap");
// the HD renderloop packs detail albedo and detail normals into a single texture.
// mapping the detail normal map, if any, to the detail map, should do the right thing if
// there is no detail albedo.
RenameTexture("_DetailAlbedoMap", "_DetailMapLegacy");
RenameTexture("_DetailMask", "_DetailMaskMapLegacy");
RenameVector("_DetailAlbedoMap_ST", "_DetailMap_ST");
// Metallic uses [Gamma] attribute in standard shader but not in Lit.
// @Seb: Should we convert?
RenameFloat("_Metallic", "_Metallic");
}

CommonConvert(srcMaterial, dstMaterial);
if (srcMaterial.GetTexture("_ParallaxMap") != null)
{
dstMaterial.SetFloat("_DisplacementMode", 2.0f);
dstMaterial.SetFloat("_DisplacementLockObjectScale", 0.0f);
dstMaterial.SetFloat("_DepthOffsetEnable", 1.0f);
}
dstMaterial.SetFloat("_EmissiveIntensity", 3.141f); // same as lights
}
[Test]
public void UpgradeMaterial()
{
var newShader = Shader.Find("HDRenderPipeline/Lit");
var mat = new Material(Shader.Find("Standard"));
var albedo = new Texture2D(1, 1);
var normals = new Texture2D(1, 1);
var baseScale = new Vector2(1, 1);
var color = Color.red;
mat.mainTexture = albedo;
mat.SetTexture("_BumpMap", normals);
mat.color = color;
mat.SetTextureScale("_MainTex", baseScale);
MaterialUpgrader.Upgrade(mat, this, MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties);
Assert.AreEqual(newShader, mat.shader);
Assert.AreEqual(albedo, mat.GetTexture("_BaseColorMap"));
Assert.AreEqual(color, mat.GetColor("_BaseColor"));
Assert.AreEqual(baseScale, mat.GetTextureScale("_BaseColorMap"));
Assert.AreEqual(normals, mat.GetTexture("_NormalMap"));
Assert.IsTrue(mat.IsKeywordEnabled("_NORMALMAP"));
}
}
}
正在加载...
取消
保存