Felipe Lira
7 年前
当前提交
c62e8861
共有 22 个文件被更改,包括 574 次插入 和 1528 次删除
-
999ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png
-
6ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png.meta
-
8ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs
-
192ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs
-
63ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
-
39ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs
-
2ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta
-
2Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMatTexture_08.mat
-
2Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMat_07.mat
-
261ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs
-
101ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs
-
11ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs.meta
-
44ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs
-
11ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs.meta
-
12ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs.meta
-
12ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs.meta
-
53ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs
-
12ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta
-
75ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs
-
165ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs
-
32ScriptableRenderPipeline/LightweightPipeline/Editor/StandardToLightweightMaterialUpgrader.cs
-
0/ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta
999
ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
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; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5faac1f019b9d88418c3721b7845b4d2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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]; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a59ed397e0917cd4aa1de2bb1495fead |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 50feba52dc59c9943b45f22d41904a77 |
|||
timeCreated: 1490024332 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6d97da3faef6c8a46bc29fcc467932b4 |
|||
timeCreated: 1489573636 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 673aad8cdc228cf499f7974fb673fa10 |
|||
timeCreated: 1496821330 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
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")); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue