浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into add-xbone-one-support

/asmdef
sebastienlagarde 7 年前
当前提交
c9ee9e33
共有 56 个文件被更改,包括 1573 次插入3021 次删除
  1. 999
      ImageTemplates/LightweightPipeline/Scenes/007_LitShaderMaps.unity.png
  2. 999
      ImageTemplates/LightweightPipeline/Scenes/016_Lighting_Scene_Directional.unity.png
  3. 14
      ImageTemplates/LightweightPipeline/Scenes/016_Lighting_Scene_Directional.unity.png.meta
  4. 999
      ImageTemplates/LightweightPipeline/Scenes/018_Lighting_Scene_DirectionalBakedIndirect.unity.png
  5. 14
      ImageTemplates/LightweightPipeline/Scenes/018_Lighting_Scene_DirectionalBakedIndirect.unity.png.meta
  6. 10
      ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs
  7. 25
      ScriptableRenderPipeline/Core/Volume/Editor/VolumeEditor.cs
  8. 6
      ScriptableRenderPipeline/Core/Volume/VolumeManager.cs
  9. 10
      ScriptableRenderPipeline/Core/Volume/VolumeParameter.cs
  10. 47
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDEditorUtils.cs
  11. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  12. 12
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  13. 10
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  14. 10
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoopDef.hlsl
  15. 30
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  16. 57
      ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs
  17. 2
      ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineResource.cs
  18. 72
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetEditor.cs
  19. 2
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightCameraEditor.cs
  20. 6
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightLightEditor.cs
  21. 200
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs
  22. 2
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardParticlesShaderGUI.cs
  23. 66
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardSimpleLightingGUI.cs
  24. 43
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightUnlitGUI.cs
  25. 2
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta
  26. 2
      ScriptableRenderPipeline/LightweightPipeline/LightweightConstantBuffer.cs
  27. 43
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  28. 16
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs
  29. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBlit.shader
  30. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCopyDepth.shader
  31. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc
  32. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  33. 62
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc
  34. 3
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader
  35. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader
  36. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticlesUnlit.shader
  37. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardTerrain.shader
  38. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightSurfaceInput.cginc
  39. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader
  40. 2
      ScriptableRenderPipeline/master-package.json
  41. 12
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset
  42. 2
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMatTexture_08.mat
  43. 2
      Tests/GraphicsTests/RenderPipeline/LightweightPipeline/Scenes/007_LitShaderMaps/007_LitShaderMaps_UnlitMat_07.mat
  44. 261
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs
  45. 101
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs
  46. 11
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightShaderGUI.cs.meta
  47. 44
      ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs
  48. 11
      ScriptableRenderPipeline/LightweightPipeline/LightweightShaderUtils.cs.meta
  49. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs.meta
  50. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs.meta
  51. 53
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs
  52. 12
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightShaderHelper.cs.meta
  53. 75
      ScriptableRenderPipeline/LightweightPipeline/Editor/LegacyShadersToLightweightPipelineUpgrader.cs
  54. 165
      ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightPipelineUpgraders.cs
  55. 32
      ScriptableRenderPipeline/LightweightPipeline/Editor/StandardToLightweightMaterialUpgrader.cs
  56. 0
      /ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightMaterialUpgrader.cs.meta

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

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

14
ImageTemplates/LightweightPipeline/Scenes/016_Lighting_Scene_Directional.unity.png.meta


fileFormatVersion: 2
guid: 9f96732e1ef8b493db200e6342576203
timeCreated: 1504695587
licenseType: Pro
serializedVersion: 4
serializedVersion: 5
mipmaps:
mipMapMode: 0
enableMipMap: 1

spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
- buildTarget: DefaultTexturePlatform
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1

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

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

14
ImageTemplates/LightweightPipeline/Scenes/018_Lighting_Scene_DirectionalBakedIndirect.unity.png.meta


fileFormatVersion: 2
guid: 89ed8247fbdb545f58bf8e0c6cf53d00
timeCreated: 1509372551
licenseType: Pro
serializedVersion: 4
serializedVersion: 5
mipmaps:
mipMapMode: 0
enableMipMap: 1

spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
- buildTarget: DefaultTexturePlatform
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1

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

10
ScriptableRenderPipeline/Core/Editor/MaterialUpgrader.cs


string m_OldShader;
string m_NewShader;
private static readonly string projectBackMessage = "Make sure to have a project backup before proceeding.";
MaterialFinalizer m_Finalizer;
Dictionary<string, string> m_TextureRename = new Dictionary<string, string>();

