浏览代码

Converted more files to new C# standard.

/main
Felipe Lira 7 年前
当前提交
733691b3
共有 9 个文件被更改,包括 577 次插入578 次删除
  1. 143
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs
  2. 130
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightCameraEditor.cs
  3. 181
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightLightEditor.cs
  4. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs
  5. 126
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  6. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs
  7. 269
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightPipelineAssetEditor.cs
  8. 270
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs
  9. 0
      /ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightPipelineAssetEditor.cs.meta

143
ScriptableRenderPipeline/LightweightPipeline/LWRP/Data/LightweightPipelineAsset.cs


public class LightweightPipelineAsset : RenderPipelineAsset, ISerializationCallbackReceiver
{
private Shader m_DefaultShader;
public static readonly string m_SearchPathProject = "Assets";
public static readonly string m_SearchPathPackage = "Packages/com.unity.render-pipelines.lightweight";
public static readonly string s_SearchPathProject = "Assets";
public static readonly string s_SearchPathPackage = "Packages/com.unity.render-pipelines.lightweight";
Shader m_DefaultShader;
[SerializeField] private int kAssetVersion = 3;
[SerializeField] private int m_MaxPixelLights = 4;
[SerializeField] private bool m_SupportsVertexLight = false;
[SerializeField] private bool m_RequireDepthTexture = false;
[SerializeField] private bool m_RequireSoftParticles = false;
[SerializeField] private bool m_RequireOpaqueTexture = false;
[SerializeField] private Downsampling m_OpaqueDownsampling = Downsampling._2xBilinear;
[SerializeField] private bool m_SupportsHDR = false;
[SerializeField] private MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] private float m_RenderScale = 1.0f;
[SerializeField] private bool m_SupportsDynamicBatching = true;
[SerializeField] int k_AssetVersion = 3;
[SerializeField] int m_MaxPixelLights = 4;
[SerializeField] bool m_SupportsVertexLight = false;
[SerializeField] bool m_RequireDepthTexture = false;
[SerializeField] bool m_RequireSoftParticles = false;
[SerializeField] bool m_RequireOpaqueTexture = false;
[SerializeField] Downsampling m_OpaqueDownsampling = Downsampling._2xBilinear;
[SerializeField] bool m_SupportsHDR = false;
[SerializeField] MSAAQuality m_MSAA = MSAAQuality._4x;
[SerializeField] float m_RenderScale = 1.0f;
[SerializeField] bool m_SupportsDynamicBatching = true;
[SerializeField] private bool m_DirectionalShadowsSupported = true;
[SerializeField] private ShadowResolution m_ShadowAtlasResolution = ShadowResolution._2048;
[SerializeField] private float m_ShadowDistance = 50.0f;
[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 bool m_LocalShadowsSupported = true;
[SerializeField] private ShadowResolution m_LocalShadowsAtlasResolution = ShadowResolution._512;
[SerializeField] private bool m_SoftShadowsSupported = false;
[SerializeField] private bool m_CustomShaderVariantStrippingSettings = false;
[SerializeField] private bool m_KeepAdditionalLightVariants = true;
[SerializeField] private bool m_KeepVertexLightVariants = true;
[SerializeField] private bool m_KeepDirectionalShadowVariants = true;
[SerializeField] private bool m_KeepLocalShadowVariants = true;
[SerializeField] private bool m_KeepSoftShadowVariants = true;
[SerializeField] bool m_DirectionalShadowsSupported = true;
[SerializeField] ShadowResolution m_ShadowAtlasResolution = ShadowResolution._2048;
[SerializeField] float m_ShadowDistance = 50.0f;
[SerializeField] ShadowCascades m_ShadowCascades = ShadowCascades.FOUR_CASCADES;
[SerializeField] float m_Cascade2Split = 0.25f;
[SerializeField] Vector3 m_Cascade4Split = new Vector3(0.067f, 0.2f, 0.467f);
[SerializeField] bool m_LocalShadowsSupported = true;
[SerializeField] ShadowResolution m_LocalShadowsAtlasResolution = ShadowResolution._512;
[SerializeField] bool m_SoftShadowsSupported = false;
[SerializeField] bool m_CustomShaderVariantStrippingSettings = false;
[SerializeField] bool m_KeepAdditionalLightVariants = true;
[SerializeField] bool m_KeepVertexLightVariants = true;
[SerializeField] bool m_KeepDirectionalShadowVariants = true;
[SerializeField] bool m_KeepLocalShadowVariants = true;
[SerializeField] bool m_KeepSoftShadowVariants = true;
[SerializeField]
private LightweightPipelineResources m_ResourcesAsset;
[SerializeField] LightweightPipelineResources m_ResourcesAsset;
[SerializeField] private ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;
[SerializeField] ShadowType m_ShadowType = ShadowType.HARD_SHADOWS;
private LightweightPipelineEditorResources m_EditorResourcesAsset;
LightweightPipelineEditorResources m_EditorResourcesAsset;
[MenuItem("Assets/Create/Rendering/Lightweight Pipeline Asset", priority = CoreUtils.assetCreateMenuPriority1)]
static void CreateLightweightPipeline()

}
}
private static T LoadResourceFile<T>() where T : ScriptableObject
static T LoadResourceFile<T>() where T : ScriptableObject
var guids = AssetDatabase.FindAssets(typeof(T).Name + " t:scriptableobject", new[] {m_SearchPathProject});
var guids = AssetDatabase.FindAssets(typeof(T).Name + " t:scriptableobject", new[] {s_SearchPathProject});
foreach (string guid in guids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);

// There's currently an issue that prevents FindAssets from find resources withing the package folder.
if (resourceAsset == null)
{
string path = m_SearchPathPackage + "/LWRP/Data/" + typeof(T).Name + ".asset";
string path = s_SearchPathPackage + "/LWRP/Data/" + typeof(T).Name + ".asset";
resourceAsset = AssetDatabase.LoadAssetAtPath<T>(path);
}
return resourceAsset;

return new LightweightPipeline(this);
}
private Material GetMaterial(DefaultMaterialType materialType)
Material GetMaterial(DefaultMaterialType materialType)
{
#if UNITY_EDITOR
if (editorResources == null)

public int GetAssetVersion()
{
return kAssetVersion;
return k_AssetVersion;
public int MaxPixelLights
public int maxPixelLights
public bool SupportsVertexLight
public bool supportsVertexLight
public bool RequireDepthTexture
public bool supportsCameraDepthTexture
public bool RequireSoftParticles
public bool supportsSoftParticles
public bool RequireOpaqueTexture
public bool supportsCameraOpaqueTexture
public Downsampling OpaqueDownsampling
public Downsampling opaqueDownsampling
public bool SupportsHDR
public bool supportsHDR
public int MsaaSampleCount
public int msaaSampleCount
public float RenderScale
public float renderScale
set { m_RenderScale = value; }
public bool SupportsDynamicBatching { get { return m_SupportsDynamicBatching; } }
public bool supportsDynamicBatching
{
get { return m_SupportsDynamicBatching; }
}
public bool SupportsDirectionalShadows
public bool supportsDirectionalShadows
public int DirectionalShadowAtlasResolution
public int directionalShadowAtlasResolution
public float ShadowDistance
public float shadowDistance
set { m_ShadowDistance = value; }
public int CascadeCount
public int cascadeCount
{
get
{

}
}
public float Cascade2Split
public float cascade2Split
public Vector3 Cascade4Split
public Vector3 cascade4Split
public bool SupportsLocalShadows
public bool supportsLocalShadows
public int LocalShadowAtlasResolution
public int localShadowAtlasResolution
public bool SupportsSoftShadows
public bool supportsSoftShadows
public bool CustomShaderVariantStripping
public bool customShaderVariantStripping
public bool KeepAdditionalLightVariants
public bool keepAdditionalLightVariants
public bool KeepVertexLightVariants
public bool keepVertexLightVariants
public bool KeepDirectionalShadowVariants
public bool keepDirectionalShadowVariants
public bool KeepLocalShadowVariants
public bool keepLocalShadowVariants
public bool KeepSoftShadowVariants
public bool keepSoftShadowVariants
{
get { return m_KeepSoftShadowVariants; }
}

return m_DefaultShader;
}
public Shader BlitShader
public Shader blitShader
public Shader CopyDepthShader
public Shader copyDepthShader
public Shader ScreenSpaceShadowShader
public Shader screenSpaceShadowShader
public Shader SamplingShader
public Shader samplingShader
{
get { return resources != null ? resources.SamplingShader : null; }
}

public void OnAfterDeserialize()
{
if (kAssetVersion < 3)
if (k_AssetVersion < 3)
kAssetVersion = 3;
k_AssetVersion = 3;
m_SoftShadowsSupported = (m_ShadowType == ShadowType.SOFT_SHADOWS);
}
}

130
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightCameraEditor.cs


public readonly string mssaDisabledWarning = "Anti Aliasing is disabled in Lightweight Pipeline settings.";
};
private static readonly int[] kRenderingPathValues = {0};
private static Styles s_Styles;
private LightweightPipelineAsset lightweightPipeline;
public Camera camera { get { return target as Camera; } }
private Camera camera { get { return target as Camera; } }
// Animation Properties
public bool isSameClearFlags { get { return !settings.clearFlags.hasMultipleDifferentValues; } }
public bool isSameOrthographic { get { return !settings.orthographic.hasMultipleDifferentValues; } }
// Animation Properties
private bool IsSameClearFlags { get { return !settings.clearFlags.hasMultipleDifferentValues; } }
private bool IsSameOrthographic { get { return !settings.orthographic.hasMultipleDifferentValues; } }
static readonly int[] s_RenderingPathValues = {0};
static Styles s_Styles;
LightweightPipelineAsset m_LightweightPipeline;
readonly AnimBool showBGColorAnim = new AnimBool();
readonly AnimBool showOrthoAnim = new AnimBool();
readonly AnimBool showTargetEyeAnim = new AnimBool();
readonly AnimBool m_ShowBGColorAnim = new AnimBool();
readonly AnimBool m_ShowOrthoAnim = new AnimBool();
readonly AnimBool m_ShowTargetEyeAnim = new AnimBool();
void SetAnimationTarget(AnimBool anim, bool initialize, bool targetValue)
{

void UpdateAnimationValues(bool initialize)
{
SetAnimationTarget(showBGColorAnim, initialize, IsSameClearFlags && (camera.clearFlags == CameraClearFlags.SolidColor || camera.clearFlags == CameraClearFlags.Skybox));
SetAnimationTarget(showOrthoAnim, initialize, IsSameOrthographic && camera.orthographic);
SetAnimationTarget(showTargetEyeAnim, initialize, settings.targetEye.intValue != (int)StereoTargetEyeMask.Both || PlayerSettings.virtualRealitySupported);
SetAnimationTarget(m_ShowBGColorAnim, initialize, isSameClearFlags && (camera.clearFlags == CameraClearFlags.SolidColor || camera.clearFlags == CameraClearFlags.Skybox));
SetAnimationTarget(m_ShowOrthoAnim, initialize, isSameOrthographic && camera.orthographic);
SetAnimationTarget(m_ShowTargetEyeAnim, initialize, settings.targetEye.intValue != (int)StereoTargetEyeMask.Both || PlayerSettings.virtualRealitySupported);
lightweightPipeline = GraphicsSettings.renderPipelineAsset as LightweightPipelineAsset;
m_LightweightPipeline = GraphicsSettings.renderPipelineAsset as LightweightPipelineAsset;
settings.OnEnable();
UpdateAnimationValues(true);

{
showBGColorAnim.valueChanged.RemoveListener(Repaint);
showOrthoAnim.valueChanged.RemoveListener(Repaint);
showTargetEyeAnim.valueChanged.RemoveListener(Repaint);
m_ShowBGColorAnim.valueChanged.RemoveListener(Repaint);
m_ShowOrthoAnim.valueChanged.RemoveListener(Repaint);
m_ShowTargetEyeAnim.valueChanged.RemoveListener(Repaint);
lightweightPipeline = null;
m_LightweightPipeline = null;
private void DrawRenderingPath()
public override void OnInspectorGUI()
{
if (s_Styles == null)
s_Styles = new Styles();
settings.Update();
UpdateAnimationValues(false);
settings.DrawClearFlags();
using (var group = new EditorGUILayout.FadeGroupScope(m_ShowBGColorAnim.faded))
if (group.visible) settings.DrawBackgroundColor();
settings.DrawCullingMask();
EditorGUILayout.Space();
settings.DrawProjection();
settings.DrawClippingPlanes();
settings.DrawNormalizedViewPort();
EditorGUILayout.Space();
settings.DrawDepth();
DrawRenderingPath();
DrawTargetTexture();
settings.DrawOcclusionCulling();
DrawHDR();
DrawMSAA();
settings.DrawVR();
settings.DrawMultiDisplay();
using (var group = new EditorGUILayout.FadeGroupScope(m_ShowTargetEyeAnim.faded))
if (group.visible) settings.DrawTargetEye();
settings.ApplyModifiedProperties();
}
void DrawRenderingPath()
EditorGUILayout.IntPopup(s_Styles.renderingPathLabel, 0, s_Styles.renderingPathOptions, kRenderingPathValues);
EditorGUILayout.IntPopup(s_Styles.renderingPathLabel, 0, s_Styles.renderingPathOptions, s_RenderingPathValues);
private void DrawHDR()
void DrawHDR()
if (settings.HDR.boolValue && !lightweightPipeline.SupportsHDR)
if (settings.HDR.boolValue && !m_LightweightPipeline.supportsHDR)
private void DrawTargetTexture()
void DrawTargetTexture()
{
EditorGUILayout.PropertyField(settings.targetTexture);

int pipelineSamplesCount = lightweightPipeline.MsaaSampleCount;
int pipelineSamplesCount = m_LightweightPipeline.msaaSampleCount;
if (texture && texture.antiAliasing > pipelineSamplesCount)
{

MessageType.Warning, true);
if (GUILayout.Button(s_Styles.fixNow))
lightweightPipeline.MsaaSampleCount = texture.antiAliasing;
m_LightweightPipeline.msaaSampleCount = texture.antiAliasing;
private void DrawMSAA()
void DrawMSAA()
if (settings.allowMSAA.boolValue && lightweightPipeline.MsaaSampleCount <= 1)
if (settings.allowMSAA.boolValue && m_LightweightPipeline.msaaSampleCount <= 1)
lightweightPipeline.MsaaSampleCount = 4;
m_LightweightPipeline.msaaSampleCount = 4;
}
public override void OnInspectorGUI()
{
if (s_Styles == null)
s_Styles = new Styles();
settings.Update();
UpdateAnimationValues(false);
settings.DrawClearFlags();
using (var group = new EditorGUILayout.FadeGroupScope(showBGColorAnim.faded))
if (group.visible) settings.DrawBackgroundColor();
settings.DrawCullingMask();
EditorGUILayout.Space();
settings.DrawProjection();
settings.DrawClippingPlanes();
settings.DrawNormalizedViewPort();
EditorGUILayout.Space();
settings.DrawDepth();
DrawRenderingPath();
DrawTargetTexture();
settings.DrawOcclusionCulling();
DrawHDR();
DrawMSAA();
settings.DrawVR();
settings.DrawMultiDisplay();
using (var group = new EditorGUILayout.FadeGroupScope(showTargetEyeAnim.faded))
if (group.visible) settings.DrawTargetEye();
settings.ApplyModifiedProperties();
}
}
}

181
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightLightEditor.cs


[CustomEditorForRenderPipeline(typeof(Light), typeof(LightweightPipelineAsset))]
class LightweightLightEditor : LightEditor
{
AnimBool animShowSpotOptions = new AnimBool();
AnimBool animShowPointOptions = new AnimBool();
AnimBool animShowDirOptions = new AnimBool();
AnimBool animShowAreaOptions = new AnimBool();
AnimBool animShowRuntimeOptions = new AnimBool();
AnimBool animShowShadowOptions = new AnimBool();
AnimBool animBakedShadowAngleOptions = new AnimBool();
AnimBool animBakedShadowRadiusOptions = new AnimBool();
AnimBool animShowLightBounceIntensity = new AnimBool();
AnimBool m_AnimShowSpotOptions = new AnimBool();
AnimBool m_AnimShowPointOptions = new AnimBool();
AnimBool m_AnimShowDirOptions = new AnimBool();
AnimBool m_AnimShowAreaOptions = new AnimBool();
AnimBool m_AnimShowRuntimeOptions = new AnimBool();
AnimBool m_AnimShowShadowOptions = new AnimBool();
AnimBool m_AnimBakedShadowAngleOptions = new AnimBool();
AnimBool m_AnimBakedShadowRadiusOptions = new AnimBool();
AnimBool m_AnimShowLightBounceIntensity = new AnimBool();
class Styles
{

static Styles s_Styles;
private bool TypeIsSame { get { return !settings.lightType.hasMultipleDifferentValues; } }
private bool ShadowTypeIsSame { get { return !settings.shadowsType.hasMultipleDifferentValues; } }
private bool LightmappingTypeIsSame { get { return !settings.lightmapping.hasMultipleDifferentValues; } }
private Light LightProperty { get { return target as Light; } }
public bool typeIsSame { get { return !settings.lightType.hasMultipleDifferentValues; } }
public bool shadowTypeIsSame { get { return !settings.shadowsType.hasMultipleDifferentValues; } }
public bool lightmappingTypeIsSame { get { return !settings.lightmapping.hasMultipleDifferentValues; } }
public Light lightProperty { get { return target as Light; } }
private bool SpotOptionsValue { get { return TypeIsSame && LightProperty.type == LightType.Spot; } }
private bool PointOptionsValue { get { return TypeIsSame && LightProperty.type == LightType.Point; } }
private bool DirOptionsValue { get { return TypeIsSame && LightProperty.type == LightType.Directional; } }
private bool AreaOptionsValue { get { return TypeIsSame && LightProperty.type == LightType.Area; } }
public bool spotOptionsValue { get { return typeIsSame && lightProperty.type == LightType.Spot; } }
public bool pointOptionsValue { get { return typeIsSame && lightProperty.type == LightType.Point; } }
public bool dirOptionsValue { get { return typeIsSame && lightProperty.type == LightType.Directional; } }
public bool areaOptionsValue { get { return typeIsSame && lightProperty.type == LightType.Area; } }
private bool RuntimeOptionsValue { get { return TypeIsSame && (LightProperty.type != LightType.Area && LightProperty.type != LightType.Point && !settings.isCompletelyBaked); } }
private bool BakedShadowRadius { get { return TypeIsSame && (LightProperty.type == LightType.Point || LightProperty.type == LightType.Spot) && settings.isBakedOrMixed; } }
private bool BakedShadowAngle { get { return TypeIsSame && LightProperty.type == LightType.Directional && settings.isBakedOrMixed; } }
private bool ShadowOptionsValue { get { return ShadowTypeIsSame && LightProperty.shadows != LightShadows.None; } }
public bool runtimeOptionsValue { get { return typeIsSame && (lightProperty.type != LightType.Area && lightProperty.type != LightType.Point && !settings.isCompletelyBaked); } }
public bool bakedShadowRadius { get { return typeIsSame && (lightProperty.type == LightType.Point || lightProperty.type == LightType.Spot) && settings.isBakedOrMixed; } }
public bool bakedShadowAngle { get { return typeIsSame && lightProperty.type == LightType.Directional && settings.isBakedOrMixed; } }
public bool shadowOptionsValue { get { return shadowTypeIsSame && lightProperty.shadows != LightShadows.None; } }
private bool BakingWarningValue { get { return !UnityEditor.Lightmapping.bakedGI && LightmappingTypeIsSame && settings.isBakedOrMixed; } }
private bool ShowLightBounceIntensity { get { return true; } }
private bool CookieWarningValue
public bool bakingWarningValue { get { return !UnityEditor.Lightmapping.bakedGI && lightmappingTypeIsSame && settings.isBakedOrMixed; } }
public bool showLightBounceIntensity { get { return true; } }
public bool cookieWarningValue
return TypeIsSame && LightProperty.type == LightType.Spot &&
return typeIsSame && lightProperty.type == LightType.Spot &&
private bool IsShadowEnabled { get { return settings.shadowsType.intValue != 0; } }
public bool isShadowEnabled { get { return settings.shadowsType.intValue != 0; } }
private bool RealtimeShadowsWarningValue
public bool realtimeShadowsWarningValue
return TypeIsSame && LightProperty.type == LightType.Point &&
ShadowTypeIsSame && IsShadowEnabled &&
LightmappingTypeIsSame && !settings.isCompletelyBaked;
return typeIsSame && lightProperty.type == LightType.Point &&
shadowTypeIsSame && isShadowEnabled &&
lightmappingTypeIsSame && !settings.isCompletelyBaked;
private void SetOptions(AnimBool animBool, bool initialize, bool targetValue)
{
if (initialize)
{
animBool.value = targetValue;
animBool.valueChanged.AddListener(Repaint);
}
else
{
animBool.target = targetValue;
}
}
private void UpdateShowOptions(bool initialize)
{
SetOptions(animShowSpotOptions, initialize, SpotOptionsValue);
SetOptions(animShowPointOptions, initialize, PointOptionsValue);
SetOptions(animShowDirOptions, initialize, DirOptionsValue);
SetOptions(animShowAreaOptions, initialize, AreaOptionsValue);
SetOptions(animShowShadowOptions, initialize, ShadowOptionsValue);
SetOptions(animShowRuntimeOptions, initialize, RuntimeOptionsValue);
SetOptions(animBakedShadowAngleOptions, initialize, BakedShadowAngle);
SetOptions(animBakedShadowRadiusOptions, initialize, BakedShadowRadius);
SetOptions(animShowLightBounceIntensity, initialize, ShowLightBounceIntensity);
}
protected override void OnEnable()
{
settings.OnEnable();

public void DrawSpotAngle()
{
EditorGUILayout.Slider(settings.spotAngle, 1f, 179f, s_Styles.SpotAngle);
}
public void DrawCookie()
{
EditorGUILayout.PropertyField(settings.cookieProp, s_Styles.Cookie);
if (CookieWarningValue)
{
// warn on spotlights if the cookie is set to repeat
EditorGUILayout.HelpBox(s_Styles.CookieWarning.text, MessageType.Warning);
}
}
public void DrawCookieSize()
{
EditorGUILayout.PropertyField(settings.cookieSize, s_Styles.CookieSize);
}
public override void OnInspectorGUI()
{
if (s_Styles == null)

// When we are switching between two light types that don't show the range (directional and area lights)
// we want the fade group to stay hidden.
using (var group = new EditorGUILayout.FadeGroupScope(1.0f - animShowDirOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(1.0f - m_AnimShowDirOptions.faded))
settings.DrawRange(animShowAreaOptions.target);
settings.DrawRange(m_AnimShowAreaOptions.target);
using (var group = new EditorGUILayout.FadeGroupScope(animShowSpotOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(m_AnimShowSpotOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(animShowAreaOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(m_AnimShowAreaOptions.faded))
if (group.visible)
settings.DrawArea();

using (var group = new EditorGUILayout.FadeGroupScope(1.0f - animShowAreaOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(1.0f - m_AnimShowAreaOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(animShowLightBounceIntensity.faded))
using (var group = new EditorGUILayout.FadeGroupScope(m_AnimShowLightBounceIntensity.faded))
if (group.visible)
settings.DrawBounceIntensity();

serializedObject.ApplyModifiedProperties();
}
void SetOptions(AnimBool animBool, bool initialize, bool targetValue)
{
if (initialize)
{
animBool.value = targetValue;
animBool.valueChanged.AddListener(Repaint);
}
else
{
animBool.target = targetValue;
}
}
void UpdateShowOptions(bool initialize)
{
SetOptions(m_AnimShowSpotOptions, initialize, spotOptionsValue);
SetOptions(m_AnimShowPointOptions, initialize, pointOptionsValue);
SetOptions(m_AnimShowDirOptions, initialize, dirOptionsValue);
SetOptions(m_AnimShowAreaOptions, initialize, areaOptionsValue);
SetOptions(m_AnimShowShadowOptions, initialize, shadowOptionsValue);
SetOptions(m_AnimShowRuntimeOptions, initialize, runtimeOptionsValue);
SetOptions(m_AnimBakedShadowAngleOptions, initialize, bakedShadowAngle);
SetOptions(m_AnimBakedShadowRadiusOptions, initialize, bakedShadowRadius);
SetOptions(m_AnimShowLightBounceIntensity, initialize, showLightBounceIntensity);
}
void DrawSpotAngle()
{
EditorGUILayout.Slider(settings.spotAngle, 1f, 179f, s_Styles.SpotAngle);
}
void DrawCookie()
{
EditorGUILayout.PropertyField(settings.cookieProp, s_Styles.Cookie);
if (cookieWarningValue)
{
// warn on spotlights if the cookie is set to repeat
EditorGUILayout.HelpBox(s_Styles.CookieWarning.text, MessageType.Warning);
}
}
void DrawCookieSize()
{
EditorGUILayout.PropertyField(settings.cookieSize, s_Styles.CookieSize);
}
float show = 1.0f - animShowAreaOptions.faded;
float show = 1.0f - m_AnimShowAreaOptions.faded;
show *= animShowShadowOptions.faded;
show *= m_AnimShowShadowOptions.faded;
using (var group = new EditorGUILayout.FadeGroupScope(show * animBakedShadowRadiusOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(show * m_AnimBakedShadowRadiusOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(show * animBakedShadowAngleOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(show * m_AnimBakedShadowAngleOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(show * animShowRuntimeOptions.faded))
using (var group = new EditorGUILayout.FadeGroupScope(show * m_AnimShowRuntimeOptions.faded))
if (BakingWarningValue)
if (bakingWarningValue)
if (RealtimeShadowsWarningValue)
if (realtimeShadowsWarningValue)
EditorGUILayout.HelpBox(s_Styles.ShadowsNotSupportedWarning.text, MessageType.Warning);
EditorGUILayout.Space();

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightForwardRenderer.cs


m_Materials = new Material[(int)MaterialHandles.Count]
{
CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader"),
CoreUtils.CreateEngineMaterial(pipelineAsset.CopyDepthShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.SamplingShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.BlitShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.ScreenSpaceShadowShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.copyDepthShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.samplingShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.blitShader),
CoreUtils.CreateEngineMaterial(pipelineAsset.screenSpaceShadowShader),
};
m_RenderPassSet = new ScriptableRenderPass[(int)RenderPassHandles.Count]

126
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


m_Renderer = new LightweightForwardRenderer(asset);
// Let engine know we have MSAA on for cases where we support MSAA backbuffer
if (QualitySettings.antiAliasing != pipelineAsset.MsaaSampleCount)
QualitySettings.antiAliasing = pipelineAsset.MsaaSampleCount;
if (QualitySettings.antiAliasing != pipelineAsset.msaaSampleCount)
QualitySettings.antiAliasing = pipelineAsset.msaaSampleCount;
Shader.globalRenderPipeline = "LightweightPipeline";
m_IsCameraRendering = false;

#endif
m_Renderer.Dispose();
}
private void SetSupportedRenderingFeatures()
{
#if UNITY_EDITOR
SupportedRenderingFeatures.active = new SupportedRenderingFeatures()
{
reflectionProbeSupportFlags = SupportedRenderingFeatures.ReflectionProbeSupportFlags.None,
defaultMixedLightingMode = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedMixedLightingModes = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedLightmapBakeTypes = LightmapBakeType.Baked | LightmapBakeType.Mixed,
supportedLightmapsModes = LightmapsMode.CombinedDirectional | LightmapsMode.NonDirectional,
rendererSupportsLightProbeProxyVolumes = false,
rendererSupportsMotionVectors = false,
rendererSupportsReceiveShadows = true,
rendererSupportsReflectionProbes = true
};
SceneViewDrawMode.SetupDrawMode();
#endif
}
public override void Render(ScriptableRenderContext context, Camera[] cameras)

}
}
public static void RenderPostProcess(CommandBuffer cmd, PostProcessRenderContext context, ref CameraData cameraData, RenderTextureFormat colorFormat, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool opaqueOnly)
{
context.Reset();
context.camera = cameraData.camera;
context.source = source;
context.sourceFormat = colorFormat;
context.destination = dest;
context.command = cmd;
context.flip = cameraData.camera.targetTexture == null;
if (opaqueOnly)
cameraData.postProcessLayer.RenderOpaqueOnly(context);
else
cameraData.postProcessLayer.Render(context);
}
void SetSupportedRenderingFeatures()
{
#if UNITY_EDITOR
SupportedRenderingFeatures.active = new SupportedRenderingFeatures()
{
reflectionProbeSupportFlags = SupportedRenderingFeatures.ReflectionProbeSupportFlags.None,
defaultMixedLightingMode = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedMixedLightingModes = SupportedRenderingFeatures.LightmapMixedBakeMode.Subtractive,
supportedLightmapBakeTypes = LightmapBakeType.Baked | LightmapBakeType.Mixed,
supportedLightmapsModes = LightmapsMode.CombinedDirectional | LightmapsMode.NonDirectional,
rendererSupportsLightProbeProxyVolumes = false,
rendererSupportsMotionVectors = false,
rendererSupportsReceiveShadows = true,
rendererSupportsReflectionProbes = true
};
SceneViewDrawMode.SetupDrawMode();
#endif
}
bool msaaEnabled = camera.allowMSAA && pipelineAsset.MsaaSampleCount > 1;
bool msaaEnabled = camera.allowMSAA && pipelineAsset.msaaSampleCount > 1;
cameraData.msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : pipelineAsset.MsaaSampleCount;
cameraData.msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : pipelineAsset.msaaSampleCount;
else
cameraData.msaaSamples = 1;

cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.SupportsHDR;
cameraData.isHdrEnabled = camera.allowHDR && pipelineAsset.supportsHDR;
cameraData.postProcessLayer = camera.GetComponent<PostProcessLayer>();
cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled;

// Discard variations lesser than kRenderScaleThreshold.
// Scale is only enabled for gameview
// XR has it's own scaling mechanism.
cameraData.renderScale = (Mathf.Abs(1.0f - pipelineAsset.RenderScale) < kRenderScaleThreshold) ? 1.0f : pipelineAsset.RenderScale;
cameraData.renderScale = (Mathf.Abs(1.0f - pipelineAsset.renderScale) < kRenderScaleThreshold) ? 1.0f : pipelineAsset.renderScale;
cameraData.requiresDepthTexture = pipelineAsset.RequireDepthTexture || cameraData.postProcessEnabled || cameraData.isSceneViewCamera;
cameraData.requiresSoftParticles = pipelineAsset.RequireSoftParticles;
cameraData.requiresOpaqueTexture = pipelineAsset.RequireOpaqueTexture;
cameraData.opaqueTextureDownsampling = pipelineAsset.OpaqueDownsampling;
cameraData.requiresDepthTexture = pipelineAsset.supportsCameraDepthTexture || cameraData.postProcessEnabled || cameraData.isSceneViewCamera;
cameraData.requiresSoftParticles = pipelineAsset.supportsSoftParticles;
cameraData.requiresOpaqueTexture = pipelineAsset.supportsCameraOpaqueTexture;
cameraData.opaqueTextureDownsampling = pipelineAsset.opaqueDownsampling;
bool anyShadowsEnabled = pipelineAsset.SupportsDirectionalShadows || pipelineAsset.SupportsLocalShadows;
cameraData.maxShadowDistance = (anyShadowsEnabled) ? pipelineAsset.ShadowDistance : 0.0f;
bool anyShadowsEnabled = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows;
cameraData.maxShadowDistance = (anyShadowsEnabled) ? pipelineAsset.shadowDistance : 0.0f;
}
void InitializeRenderingData(ref CameraData cameraData, List<VisibleLight> visibleLights, int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights, out RenderingData renderingData)

renderingData.cameraData = cameraData;
InitializeLightData(visibleLights, maxSupportedLocalLightsPerPass, maxSupportedVertexLights, out renderingData.lightData);
InitializeShadowData(hasDirectionalShadowCastingLight, hasLocalShadowCastingLight, out renderingData.shadowData);
renderingData.supportsDynamicBatching = pipelineAsset.SupportsDynamicBatching;
renderingData.supportsDynamicBatching = pipelineAsset.supportsDynamicBatching;
}
void InitializeShadowData(bool hasDirectionalShadowCastingLight, bool hasLocalShadowCastingLight, out ShadowData shadowData)

shadowData.renderDirectionalShadows = pipelineAsset.SupportsDirectionalShadows && hasDirectionalShadowCastingLight;
shadowData.renderDirectionalShadows = pipelineAsset.supportsDirectionalShadows && hasDirectionalShadowCastingLight;
shadowData.directionalLightCascadeCount = (shadowData.requiresScreenSpaceShadowResolve) ? pipelineAsset.CascadeCount : 1;
shadowData.directionalShadowAtlasWidth = pipelineAsset.DirectionalShadowAtlasResolution;
shadowData.directionalShadowAtlasHeight = pipelineAsset.DirectionalShadowAtlasResolution;
shadowData.directionalLightCascadeCount = (shadowData.requiresScreenSpaceShadowResolve) ? pipelineAsset.cascadeCount : 1;
shadowData.directionalShadowAtlasWidth = pipelineAsset.directionalShadowAtlasResolution;
shadowData.directionalShadowAtlasHeight = pipelineAsset.directionalShadowAtlasResolution;
switch (shadowData.directionalLightCascadeCount)
{

case 2:
shadowData.directionalLightCascades = new Vector3(pipelineAsset.Cascade2Split, 1.0f, 0.0f);
shadowData.directionalLightCascades = new Vector3(pipelineAsset.cascade2Split, 1.0f, 0.0f);
shadowData.directionalLightCascades = pipelineAsset.Cascade4Split;
shadowData.directionalLightCascades = pipelineAsset.cascade4Split;
shadowData.renderLocalShadows = pipelineAsset.SupportsLocalShadows && hasLocalShadowCastingLight;
shadowData.localShadowAtlasWidth = shadowData.localShadowAtlasHeight = pipelineAsset.LocalShadowAtlasResolution;
shadowData.supportsSoftShadows = pipelineAsset.SupportsSoftShadows;
shadowData.renderLocalShadows = pipelineAsset.supportsLocalShadows && hasLocalShadowCastingLight;
shadowData.localShadowAtlasWidth = shadowData.localShadowAtlasHeight = pipelineAsset.localShadowAtlasResolution;
shadowData.supportsSoftShadows = pipelineAsset.supportsSoftShadows;
shadowData.bufferBitCount = 16;
shadowData.renderedDirectionalShadowQuality = LightShadows.None;

void InitializeLightData(List<VisibleLight> visibleLights, int maxSupportedLocalLightsPerPass, int maxSupportedVertexLights, out LightData lightData)
{
int visibleLightsCount = Math.Min(visibleLights.Count, pipelineAsset.MaxPixelLights);
int visibleLightsCount = Math.Min(visibleLights.Count, pipelineAsset.maxPixelLights);
int vertexLightCount = (pipelineAsset.SupportsVertexLight) ? Math.Min(visibleLights.Count, maxSupportedLocalLightsPerPass) - additionalPixelLightsCount : 0;
int vertexLightCount = (pipelineAsset.supportsVertexLight) ? Math.Min(visibleLights.Count, maxSupportedLocalLightsPerPass) - additionalPixelLightsCount : 0;
vertexLightCount = Math.Min(vertexLightCount, maxSupportedVertexLights);
lightData.pixelAdditionalLightsCount = additionalPixelLightsCount;

{
int totalVisibleLights = visibleLights.Count;
if (totalVisibleLights == 0 || pipelineAsset.MaxPixelLights == 0)
if (totalVisibleLights == 0 || pipelineAsset.maxPixelLights == 0)
return -1;
for (int i = 0; i < totalVisibleLights; ++i)

return -1;
}
private void SetupPerFrameShaderConstants()
void SetupPerFrameShaderConstants()
{
// When glossy reflections are OFF in the shader we set a constant color to use as indirect specular
SphericalHarmonicsL2 ambientSH = RenderSettings.ambientProbe;

Shader.SetGlobalVector(PerFrameBuffer._SubtractiveShadowColor, CoreUtils.ConvertSRGBToActiveColorSpace(RenderSettings.subtractiveShadowColor));
}
private void SetupPerCameraShaderConstants(CameraData cameraData)
void SetupPerCameraShaderConstants(CameraData cameraData)
{
float cameraWidth = (float)cameraData.camera.pixelWidth * cameraData.renderScale;
float cameraHeight = (float)cameraData.camera.pixelWidth * cameraData.renderScale;

private bool IsStereoEnabled(Camera camera)
bool IsStereoEnabled(Camera camera)
{
#if !UNITY_SWITCH
bool isSceneViewCamera = camera.cameraType == CameraType.SceneView;

#endif
}
public static void RenderPostProcess(CommandBuffer cmd, PostProcessRenderContext context, ref CameraData cameraData, RenderTextureFormat colorFormat, RenderTargetIdentifier source, RenderTargetIdentifier dest, bool opaqueOnly)
{
context.Reset();
context.camera = cameraData.camera;
context.source = source;
context.sourceFormat = colorFormat;
context.destination = dest;
context.command = cmd;
context.flip = cameraData.camera.targetTexture == null;
if (opaqueOnly)
cameraData.postProcessLayer.RenderOpaqueOnly(context);
else
cameraData.postProcessLayer.Render(context);
}
}
}

28
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipelineCore.cs


}
public enum MixedLightingSetup
{
None = 0,
None,
ShadowMask,
Subtractive,
};

}
}
public class LightweightKeywords
public static class LightweightKeywords
{
public static readonly string AdditionalLightsText = "_ADDITIONAL_LIGHTS";
public static readonly string VertexLightsText = "_VERTEX_LIGHTS";

s_PipelineCapabilities = 0U;
// Strip variants based on selected pipeline features
if (!pipelineAsset.CustomShaderVariantStripping)
if (!pipelineAsset.customShaderVariantStripping)
if (pipelineAsset.MaxPixelLights > 1 || pipelineAsset.SupportsVertexLight)
if (pipelineAsset.maxPixelLights > 1 || pipelineAsset.supportsVertexLight)
if (pipelineAsset.SupportsVertexLight)
if (pipelineAsset.supportsVertexLight)
if (pipelineAsset.SupportsDirectionalShadows)
if (pipelineAsset.supportsDirectionalShadows)
if (pipelineAsset.SupportsLocalShadows)
if (pipelineAsset.supportsLocalShadows)
bool anyShadows = pipelineAsset.SupportsDirectionalShadows || pipelineAsset.SupportsLocalShadows;
if (pipelineAsset.SupportsSoftShadows && anyShadows)
bool anyShadows = pipelineAsset.supportsDirectionalShadows || pipelineAsset.supportsLocalShadows;
if (pipelineAsset.supportsSoftShadows && anyShadows)
if (pipelineAsset.KeepAdditionalLightVariants)
if (pipelineAsset.keepAdditionalLightVariants)
if (pipelineAsset.KeepVertexLightVariants)
if (pipelineAsset.keepVertexLightVariants)
if (pipelineAsset.KeepDirectionalShadowVariants)
if (pipelineAsset.keepDirectionalShadowVariants)
if (pipelineAsset.KeepLocalShadowVariants)
if (pipelineAsset.keepLocalShadowVariants)
if (pipelineAsset.KeepSoftShadowVariants)
if (pipelineAsset.keepSoftShadowVariants)
s_PipelineCapabilities |= PipelineCapabilities.SoftShadows;
}
}

269
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightPipelineAssetEditor.cs


using System.Linq;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[CustomEditor(typeof(LightweightPipelineAsset))]
public class LightweightPipelineAssetEditor : Editor
{
internal class Styles
{
public static GUIContent renderingLabel = new GUIContent("Rendering");
public static GUIContent shadowLabel = new GUIContent("Shadows");
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("Pixel Lights",
"Controls the amount of pixel lights that run in fragment light loop. Lights are sorted and culled per-object.");
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 requireDepthTexture = new GUIContent("Depth Texture", "If enabled the pipeline will generate camera's depth that can be bound in shaders as _CameraDepthTexture.");
public static GUIContent requireSoftParticles = new GUIContent("Soft Particles", "If enabled the pipeline will enable SOFT_PARTICLES keyword.");
public static GUIContent requireOpaqueTexture = new GUIContent("Opaque Texture", "If enabled the pipeline will copy the screen to texture after opaque objects are drawn. For transparent objects this can be bound in shaders as _CameraOpaqueTexture.");
public static GUIContent opaqueDownsampling = new GUIContent("Opaque Downsampling", "The downsampling method that is used for the opaque texture");
public static GUIContent hdrContent = new GUIContent("HDR", "Controls the global HDR settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static GUIContent dynamicBatching = new GUIContent("Dynamic Batching", "If enabled the pipeline will batch drawcalls with few triangles together by copying their vertex buffers into a shared buffer on a per-frame basis.");
public static GUIContent supportsSoftShadows = new GUIContent("Soft Shadows", "If enabled pipeline will perform shadow filtering. Otherwise all lights that cast shadows will fallback to perform a single shadow sample.");
public static GUIContent supportsDirectionalShadows = new GUIContent("Directional Shadows", "If enabled shadows will be supported for directional lights.");
public static GUIContent shadowDistance = new GUIContent("Distance", "Max shadow rendering distance.");
public static GUIContent directionalShadowAtlasResolution = new GUIContent("Atlas Resolution",
"Resolution of the directional 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("Cascades",
"Number of cascades used in directional lights shadows");
public static GUIContent shadowCascadeSplit = new GUIContent("Cascades Split",
"Percentages to split shadow volume");
public static GUIContent supportsLocalShadows = new GUIContent("Local Shadows", "If enabled shadows will be supported for spot lights.");
public static GUIContent localShadowsAtlasResolution = new GUIContent("Atlas Resolution",
"All local lights are packed into a single atlas. This setting controls the atlas size.");
public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
public static string[] opaqueDownsamplingOptions = {"None", "2x (Bilinear)", "4x (Box)", "4x (Bilinear)"};
}
public static class StrippingStyles
{
public static GUIContent strippingLabel = new GUIContent("Shader Stripping");
public static GUIContent pipelineCapabilitiesLabel = new GUIContent("Pipeline Capabilities", "Select pipeline capabilities variants to be kept in the build.");
public static string[] strippingOptions = {"Automatic", "Custom"};
public static GUIContent localLightsLabel = new GUIContent("Additional Lights", "If enabled additional lights variants won't be stripped from build.");
public static GUIContent vertexLightsLabel = new GUIContent("Vertex Lights", "If enabled vertex lights variants wont' be stripped from build.");
public static GUIContent directionalShadowsLabel = new GUIContent("Directional Shadows", "If enabled directional shadows variants won't be stripped from build.");
public static GUIContent localShadowsLabel = new GUIContent("Local Shadows", "If enabled local shadows variants won't be stripped from build.");
public static GUIContent softShadowsLabel = new GUIContent("Soft Shadows", "If enabled soft shadows variants won't be stripped from build.");
}
AnimBool m_ShowSoftParticles = new AnimBool();
AnimBool m_ShowOpaqueTextureScale = new AnimBool();
int k_MaxSupportedPixelLights = 8;
float k_MinRenderScale = 0.1f;
float k_MaxRenderScale = 4.0f;
SerializedProperty m_RenderScale;
SerializedProperty m_MaxPixelLights;
SerializedProperty m_SupportsVertexLightProp;
SerializedProperty m_RequireDepthTextureProp;
SerializedProperty m_RequireSoftParticlesProp;
SerializedProperty m_RequireOpaqueTextureProp;
SerializedProperty m_OpaqueDownsamplingProp;
SerializedProperty m_HDR;
SerializedProperty m_MSAA;
SerializedProperty m_SupportsDynamicBatching;
SerializedProperty m_SoftShadowsSupportedProp;
SerializedProperty m_DirectionalShadowsSupportedProp;
SerializedProperty m_ShadowDistanceProp;
SerializedProperty m_DirectionalShadowAtlasResolutionProp;
SerializedProperty m_ShadowCascadesProp;
SerializedProperty m_ShadowCascade2SplitProp;
SerializedProperty m_ShadowCascade4SplitProp;
SerializedProperty m_LocalShadowSupportedProp;
SerializedProperty m_LocalShadowsAtlasResolutionProp;
SerializedProperty m_CustomShaderVariantStripSettingsProp;
SerializedProperty m_KeepAdditionalLightsProp;
SerializedProperty m_KeepVertexLightsProp;
SerializedProperty m_KeepDirectionalShadowsProp;
SerializedProperty m_KeepLocalShadowsProp;
SerializedProperty m_KeepSoftShadowsProp;
public override void OnInspectorGUI()
{
serializedObject.Update();
UpdateAnimationValues();
DrawRenderingSettings();
DrawShadowSettings();
DrawStrippingSettings();
serializedObject.ApplyModifiedProperties();
}
void OnEnable()
{
m_RenderScale = serializedObject.FindProperty("m_RenderScale");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");
m_RequireDepthTextureProp = serializedObject.FindProperty("m_RequireDepthTexture");
m_RequireSoftParticlesProp = serializedObject.FindProperty("m_RequireSoftParticles");
m_RequireOpaqueTextureProp = serializedObject.FindProperty("m_RequireOpaqueTexture");
m_OpaqueDownsamplingProp = serializedObject.FindProperty("m_OpaqueDownsampling");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_SupportsDynamicBatching = serializedObject.FindProperty("m_SupportsDynamicBatching");
m_DirectionalShadowsSupportedProp = serializedObject.FindProperty("m_DirectionalShadowsSupported");
m_ShadowDistanceProp = serializedObject.FindProperty("m_ShadowDistance");
m_DirectionalShadowAtlasResolutionProp = serializedObject.FindProperty("m_ShadowAtlasResolution");
m_ShadowCascadesProp = serializedObject.FindProperty("m_ShadowCascades");
m_ShadowCascade2SplitProp = serializedObject.FindProperty("m_Cascade2Split");
m_ShadowCascade4SplitProp = serializedObject.FindProperty("m_Cascade4Split");
m_LocalShadowSupportedProp = serializedObject.FindProperty("m_LocalShadowsSupported");
m_LocalShadowsAtlasResolutionProp = serializedObject.FindProperty("m_LocalShadowsAtlasResolution");
m_SoftShadowsSupportedProp = serializedObject.FindProperty("m_SoftShadowsSupported");
m_CustomShaderVariantStripSettingsProp = serializedObject.FindProperty("m_CustomShaderVariantStrippingSettings");
m_KeepAdditionalLightsProp = serializedObject.FindProperty("m_KeepAdditionalLightVariants");
m_KeepVertexLightsProp = serializedObject.FindProperty("m_KeepVertexLightVariants");
m_KeepDirectionalShadowsProp = serializedObject.FindProperty("m_KeepDirectionalShadowVariants");
m_KeepLocalShadowsProp = serializedObject.FindProperty("m_KeepLocalShadowVariants");
m_KeepSoftShadowsProp = serializedObject.FindProperty("m_KeepSoftShadowVariants");
m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;
m_ShowOpaqueTextureScale.valueChanged.AddListener(Repaint);
m_ShowOpaqueTextureScale.value = m_RequireOpaqueTextureProp.boolValue;
}
void OnDisable()
{
m_ShowSoftParticles.valueChanged.RemoveListener(Repaint);
m_ShowOpaqueTextureScale.valueChanged.RemoveListener(Repaint);
}
void UpdateAnimationValues()
{
m_ShowSoftParticles.target = m_RequireDepthTextureProp.boolValue;
m_ShowOpaqueTextureScale.target = m_RequireOpaqueTextureProp.boolValue;
}
void DrawAnimatedProperty(SerializedProperty prop, GUIContent content, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
EditorGUILayout.PropertyField(prop, content);
}
void DrawAnimatedPopup(SerializedProperty prop, GUIContent content, string[] options, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
CoreEditorUtils.DrawPopup(content, prop, options);
}
void DrawRenderingSettings()
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.renderingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.renderScaleLabel);
m_RenderScale.floatValue = EditorGUILayout.Slider(m_RenderScale.floatValue, k_MinRenderScale, k_MaxRenderScale);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.maxPixelLightsLabel);
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxPixelLights.intValue, 0, k_MaxSupportedPixelLights);
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(m_SupportsVertexLightProp, Styles.enableVertexLightLabel);
EditorGUILayout.PropertyField(m_RequireDepthTextureProp, Styles.requireDepthTexture);
DrawAnimatedProperty(m_RequireSoftParticlesProp, Styles.requireSoftParticles, m_ShowSoftParticles);
EditorGUILayout.PropertyField(m_RequireOpaqueTextureProp, Styles.requireOpaqueTexture);
DrawAnimatedPopup(m_OpaqueDownsamplingProp, Styles.opaqueDownsampling, Styles.opaqueDownsamplingOptions, m_ShowOpaqueTextureScale);
EditorGUILayout.PropertyField(m_HDR, Styles.hdrContent);
EditorGUILayout.PropertyField(m_MSAA, Styles.msaaContent);
EditorGUILayout.PropertyField(m_SupportsDynamicBatching, Styles.dynamicBatching);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawShadowSettings()
{
EditorGUILayout.LabelField(Styles.shadowLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DirectionalShadowsSupportedProp, Styles.supportsDirectionalShadows);
bool directionalShadows = m_DirectionalShadowsSupportedProp.boolValue;
if (directionalShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DirectionalShadowAtlasResolutionProp, Styles.directionalShadowAtlasResolution);
m_ShadowDistanceProp.floatValue = Mathf.Max(0.0f,
EditorGUILayout.FloatField(Styles.shadowDistance, m_ShadowDistanceProp.floatValue));
CoreEditorUtils.DrawPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
if (cascades == ShadowCascades.FOUR_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<Vector3>(ref m_ShadowCascade4SplitProp);
else if (cascades == ShadowCascades.TWO_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<float>(ref m_ShadowCascade2SplitProp);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
EditorGUILayout.PropertyField(m_LocalShadowSupportedProp, Styles.supportsLocalShadows);
bool localShadows = m_LocalShadowSupportedProp.boolValue;
if (localShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LocalShadowsAtlasResolutionProp, Styles.localShadowsAtlasResolution);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
if (directionalShadows || localShadows)
EditorGUILayout.PropertyField(m_SoftShadowsSupportedProp, Styles.supportsSoftShadows);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawStrippingSettings()
{
EditorGUILayout.LabelField(StrippingStyles.strippingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
CoreEditorUtils.DrawPopup(StrippingStyles.pipelineCapabilitiesLabel, m_CustomShaderVariantStripSettingsProp, StrippingStyles.strippingOptions);
if (m_CustomShaderVariantStripSettingsProp.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_KeepAdditionalLightsProp, StrippingStyles.localLightsLabel);
EditorGUILayout.PropertyField(m_KeepVertexLightsProp, StrippingStyles.vertexLightsLabel);
EditorGUILayout.PropertyField(m_KeepDirectionalShadowsProp, StrippingStyles.directionalShadowsLabel);
EditorGUILayout.PropertyField(m_KeepLocalShadowsProp, StrippingStyles.localShadowsLabel);
EditorGUILayout.PropertyField(m_KeepSoftShadowsProp, StrippingStyles.softShadowsLabel);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
}
}

270
ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs


using System.Linq;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[CustomEditor(typeof(LightweightPipelineAsset))]
public class LightweightAssetEditor : Editor
{
internal class Styles
{
public static GUIContent renderingLabel = new GUIContent("Rendering");
public static GUIContent shadowLabel = new GUIContent("Shadows");
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("Pixel Lights",
"Controls the amount of pixel lights that run in fragment light loop. Lights are sorted and culled per-object.");
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 requireDepthTexture = new GUIContent("Depth Texture", "If enabled the pipeline will generate camera's depth that can be bound in shaders as _CameraDepthTexture.");
public static GUIContent requireSoftParticles = new GUIContent("Soft Particles", "If enabled the pipeline will enable SOFT_PARTICLES keyword.");
public static GUIContent requireOpaqueTexture = new GUIContent("Opaque Texture", "If enabled the pipeline will copy the screen to texture after opaque objects are drawn. For transparent objects this can be bound in shaders as _CameraOpaqueTexture.");
public static GUIContent opaqueDownsampling = new GUIContent("Opaque Downsampling", "The downsampling method that is used for the opaque texture");
public static GUIContent hdrContent = new GUIContent("HDR", "Controls the global HDR settings.");
public static GUIContent msaaContent = new GUIContent("Anti Aliasing (MSAA)", "Controls the global anti aliasing settings.");
public static GUIContent dynamicBatching = new GUIContent("Dynamic Batching", "If enabled the pipeline will batch drawcalls with few triangles together by copying their vertex buffers into a shared buffer on a per-frame basis.");
public static GUIContent supportsSoftShadows = new GUIContent("Soft Shadows", "If enabled pipeline will perform shadow filtering. Otherwise all lights that cast shadows will fallback to perform a single shadow sample.");
public static GUIContent supportsDirectionalShadows = new GUIContent("Directional Shadows", "If enabled shadows will be supported for directional lights.");
public static GUIContent shadowDistance = new GUIContent("Distance", "Max shadow rendering distance.");
public static GUIContent directionalShadowAtlasResolution = new GUIContent("Atlas Resolution",
"Resolution of the directional 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("Cascades",
"Number of cascades used in directional lights shadows");
public static GUIContent shadowCascadeSplit = new GUIContent("Cascades Split",
"Percentages to split shadow volume");
public static GUIContent supportsLocalShadows = new GUIContent("Local Shadows", "If enabled shadows will be supported for spot lights.");
public static GUIContent localShadowsAtlasResolution = new GUIContent("Atlas Resolution",
"All local lights are packed into a single atlas. This setting controls the atlas size.");
public static string[] shadowCascadeOptions = {"No Cascades", "Two Cascades", "Four Cascades"};
public static string[] opaqueDownsamplingOptions = {"None", "2x (Bilinear)", "4x (Box)", "4x (Bilinear)"};
}
public static class StrippingStyles
{
public static GUIContent strippingLabel = new GUIContent("Shader Stripping");
public static GUIContent pipelineCapabilitiesLabel = new GUIContent("Pipeline Capabilities", "Select pipeline capabilities variants to be kept in the build.");
public static string[] strippingOptions = {"Automatic", "Custom"};
public static GUIContent localLightsLabel = new GUIContent("Additional Lights", "If enabled additional lights variants won't be stripped from build.");
public static GUIContent vertexLightsLabel = new GUIContent("Vertex Lights", "If enabled vertex lights variants wont' be stripped from build.");
public static GUIContent directionalShadowsLabel = new GUIContent("Directional Shadows", "If enabled directional shadows variants won't be stripped from build.");
public static GUIContent localShadowsLabel = new GUIContent("Local Shadows", "If enabled local shadows variants won't be stripped from build.");
public static GUIContent softShadowsLabel = new GUIContent("Soft Shadows", "If enabled soft shadows variants won't be stripped from build.");
}
AnimBool m_ShowSoftParticles = new AnimBool();
AnimBool m_ShowOpaqueTextureScale = new AnimBool();
private int kMaxSupportedPixelLights = 8;
private float kMinRenderScale = 0.1f;
private float kMaxRenderScale = 4.0f;
private SerializedProperty m_RenderScale;
private SerializedProperty m_MaxPixelLights;
private SerializedProperty m_SupportsVertexLightProp;
private SerializedProperty m_RequireDepthTextureProp;
private SerializedProperty m_RequireSoftParticlesProp;
private SerializedProperty m_RequireOpaqueTextureProp;
private SerializedProperty m_OpaqueDownsamplingProp;
private SerializedProperty m_HDR;
private SerializedProperty m_MSAA;
private SerializedProperty m_SupportsDynamicBatching;
private SerializedProperty m_SoftShadowsSupportedProp;
private SerializedProperty m_DirectionalShadowsSupportedProp;
private SerializedProperty m_ShadowDistanceProp;
private SerializedProperty m_DirectionalShadowAtlasResolutionProp;
private SerializedProperty m_ShadowCascadesProp;
private SerializedProperty m_ShadowCascade2SplitProp;
private SerializedProperty m_ShadowCascade4SplitProp;
private SerializedProperty m_LocalShadowSupportedProp;
private SerializedProperty m_LocalShadowsAtlasResolutionProp;
private SerializedProperty m_CustomShaderVariantStripSettingsProp;
private SerializedProperty m_KeepAdditionalLightsProp;
private SerializedProperty m_KeepVertexLightsProp;
private SerializedProperty m_KeepDirectionalShadowsProp;
private SerializedProperty m_KeepLocalShadowsProp;
private SerializedProperty m_KeepSoftShadowsProp;
void OnEnable()
{
m_RenderScale = serializedObject.FindProperty("m_RenderScale");
m_MaxPixelLights = serializedObject.FindProperty("m_MaxPixelLights");
m_SupportsVertexLightProp = serializedObject.FindProperty("m_SupportsVertexLight");
m_RequireDepthTextureProp = serializedObject.FindProperty("m_RequireDepthTexture");
m_RequireSoftParticlesProp = serializedObject.FindProperty("m_RequireSoftParticles");
m_RequireOpaqueTextureProp = serializedObject.FindProperty("m_RequireOpaqueTexture");
m_OpaqueDownsamplingProp = serializedObject.FindProperty("m_OpaqueDownsampling");
m_HDR = serializedObject.FindProperty("m_SupportsHDR");
m_MSAA = serializedObject.FindProperty("m_MSAA");
m_SupportsDynamicBatching = serializedObject.FindProperty("m_SupportsDynamicBatching");
m_DirectionalShadowsSupportedProp = serializedObject.FindProperty("m_DirectionalShadowsSupported");
m_ShadowDistanceProp = serializedObject.FindProperty("m_ShadowDistance");
m_DirectionalShadowAtlasResolutionProp = serializedObject.FindProperty("m_ShadowAtlasResolution");
m_ShadowCascadesProp = serializedObject.FindProperty("m_ShadowCascades");
m_ShadowCascade2SplitProp = serializedObject.FindProperty("m_Cascade2Split");
m_ShadowCascade4SplitProp = serializedObject.FindProperty("m_Cascade4Split");
m_LocalShadowSupportedProp = serializedObject.FindProperty("m_LocalShadowsSupported");
m_LocalShadowsAtlasResolutionProp = serializedObject.FindProperty("m_LocalShadowsAtlasResolution");
m_SoftShadowsSupportedProp = serializedObject.FindProperty("m_SoftShadowsSupported");
m_CustomShaderVariantStripSettingsProp = serializedObject.FindProperty("m_CustomShaderVariantStrippingSettings");
m_KeepAdditionalLightsProp = serializedObject.FindProperty("m_KeepAdditionalLightVariants");
m_KeepVertexLightsProp = serializedObject.FindProperty("m_KeepVertexLightVariants");
m_KeepDirectionalShadowsProp = serializedObject.FindProperty("m_KeepDirectionalShadowVariants");
m_KeepLocalShadowsProp = serializedObject.FindProperty("m_KeepLocalShadowVariants");
m_KeepSoftShadowsProp = serializedObject.FindProperty("m_KeepSoftShadowVariants");
m_ShowSoftParticles.valueChanged.AddListener(Repaint);
m_ShowSoftParticles.value = m_RequireSoftParticlesProp.boolValue;
m_ShowOpaqueTextureScale.valueChanged.AddListener(Repaint);
m_ShowOpaqueTextureScale.value = m_RequireOpaqueTextureProp.boolValue;
}
void OnDisable()
{
m_ShowSoftParticles.valueChanged.RemoveListener(Repaint);
m_ShowOpaqueTextureScale.valueChanged.RemoveListener(Repaint);
}
void UpdateAnimationValues()
{
m_ShowSoftParticles.target = m_RequireDepthTextureProp.boolValue;
m_ShowOpaqueTextureScale.target = m_RequireOpaqueTextureProp.boolValue;
}
void DrawAnimatedProperty(SerializedProperty prop, GUIContent content, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
EditorGUILayout.PropertyField(prop, content);
}
void DrawAnimatedPopup(SerializedProperty prop, GUIContent content, string[] options, AnimBool animation)
{
using (var group = new EditorGUILayout.FadeGroupScope(animation.faded))
if (group.visible)
CoreEditorUtils.DrawPopup(content, prop, options);
}
void DrawRenderingSettings()
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(Styles.renderingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.renderScaleLabel);
m_RenderScale.floatValue = EditorGUILayout.Slider(m_RenderScale.floatValue, kMinRenderScale, kMaxRenderScale);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(Styles.maxPixelLightsLabel);
m_MaxPixelLights.intValue = EditorGUILayout.IntSlider(m_MaxPixelLights.intValue, 0, kMaxSupportedPixelLights);
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(m_SupportsVertexLightProp, Styles.enableVertexLightLabel);
EditorGUILayout.PropertyField(m_RequireDepthTextureProp, Styles.requireDepthTexture);
DrawAnimatedProperty(m_RequireSoftParticlesProp, Styles.requireSoftParticles, m_ShowSoftParticles);
EditorGUILayout.PropertyField(m_RequireOpaqueTextureProp, Styles.requireOpaqueTexture);
DrawAnimatedPopup(m_OpaqueDownsamplingProp, Styles.opaqueDownsampling, Styles.opaqueDownsamplingOptions, m_ShowOpaqueTextureScale);
EditorGUILayout.PropertyField(m_HDR, Styles.hdrContent);
EditorGUILayout.PropertyField(m_MSAA, Styles.msaaContent);
EditorGUILayout.PropertyField(m_SupportsDynamicBatching, Styles.dynamicBatching);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawShadowSettings()
{
EditorGUILayout.LabelField(Styles.shadowLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DirectionalShadowsSupportedProp, Styles.supportsDirectionalShadows);
bool directionalShadows = m_DirectionalShadowsSupportedProp.boolValue;
if (directionalShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DirectionalShadowAtlasResolutionProp, Styles.directionalShadowAtlasResolution);
m_ShadowDistanceProp.floatValue = Mathf.Max(0.0f,
EditorGUILayout.FloatField(Styles.shadowDistance, m_ShadowDistanceProp.floatValue));
CoreEditorUtils.DrawPopup(Styles.shadowCascades, m_ShadowCascadesProp, Styles.shadowCascadeOptions);
ShadowCascades cascades = (ShadowCascades)m_ShadowCascadesProp.intValue;
if (cascades == ShadowCascades.FOUR_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<Vector3>(ref m_ShadowCascade4SplitProp);
else if (cascades == ShadowCascades.TWO_CASCADES)
CoreEditorUtils.DrawCascadeSplitGUI<float>(ref m_ShadowCascade2SplitProp);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
EditorGUILayout.PropertyField(m_LocalShadowSupportedProp, Styles.supportsLocalShadows);
bool localShadows = m_LocalShadowSupportedProp.boolValue;
if (localShadows)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LocalShadowsAtlasResolutionProp, Styles.localShadowsAtlasResolution);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
if (directionalShadows || localShadows)
EditorGUILayout.PropertyField(m_SoftShadowsSupportedProp, Styles.supportsSoftShadows);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
void DrawStrippingSettings()
{
EditorGUILayout.LabelField(StrippingStyles.strippingLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
CoreEditorUtils.DrawPopup(StrippingStyles.pipelineCapabilitiesLabel, m_CustomShaderVariantStripSettingsProp, StrippingStyles.strippingOptions);
if (m_CustomShaderVariantStripSettingsProp.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_KeepAdditionalLightsProp, StrippingStyles.localLightsLabel);
EditorGUILayout.PropertyField(m_KeepVertexLightsProp, StrippingStyles.vertexLightsLabel);
EditorGUILayout.PropertyField(m_KeepDirectionalShadowsProp, StrippingStyles.directionalShadowsLabel);
EditorGUILayout.PropertyField(m_KeepLocalShadowsProp, StrippingStyles.localShadowsLabel);
EditorGUILayout.PropertyField(m_KeepSoftShadowsProp, StrippingStyles.softShadowsLabel);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.Space();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
UpdateAnimationValues();
DrawRenderingSettings();
DrawShadowSettings();
DrawStrippingSettings();
serializedObject.ApplyModifiedProperties();
}
}
}

/ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightAssetEditor.cs.meta → /ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightPipelineAssetEditor.cs.meta

正在加载...
取消
保存