浏览代码

Moved Cascade and Contact shadows settings to the volume system.

/main
Julien Ignace 7 年前
当前提交
c4e4129a
共有 14 个文件被更改,包括 238 次插入89 次删除
  1. 2
      ScriptableRenderPipeline/Core/CoreRP/Editor/Volume/VolumeProfileFactory.cs
  2. 10
      ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs
  3. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  4. 58
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/SkySettingsEditor.cs
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
  7. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
  8. 46
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/HDShadowSettings.cs
  9. 57
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/ContactShadowsEditor.cs
  10. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/ContactShadowsEditor.cs.meta
  11. 66
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/HDShadowSettingsEditor.cs
  12. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/HDShadowSettingsEditor.cs.meta
  13. 16
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs
  14. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs.meta

2
ScriptableRenderPipeline/Core/CoreRP/Editor/Volume/VolumeProfileFactory.cs


else
{
var scenePath = Path.GetDirectoryName(scene.path);
var extPath = scene.name + "_Profiles";
var extPath = scene.name;
var profilePath = scenePath + "/" + extPath;
if (!AssetDatabase.IsValidFolder(profilePath))

10
ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs


[Range(0.0f, 1.0f)]
public float shadowDimmer = 1.0f;
public float shadowFadeDistance = 10000.0f;
// Contact shadows
public bool enableContactShadows = false;
[Range(0.0f, 1.0f)]
public float contactShadowLength = 0.0f;
[Range(0.0f, 1.0f)]
public float contactShadowDistanceScaleFactor = 0.5f;
public float contactShadowMaxDistance = 50.0f;
public float contactShadowFadeDistance = 5.0f;
[Range(4, 64)]
public uint contactShadowSampleCount = 8;
// bias control
public float viewBiasMin = 0.5f;
public float viewBiasMax = 10.0f;

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent[] shapeNames;
// Additional shadow data
public readonly GUIContent shadowCascades = new GUIContent("Cascades", "");
public readonly GUIContent shadowCascadeCount = new GUIContent("Cascade Count", "");
public readonly GUIContent[] shadowCascadeRatios = { new GUIContent("Cascade 1"), new GUIContent("Cascade 2"), new GUIContent("Cascade 3") };
public readonly GUIContent contactShadow = new GUIContent("Contact Shadows");
public readonly GUIContent contactShadowLength = new GUIContent("Length", "Length of rays used to gather contact shadows in world units.\nZero will disable the feature.");
public readonly GUIContent contactShadowDistanceScaleFactor = new GUIContent("Distance Scale Factor", "Contact Shadows are scaled up with distance. Use this parameter to dampen this effect.");
public readonly GUIContent contactShadowMaxDistance = new GUIContent("Max Distance", "Distance from the camera in world units at which contact shadows are faded out to zero.");
public readonly GUIContent contactShadowFadeDistance = new GUIContent("Fade Distance", "Distance in world units over which the contact shadows are faded out (see Max Distance).");
public readonly GUIContent contactShadowSampleCount = new GUIContent("Sample Count", "Number of samples when ray casting.");
// Bias control
public readonly GUIContent viewBiasMin = new GUIContent("View Bias");

58
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs


{
public SerializedProperty dimmer;
public SerializedProperty fadeDistance;
public SerializedProperty cascadeCount;
public SerializedProperty cascadeRatios;
public SerializedProperty cascadeBorders;
public SerializedProperty enableContactShadows;
public SerializedProperty contactShadowLength;
public SerializedProperty contactShadowDistanceScaleFactor;
public SerializedProperty contactShadowMaxDistance;
public SerializedProperty contactShadowFadeDistance;
public SerializedProperty contactShadowSampleCount;
// Bias control
public SerializedProperty viewBiasMin;

{
dimmer = o.Find(x => x.shadowDimmer),
fadeDistance = o.Find(x => x.shadowFadeDistance),
cascadeCount = o.Find("shadowCascadeCount"),
cascadeRatios = o.Find("shadowCascadeRatios"),
cascadeBorders = o.Find("shadowCascadeBorders"),
enableContactShadows = o.Find(x => x.enableContactShadows),
contactShadowLength = o.Find(x => x.contactShadowLength),
contactShadowDistanceScaleFactor = o.Find(x => x.contactShadowDistanceScaleFactor),
contactShadowMaxDistance = o.Find(x => x.contactShadowMaxDistance),
contactShadowFadeDistance = o.Find(x => x.contactShadowFadeDistance),
contactShadowSampleCount = o.Find(x => x.contactShadowSampleCount),
viewBiasMin = o.Find(x => x.viewBiasMin),
viewBiasMax = o.Find(x => x.viewBiasMax),

{
bool shadowsEnabled = EditorGUILayout.Toggle(CoreEditorUtils.GetContent("Enable Shadows"), settings.shadowsType.enumValueIndex != 0);
settings.shadowsType.enumValueIndex = shadowsEnabled ? (int)LightShadows.Hard : (int)LightShadows.None;
if (settings.lightType.enumValueIndex == (int)LightType.Directional)
{
EditorGUILayout.PropertyField(m_AdditionalShadowData.enableContactShadows, CoreEditorUtils.GetContent("Enable Contact Shadows"));
}
}
EditorGUILayout.PropertyField(m_AdditionalLightData.showAdditionalSettings);

//EditorGUILayout.Slider(settings.shadowsNormalBias, 0.001f, 1f, s_Styles.shadowNormalBias);
EditorGUILayout.Slider(m_AdditionalShadowData.viewBiasScale, 0.0f, 15.0f, s_Styles.viewBiasScale);
EditorGUILayout.Slider(settings.shadowsNearPlane, 0.01f, 10f, s_Styles.shadowNearPlane);
if (settings.lightType.enumValueIndex == (int)LightType.Directional)
{
using (var scope = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.IntSlider(m_AdditionalShadowData.cascadeCount, 1, 4, s_Styles.shadowCascadeCount);
if (scope.changed)
{
int len = m_AdditionalShadowData.cascadeCount.intValue;
m_AdditionalShadowData.cascadeRatios.arraySize = len - 1;
m_AdditionalShadowData.cascadeBorders.arraySize = len;
}
}
EditorGUI.indentLevel++;
int arraySize = m_AdditionalShadowData.cascadeRatios.arraySize;
for (int i = 0; i < arraySize; i++)
EditorGUILayout.Slider(m_AdditionalShadowData.cascadeRatios.GetArrayElementAtIndex(i), 0f, 1f, s_Styles.shadowCascadeRatios[i]);
EditorGUI.indentLevel--;
if(!m_AdditionalShadowData.enableContactShadows.hasMultipleDifferentValues && m_AdditionalShadowData.enableContactShadows.boolValue)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.contactShadow, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadowLength, s_Styles.contactShadowLength);
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadowDistanceScaleFactor, s_Styles.contactShadowDistanceScaleFactor);
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadowMaxDistance, s_Styles.contactShadowMaxDistance);
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadowFadeDistance, s_Styles.contactShadowFadeDistance);
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadowSampleCount, s_Styles.contactShadowSampleCount);
EditorGUI.indentLevel--;
}
}
if (settings.isBakedOrMixed)
DrawBakedShadowParameters();

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/SkySettingsEditor.cs


SerializedDataParameter m_EnvUpdateMode;
SerializedDataParameter m_EnvUpdatePeriod;
SerializedProperty m_UseForBaking;
public override void OnEnable()
{
var o = new PropertyFetcher<SkySettings>(serializedObject);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs


cmd.Blit(source, destination, new Vector2(camera.scaleBias.x, camera.scaleBias.y), Vector2.zero);
}
// This particular case is for blitting a camera-scaled texture into a non scaling texture. So we setup the full viewport (implicit in cmd.Blit) but have to scale the input UVs.
// This particular case is for blitting a non-scaled texture into a scaled texture. So we setup the partial viewport but don't scale the input UVs.
public static void BlitCameraTexture(CommandBuffer cmd, HDCamera camera, RenderTargetIdentifier source, RTHandle destination)
{
// Will set the correct camera viewport as well.

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


directionalLightData.dynamicShadowCasterOnly = 0;
}
// Fallback to the first non shadow casting directional light.
m_CurrentSunLight = m_CurrentSunLight == null ? light.light : m_CurrentSunLight;
m_lightList.directionalLights.Add(directionalLightData);

AdditionalShadowData asd = vl.light.GetComponent<AdditionalShadowData>();
if (asd != null && asd.shadowDimmer > 0.0f)
{
// Discover sun light and update cascade info from Volumes
// TODO: This should be moved to GetDirectionalLightData when we merge the two loops here.
// Careful it must still be done BEFORE the call to ProcessShadowRequests
if (vl.lightType == LightType.Directional && m_CurrentSunLight == null)
{
var hdShadowSettings = VolumeManager.instance.stack.GetComponent<HDShadowSettings>();
asd.SetShadowCascades(hdShadowSettings.cascadeShadowSplitCount, hdShadowSettings.cascadeShadowSplits, hdShadowSettings.cascadeShadowBorders );
}
}
uint shadowRequestCount = (uint)m_ShadowRequests.Count;
uint shadowRequestCount = (uint)m_ShadowRequests.Count;
//TODO: Do not call ToArray here to avoid GC, refactor API
int[] shadowRequests = m_ShadowRequests.ToArray();
int[] shadowDataIndices;

using (new ProfilingSample(cmd, "Deferred Directional Shadow", CustomSamplerId.TPDeferredDirectionalShadow.GetSampler()))
{
AdditionalShadowData asd = m_CurrentSunLight.GetComponent<AdditionalShadowData>();
ContactShadows contactShadows = VolumeManager.instance.stack.GetComponent<ContactShadows>();
bool enableContactShadows = m_FrameSettings.enableContactShadows && asd.enableContactShadows && asd.contactShadowLength > 0.0f;
bool enableContactShadows = m_FrameSettings.enableContactShadows && contactShadows.enable && contactShadows.length > 0.0f;
int kernel;
if (enableContactShadows)
kernel = m_FrameSettings.enableForwardRenderingOnly ? s_deferredDirectionalShadow_Contact_Kernel : s_deferredDirectionalShadow_Contact_Normals_Kernel;

if (enableContactShadows)
{
float contactShadowRange = Mathf.Clamp(asd.contactShadowFadeDistance, 0.0f, asd.contactShadowMaxDistance);
float contactShadowFadeEnd = asd.contactShadowMaxDistance;
float contactShadowRange = Mathf.Clamp(contactShadows.fadeDistance, 0.0f, contactShadows.maxDistance);
float contactShadowFadeEnd = contactShadows.maxDistance;
Vector4 contactShadowParams = new Vector4(asd.contactShadowLength, asd.contactShadowDistanceScaleFactor, contactShadowFadeEnd, contactShadowOneOverFadeRange);
Vector4 contactShadowParams = new Vector4(contactShadows.length, contactShadows.distanceScaleFactor, contactShadowFadeEnd, contactShadowOneOverFadeRange);
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalContactShadowSampleCount, (int)asd.contactShadowSampleCount);
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalContactShadowSampleCount, contactShadows.sampleCount);
}
cmd.SetComputeIntParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalShadowIndex, m_CurrentSunLightShadowIndex);

46
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/HDShadowSettings.cs