public static void UpgradeProjectFolder(List<MaterialUpgrader> upgraders, string progressBarName, UpgradeFlags flags = UpgradeFlags.None)
{
if (!EditorUtility.DisplayDialog("Material Upgrader", "The upgrade will overwrite material settings in your project." +
"Be sure to have a project backup before proceeding", "Proceed", "Cancel"))
if (!EditorUtility.DisplayDialog("Material Upgrader", "The upgrade will overwrite materials in your project. " + projectBackMessage, "Proceed", "Cancel"))
return;
int totalMaterialCount = 0;

if (upgrader != null)
upgrader.Upgrade(material, flags);
else if ((flags & UpgradeFlags.LogMessageWhenNoUpgraderFound) == UpgradeFlags.LogMessageWhenNoUpgraderFound)
Debug.Log(string.Format("There's no upgrader to convert {0} shader to selected pipeline", material.shader.name));
Debug.Log(string.Format("{0} material was not upgraded. There's no upgrader to convert {1} shader to selected pipeline", material.name, material.shader.name));
if (!EditorUtility.DisplayDialog("Material Upgrader", string.Format("The upgrade will possibly overwrite all the {0} selected material settings", selection.Length) +
"Be sure to have a project backup before proceeding", "Proceed", "Cancel"))
if (!EditorUtility.DisplayDialog("Material Upgrader", string.Format("The upgrade will overwrite {0} selected material{1}. ", selection.Length, (selection.Length > 1) ? "s" : "") +
projectBackMessage, "Proceed", "Cancel"))
return;
string lastMaterialName = "";

25
ScriptableRenderPipeline/Core/Volume/Editor/VolumeEditor.cs


Undo.DestroyObjectImmediate(prevSettings);
}
void MoveComponent(int id, int offset)
{
// Move components
serializedObject.Update();
m_Components.MoveArrayElement(id, id + offset);
serializedObject.ApplyModifiedProperties();
// Move editors
var prev = m_Editors[id + offset];
m_Editors[id + offset] = m_Editors[id];
m_Editors[id] = prev;
}
if (id == 0)
menu.AddDisabledItem(CoreEditorUtils.GetContent("Move Up"));
else
menu.AddItem(CoreEditorUtils.GetContent("Move Up"), false, () => MoveComponent(id, -1));
if (id == m_Editors.Count - 1)
menu.AddDisabledItem(CoreEditorUtils.GetContent("Move Down"));
else
menu.AddItem(CoreEditorUtils.GetContent("Move Down"), false, () => MoveComponent(id, 1));
menu.AddSeparator(string.Empty);
menu.AddItem(CoreEditorUtils.GetContent("Reset"), false, () => ResetComponent(targetComponent.GetType(), id));
menu.AddItem(CoreEditorUtils.GetContent("Remove"), false, () => RemoveComponent(id));
menu.AddSeparator(string.Empty);

6
ScriptableRenderPipeline/Core/Volume/VolumeManager.cs


float blendDistSqr = volume.blendDistance * volume.blendDistance;
// Volume has no influence, ignore it
// Note: Volume doesn't do anything when `closestDistanceSqr = blendDistSqr` but
// we can't use a >= comparison as blendDistSqr could be set to 0 in which
// case volume would have total influence
// Note: Volume doesn't do anything when `closestDistanceSqr = blendDistSqr` but we
// can't use a >= comparison as blendDistSqr could be set to 0 in which case
// volume would have total influence
if (closestDistanceSqr > blendDistSqr)
continue;

10
ScriptableRenderPipeline/Core/Volume/VolumeParameter.cs


return string.Format("{0} ({1})", value, overrideState);
}
public static bool operator ==(VolumeParameter<T> lhs, T rhs)
{
return lhs.value.Equals(rhs);
}
public static bool operator !=(VolumeParameter<T> lhs, T rhs)
{
return !(lhs == rhs);
}
//
// Implicit conversion; assuming the following:
//

47
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDEditorUtils.cs


using System;
using System.Linq;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline

{ "HDRenderPipeline/Unlit", UnlitGUI.SetupMaterialKeywordsAndPass }
};
public static string GetHDRenderPipelinePath()
// Note: This function returns null if used with a package setup.
static string GetScriptableRenderPipelinePath()
// We know that DefaultHDMaterial exist and we know where it is, let's use that to find the current directory.
var guid = AssetDatabase.FindAssets("DefaultHDMaterial t:material");
string path = AssetDatabase.GUIDToAssetPath(guid[0]);
path = Path.GetDirectoryName(path); // Asset is in HDRenderPipeline/RenderPipelineResources/DefaultHDMaterial.mat
path = path.Replace("RenderPipelineResources", ""); // Keep only path with HDRenderPipeline
return path;
// We do that using the SRPMARKER file.
var srpMarkerPath = Directory.GetFiles(Application.dataPath, "SRPMARKER", SearchOption.AllDirectories).FirstOrDefault();
if (srpMarkerPath != null)
return new Uri(Application.dataPath).MakeRelativeUri(new Uri(Directory.GetParent(srpMarkerPath).ToString())).ToString();
return null;
// TODO: The following functions depend on HDRP, they should be made generic
public static string GetScriptableRenderPipelinePath()
public static string GetHDRenderPipelinePath()
var hdrpPath = GetHDRenderPipelinePath();
var fullPath = Path.GetFullPath(hdrpPath + "../");
var relativePath = fullPath.Substring(fullPath.IndexOf("Assets"));
return relativePath.Replace("\\", "/") + "/";
var srpPath = GetScriptableRenderPipelinePath();
if (srpPath != null)
return Path.Combine(srpPath, "ScriptableRenderPipeline/HDRenderPipeline/");
// If the SRPMARKER is not found, we assume that a package setup is used.
return "Packages/com.unity.render-pipelines.high-quality/";
var hdrpPath = GetHDRenderPipelinePath();
var fullPath = Path.GetFullPath(hdrpPath + "../../PostProcessing/PostProcessing");
var relativePath = fullPath.Substring(fullPath.IndexOf("Assets"));
return relativePath.Replace("\\", "/") + "/";
var srpPath = GetScriptableRenderPipelinePath();
if (srpPath != null)
return Path.Combine(srpPath, "PostProcessing/PostProcessing/");
// If the SRPMARKER is not found, we assume that a package setup is used.
return "Packages/com.unity.postprocessing/";
var hdrpPath = GetHDRenderPipelinePath();
var fullPath = Path.GetFullPath(hdrpPath + "../Core");
var relativePath = fullPath.Substring(fullPath.IndexOf("Assets"));
return relativePath.Replace("\\", "/") + "/";
var srpPath = GetScriptableRenderPipelinePath();
if (srpPath != null)
return Path.Combine(srpPath, "ScriptableRenderPipeline/Core/");
// If the SRPMARKER is not found, we assume that a package setup is used.
return "Packages/com.unity.render-pipelines.core/";
}
public static bool ResetMaterialKeywords(Material material)

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public struct DirectionalLightData
{
public Vector3 positionWS;
public bool tileCookie;
public int tileCookie; // TODO: make it a bool
public Vector3 color;
public int shadowIndex; // -1 if unused

public Vector2 fadeDistanceScaleAndBias; // Use with ShadowMask feature
public float unused0;
public bool dynamicShadowCasterOnly; // Use with ShadowMask feature
public int dynamicShadowCasterOnly; // Use with ShadowMask feature // TODO: make it a bool
public Vector4 shadowMaskSelector; // Use with ShadowMask feature
};

