浏览代码

Refactored upgraders. Added Terrain and Particles upgraders.

/main
Felipe Lira 7 年前
当前提交
c62e8861
共有 22 个文件被更改,包括 574 次插入1528 次删除
  1. 999
      ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png
  2. 6
      ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png.meta
  3. 8
      ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs
  4. 192
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs
  5. 63
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
  6. 39
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs
  7. 2
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta
  8. 2
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMatTexture_08.mat
  9. 2
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMat_07.mat
  10. 261
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs
  11. 101
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs
  12. 11
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs.meta
  13. 44
      ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs
  14. 11
      ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs.meta
  15. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs.meta
  16. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs.meta
  17. 53
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs
  18. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta
  19. 75
      ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs
  20. 165
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs
  21. 32
      ScriptableRenderPipeline/LightweightPipeline/Editor/StandardToLightweightMaterialUpgrader.cs
  22. 0
      /ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta

999
ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png
文件差异内容过多而无法显示
查看文件

6
ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png.meta


sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
vertices: []
indices:
edges: []
weights: []
spritePackingTag:
userData:
assetBundleName:

8
ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs


public class LightweightPipelineAsset : RenderPipelineAsset
{
public static readonly string m_SimpleLightShaderPath = "LightweightPipeline/Standard (Simple Lighting)";
public static readonly string m_StandardShaderPath = "LightweightPipeline/Standard (Physically Based)";
public static readonly string[] m_SearchPaths = {"Assets", "Packages/com.unity.render-pipelines"};
// Default values set when a new LightweightPipeline asset is created

instance.m_DefaultTerrainMaterial = resourceAsset.DefaultTerrainMaterial;
}
instance.m_DefaultShader = Shader.Find(m_StandardShaderPath);
instance.m_BlitShader = Shader.Find("Hidden/LightweightPipeline/Blit");
instance.m_CopyDepthShader = Shader.Find("Hidden/LightweightPipeline/CopyDepth");
instance.m_DefaultShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_PBS));
instance.m_BlitShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.HIDDEN_BLIT));
instance.m_CopyDepthShader = Shader.Find(LightweightShaderUtils.GetShaderPath(ShaderPathID.HIDDEN_DEPTH_COPY));
string assetPath = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Lightweight Asset", "LightweightAsset", "asset",
"Please enter a file name to save the asset to");

192
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs


using System;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Experimental.Rendering;
internal class LightweightStandardGUI : ShaderGUI
internal class LightweightStandardGUI : LightweightShaderGUI
public enum WorkflowMode : int
public enum WorkflowMode
public enum BlendMode : int
{
Opaque,
Cutout,
Fade, // Old school alpha-blending mode, fresnel does not affect amount of transparency
Transparent // Physically plausible transparency mode, implemented as alpha pre-multiply
}
public enum SmoothnessMapChannel : int
public enum SmoothnessMapChannel
{
SpecularMetallicAlpha,
AlbedoAlpha,

public static readonly string[] specularSmoothnessChannelNames = {"Specular Alpha", "Albedo Alpha"};
}
#pragma warning disable 0414
private MaterialProperty workflowMode;
private MaterialProperty blendMode;

private MaterialProperty emissionColorForRendering;
private MaterialProperty emissionMap;
private MaterialEditor m_MaterialEditor;
private bool m_FirstTimeApply = true;
#pragma warning restore 0414
public void FindProperties(MaterialProperty[] props)
public override void FindProperties(MaterialProperty[] properties)
workflowMode = FindProperty("_WorkflowMode", props);
blendMode = FindProperty("_Mode", props);
albedoColor = FindProperty("_Color", props);
albedoMap = FindProperty("_MainTex", props);
alphaCutoff = FindProperty("_Cutoff", props);
workflowMode = FindProperty("_WorkflowMode", properties);
blendMode = FindProperty("_Mode", properties);
albedoColor = FindProperty("_Color", properties);
albedoMap = FindProperty("_MainTex", properties);
alphaCutoff = FindProperty("_Cutoff", properties);
smoothness = FindProperty("_Glossiness", props);
smoothnessScale = FindProperty("_GlossMapScale", props, false);
smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props, false);
smoothness = FindProperty("_Glossiness", properties);
smoothnessScale = FindProperty("_GlossMapScale", properties, false);
smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", properties, false);
metallic = FindProperty("_Metallic", props);
specColor = FindProperty("_SpecColor", props);
metallicGlossMap = FindProperty("_MetallicGlossMap", props);
specGlossMap = FindProperty("_SpecGlossMap", props);
highlights = FindProperty("_SpecularHighlights", props);
reflections = FindProperty("_GlossyReflections", props);
metallic = FindProperty("_Metallic", properties);
specColor = FindProperty("_SpecColor", properties);
metallicGlossMap = FindProperty("_MetallicGlossMap", properties);
specGlossMap = FindProperty("_SpecGlossMap", properties);
highlights = FindProperty("_SpecularHighlights", properties);
reflections = FindProperty("_GlossyReflections", properties);
bumpScale = FindProperty("_BumpScale", props);
bumpMap = FindProperty("_BumpMap", props);
occlusionStrength = FindProperty("_OcclusionStrength", props);
occlusionMap = FindProperty("_OcclusionMap", props);
emissionColorForRendering = FindProperty("_EmissionColor", props);
emissionMap = FindProperty("_EmissionMap", props);
bumpScale = FindProperty("_BumpScale", properties);
bumpMap = FindProperty("_BumpMap", properties);
occlusionStrength = FindProperty("_OcclusionStrength", properties);
occlusionMap = FindProperty("_OcclusionMap", properties);
emissionColorForRendering = FindProperty("_EmissionColor", properties);
emissionMap = FindProperty("_EmissionMap", properties);
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
public override void MaterialChanged(Material material)
FindProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
// Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing
// material to a lightweight shader.
if (m_FirstTimeApply)
{
MaterialChanged(material);
m_FirstTimeApply = false;
}
ShaderPropertiesGUI(material);
material.shaderKeywords = null;
SetupMaterialBlendMode(material);
SetMaterialKeywords(material);
public void ShaderPropertiesGUI(Material material)
public override void ShaderPropertiesGUI(Material material)
{
// Use default labelWidth
EditorGUIUtility.labelWidth = 0f;

if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/"))
{
SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
SetupMaterialBlendMode(material);
return;
}

MaterialChanged(material);
}
private void DoPopup(string label, MaterialProperty property, string[] options)
void DoAlbedoArea(Material material)
EditorGUI.showMixedValue = property.hasMixedValue;
var mode = property.floatValue;
EditorGUI.BeginChangeCheck();
mode = EditorGUILayout.Popup(label, (int) mode, options);
if (EditorGUI.EndChangeCheck())
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
if (((BlendMode)material.GetFloat("_Mode") == BlendMode.Cutout))
m_MaterialEditor.RegisterPropertyChangeUndo(label);
property.floatValue = (float)mode;
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
EditorGUI.showMixedValue = false;
}
void DoNormalArea()

if (m_MaterialEditor.HelpBoxWithButton(Styles.bumpScaleNotSupported, Styles.fixNow))
bumpScale.floatValue = 1;
}
void DoAlbedoArea(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoText, albedoMap, albedoColor);
if (((BlendMode)material.GetFloat("_Mode") == BlendMode.Cutout))
{
m_MaterialEditor.ShaderProperty(alphaCutoff, Styles.alphaCutoffText.text, MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1);
}
}
void DoEmissionArea(Material material)

EditorGUI.indentLevel = prevIndentLevel;
}
public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode)
{
switch (blendMode)
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
break;
case BlendMode.Cutout:
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
break;
case BlendMode.Fade:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case BlendMode.Transparent:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
}
}
else
return SmoothnessMapChannel.SpecularMetallicAlpha;
return SmoothnessMapChannel.SpecularMetallicAlpha;
}
static void SetMaterialKeywords(Material material)