[Serializable]
public class HDShadowSettings : VolumeComponent
{
public NoInterpMinFloatParameter maxShadowDistance = new NoInterpMinFloatParameter(500.0f, 0.0f);
float[] m_CascadeShadowSplits = new float[3];
float[] m_CascadeShadowBorders = new float[4];
public float[] cascadeShadowSplits
{
get
{
m_CascadeShadowSplits[0] = cascadeShadowSplit0;
m_CascadeShadowSplits[1] = cascadeShadowSplit1;
m_CascadeShadowSplits[2] = cascadeShadowSplit2;
return m_CascadeShadowSplits;
}
}
public float[] cascadeShadowBorders
{
get
{
m_CascadeShadowBorders[0] = cascadeShadowBorder0;
m_CascadeShadowBorders[1] = cascadeShadowBorder1;
m_CascadeShadowBorders[2] = cascadeShadowBorder2;
m_CascadeShadowBorders[3] = cascadeShadowBorder3;
return m_CascadeShadowBorders;
}
}
[Tooltip("Maximum shadow distance for all light types.")]
public NoInterpMinFloatParameter maxShadowDistance = new NoInterpMinFloatParameter(500.0f, 0.0f);
[Tooltip("Number of splits for cascaded shadow maps.")]
public NoInterpClampedIntParameter cascadeShadowSplitCount = new NoInterpClampedIntParameter(4, 1, 4);
[Tooltip("Ratio of the first split against max shadow distance.")]
public NoInterpClampedFloatParameter cascadeShadowSplit0 = new NoInterpClampedFloatParameter(0.05f, 0.0f, 1.0f);
[Tooltip("Ratio of the second split against max shadow distance.")]
public NoInterpClampedFloatParameter cascadeShadowSplit1 = new NoInterpClampedFloatParameter(0.15f, 0.0f, 1.0f);
[Tooltip("Ratio of the third split against max shadow distance.")]
public NoInterpClampedFloatParameter cascadeShadowSplit2 = new NoInterpClampedFloatParameter(0.3f, 0.0f, 1.0f);
[Tooltip("Border size between first and second split.")]
public NoInterpMinFloatParameter cascadeShadowBorder0 = new NoInterpMinFloatParameter(0.0f, 0.0f);
[Tooltip("Border size between second and third split.")]
public NoInterpMinFloatParameter cascadeShadowBorder1 = new NoInterpMinFloatParameter(0.0f, 0.0f);
[Tooltip("Border size between third and last split.")]
public NoInterpMinFloatParameter cascadeShadowBorder2 = new NoInterpMinFloatParameter(0.0f, 0.0f);
[Tooltip("Border size at the end of last split.")]
public NoInterpMinFloatParameter cascadeShadowBorder3 = new NoInterpMinFloatParameter(0.0f, 0.0f);
}
}

57
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/ContactShadowsEditor.cs