public float angleScale; // Spot light
public float angleOffset; // Spot light
public float shadowDimmer;
public bool dynamicShadowCasterOnly; // Use with ShadowMask feature
public int dynamicShadowCasterOnly; // Use with ShadowMask feature // TODO: make it a bool
public Vector4 shadowMaskSelector; // Use with ShadowMask feature

12
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


struct DirectionalLightData
{
float3 positionWS;
bool tileCookie;
int tileCookie;
float3 color;
int shadowIndex;
float3 forward;

float diffuseScale;
float2 fadeDistanceScaleAndBias;
float unused0;
bool dynamicShadowCasterOnly;
int dynamicShadowCasterOnly;
float4 shadowMaskSelector;
};

float angleScale;
float angleOffset;
float shadowDimmer;
bool dynamicShadowCasterOnly;
int dynamicShadowCasterOnly;
float4 shadowMaskSelector;
float2 size;
int lightType;

{
return value.positionWS;
}
bool GetTileCookie(DirectionalLightData value)
int GetTileCookie(DirectionalLightData value)
{
return value.tileCookie;
}

{
return value.unused0;
}
bool GetDynamicShadowCasterOnly(DirectionalLightData value)
int GetDynamicShadowCasterOnly(DirectionalLightData value)
{
return value.dynamicShadowCasterOnly;
}

{
return value.shadowDimmer;
}
bool GetDynamicShadowCasterOnly(LightData value)
int GetDynamicShadowCasterOnly(LightData value)
{
return value.dynamicShadowCasterOnly;
}

10
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


if (light.light.cookie != null)
{
directionalLightData.tileCookie = light.light.cookie.wrapMode == TextureWrapMode.Repeat;
directionalLightData.tileCookie = light.light.cookie.wrapMode == TextureWrapMode.Repeat ? 1 : 0;
directionalLightData.cookieIndex = m_CookieTexArray.FetchSlice(cmd, light.light.cookie);
}
// fix up shadow information

{
directionalLightData.shadowMaskSelector[light.light.bakingOutput.occlusionMaskChannel] = 1.0f;
// TODO: make this option per light, not global
directionalLightData.dynamicShadowCasterOnly = QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask;
directionalLightData.dynamicShadowCasterOnly = QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask ? 1 : 0;
directionalLightData.dynamicShadowCasterOnly = false;
directionalLightData.dynamicShadowCasterOnly = 0;
}
m_CurrentSunLight = m_CurrentSunLight == null ? light.light : m_CurrentSunLight;

{
lightData.shadowMaskSelector[light.light.bakingOutput.occlusionMaskChannel] = 1.0f;
// TODO: make this option per light, not global
lightData.dynamicShadowCasterOnly = QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask;
lightData.dynamicShadowCasterOnly = QualitySettings.shadowmaskMode == ShadowmaskMode.Shadowmask ? 1 : 0;
lightData.dynamicShadowCasterOnly = false;
lightData.dynamicShadowCasterOnly = 0;
}
m_lightList.lights.Add(lightData);

10
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoopDef.hlsl


// ----------------------------------------------------------------------------
// Used by directional and spot lights.
// Returns the color in the RGB components, and the transparency (lack of occlusion) in A.
float4 SampleCookie2D(LightLoopContext lightLoopContext, float2 coord, int index)
float3 SampleCookie2D(LightLoopContext lightLoopContext, float2 coord, int index)
return SAMPLE_TEXTURE2D_ARRAY_LOD(_CookieTextures, sampler_CookieTextures, coord, index, 0);
return SAMPLE_TEXTURE2D_ARRAY_LOD(_CookieTextures, sampler_CookieTextures, coord, index, 0).rgb;
// Returns the color in the RGB components, and the transparency (lack of occlusion) in A.
float4 SampleCookieCube(LightLoopContext lightLoopContext, float3 coord, int index)
float3 SampleCookieCube(LightLoopContext lightLoopContext, float3 coord, int index)
return SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_CookieCubeTextures, sampler_CookieCubeTextures, coord, index, 0);
return SAMPLE_TEXTURECUBE_ARRAY_LOD_ABSTRACT(_CookieCubeTextures, sampler_CookieCubeTextures, coord, index, 0).rgb;
}
//-----------------------------------------------------------------------------

30
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// EvaluateBSDF_Directional
//-----------------------------------------------------------------------------
float4 EvaluateCookie_Directional(LightLoopContext lightLoopContext, DirectionalLightData lightData,
float3 EvaluateCookie_Directional(LightLoopContext lightLoopContext, DirectionalLightData lightData,
float3 lighToSample)
{
// Compute the CS position (in [-1, 1]^2) by projecting 'positionWS' onto the near plane.

float2 positionCS = positionLS.xy;
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2.
float2 positionNDC = positionCS * 0.5 + 0.5;
bool isInBounds = lightData.tileCookie || max(abs(positionCS.x), abs(positionCS.y)) <= 1.0;
// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2.
float2 positionNDC = frac(positionCS * 0.5 + 0.5);
positionNDC = lightData.tileCookie ? frac(positionNDC) : positionNDC;
float4 cookie = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex);
cookie.a = isInBounds ? cookie.a : 0;
return cookie;
return SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex);
}
// None of the outputs are premultiplied.

[branch] if (lightData.cookieIndex >= 0)
{
float3 lightToSample = positionWS - lightData.positionWS;
float4 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample);
float3 cookie = EvaluateCookie_Directional(lightLoopContext, lightData, lightToSample);
color *= cookie.rgb;
attenuation *= cookie.a;
color *= cookie;
}
}

[branch] if (lightType == GPULIGHTTYPE_POINT)
{
cookie = SampleCookieCube(lightLoopContext, positionLS, lightData.cookieIndex);
cookie.rgb = SampleCookieCube(lightLoopContext, positionLS, lightData.cookieIndex);
cookie.a = 1;
}
else
{

// Remap the texture coordinates from [-1, 1]^2 to [0, 1]^2.
float2 positionNDC = positionCS * 0.5 + 0.5;
// We let the sampler handle clamping to border.
cookie = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex);
cookie.a = isInBounds ? cookie.a : 0;
// Manually clamp to border (black).
cookie.rgb = SampleCookie2D(lightLoopContext, positionNDC, lightData.cookieIndex);
cookie.a = isInBounds ? 1 : 0;
}
return cookie;

57
ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineAsset.cs


{
public enum ShadowCascades
{
NO_CASCADES = 1,
TWO_CASCADES = 2,
FOUR_CASCADES = 4,
NO_CASCADES = 0,
TWO_CASCADES,
FOUR_CASCADES,
}
public enum ShadowType

{
_512 = 512,
_1024 = 1024,
_2048 = 2048
_2048 = 2048,
_4096 = 4096
}
public enum MSAAQuality

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

[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] private float m_RenderScale = 1.0f;
[SerializeField] private ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;
[SerializeField] private ShadowResolution m_ShadowAtlasResolution = ShadowResolution._1024;
[SerializeField] private ShadowResolution m_ShadowAtlasResolution = ShadowResolution._2048;
[SerializeField] private ShadowCascades m_ShadowCascades = ShadowCascades.NO_CASCADES;
[SerializeField] private ShadowCascades m_ShadowCascades = ShadowCascades.FOUR_CASCADES;
[SerializeField] private float m_Cascade2Split = 0.25f;
[SerializeField] private Vector3 m_Cascade4Split = new Vector3(0.067f, 0.2f, 0.467f);

[SerializeField] private Shader m_CopyDepthShader;
#if UNITY_EDITOR
#if UNITY_EDITOR
[UnityEditor.MenuItem("Assets/Create/Render Pipeline/Lightweight/Render Pipeline", priority = CoreUtils.assetCreateMenuPriority1)]
[UnityEditor.MenuItem("Assets/Create/Render Pipeline/Lightweight/Pipeline Asset", priority = CoreUtils.assetCreateMenuPriority1)]
static void CreateLightweightPipeline()
{
var instance = CreateInstance<LightweightPipelineAsset>();

// There's currently an issue that prevents FindAssets from find resources withing the package folder.
if (resourceAsset == null)
{
string path = "Packages/com.unity.render-pipelines.lightweight/Resources/LightweightPipelineResource.asset";
string path = "Packages/com.unity.render-pipelines.lightweight/Data/LightweightPipelineResource.asset";
resourceAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<LightweightPipelineResource>(path);
}

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));
"Please enter a file name to save the asset to");
"Please enter a file name to save the asset to");
#endif
protected override IRenderPipeline InternalCreatePipeline()

public int CascadeCount
{
get { return (int)m_ShadowCascades; }
private set { m_ShadowCascades = (ShadowCascades)value; }
get
{
switch (m_ShadowCascades)
{
case ShadowCascades.TWO_CASCADES:
return 2;
case ShadowCascades.FOUR_CASCADES:
return 4;
default:
return 1;
}
}
}
public float Cascade2Split

public override Material GetDefaultMaterial()
{
#if UNITY_EDITOR
#else
return null;
#endif
#if UNITY_EDITOR
#else
return null;
#endif
}
public override Material GetDefaultLineMaterial()

public override Material GetDefaultTerrainMaterial()
{
#if UNITY_EDITOR
#else
return null;
#endif
}
public override Material GetDefaultUIMaterial()