else
hasGlossMap = material.GetTexture("_MetallicGlossMap");
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_SETUP", isSpecularWorkFlow);
CoreUtils.SetKeyword(material, "_SPECULAR_SETUP", isSpecularWorkFlow);
LightweightShaderHelper.SetKeyword(material, "_METALLICSPECGLOSSMAP", hasGlossMap);
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap && isSpecularWorkFlow);
LightweightShaderHelper.SetKeyword(material, "_METALLICGLOSSMAP", hasGlossMap && !isSpecularWorkFlow);
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", hasGlossMap);
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap && isSpecularWorkFlow);
CoreUtils.SetKeyword(material, "_METALLICGLOSSMAP", hasGlossMap && !isSpecularWorkFlow);
LightweightShaderHelper.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
LightweightShaderHelper.SetKeyword(material, "_SPECULARHIGHLIGHTS_OFF", material.GetFloat("_SpecularHighlights") == 0.0f);
LightweightShaderHelper.SetKeyword(material, "_GLOSSYREFLECTIONS_OFF", material.GetFloat("_GlossyReflections") == 0.0f);
CoreUtils.SetKeyword(material, "_SPECULARHIGHLIGHTS_OFF", material.GetFloat("_SpecularHighlights") == 0.0f);
CoreUtils.SetKeyword(material, "_GLOSSYREFLECTIONS_OFF", material.GetFloat("_GlossyReflections") == 0.0f);
LightweightShaderHelper.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
LightweightShaderHelper.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
LightweightShaderHelper.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
CoreUtils.SetKeyword(material, "_PARALLAXMAP", material.GetTexture("_ParallaxMap"));
CoreUtils.SetKeyword(material, "_DETAIL_MULX2", material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"));
// A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
// or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.

LightweightShaderHelper.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
CoreUtils.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
LightweightShaderHelper.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha);
CoreUtils.SetKeyword(material, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A", GetSmoothnessMapChannel(material) == SmoothnessMapChannel.AlbedoAlpha);
}
static void MaterialChanged(Material material)
{
material.shaderKeywords = null;
SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode"));
SetMaterialKeywords(material);
}
}
}

63
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs


using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Experimental.Rendering;
public class LightweightStandardSimpleLightingGUI : ShaderGUI
public class LightweightStandardSimpleLightingGUI : LightweightShaderGUI
{
private const float kMinShininessValue = 0.01f;
private MaterialProperty blendModeProp;

private MaterialProperty bumpMapProp;
private MaterialProperty emissionMapProp;
private MaterialProperty emissionColorProp;
private MaterialEditor m_MaterialEditor;
private static class Styles
{

public static string emissionColorLabel = "Emission Color";
}
private void FindMaterialProperties(MaterialProperty[] properties)
public override void FindProperties(MaterialProperty[] properties)
{
blendModeProp = FindProperty("_Mode", properties);
albedoMapProp = FindProperty("_MainTex", properties);

emissionColorProp = FindProperty("_EmissionColor", properties);
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
public override void ShaderPropertiesGUI(Material material)
Material material = materialEditor.target as Material;
m_MaterialEditor = materialEditor;
FindMaterialProperties(properties);
EditorGUI.BeginChangeCheck();
{
DoBlendMode();

emissionMapProp.textureScaleAndOffset = albedoMapProp.textureScaleAndOffset; // Apply the main texture scale and offset to the emission texture as well, for Enlighten's sake
}
if (EditorGUI.EndChangeCheck())
LegacyBlinnPhongUpgrader.UpdateMaterialKeywords(material);
{
foreach (var obj in blendModeProp.targets)
MaterialChanged((Material)obj);
}
}
materialEditor.RenderQueueField();
public override void MaterialChanged(Material material)
{
material.shaderKeywords = null;
SetupMaterialBlendMode(material);
SetMaterialKeywords(material);
}
private void SetMaterialKeywords(Material material)
{
material.shaderKeywords = null;
SetupMaterialBlendMode(material);
UpdateMaterialSpecularSource(material);
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
EditorGUILayout.Space();
EditorGUILayout.Space();
// A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
// or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
// The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color.
MaterialEditor.FixupEmissiveFlag(material);
bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
CoreUtils.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
}
private void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource");
if (specSource == SpecularSource.NoSpecular)
{
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false);
CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false);
CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
}
else
{
GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource");
bool hasGlossMap = material.GetTexture("_SpecGlossMap");
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap);
CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasGlossMap);
CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", glossSource == GlossinessSource.BaseAlpha);
}
}
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)

ConvertFromLegacy(material, oldShaderName);
}
LegacyBlinnPhongUpgrader.UpdateMaterialKeywords(material);
StandardSimpleLightingUpgrader.UpdateMaterialKeywords(material);
}
private void DoBlendMode()

39
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs


using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Experimental.Rendering;
public class LightweightUnlitGUI : ShaderGUI
public class LightweightUnlitGUI : LightweightShaderGUI
{
private MaterialProperty blendModeProp;
private MaterialProperty mainTexProp;

private MaterialProperty bumpMap;
private MaterialEditor m_MaterialEditor;
private static class Styles
{

public static GUIContent sampleGILabel = new GUIContent("Sample GI", "If enabled GI will be sampled from SH or Lightmap.");
}
private void FindMaterialProperties(MaterialProperty[] properties)
public override void FindProperties(MaterialProperty[] properties)
{
blendModeProp = FindProperty("_Mode", properties);
mainTexProp = FindProperty("_MainTex", properties);

bumpMap = FindProperty("_BumpMap", properties, false);
}
private void DoPopup(string label, MaterialProperty property, string[] options)
public override void ShaderPropertiesGUI(Material material)
EditorGUI.showMixedValue = property.hasMixedValue;
var mode = property.floatValue;
EditorGUI.BeginChangeCheck();
mode = EditorGUILayout.Popup(label, (int)mode, options);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo(label);
property.floatValue = mode;
}
EditorGUI.showMixedValue = false;
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
m_MaterialEditor = materialEditor;
FindMaterialProperties(properties);
EditorGUI.BeginChangeCheck();
{
DoPopup(Styles.renderingModeLabel, blendModeProp, Styles.blendNames);

EditorGUILayout.Space();
EditorGUILayout.Space();
materialEditor.RenderQueueField();
}
if (EditorGUI.EndChangeCheck())
{

EditorGUILayout.Space();
}
private void MaterialChanged(Material material)
public override void MaterialChanged(Material material)
LightweightShaderHelper.SetMaterialBlendMode(material);
LightweightShaderHelper.SetKeyword(material, "_SAMPLE_GI", sampleGI);
LightweightShaderHelper.SetKeyword(material, "_NORMAL_MAP", sampleGI && material.GetTexture("_BumpMap"));
SetupMaterialBlendMode(material);
CoreUtils.SetKeyword(material, "_SAMPLE_GI", sampleGI);
CoreUtils.SetKeyword(material, "_NORMAL_MAP", sampleGI && material.GetTexture("_BumpMap"));
}
}

2
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta


fileFormatVersion: 2
guid: d639cdbf740deb94687e01a181ea790a
guid: aec5479bdc442cb4d96b1de3f5e5c818
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMatTexture_08.mat


m_PrefabInternal: {fileID: 0}
m_Name: 007_LitShaderMaps_UnlitMatTexture_08
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords: _SAMPLE_GI
m_ShaderKeywords: _NORMAL_MAP _SAMPLE_GI
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

2
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMat_07.mat


m_PrefabInternal: {fileID: 0}
m_Name: 007_LitShaderMaps_UnlitMat_07
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords: _ALPHABLEND_ON _SAMPLE_GI
m_ShaderKeywords: _ALPHABLEND_ON _NORMAL_MAP _SAMPLE_GI
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0

