浏览代码

Added emission map. Upgrade selected, and specular power now has a similar computation to legacy ones (shininess multiply) so when upgrading projects lighting behaves more or like the same as legacy.

/vr_sandbox
Felipe Lira 8 年前
当前提交
37ce1cf7
共有 5 个文件被更改,包括 81 次插入50 次删除
  1. 81
      Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs
  2. 15
      Assets/LowEndMobilePipeline/Editor/StandardToLowEndMaterialUpgrader.cs
  3. 18
      Assets/LowEndMobilePipeline/LowEndMobilePipeline.shader
  4. 13
      Assets/LowEndMobilePipeline/LowEndMobilePipelineCore.cginc
  5. 4
      Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs

81
Assets/LowEndMobilePipeline/Editor/LowendMobilePipelineMaterialEditor.cs


public class LowendMobilePipelineMaterialEditor : MaterialEditor
{
private MaterialProperty blendMode = null;
private MaterialProperty albedoMap = null;
private MaterialProperty albedoColor = null;
private MaterialProperty alphaCutoff = null;
private MaterialProperty specularSource = null;
private MaterialProperty blendModeProp = null;
private MaterialProperty albedoMapProp = null;
private MaterialProperty albedoColorProp = null;
private MaterialProperty alphaCutoffProp = null;
private MaterialProperty specularSourceProp = null;
private MaterialProperty specularGlossMap = null;
private MaterialProperty specularColor = null;
private MaterialProperty specularStrength = null;
private MaterialProperty bumpMap = null;
private MaterialProperty emissionColor = 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;
public enum BlendMode
{

};
public static GUIContent normalMapText = new GUIContent("Normal Map", "Normal Map");
public static GUIContent emissionMapLabel = new GUIContent("Emission Map", "Emission Map");
public static GUIContent alphaCutoutWarning =
new GUIContent(

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 specularStrength = "Specular Strength";
public static string shininessLabel = "Shininess";
public static string normalMapLabel = "Normal map";
public static string emissionColorLabel = "Emission Color";
}

Material[] mats = { material };
blendMode = GetMaterialProperty(mats, "_Mode");
albedoMap = GetMaterialProperty(mats, "_MainTex");
albedoColor = GetMaterialProperty(mats, "_Color");
blendModeProp = GetMaterialProperty(mats, "_Mode");
albedoMapProp = GetMaterialProperty(mats, "_MainTex");
albedoColorProp = GetMaterialProperty(mats, "_Color");
alphaCutoff = GetMaterialProperty(mats, "_Cutoff");
specularSource = GetMaterialProperty(mats, "_SpecSource");
alphaCutoffProp = GetMaterialProperty(mats, "_Cutoff");
specularSourceProp = GetMaterialProperty(mats, "_SpecSource");
specularGlossMap = GetMaterialProperty(mats, "_SpecGlossMap");
specularColor = GetMaterialProperty(mats, "_SpecColor");
specularStrength = GetMaterialProperty(mats, "_SpecularStrength");
bumpMap = GetMaterialProperty(mats, "_BumpMap");
emissionColor = GetMaterialProperty(mats, "_EmissionColor");
specularGlossMapProp = GetMaterialProperty(mats, "_SpecGlossMap");
specularColorProp = GetMaterialProperty(mats, "_SpecColor");
shininessProp = GetMaterialProperty(mats, "_Shininess");
bumpMapProp = GetMaterialProperty(mats, "_BumpMap");
emissionMapProp = GetMaterialProperty(mats, "_EmissionMap");
emissionColorProp = GetMaterialProperty(mats, "_EmissionColor");
}
public override void OnInspectorGUI()

DoSpecular();
EditorGUILayout.Space();
TexturePropertySingleLine(Styles.normalMapText, bumpMap);
TexturePropertySingleLine(Styles.normalMapText, bumpMapProp);
ColorProperty(emissionColor, Styles.emissionColorLabel);
TexturePropertySingleLine(Styles.emissionMapLabel, emissionMapProp, emissionColorProp);
if (EditorGUI.EndChangeCheck())
UpdateMaterialKeywords(material);

if ((BlendMode)blendMode.floatValue == BlendMode.Cutout)
if ((BlendMode)blendModeProp.floatValue == BlendMode.Cutout)
{
Styles.warningStyle.normal.textColor = Color.yellow;
EditorGUILayout.LabelField(Styles.alphaCutoutWarning, Styles.warningStyle);

private void DoBlendMode()
{
int modeValue = (int)blendMode.floatValue;
int modeValue = (int)blendModeProp.floatValue;
blendMode.floatValue = modeValue;
blendModeProp.floatValue = modeValue;
BlendMode mode = (BlendMode)blendMode.floatValue;
BlendMode mode = (BlendMode)blendModeProp.floatValue;
EditorGUILayout.Space();

TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMap, albedoColor);
TextureScaleOffsetProperty(albedoMap);
TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMapProp, albedoColorProp);
TextureScaleOffsetProperty(albedoMapProp);
TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMap, albedoColor);
TextureScaleOffsetProperty(albedoMap);
TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMapProp, albedoColorProp);
TextureScaleOffsetProperty(albedoMapProp);
RangeProperty(alphaCutoff, "Cutoff");
RangeProperty(alphaCutoffProp, "Cutoff");
}
}

