浏览代码

Added partial support for specular setup conversion

/system-shock-transitional-shader
Paul Melamed 7 年前
当前提交
f735f83d
共有 9 个文件被更改,包括 169 次插入23 次删除
  1. 17
      ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  3. 3
      ScriptableRenderPipeline/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs
  4. 33
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitTransitionalUI.cs
  5. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitMaterialUpgrader_SS.cs
  6. 3
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl
  7. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTransitonal.shader
  8. 19
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBufferTransitional.hlsl
  9. 82
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader_SS.cs

17
ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs


}
Convert(material, newMaterial);
if (newMaterial.shaderKeywords.Length > 250)
{
Debug.LogError(string.Format("Too many keywords in material {0}", material.name));
}
material.shader = Shader.Find(m_NewShader);
material.CopyPropertiesFromMaterial(newMaterial);

dstMaterial.SetColor(prop.Key, prop.Value);
foreach (var t in m_KeywordFloatRename)
dstMaterial.SetFloat(t.property, srcMaterial.IsKeywordEnabled(t.keyword) ? t.setVal : t.unsetVal);
if (srcMaterial.GetTexture("_MetallicGlossMap") != null)
{
dstMaterial.SetFloat("_Metallic", 1.0f);
}
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)

4
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


if (light.GetComponent<HDAdditionalLightData>() == null)
light.gameObject.AddComponent<HDAdditionalLightData>();
if (light.GetComponent<AdditionalShadowData>() == null)
light.gameObject.AddComponent<AdditionalShadowData>();
// if (light.GetComponent<AdditionalShadowData>() == null)
// light.gameObject.AddComponent<AdditionalShadowData>();
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs


static List<MaterialUpgrader> GetHDUpgraders_SS()
{
var upgraders = new List<MaterialUpgrader>();
upgraders.Add(new StandardToHDLitMaterialUpgrader_SS("Standard", "HDRenderPipeline/LitTransitional", LitGUI.SetupMaterialKeywordsAndPass));
upgraders.Add(new StandardToHDLitMaterialUpgrader_SS("Standard", "HDRenderPipeline/LitTransitional", LitTransitionalGUI.SetupMaterialKeywordsAndPass));
upgraders.Add(new StandardSpecularToHDLitMaterialUpgrader_SS("Standard (Specular setup)", "HDRenderPipeline/LitTransitional", LitTransitionalGUI.SetupMaterialKeywordsAndPass));
return upgraders;
}

33
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitTransitionalUI.cs


{
protected MaterialProperty occlusionMap = new MaterialProperty();
protected const string kOcclusionMap = "_OcclusionMap";
protected MaterialProperty detailMapLegacy = new MaterialProperty();
protected const string kDetailMapLegacy = "_DetailMapLegacy";
protected MaterialProperty detailMaskMapLegacy = new MaterialProperty();
protected const string kDetailMaskMapLegacy = "_DetailMaskMapLegacy";
public static GUIContent detailMaskMapLegacyText = new GUIContent("Detail Mask Map", "Detail Mask Map");
public static GUIContent detailMapLegacyText = new GUIContent("Detail Map", "Detail Map");
public static string LegacyText = "Legacy";
base.MaterialPropertiesGUI(material);
EditorGUILayout.LabelField(Styles.LegacyText, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMapLegacyText, detailMapLegacy);
m_MaterialEditor.TexturePropertySingleLine(Styles.detailMaskMapLegacyText, detailMaskMapLegacy);
EditorGUI.indentLevel--;
base.MaterialPropertiesGUI(material);
}
protected override void FindMaterialProperties(MaterialProperty[] props)

detailMapLegacy = FindProperty(string.Format("{0}{1}", kDetailMapLegacy, ""), props);
detailMaskMapLegacy = FindProperty(string.Format("{0}{1}", kDetailMaskMapLegacy, ""), props);
}
static public void SetupLitTransitionalKeywords(Material material)
{
SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture(kOcclusionMap));
SetKeyword(material, "_DETAIL_MAP_LEGACY", material.GetTexture(kDetailMapLegacy));
SetKeyword(material, "_DETAIL_MASK_MAP_LEGACY", material.GetTexture(kDetailMaskMapLegacy));
SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture(kOcclusionMap));
SetupLitTransitionalKeywords(material);
}
static public void SetupMaterialKeywordsAndPass(Material material)
{
LitGUI.SetupMaterialKeywordsAndPass(material);
SetupLitTransitionalKeywords(material);
}
}
}

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitMaterialUpgrader_SS.cs


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.
if (srcMaterial.GetTexture("_MetallicGlossMap") != null)
{
dstMaterial.SetFloat("_Metallic", 1.0f);
}
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]

3
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl


TEXTURE2D(_DetailMap);
SAMPLER2D(sampler_DetailMap);
TEXTURE2D(_DetailMask);
SAMPLER2D(sampler_DetailMask);
TEXTURE2D(_HeightMap);
SAMPLER2D(sampler_HeightMap);

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTransitonal.shader


_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0
_MaskMap("MaskMap", 2D) = "white" {}
_OcclusionMap("Occlusion", 2D) = "white" {}
_DetailMapLegacy("Detail Map", 2D) = "white" {}
_DetailMaskMapLegacy("Detail Mask Map", 2D) = "white" {}
_SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0
_SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0

_HeightMax("Heightmap Max", Float) = 1
_HeightCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space
_DetailMap("DetailMap", 2D) = "black" {}
_DetailMap("DetailMap", 2D) = "grey" {}
_DetailMask("DetailMask", 2D) = "white" {}
_DetailNormalMap("DetailNormalMap", 2D) = "bump" {}
_DetailAlbedoScale("_DetailAlbedoScale", Range(0.0, 2.0)) = 1
_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1

#pragma shader_feature _NORMALMAP
#pragma shader_feature _MASKMAP
#pragma shader_feature _OCCLUSIONMAP
#pragma shader_feature _DETAILMAP_LEGACY
#pragma shader_feature _BENTNORMALMAP
#pragma shader_feature _EMISSIVE_COLOR_MAP
#pragma shader_feature _ENABLESPECULAROCCLUSION

#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _DETAIL_MAP_LEGACY
#pragma shader_feature _DETAIL_MASK_MAP_LEGACY
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESSMAP
#pragma shader_feature _SPECULARCOLORMAP

// variable declaration
//-------------------------------------------------------------------------------------
#include "../../Material/Lit/LitProperties.hlsl"
TEXTURE2D(_DetailMapLegacy);
SAMPLER2D(sampler_DetailMapLegacy);
TEXTURE2D(_DetailMaskMapLegacy);
SAMPLER2D(sampler_DetailMaskMapLegacy);
#include "../../Material/Lit/LitProperties.hlsl"
// All our shaders use same name for entry point
#pragma vertex Vert

19
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassGBufferTransitional.hlsl


#endif // TESSELLATION_ON
half3 LerpWhiteTo(half3 b, half t)
{
half oneMinusT = 1 - t;
return half3(oneMinusT, oneMinusT, oneMinusT) + b * t;
}
void Frag( PackedVaryingsToPS packedInput,
OUTPUT_GBUFFER(outGBuffer)
OUTPUT_GBUFFER_VELOCITY(outVelocityBuffer)

#else
surfaceData.ambientOcclusion = 1.0f;
#endif
#ifdef _DETAIL_MAP_LEGACY
UVMapping detailTexcoord;
ZERO_INITIALIZE(UVMapping, detailTexcoord);
detailTexcoord.uv = input.texCoord0 * _DetailMap_ST.xy + _DetailMap_ST.zw;
float3 detailAlbedo = saturate(SAMPLE_UVMAPPING_TEXTURE2D(_DetailMapLegacy, sampler_DetailMapLegacy, detailTexcoord).rgb * 2.0f);
float detailMask = 1.0f;
#ifdef _DETAIL_MASK_MAP_LEGACY
detailMask = SAMPLE_UVMAPPING_TEXTURE2D(_DetailMaskMapLegacy, sampler_DetailMaskMapLegacy, detailTexcoord).a;
#endif
surfaceData.baseColor *= LerpWhiteTo (detailAlbedo, detailMask);
#endif
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);

82
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader_SS.cs


using NUnit.Framework;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
class StandardSpecularToHDLitMaterialUpgrader_SS : MaterialUpgrader
{
public StandardSpecularToHDLitMaterialUpgrader_SS() : this("Standard (Specular setup)", "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass) { }
public StandardSpecularToHDLitMaterialUpgrader_SS(string sourceShaderName, string destShaderName, MaterialFinalizer finalizer)
{
// Anything reasonable that can be done here?
//RenameFloat("_SpecColor", ...);
RenameShader(sourceShaderName, destShaderName, finalizer);
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("_SpecGlossMap", "_SpecularColorMap");
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");
// Metallic uses [Gamma] attribute in standard shader but not in Lit.
// @Seb: Should we convert?
RenameFloat("_Metallic", "_Metallic");
}
public override void Convert(Material srcMaterial, Material dstMaterial)
{
base.Convert(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
dstMaterial.SetFloat("_MaterialID", 4.0f);
Color c = new Color(1,1,1,1);
dstMaterial.SetColor("_SpecularColor", c);
float smoothness = srcMaterial.GetFloat("_Glossiness");
dstMaterial.SetFloat("_Smoothness", smoothness * smoothness);
}
[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"));
}
}
}
正在加载...
取消
保存