261
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public class LightweightMaterialUpgrader
{
[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Project Materials", priority = CoreUtils.editMenuPriority2)]
private static void UpgradeProjectMaterials()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to Lightweight Pipeline Materials");
}
[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Selected Materials", priority = CoreUtils.editMenuPriority2)]
private static void UpgradeSelectedMaterials()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to Lightweight Pipeline Materials");
}
private static void GetUpgraders(ref List<MaterialUpgrader> upgraders)
{
/////////////////////////////////////
// Unity Standard Upgraders //
/////////////////////////////////////
upgraders.Add(new StandardUpgrader("Standard"));
upgraders.Add(new StandardUpgrader("Standard (Specular setup)"));
/////////////////////////////////////
// Legacy Shaders upgraders /
/////////////////////////////////////
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Specular", SupportedUpgradeParams.specularOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Bumped Specular", SupportedUpgradeParams.specularOpaque));
// TODO:
//upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Reflective/Bumped Diffuse", SupportedUpgradeParams.diffuseCubemap));
//upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Reflective/Bumped Specular", SupportedUpgradeParams.specularOpaque));
//upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Reflective/Diffuse", SupportedUpgradeParams.diffuseCubemap));
//upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Reflective/Specular", SupportedUpgradeParams.specularOpaque));
// Self-Illum upgrader
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Self-Illumin/Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Self-Illumin/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Self-Illumin/Specular", SupportedUpgradeParams.specularOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Self-Illumin/Bumped Specular", SupportedUpgradeParams.specularOpaque));
// Alpha Blended
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Diffuse", SupportedUpgradeParams.diffuseAlpha));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Specular", SupportedUpgradeParams.specularAlpha));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Bumped Diffuse", SupportedUpgradeParams.diffuseAlpha));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Bumped Specular", SupportedUpgradeParams.specularAlpha));
// Cutout
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Cutout/Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Cutout/Specular", SupportedUpgradeParams.specularAlphaCutout));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Diffuse", SupportedUpgradeParams.diffuseAlphaCutout));
upgraders.Add(new StandardSimpleLightingUpgrader("Legacy Shaders/Transparent/Cutout/Bumped Specular", SupportedUpgradeParams.specularAlphaCutout));
/////////////////////////////////////
// Mobile Upgraders /
/////////////////////////////////////
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/Bumped Specular", SupportedUpgradeParams.specularOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/Bumped Specular (1 Directional Light)", SupportedUpgradeParams.specularOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/Bumped Diffuse", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/Unlit (Supports Lightmap)", SupportedUpgradeParams.diffuseOpaque));
upgraders.Add(new StandardSimpleLightingUpgrader("Mobile/VertexLit", SupportedUpgradeParams.specularOpaque));
////////////////////////////////////
// Terrain Upgraders //
////////////////////////////////////
upgraders.Add(new TerrainUpgrader("Nature/Terrain/Standard"));
////////////////////////////////////
// Particle Upgraders //
////////////////////////////////////
upgraders.Add(new ParticleUpgrader("Particles/Standard Surface"));
upgraders.Add(new ParticleUpgrader("Particles/Standard Unlit"));
}
}
public static class SupportedUpgradeParams
{
static public UpgradeParams diffuseOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams diffuseAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams specularAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams diffuseAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams specularAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams diffuseCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams diffuseCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
}
public class StandardUpgrader : MaterialUpgrader
{
public static void UpdateStandardMaterialKeywords(Material material)
{
material.SetFloat("_WorkflowMode", 1.0f);
CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
}
public static void UpdateStandardSpecularMaterialKeywords(Material material)
{
material.SetFloat("_WorkflowMode", 0.0f);
CoreUtils.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
CoreUtils.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
CoreUtils.SetKeyword(material, "_SPECULAR_SETUP", true);
}
public StandardUpgrader(string oldShaderName)
{
string standardShaderPath = LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_PBS);
if (oldShaderName.Contains("Specular"))
RenameShader(oldShaderName, standardShaderPath, UpdateStandardSpecularMaterialKeywords);
else
RenameShader(oldShaderName, standardShaderPath, UpdateStandardMaterialKeywords);
}
}
public class StandardSimpleLightingUpgrader : MaterialUpgrader
{
public StandardSimpleLightingUpgrader(string oldShaderName, UpgradeParams upgradeParams)
{
RenameShader(oldShaderName, LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_SIMPLE_LIGHTING), UpdateMaterialKeywords);
SetFloat("_Mode", (float)upgradeParams.blendMode);
SetFloat("_SpecSource", (float)upgradeParams.specularSource);
SetFloat("_GlossinessSource", (float)upgradeParams.glosinessSource);
if (oldShaderName.Contains("Legacy Shaders/Self-Illumin"))
{
RenameTexture("_MainTex", "_EmissionMap");
RemoveTexture("_MainTex");
SetColor("_EmissionColor", Color.white);
}
}
public static void UpdateMaterialKeywords(Material material)
{
material.shaderKeywords = null;
LightweightShaderGUI.SetupMaterialBlendMode(material);
UpdateMaterialSpecularSource(material);
CoreUtils.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
// A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
// or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
// The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color.
MaterialEditor.FixupEmissiveFlag(material);
bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
CoreUtils.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
}
private static void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource");
if (specSource == SpecularSource.NoSpecular)
{
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", false);
CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", false);
CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
}
else
{
GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource");
bool hasGlossMap = material.GetTexture("_SpecGlossMap");
CoreUtils.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap);
CoreUtils.SetKeyword(material, "_SPECULAR_COLOR", !hasGlossMap);
CoreUtils.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", glossSource == GlossinessSource.BaseAlpha);
}
}
}
public class TerrainUpgrader : MaterialUpgrader
{
public TerrainUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_TERRAIN));
}
}
public class ParticleUpgrader : MaterialUpgrader
{
public ParticleUpgrader(string oldShaderName)
{
if (oldShaderName.Contains("Unlit"))
RenameShader(oldShaderName, LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_PARTICLES_UNLIT));
else
RenameShader(oldShaderName, LightweightShaderUtils.GetShaderPath(ShaderPathID.STANDARD_PARTICLES_LIT));
}
}
}

101
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs


using UnityEditor;
using UnityEngine;
public abstract class LightweightShaderGUI : ShaderGUI
{
public enum BlendMode
{
Opaque,
Cutout,
Fade, // Old school alpha-blending mode, fresnel does not affect amount of transparency
Transparent // Physically plausible transparency mode, implemented as alpha pre-multiply
}
public abstract void FindProperties(MaterialProperty[] props);
public abstract void ShaderPropertiesGUI(Material material);
public abstract void MaterialChanged(Material material);
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
FindProperties(properties); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor;
Material material = materialEditor.target as Material;
// Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing
// material to a lightweight shader.
if (m_FirstTimeApply)
{
MaterialChanged(material);
m_FirstTimeApply = false;
}
ShaderPropertiesGUI(material);
}
protected void DoPopup(string label, MaterialProperty property, string[] options)
{
EditorGUI.showMixedValue = property.hasMixedValue;
var mode = property.floatValue;
EditorGUI.BeginChangeCheck();
mode = EditorGUILayout.Popup(label, (int)mode, options);
if (EditorGUI.EndChangeCheck())
{
m_MaterialEditor.RegisterPropertyChangeUndo(label);
property.floatValue = (float)mode;
}
EditorGUI.showMixedValue = false;
}
public static void SetupMaterialBlendMode(Material material)
{
BlendMode blendMode = (BlendMode) material.GetFloat("_Mode");
switch (blendMode)
{
case BlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = -1;
break;
case BlendMode.Cutout:
material.SetOverrideTag("RenderType", "TransparentCutout");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
break;
case BlendMode.Fade:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHABLEND_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
case BlendMode.Transparent:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHABLEND_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
}
}
protected MaterialEditor m_MaterialEditor;
private bool m_FirstTimeApply = true;
}

11
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs.meta


fileFormatVersion: 2
guid: 5faac1f019b9d88418c3721b7845b4d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

44
ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs


namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
public enum ShaderPathID
{
STANDARD_PBS = 0,
STANDARD_SIMPLE_LIGHTING,
STANDARD_UNLIT,
STANDARD_TERRAIN,
STANDARD_PARTICLES_LIT,
STANDARD_PARTICLES_UNLIT,
HIDDEN_BLIT,
HIDDEN_DEPTH_COPY,
SHADER_PATH_COUNT
}
public static class LightweightShaderUtils
{
private static readonly string[] m_ShaderPaths =
{
"LightweightPipeline/Standard (Physically Based)",
"LightweightPipeline/Standard (Simple Lighting)",
"LightweightPipeline/Standard Unlit",
"LightweightPipeline/Standard Terrain",
"LightweightPipeline/Particles/Standard",
"LightweightPipeline/Particles/Standard Unlit",
"Hidden/LightweightPipeline/Blit",
"Hidden/LightweightPipeline/CopyDepth"
};
public static string GetShaderPath(ShaderPathID id)
{
int index = (int) id;
if (index < 0 && index >= (int) ShaderPathID.SHADER_PATH_COUNT)
{
Debug.LogError("Trying to access lightweight shader path out of bounds");
return "";
}
return m_ShaderPaths[index];
}
}
}

11
ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs.meta


fileFormatVersion: 2
guid: a59ed397e0917cd4aa1de2bb1495fead
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs.meta


fileFormatVersion: 2
guid: 50feba52dc59c9943b45f22d41904a77
timeCreated: 1490024332
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs.meta


fileFormatVersion: 2
guid: 6d97da3faef6c8a46bc29fcc467932b4
timeCreated: 1489573636
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

53
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs


using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public static class LightweightShaderHelper
{
public static void SetMaterialBlendMode(Material material)
{
UpgradeBlendMode mode = (UpgradeBlendMode) material.GetFloat("_Mode");
switch (mode)
{
case UpgradeBlendMode.Opaque:
material.SetOverrideTag("RenderType", "");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = -1;
break;
case UpgradeBlendMode.Cutout:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.One);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.Zero);
material.SetInt("_ZWrite", 1);
SetKeyword(material, "_ALPHATEST_ON", true);
SetKeyword(material, "_ALPHABLEND_ON", false);
material.renderQueue = (int) RenderQueue.AlphaTest;
break;
case UpgradeBlendMode.Alpha:
material.SetOverrideTag("RenderType", "Transparent");
material.SetInt("_SrcBlend", (int) UnityEngine.Rendering.BlendMode.SrcAlpha);
material.SetInt("_DstBlend", (int) UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
material.SetInt("_ZWrite", 0);
SetKeyword(material, "_ALPHATEST_ON", false);
SetKeyword(material, "_ALPHABLEND_ON", true);
material.renderQueue = (int) RenderQueue.Transparent;
break;
}
}
public static void SetKeyword(Material material, string keyword, bool enable)
{
if (enable)
material.EnableKeyword(keyword);
else
material.DisableKeyword(keyword);
}
}
}

12
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta


fileFormatVersion: 2
guid: 673aad8cdc228cf499f7974fb673fa10
timeCreated: 1496821330
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

75
ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs


using System.Collections.Generic;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public class LegacyShadersToLightweightPipelineUpgrader
{
//[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Legacy Materials to Lightweight Pipeline (Project)", priority = CoreUtils.editMenuPriority)]
//public static void UpgradeMaterialsToLDProject()
//{
// List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
// GetUpgraders(ref materialUpgraders);
// MaterialUpgrader.UpgradeProjectFolder(materialUpgraders, "Upgrade to LD Materials");
//}
//[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Legacy Materials to Lightweight Pipeline (Selection)", priority = CoreUtils.editMenuPriority)]
//public static void UpgradeMaterialsToLDSelection()
//{
// List<MaterialUpgrader> materialUpgraders = new List<MaterialUpgrader>();
// GetUpgraders(ref materialUpgraders);
// MaterialUpgrader.UpgradeSelection(materialUpgraders, "Upgrade to Lightweight Materials");
//}
private static void GetUpgraders(ref List<MaterialUpgrader> materialUpgraders)
{
/////////////////////////////////////
// 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));
// TODO: option to use environment map as texture or use reflection probe
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));
// Self-Illum upgrader
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));
// Alpha Blended
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));
// Cutout
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));
/////////////////////////////////////
// Reflective Shader Upgraders /
/////////////////////////////////////
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));
/////////////////////////////////////
// Mobile Upgraders /
/////////////////////////////////////
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));
}
}
}