{
return null;
}
public override Shader GetDefaultShader()
{
return m_DefaultShader;

2
ScriptableRenderPipeline/LightweightPipeline/Data/LightweightPipelineResource.cs


using UnityEngine;
using UnityEngine;
public class LightweightPipelineResource : ScriptableObject
{

72
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightAssetEditor.cs


{
public static GUIContent renderingLabel = new GUIContent("Rendering");
public static GUIContent shadowLabel = new GUIContent("Shadows");
public static GUIContent defaults = new GUIContent("Defaults");
public static GUIContent defaults = new GUIContent("Default Materials");
public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Allows game to render at a resolution different than native resolution. UI is always rendered at native resolution.");
public static GUIContent renderScaleLabel = new GUIContent("Render Scale", "Scales the camera render target allowing the game to render at a resolution different than native resolution. UI is always rendered at native resolution. When in VR mode, VR scaling configuration is used instead.");
public static GUIContent maxPixelLightsLabel = new GUIContent("Max Pixel Lights",
public static GUIContent maxPixelLightsLabel = new GUIContent("Pixel Lights",
public static GUIContent enableVertexLightLabel = new GUIContent("Enable Vertex Light",
"If enabled, shades additional lights exceeding maxAdditionalPixelLights per-vertex up to the maximum of 8 lights.");
public static GUIContent enableVertexLightLabel = new GUIContent("Vertex Lighting",
"If enabled shades additional lights exceeding the maximum number of pixel lights per-vertex up to the maximum of 8 lights.");
public static GUIContent requireCameraDepthTexture = new GUIContent("Camera Depth Texture", "If enabled the the pipeline will generate depth texture necessary for some effects like soft particles.");
public static GUIContent requireCameraDepthTexture = new GUIContent("Camera Depth Texture", "If enabled the pipeline will generate camera's depth that can be bound in shaders as _CameraDepthTexture. This is necessary for some effect like Soft Particles.");
public static GUIContent shadowType = new GUIContent("Shadow Type",
"Single directional shadow supported. SOFT_SHADOWS applies shadow filtering.");
public static GUIContent shadowType = new GUIContent("Type",
"Global shadow settings. Options are NO_SHADOW, HARD_SHADOWS and SOFT_SHADOWS.");
public static GUIContent shadowNearPlaneOffset = new GUIContent("Shadow Near Plane Offset",
"Offset shadow near plane to account for large triangles being distorted by pancaking");
public static GUIContent shadowNearPlaneOffset = new GUIContent("Near Plane Offset",
"Offset shadow near plane to account for large triangles being distorted by pancaking.");
public static GUIContent shadowDistante = new GUIContent("Shadow Distance", "Max shadow drawing distance");
public static GUIContent shadowDistante = new GUIContent("Distance", "Max shadow rendering distance.");
public static GUIContent shadowAtlasResolution = new GUIContent("Shadow Map Resolution",
"Resolution of shadow map texture. If cascades are enabled all cascades will be packed into this texture resolution.");
public static GUIContent shadowAtlasResolution = new GUIContent("Shadowmap Resolution",
"Resolution of shadow map texture. If cascades are enabled, cascades will be packed into an atlas and this setting controls the max shadows atlas resolution.");
public static GUIContent shadowCascades = new GUIContent("Shadow Cascades",
"Number of cascades for directional shadows");
public static GUIContent shadowCascades = new GUIContent("Cascades",
"Number of cascades used in directional lights shadows");
public static GUIContent shadowCascadeSplit = new GUIContent("Shadow Cascade Split",
"Percentages to split shadow volume");
public static GUIContent shadowCascadeSplit = new GUIContent("Cascades Split",
"Percentages to split shadow volume");
public static GUIContent defaultMaterial = new GUIContent("Default Material",
"Material to use when creating 3D objects");
public static GUIContent defaultMaterial = new GUIContent("Mesh",
"Material to use when creating 3D objects");
public static GUIContent defaultParticleMaterial = new GUIContent("Particles",
"Material to use when creating Particle Systems");
public static GUIContent defaultParticleMaterial = new GUIContent("Default Particle Material",
"Material to use when creating Particle Systems");
public static GUIContent defaultTerrainMaterial = new GUIContent("Terrain",
"Material to use in Terrains");
public static GUIContent defaultTerrainMaterial = new GUIContent("Default Terrain Material",
"Material to use in Terrains");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing applied to all cameras.");
public static string[] shadowTypeOptions = {"No Shadows", "Hard Shadows", "Hard and Soft Shadows"};
public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
private float kMinRenderScale = 0.1f;
private float kMaxRenderScale = 4.0f;
private SerializedProperty m_RenderScale;
private SerializedProperty m_MaxPixelLights;
private SerializedProperty m_SupportsVertexLightProp;

m_MSAA = serializedObject.FindProperty("m_MSAA");
}
protected void DoPopup(GUIContent label, SerializedProperty property, string[] options)
{
var mode = property.intValue;
EditorGUI.BeginChangeCheck();
mode = EditorGUILayout.Popup(label, mode, options);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(property.objectReferenceValue, property.name);
property.intValue = mode;
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.renderScaleLabel);
m_RenderScale.floatValue = EditorGUILayout.Slider(m_RenderScale.floatValue, 0.1f, 1.0f);
m_RenderScale.floatValue = EditorGUILayout.Slider(m_RenderScale.floatValue, kMinRenderScale, kMaxRenderScale);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.maxPixelLightsLabel);

EditorGUILayout.LabelField(Styles.shadowLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_ShadowTypeProp, Styles.shadowType);
DoPopup(Styles.shadowType, m_ShadowTypeProp, Styles.shadowTypeOptions);
EditorGUILayout.PropertyField(m_ShadowCascadesProp, Styles.shadowCascades);
DoPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
if (cascades == ShadowCascades.FOUR_CASCADES)

2
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightCameraEditor.cs


using System;
using System;
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.Rendering;

6
ScriptableRenderPipeline/LightweightPipeline/Editor/LightweightLightEditor.cs


using UnityEditor.AnimatedValues;
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.Experimental.Rendering.LightweightPipeline;

get
{
return TypeIsSame && LightProperty.type == LightType.Point &&
ShadowTypeIsSame && IsShadowEnabled &&
LightmappingTypeIsSame && !settings.isCompletelyBaked;
ShadowTypeIsSame && IsShadowEnabled &&
LightmappingTypeIsSame && !settings.isCompletelyBaked;
}
}

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


using System;
using UnityEditor.Experimental.Rendering.LightweightPipeline;
using System;
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;
}

if (oldShader.name.Equals("Standard (Specular setup)"))
{
material.SetFloat("_WorkflowMode", (float) WorkflowMode.Specular);
material.SetFloat("_WorkflowMode", (float)WorkflowMode.Specular);
Texture texture = material.GetTexture("_SpecGlossMap");
if (texture != null)
material.SetTexture("_MetallicSpecGlossMap", texture);

material.SetFloat("_WorkflowMode", (float) WorkflowMode.Metallic);
material.SetFloat("_WorkflowMode", (float)WorkflowMode.Metallic);
Texture texture = material.GetTexture("_MetallicGlossMap");
if (texture != null)
material.SetTexture("_MetallicSpecGlossMap", texture);

}
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()

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)
{
// Emission for GI?

{
string[] metallicSpecSmoothnessChannelName;
bool hasGlossMap = false;
if ((WorkflowMode) workflowMode.floatValue == WorkflowMode.Metallic)
if ((WorkflowMode)workflowMode.floatValue == WorkflowMode.Metallic)
{
hasGlossMap = metallicGlossMap.textureValue != null;
metallicSpecSmoothnessChannelName = Styles.metallicSmoothnessChannelNames;

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);
}
}
}