using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[VolumeComponentEditor(typeof(ContactShadows))]
public class ContactShadowsEditor : VolumeComponentEditor
{
public readonly GUIContent contactShadow = new GUIContent("Contact Shadows");
public readonly GUIContent contactShadowLength = new GUIContent("Length", "Length of rays used to gather contact shadows in world units.\nZero will disable the feature.");
public readonly GUIContent contactShadowDistanceScaleFactor = new GUIContent("Distance Scale Factor", "Contact Shadows are scaled up with distance. Use this parameter to dampen this effect.");
public readonly GUIContent contactShadowMaxDistance = new GUIContent("Max Distance", "Distance from the camera in world units at which contact shadows are faded out to zero.");
public readonly GUIContent contactShadowFadeDistance = new GUIContent("Fade Distance", "Distance in world units over which the contact shadows are faded out (see Max Distance).");
public readonly GUIContent contactShadowSampleCount = new GUIContent("Sample Count", "Number of samples when ray casting.");
SerializedDataParameter m_Enable;
SerializedDataParameter m_Length;
SerializedDataParameter m_DistanceScaleFactor;
SerializedDataParameter m_MaxDistance;
SerializedDataParameter m_FadeDistance;
SerializedDataParameter m_SampleCount;
public override void OnEnable()
{
var o = new PropertyFetcher<ContactShadows>(serializedObject);
m_Enable = Unpack(o.Find(x => x.enable));
m_Length = Unpack(o.Find(x => x.length));
m_DistanceScaleFactor = Unpack(o.Find(x => x.distanceScaleFactor));
m_MaxDistance = Unpack(o.Find(x => x.maxDistance));
m_FadeDistance = Unpack(o.Find(x => x.fadeDistance));
m_SampleCount = Unpack(o.Find(x => x.sampleCount));
}
public override void OnInspectorGUI()
{
PropertyField(m_Enable, CoreEditorUtils.GetContent("Enable"));
if (!m_Enable.value.hasMultipleDifferentValues)
{
using (new EditorGUI.DisabledGroupScope(!m_Enable.value.boolValue))
{
PropertyField(m_Length, CoreEditorUtils.GetContent("Length|Length of rays used to gather contact shadows in world units."));
PropertyField(m_DistanceScaleFactor, CoreEditorUtils.GetContent("Distance Scale Factor|Contact Shadows are scaled up with distance. Use this parameter to dampen this effect."));
PropertyField(m_MaxDistance, CoreEditorUtils.GetContent("Max Distance|Distance from the camera in world units at which contact shadows are faded out to zero."));
PropertyField(m_FadeDistance, CoreEditorUtils.GetContent("Fade Distance|Distance in world units over which the contact shadows fade out (see Max Distance)."));
PropertyField(m_SampleCount, CoreEditorUtils.GetContent("Sample Count|Number of samples when ray casting."));
}
}
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/ContactShadowsEditor.cs.meta


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

66
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/HDShadowSettingsEditor.cs


using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[VolumeComponentEditor(typeof(HDShadowSettings))]
public class HDShadowSettingsEditor : VolumeComponentEditor
{
SerializedDataParameter m_MaxShadowDistance;
SerializedDataParameter m_CascadeShadowSplitCount;
SerializedDataParameter[] m_CascadeShadowSplits = new SerializedDataParameter[3];
SerializedDataParameter[] m_CascadeShadowBorders = new SerializedDataParameter[4];
// For now we don't use borders so we hide the UI.
bool m_bShowBorders = false;
public override void OnEnable()
{
var o = new PropertyFetcher<HDShadowSettings>(serializedObject);
m_MaxShadowDistance = Unpack(o.Find(x => x.maxShadowDistance));
m_CascadeShadowSplitCount = Unpack(o.Find(x => x.cascadeShadowSplitCount));
m_CascadeShadowSplits[0] = Unpack(o.Find(x => x.cascadeShadowSplit0));
m_CascadeShadowSplits[1] = Unpack(o.Find(x => x.cascadeShadowSplit1));
m_CascadeShadowSplits[2] = Unpack(o.Find(x => x.cascadeShadowSplit2));
m_CascadeShadowBorders[0] = Unpack(o.Find(x => x.cascadeShadowBorder0));
m_CascadeShadowBorders[1] = Unpack(o.Find(x => x.cascadeShadowBorder1));
m_CascadeShadowBorders[2] = Unpack(o.Find(x => x.cascadeShadowBorder2));
m_CascadeShadowBorders[3] = Unpack(o.Find(x => x.cascadeShadowBorder3));
}
public override void OnInspectorGUI()
{
PropertyField(m_MaxShadowDistance, CoreEditorUtils.GetContent("Max Distance"));
EditorGUILayout.Space();
PropertyField(m_CascadeShadowSplitCount, CoreEditorUtils.GetContent("Cascade Count"));
if (!m_CascadeShadowSplitCount.value.hasMultipleDifferentValues)
{
EditorGUI.indentLevel++;
int splitCount = m_CascadeShadowSplitCount.value.intValue;
for (int i = 0; i < splitCount - 1; i++)
{
PropertyField(m_CascadeShadowSplits[i], CoreEditorUtils.GetContent(string.Format("Split {0}", i + 1)));
}
if(m_bShowBorders)
{
EditorGUILayout.Space();
for (int i = 0; i < splitCount; i++)
{
PropertyField(m_CascadeShadowBorders[i], CoreEditorUtils.GetContent(string.Format("Border {0}", i + 1)));
}
}
EditorGUI.indentLevel--;
}
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/HDShadowSettingsEditor.cs.meta


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

16
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs


using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public class ContactShadows : VolumeComponent
{
// Contact shadows
public BoolParameter enable = new BoolParameter(false);
public ClampedFloatParameter length = new ClampedFloatParameter(0.15f, 0.0f, 1.0f);
public ClampedFloatParameter distanceScaleFactor = new ClampedFloatParameter(0.5f, 0.0f, 1.0f);
public MinFloatParameter maxDistance = new MinFloatParameter(50.0f, 0.0f);
public MinFloatParameter fadeDistance = new MinFloatParameter(5.0f, 0.0f);
public NoInterpClampedIntParameter sampleCount = new NoInterpClampedIntParameter(8, 4, 64);
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Shadows/ContactShadows.cs.meta


fileFormatVersion: 2
guid: 56b145d2b9ee1ac4f846968484e7485a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存