165
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public static class SupportedUpgradeParams
{
static public UpgradeParams diffuseOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularOpaque = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams diffuseAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams specularAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams diffuseAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams specularAlphaCutout = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Cutout,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.SpecularAlpha,
};
static public UpgradeParams diffuseCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularCubemap = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Opaque,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams diffuseCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.NoSpecular,
glosinessSource = GlossinessSource.BaseAlpha,
};
static public UpgradeParams specularCubemapAlpha = new UpgradeParams()
{
blendMode = UpgradeBlendMode.Alpha,
specularSource = SpecularSource.SpecularTextureAndColor,
glosinessSource = GlossinessSource.BaseAlpha,
};
}
public class LegacyBlinnPhongUpgrader : MaterialUpgrader
{
public LegacyBlinnPhongUpgrader(string oldShaderName, UpgradeParams upgradeParams)
{
RenameShader(oldShaderName, LightweightPipelineAsset.m_SimpleLightShaderPath, UpdateMaterialKeywords);
SetFloat("_Mode", (float)upgradeParams.blendMode);
SetFloat("_SpecSource", (float)upgradeParams.specularSource);
SetFloat("_GlossinessSource", (float)upgradeParams.glosinessSource);
if (oldShaderName.Contains("Legacy Shaders/Self-Illumin"))
{
RenameTexture("_MainTex", "_EmissionMap");
RemoveTexture("_MainTex");
SetColor("_EmissionColor", Color.white);
}
}
public static void UpdateMaterialKeywords(Material material)
{
material.shaderKeywords = null;
LightweightShaderHelper.SetMaterialBlendMode(material);
UpdateMaterialSpecularSource(material);
LightweightShaderHelper.SetKeyword(material, "_NORMALMAP", material.GetTexture("_BumpMap"));
// A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
// or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
// The fixup routine makes sure that the material is in the correct state if/when changes are made to the mode or color.
MaterialEditor.FixupEmissiveFlag(material);
bool shouldEmissionBeEnabled = (material.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
LightweightShaderHelper.SetKeyword(material, "_EMISSION", shouldEmissionBeEnabled);
}
private static void UpdateMaterialSpecularSource(Material material)
{
SpecularSource specSource = (SpecularSource)material.GetFloat("_SpecSource");
if (specSource == SpecularSource.NoSpecular)
{
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", false);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", false);
LightweightShaderHelper.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", false);
}
else
{
GlossinessSource glossSource = (GlossinessSource)material.GetFloat("_GlossinessSource");
bool hasGlossMap = material.GetTexture("_SpecGlossMap");
LightweightShaderHelper.SetKeyword(material, "_SPECGLOSSMAP", hasGlossMap);
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_COLOR", !hasGlossMap);
LightweightShaderHelper.SetKeyword(material, "_GLOSSINESS_FROM_BASE_ALPHA", glossSource == GlossinessSource.BaseAlpha);
}
}
}
public class StandardUpgrader : MaterialUpgrader
{
public static void UpdateStandardMaterialKeywords(Material material)
{
material.SetFloat("_WorkflowMode", 1.0f);
LightweightShaderHelper.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
LightweightShaderHelper.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_MetallicGlossMap"));
}
public static void UpdateStandardSpecularMaterialKeywords(Material material)
{
material.SetFloat("_WorkflowMode", 0.0f);
LightweightShaderHelper.SetKeyword(material, "_OCCLUSIONMAP", material.GetTexture("_OcclusionMap"));
LightweightShaderHelper.SetKeyword(material, "_METALLICSPECGLOSSMAP", material.GetTexture("_SpecGlossMap"));
LightweightShaderHelper.SetKeyword(material, "_SPECULAR_SETUP", true);
}
public StandardUpgrader(string oldShaderName)
{
if (oldShaderName.Contains("Specular"))
RenameShader(oldShaderName, LightweightPipelineAsset.m_StandardShaderPath, UpdateStandardSpecularMaterialKeywords);
else
RenameShader(oldShaderName, LightweightPipelineAsset.m_StandardShaderPath, UpdateStandardMaterialKeywords);
}
}
public class TerrainUpgrader : MaterialUpgrader
{
public TerrainUpgrader(string oldShaderName)
{
RenameShader(oldShaderName, LightweightPipelineAsset.m_StandardShaderPath);
SetFloat("_Shininess", 1.0f);
}
}
}

32
ScriptableRenderPipeline/LightweightPipeline/Editor/StandardToLightweightMaterialUpgrader.cs


using System.Collections.Generic;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
{
public class StandardToLightweightMaterialUpgrader
{
[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Project Materials", priority = CoreUtils.editMenuPriority2)]
private static void UpgradeMaterialsToLDProject()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeProjectFolder(upgraders, "Upgrade to Lightweight Pipeline Materials");
}
[MenuItem("Edit/Render Pipeline/Upgrade/Lightweight/Upgrade Selected Materials", priority = CoreUtils.editMenuPriority2)]
private static void UpgradeMaterialsToLDSelection()
{
List<MaterialUpgrader> upgraders = new List<MaterialUpgrader>();
GetUpgraders(ref upgraders);
MaterialUpgrader.UpgradeSelection(upgraders, "Upgrade to Lightweight Pipeline Materials");
}
private static void GetUpgraders(ref List<MaterialUpgrader> upgraders)
{
upgraders.Add(new StandardUpgrader("Standard (Specular setup)"));
upgraders.Add(new StandardUpgrader("Standard"));
}
}
}

/ScriptableRenderPipeline/LightweightPipeline/Editor/StandardToLightweightMaterialUpgrader.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta

正在加载...
取消
保存