2
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardParticlesShaderGUI.cs


using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

66
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);
}
EditorGUILayout.Space();
EditorGUILayout.Space();
private void SetMaterialKeywords(Material material)
{
material.shaderKeywords = null;
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 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()

int glossSource = (int)glossinessSourceProp.floatValue;
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMapProp,
albedoColorProp);
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);}
m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp);
}
else
{
m_MaterialEditor.TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMapProp, albedoColorProp);

43
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);
int modeValue = (int) blendModeProp.floatValue;
int modeValue = (int)blendModeProp.floatValue;
if ((UpgradeBlendMode) modeValue == UpgradeBlendMode.Cutout)
if ((UpgradeBlendMode)modeValue == UpgradeBlendMode.Cutout)
m_MaterialEditor.RangeProperty(alphaCutoffProp, Styles.alphaCutoffLabel);
EditorGUILayout.Space();

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
ScriptableRenderPipeline/LightweightPipeline/LightweightConstantBuffer.cs


using UnityEngine;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{

43
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


public Vector3 directionalLightCascades;
public float directionalLightNearPlaneOffset;
public RenderTextureFormat renderTextureFormat;
static ShadowSettings defaultShadowSettings = null;
public static ShadowSettings Default

defaultShadowSettings.directionalLightCascadeCount = 4;
defaultShadowSettings.directionalLightNearPlaneOffset = 5;
defaultShadowSettings.maxShadowDistance = 1000.0F;
defaultShadowSettings.renderTextureFormat = RenderTextureFormat.Shadowmap;
}
return defaultShadowSettings;
}

continue;
cullingParameters.shadowDistance = Mathf.Min(m_ShadowSettings.maxShadowDistance,
m_CurrCamera.farClipPlane);
m_CurrCamera.farClipPlane);
#if UNITY_EDITOR
// Emit scene view UI

// If no additional lights then no light sorting is performed and the indices match.
int shadowOriginalIndex = (lightData.totalAdditionalLightsCount > 0) ? GetLightUnsortedIndex(lightData.mainLightIndex) : lightData.mainLightIndex;
lightData.shadowsRendered = RenderShadows(ref m_CullResults, ref mainLight,
shadowOriginalIndex, ref context);
shadowOriginalIndex, ref context);
}
}
}

m_ShadowSettings.shadowAtlasWidth = m_Asset.ShadowAtlasResolution;
m_ShadowSettings.shadowAtlasHeight = m_Asset.ShadowAtlasResolution;
m_ShadowSettings.maxShadowDistance = m_Asset.ShadowDistance;
m_ShadowSettings.renderTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
? RenderTextureFormat.Shadowmap
: RenderTextureFormat.Depth;
switch (m_ShadowSettings.directionalLightCascadeCount)
{

m_IntermediateTextureArray = false;
bool intermediateTexture = m_CurrCamera.targetTexture != null || m_CurrCamera.cameraType == CameraType.SceneView ||
m_Asset.RenderScale < 1.0f || m_CurrCamera.allowHDR;
m_Asset.RenderScale < 1.0f || m_CurrCamera.allowHDR;
m_ColorFormat = m_CurrCamera.allowHDR ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
m_RequiredDepth = false;

}
Light light = lightData.light;
if (light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed)
if (light != null && light.bakingOutput.mixedLightingMode == MixedLightingMode.Subtractive && light.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed)
{
// TODO: Add support to shadow mask
if (m_MixedLightingSetup == MixedLightingSetup.None && lightData.light.shadows != LightShadows.None)

// We do it by settings the perObjectLightIndexMap to the appropriate additionalLightIndex.
perObjectLightIndexMap[GetLightUnsortedIndex(i)] = additionalLightIndex;
InitializeLightConstants(lights, i, out m_LightPositions[additionalLightIndex],
out m_LightColors[additionalLightIndex],
out m_LightDistanceAttenuations[additionalLightIndex],
out m_LightSpotDirections[additionalLightIndex],
out m_LightSpotAttenuations[additionalLightIndex]);
out m_LightColors[additionalLightIndex],
out m_LightDistanceAttenuations[additionalLightIndex],
out m_LightSpotDirections[additionalLightIndex],
out m_LightSpotAttenuations[additionalLightIndex]);
additionalLightIndex++;
}
}

lightData.totalAdditionalLightsCount, 0.0f, 0.0f));
lightData.totalAdditionalLightsCount, 0.0f, 0.0f));
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightPosition, m_LightPositions);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightColor, m_LightColors);
cmd.SetGlobalVectorArray(PerCameraBuffer._AdditionalLightDistanceAttenuation, m_LightDistanceAttenuations);