int source = (int)specularSource.floatValue;
int source = (int)specularSourceProp.floatValue;
specularSource.floatValue = source;
specularSourceProp.floatValue = source;
SpecularSource specSource = (SpecularSource)specularSource.floatValue;
SpecularSource specSource = (SpecularSource)specularSourceProp.floatValue;
if (specSource != SpecularSource.NoSpecular)
{
int glossinessSource = (int)glossinessSourceProp.floatValue;

int glossSource = (int)glossinessSourceProp.floatValue;
if (specSource == SpecularSource.SpecularTextureAndColor)
{
TexturePropertySingleLine(Styles.specularGlossMapLabels[glossSource], specularGlossMap, specularColor);
TexturePropertySingleLine(Styles.specularGlossMapLabels[glossSource], specularGlossMapProp, specularColorProp);
RangeProperty(specularStrength, Styles.specularStrength);
RangeProperty(shininessProp, Styles.shininessLabel);
}
}

private void UpdateMaterialBlendMode(Material material)
{
BlendMode mode = (BlendMode)blendMode.floatValue;
BlendMode mode = (BlendMode)blendModeProp.floatValue;
switch (mode)
{
case BlendMode.Opaque:

private void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource)specularSource.floatValue;
SpecularSource specSource = (SpecularSource)specularSourceProp.floatValue;
if (specSource == SpecularSource.NoSpecular)
{
SetKeyword(material, "_SHARED_SPECULAR_DIFFUSE", false);

15
Assets/LowEndMobilePipeline/Editor/StandardToLowEndMaterialUpgrader.cs


public class StandardToLowEndMaterialUpgrader : MaterialUpgrader
{
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile")]
private static void UpgradeMaterialsToLD()
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Selection")]
private static void UpgradeMaterialsToLDProject()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard (Specular setup)"));

MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to LD Materials");
}
[MenuItem("RenderPipeline/LowEndMobilePipeline/Material Upgraders/Upgrade Standard Materials to Low End Mobile - Project Folder")]
private static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard (Specular setup)"));
upgraders.Add(new StandardToLowEndMaterialUpgrader("Standard"));
upgraders.Add(new StandardToLowEndMaterialUpgrader("TerrainSurface"));
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to LD Materials");
}
StandardToLowEndMaterialUpgrader(string oldShaderName)

18
Assets/LowEndMobilePipeline/LowEndMobilePipeline.shader


_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness("Shininess", Range(0.0, 1.0)) = 0.5
_SpecularStrength("Specular Strength", Range(0.0, 255.0)) = 200
_Glossiness("Glossiness", Range(0.0, 1.0)) = 0.5
_Shininess("Shininess", Range(0.0, 1.0)) = 1.0
_GlossMapScale("Smoothness Factor", Range(0.0, 1.0)) = 1.0
[Enum(Specular Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0

#pragma shader_feature _ _SHARED_SPECULAR_DIFFUSE _SPECGLOSSMAP _SPECULAR_COLOR
#pragma shader_feature _GLOSSINESS_FROM_BASE_ALPHA
#pragma shader_feature _NORMALMAP
#pragma shader_feature _EMISSION_MAP
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ HARD_SHADOWS SOFT_SHADOWS

half alpha = diffuseAlpha.a * _Color.a;
// Keep for compatibility reasons. Shader Inpector throws a warning when using cutoff
// due overdraw performance impact.
// due overdraw performance impact.
#ifdef _ALPHATEST_ON
clip(alpha - _Cutoff);
#endif

half3 indirectDiffuse;
IndirectDiffuse(i, diffuse, indirectDiffuse);
half3 emissionColor;
Emission(i, emissionColor);
// Compute direct contribution from main directional light.
// Only a single directional shadow caster is supported.
LightInput mainLight;

#if defined(HARD_SHADOWS) || defined(SOFT_SHADOWS)
directColor *= ComputeShadowAttenuation(i);
#endif
// Compute direct contribution from additional lights.
for (int lightIndex = 1; lightIndex < globalLightCount.x; ++lightIndex)
{

}
half3 color = directColor + indirectDiffuse + _EmissionColor;
half3 color = directColor + indirectDiffuse + emissionColor;
UNITY_APPLY_FOG(i.fogCoord, color);
return OutputColor(color, alpha);

ENDCG
}
}
Fallback "Standard (Specular setup)"
CustomEditor "LowendMobilePipelineMaterialEditor"
Fallback "Standard (Specular setup)"
CustomEditor "LowendMobilePipelineMaterialEditor"
}

13
Assets/LowEndMobilePipeline/LowEndMobilePipelineCore.cginc


half4x4 _WorldToShadow[MAX_SHADOW_CASCADES];
float4 _DirShadowSplitSpheres[MAX_SHADOW_CASCADES];
half _SpecularStrength;
half _Shininess;
inline void NormalMap(v2f i, out half3 normal)

#else
specularGloss = _SpecColor;
#endif
#endif
}
inline void Emission(v2f i, out half3 emission)
{
#ifdef _EMISSION_MAP
emission = tex2D(_EmissionMap, i.uv01.xy) * _EmissionColor
#else
emission = _EmissionColor;
#endif
}

half3 diffuse = diffuseColor * lightColor * NdotL;
#if defined(_SHARED_SPECULAR_DIFFUSE) || defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, 256.0 - _SpecularStrength) * specularGloss.a;
half3 specular = specularGloss.rgb * lightColor * pow(NdotH, _Shininess * 128.0) * specularGloss.a;
return diffuse + specular;
#else
return diffuse;

4
Assets/ScriptableRenderPipeline/Editor/MaterialUpgrader.cs


public static void UpgradeSelection(List<MaterialUpgrader> upgraders, string progressBarName)
{
if (!EditorUtility.DisplayDialog("Material Upgrader", "The upgrade will overwrite all selected material settings" +
"Be sure to have a project backup before proceeding", "Proceed", "Cancel"))
return;
string lastMaterialName = "";
var selection = Selection.objects;
for (int i = 0; i < selection.Length; i++)

正在加载...
取消
保存