|
|
|
|
|
|
|
|
|
|
namespace UnityEditor.Experimental.ScriptableRenderLoop |
|
|
|
{ |
|
|
|
class StandardToHDLitMaterialUpgrader : MaterialUpgrader |
|
|
|
{ |
|
|
|
public StandardToHDLitMaterialUpgrader() |
|
|
|
{ |
|
|
|
RenameShader("Standard", "HDRenderLoop/LitLegacySupport"); |
|
|
|
class StandardToHDLitMaterialUpgrader : MaterialUpgrader |
|
|
|
{ |
|
|
|
public StandardToHDLitMaterialUpgrader() |
|
|
|
{ |
|
|
|
RenameShader("Standard", "HDRenderLoop/LitLegacySupport"); |
|
|
|
RenameFloat("_Glossiness", "_Smoothness"); |
|
|
|
RenameTexture("_BumpMap", "_NormalMap"); |
|
|
|
RenameColor("_EmissionColor", "_EmissiveColor"); |
|
|
|
RenameFloat("_Glossiness", "_Smoothness"); |
|
|
|
RenameTexture("_BumpMap", "_NormalMap"); |
|
|
|
RenameColor("_EmissionColor", "_EmissiveColor"); |
|
|
|
RenameFloat("_DetailNormalMapScale", "_DetailNormalScale"); |
|
|
|
|
|
|
|
// the HD renderloop packs detail albedo and detail normals into a single texture.
|
|
|
|
|
|
|
// @Seb: Should we convert?
|
|
|
|
RenameFloat("_Metallic", "_Metallic"); |
|
|
|
|
|
|
|
//@TODO: Seb. Why do we multiply color by intensity
|
|
|
|
// in shader when we can just store a color?
|
|
|
|
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|
|
|
} |
|
|
|
//@TODO: Seb. Why do we multiply color by intensity
|
|
|
|
// in shader when we can just store a color?
|
|
|
|
// builtinData.emissiveColor * builtinData.emissiveIntensity
|
|
|
|
} |
|
|
|
public override void Convert(Material srcMaterial, Material dstMaterial) |
|
|
|
{ |
|
|
|
base.Convert (srcMaterial, dstMaterial); |
|
|
|
//@TODO: Find a good way of setting up keywords etc from properties.
|
|
|
|
// Code should be shared with material UI code.
|
|
|
|
} |
|
|
|
public override void Convert(Material srcMaterial, Material dstMaterial) |
|
|
|
{ |
|
|
|
base.Convert(srcMaterial, dstMaterial); |
|
|
|
//@TODO: Find a good way of setting up keywords etc from properties.
|
|
|
|
// Code should be shared with material UI code.
|
|
|
|
} |
|
|
|
[Test] |
|
|
|
public void UpgradeMaterial() |
|
|
|
{ |
|
|
|
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport"); |
|
|
|
var mat = new Material (Shader.Find("Standard")); |
|
|
|
var albedo = new Texture2D(1, 1); |
|
|
|
[Test] |
|
|
|
public void UpgradeMaterial() |
|
|
|
{ |
|
|
|
var newShader = Shader.Find("HDRenderLoop/LitLegacySupport"); |
|
|
|
var mat = new Material(Shader.Find("Standard")); |
|
|
|
var albedo = new Texture2D(1, 1); |
|
|
|
mat.mainTexture = albedo; |
|
|
|
mat.mainTexture = albedo; |
|
|
|
mat.color = color; |
|
|
|
mat.color = color; |
|
|
|
MaterialUpgrader.Upgrade(mat, new StandardToHDLitMaterialUpgrader (), MaterialUpgrader.UpgradeFlags.CleanupNonUpgradedProperties); |
|
|
|
MaterialUpgrader.Upgrade(mat, new StandardToHDLitMaterialUpgrader(), 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.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")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|