for (int i = 0; i < cascadeCount; ++i)
shadowMatrices[i] = (cascadeCount >= i) ? m_ShadowSlices[i].shadowTransform : Matrix4x4.identity;
// TODO: shadow resolution per cascade in case cascades endup being supported.
float invShadowResolution = 1.0f / shadowResolution;
float[] pcfKernel =
{
-0.5f * invShadowResolution, 0.5f * invShadowResolution,
0.5f * invShadowResolution, 0.5f * invShadowResolution,
-0.5f * invShadowResolution, -0.5f * invShadowResolution,
0.5f * invShadowResolution, -0.5f * invShadowResolution
};
float invShadowResolution = 0.5f / shadowResolution;
cmd.SetGlobalFloatArray("_PCFKernel", pcfKernel);
cmd.SetGlobalVector("_ShadowOffset0", new Vector4(-invShadowResolution, -invShadowResolution, 0.0f, 0.0f));
cmd.SetGlobalVector("_ShadowOffset1", new Vector4(invShadowResolution, -invShadowResolution, 0.0f, 0.0f));
cmd.SetGlobalVector("_ShadowOffset2", new Vector4(-invShadowResolution, invShadowResolution, 0.0f, 0.0f));
cmd.SetGlobalVector("_ShadowOffset3", new Vector4(invShadowResolution, invShadowResolution, 0.0f, 0.0f));
}
private void SetShaderKeywords(CommandBuffer cmd, ref LightData lightData, VisibleLight[] visibleLights)

var cmd = CommandBufferPool.Get();
cmd.name = "Render packed shadows";
cmd.GetTemporaryRT(m_ShadowMapRTID, m_ShadowSettings.shadowAtlasWidth,
m_ShadowSettings.shadowAtlasHeight, kShadowDepthBufferBits, FilterMode.Bilinear, RenderTextureFormat.Depth);
m_ShadowSettings.shadowAtlasHeight, kShadowDepthBufferBits, FilterMode.Bilinear, m_ShadowSettings.renderTextureFormat);
SetRenderTarget(cmd, m_ShadowMapRT, ClearFlag.All);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

if (m_RequiredDepth && !LightweightUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.DepthPass))
depthRT = m_DepthRT;
}
if (ForceClear())
{

16
ScriptableRenderPipeline/LightweightPipeline/LightweightPipelineUtils.cs


using System;
using System;
using System.Collections.Generic;
using UnityEngine.Rendering;

// Punctual lights are sorted per-object by the engine based on distance to object center + luminance
// Here we sort globally the light list per camera distance to fit the closest lights in the global light buffer
// Check MAX_VISIBLE_LIGHTS in the LightweightLighting.cginc to see the max global buffer list size
int lhsDistance = (int) (SquaredDistanceToCamera(lhsLight.transform.position)*100.0f);
int rhsDistance = (int) (SquaredDistanceToCamera(rhsLight.transform.position)*100.0f);
int lhsDistance = (int)(SquaredDistanceToCamera(lhsLight.transform.position) * 100.0f);
int rhsDistance = (int)(SquaredDistanceToCamera(rhsLight.transform.position) * 100.0f);
int result = lhsDistance - rhsDistance;
return result;
}

if (light.lightType == LightType.Directional)
{
float scale = 1.0f/light.light.cookieSize;
float scale = 1.0f / light.light.cookieSize;
cookieMatrix.SetRow(0, new Vector4(row0.x*scale, row0.y*scale, row0.z*scale, row0.w*scale + 0.5f));
cookieMatrix.SetRow(1, new Vector4(row1.x*scale, row1.y*scale, row1.z*scale, row1.w*scale + 0.5f));
cookieMatrix.SetRow(0, new Vector4(row0.x * scale, row0.y * scale, row0.z * scale, row0.w * scale + 0.5f));
cookieMatrix.SetRow(1, new Vector4(row1.x * scale, row1.y * scale, row1.z * scale, row1.w * scale + 0.5f));
}
else if (light.lightType == LightType.Spot)
{

{
new Vector3(-1.0f, -1.0f, 0.0f),
new Vector3(-1.0f, 1.0f, 0.0f),
new Vector3( 1.0f, -1.0f, 0.0f),
new Vector3( 1.0f, 1.0f, 0.0f)
new Vector3(1.0f, -1.0f, 0.0f),
new Vector3(1.0f, 1.0f, 0.0f)
};
mesh.uv = new Vector2[]

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightBlit.shader


Shader "Hidden/LightweightPipeline/Blit"
Shader "Hidden/LightweightPipeline/Blit"
{
SubShader
{

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightCopyDepth.shader


Shader "Hidden/LightweightPipeline/CopyDepth"
Shader "Hidden/LightweightPipeline/CopyDepth"
{
SubShader
{

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc


#ifndef LIGHTWEIGHT_INPUT_INCLUDED
#ifndef LIGHTWEIGHT_INPUT_INCLUDED
#define LIGHTWEIGHT_INPUT_INCLUDED
#define MAX_VISIBLE_LIGHTS 16

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


#ifndef LIGHTWEIGHT_LIGHTING_INCLUDED
#ifndef LIGHTWEIGHT_LIGHTING_INCLUDED
#define LIGHTWEIGHT_LIGHTING_INCLUDED
#include "LightweightCore.cginc"

62
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc


#define LIGHTWEIGHT_SHADOW_ATTENUATION(posWorld, vertexNormal, shadowDir) 1.0h
#endif
sampler2D_float _ShadowMap;
float _PCFKernel[8];
UNITY_DECLARE_SHADOWMAP(_ShadowMap);
half4 _ShadowData;
half4 _ShadowOffset0;
half4 _ShadowOffset1;
half4 _ShadowOffset2;
half4 _ShadowOffset3;
half4 _ShadowData; // (x: 1.0 - shadowStrength, y: bias, z: normal bias, w: near plane offset)
float ApplyDepthBias(float clipZ)
{
#ifdef UNITY_REVERSED_Z
return clipZ + _ShadowData.y;
#endif
return clipZ - _ShadowData.y;
}
inline half ShadowAttenuation(float3 shadowCoord)
inline half SampleShadowmap(float4 shadowCoord)
if (shadowCoord.x <= 0 || shadowCoord.x >= 1 || shadowCoord.y <= 0 || shadowCoord.y >= 1)
float3 coord = shadowCoord.xyz /= shadowCoord.w;
coord.z = saturate(ApplyDepthBias(coord.z));
if (coord.x <= 0 || coord.x >= 1 || coord.y <= 0 || coord.y >= 1)
float depth = tex2D(_ShadowMap, shadowCoord).r;
#if defined(UNITY_REVERSED_Z)
return step(depth - _ShadowData.y, shadowCoord.z);
#if defined(_SOFT_SHADOWS) || defined(_SOFT_SHADOWS_CASCADES)
// 4-tap hardware comparison
half4 attenuation;
attenuation.x = UNITY_SAMPLE_SHADOW(_ShadowMap, coord + _ShadowOffset0.xyz);
attenuation.y = UNITY_SAMPLE_SHADOW(_ShadowMap, coord + _ShadowOffset1.xyz);
attenuation.z = UNITY_SAMPLE_SHADOW(_ShadowMap, coord + _ShadowOffset2.xyz);
attenuation.w = UNITY_SAMPLE_SHADOW(_ShadowMap, coord + _ShadowOffset3.xyz);
lerp(attenuation, 1.0, _ShadowData.xxxx);
return dot(attenuation, 0.25);
return step(shadowCoord.z, depth + _ShadowData.y);
// 1-tap hardware comparison
half attenuation = UNITY_SAMPLE_SHADOW(_ShadowMap, coord);
return lerp(attenuation, 1.0, _ShadowData.x);
#endif
}

return 4 - dot(weights, fixed4(4, 3, 2, 1));
}
inline half ShadowPCF(half3 shadowCoord)
{
// TODO: simulate textureGatherOffset not available, simulate it
half2 offset = half2(0, 0);
half attenuation = ShadowAttenuation(half3(shadowCoord.xy + half2(_PCFKernel[0], _PCFKernel[1]) + offset, shadowCoord.z)) +
ShadowAttenuation(half3(shadowCoord.xy + half2(_PCFKernel[2], _PCFKernel[3]) + offset, shadowCoord.z)) +
ShadowAttenuation(half3(shadowCoord.xy + half2(_PCFKernel[4], _PCFKernel[5]) + offset, shadowCoord.z)) +
ShadowAttenuation(half3(shadowCoord.xy + half2(_PCFKernel[6], _PCFKernel[7]) + offset, shadowCoord.z));
return attenuation * 0.25;
}
inline half ComputeShadowAttenuation(float3 posWorld, half3 vertexNormal, half3 shadowDir)
{
half NdotL = dot(vertexNormal, shadowDir);

if (cascadeIndex >= MAX_SHADOW_CASCADES)
return 1.0;
#endif
shadowCoord.xyz /= shadowCoord.w;
shadowCoord.z = saturate(shadowCoord.z);
#if defined(_SOFT_SHADOWS) || defined(_SOFT_SHADOWS_CASCADES)
return ShadowPCF(shadowCoord.xyz);
#else
return ShadowAttenuation(shadowCoord.xyz);
#endif
return SampleShadowmap(shadowCoord);
}
half MixRealtimeAndBakedOcclusion(half realtimeAttenuation, half4 bakedOcclusion, half4 distanceAttenuation)

3
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandard.shader


Shader "LightweightPipeline/Standard (Physically Based)"
Shader "LightweightPipeline/Standard (Physically Based)"
{
Properties
{

FallBack "Hidden/InternalErrorShader"
CustomEditor "LightweightStandardGUI"
}

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticles.shader


Shader "LightweightPipeline/Particles/Standard"
Shader "LightweightPipeline/Particles/Standard"
{
Properties
{

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardParticlesUnlit.shader


Shader "LightweightPipeline/Particles/Standard Unlit"
Shader "LightweightPipeline/Particles/Standard Unlit"
{
Properties
{

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardTerrain.shader


Shader "LightweightPipeline/Standard Terrain"
Shader "LightweightPipeline/Standard Terrain"
{
Properties
{

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightSurfaceInput.cginc


#ifndef LIGHTWEIGHT_SURFACE_INPUT_INCLUDED
#ifndef LIGHTWEIGHT_SURFACE_INPUT_INCLUDED
#define LIGHTWEIGHT_SURFACE_INPUT_INCLUDED
#include "LightweightCore.cginc"

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightUnlit.shader


Shader "LightweightPipeline/Unlit"
Shader "LightweightPipeline/Standard Unlit"
{
Properties
{

2
ScriptableRenderPipeline/master-package.json


{
"version": "0.1.11",
"version": "0.1.12",
"unity": "2018.1",
"dependencies": {
"com.unity.postprocessing": "0.1.4"

12
Tests/GraphicsTests/RenderPipeline/LightweightPipeline/LightweightPipelineAsset.asset


m_EditorClassIdentifier:
m_MaxPixelLights: 4
m_SupportsVertexLight: 0
m_SupportSoftParticles: 0
m_RequireCameraDepthTexture: 0
m_ShadowAtlasResolution: 1024
m_ShadowAtlasResolution: 2048
m_ShadowCascades: 1
m_ShadowCascades: 4
m_DefaultShader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_BlitShader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
m_CopyDepthShader: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
m_DefaultShader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_BlitShader: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
m_CopyDepthShader: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}

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", MaterialUpgrader.UpgradeFlags.LogMessageWhenNoUpgraderFound);
}
[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", MaterialUpgrader.UpgradeFlags.LogMessageWhenNoUpgraderFound);
}
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 Standard Materials to Lightweight Pipeline (Project)", 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 Standard Materials to Lightweight Pipeline (Selection)", 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

正在加载...
取消
保存