浏览代码

Merge pull request #285 from Unity-Technologies/Branch_CommonSettingCleanup

Branch commonsettingcleanup
/RenderPassXR_Sandbox
GitHub 7 年前
当前提交
db3ff271
共有 17 个文件被更改,包括 186 次插入362 次删除
  1. 1
      Assets/ScriptableRenderPipeline/Core/AdditionalLightData.cs
  2. 25
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  3. 13
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
  4. 5
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
  5. 3
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs
  6. 8
      Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  7. 42
      Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs
  8. 22
      Assets/ScriptableRenderPipeline/Core/TextureSettings.cs
  9. 14
      Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs
  10. 29
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  11. 98
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  12. 27
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
  13. 92
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  14. 16
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  15. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
  16. 24
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/CommonSettings.cs
  17. 126
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs

1
Assets/ScriptableRenderPipeline/Core/AdditionalLightData.cs


[HideInInspector, SerializeField] private ShadowData shadowData;
[HideInInspector, SerializeField] private ShadowData[] shadowDatas = new ShadowData[0];
public int cascadeCount { get { return shadowCascadeCount; } }
public void GetShadowCascades( out int cascadeCount, out float[] cascadeRatios ) { cascadeCount = shadowCascadeCount; cascadeRatios = shadowCascadeRatios; }
public void GetShadowAlgorithm( out int algorithm, out int variant, out int precision ) { algorithm = shadowAlgorithm; variant = shadowVariant; precision = shadowPrecision; }
public void SetShadowAlgorithm( int algorithm, int variant, int precision, int format, int[] data )

25
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs


public int panelCount { get { return m_DebugPanels.Count; } }
public DebugMenuUI menuUI { get { return m_DebugMenuUI; } }
private DebugMenuState m_DebugMenuState = null;
private bool m_DebugMenuStateDirty = false;
DebugMenuManager()
{
m_PersistentDebugPanel = new DebugPanel<DebugPanelUI>("Persistent");

public void Update()
{
if(m_DebugMenuState != null && m_DebugMenuStateDirty)
{
m_DebugMenuStateDirty = false;
m_DebugMenuState.UpdateAllDebugItems();
}
m_DebugMenuUI.Update();
}

public void AddDebugItem<DebugPanelType, DebugItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugPanelType : DebugPanel
{
DebugPanelType debugMenu = GetDebugPanel<DebugPanelType>();
if (debugMenu != null)
DebugPanelType debugPanel = GetDebugPanel<DebugPanelType>();
if (debugPanel != null)
debugMenu.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
m_DebugMenuStateDirty = true;
}
public void AddDebugItem<DebugItemType>(string debugPanelName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null)

{
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
}
m_DebugMenuStateDirty = true;
}
public void SetDebugMenuState(DebugMenuState state)
{
m_DebugMenuStateDirty = true;
m_DebugMenuState = state;
}
}
}

13
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs


}
}
m_DebugItem.SetValue(value, false);
if(m_DebugItem != null) // Can happen if not all menu are populated yet (depends on call order...)
m_DebugItem.SetValue(value, false);
}
}

#if UNITY_EDITOR
UnityEditor.Undo.undoRedoPerformed += OnUndoRedoPerformed;
#endif
for (int panelIdx = 0 ; panelIdx < dmm.panelCount ; ++panelIdx)
for (int panelIdx = 0; panelIdx < dmm.panelCount; ++panelIdx)
for(int itemIdx = 0 ; itemIdx < panel.itemCount ; ++itemIdx)
for (int itemIdx = 0; itemIdx < panel.itemCount; ++itemIdx)
{
DebugItem item = panel.GetDebugItem(itemIdx);
DebugItemState debugItemState = FindDebugItemState(item);

}
}
UpdateAllDebugItems();
DebugMenuManager.instance.SetDebugMenuState(this);
}
public void OnDisable()

{
itemState.UpdateDebugItemValue();
}
#if UNITY_EDITOR
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
#endif
}
}
}

5
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs


{
if (handler == null)
handler = new DefaultDebugItemHandler();
DebugItem oldItem = GetDebugItem(itemName);
if (oldItem != null)
RemoveDebugItem(oldItem);
DebugItem newItem = new DebugItem(itemName, m_Name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
handler.SetDebugItem(newItem);
m_Items.Add(newItem);

3
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs


public void RebuildGUI()
{
if (m_Root == null)
return;
for (int i = 0; i < m_Root.transform.childCount; ++i)
{
Object.DestroyImmediate(m_Root.transform.GetChild(i).gameObject);

8
Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs


protected uint m_ActiveEntriesCount;
protected FrameId m_FrameId;
protected string m_ShaderKeyword;
protected int m_CascadeCount;
protected Vector3 m_CascadeRatios;
protected uint m_TexSlot;
protected uint m_SampSlot;
protected uint[] m_TmpWidths = new uint[ShadowmapBase.ShadowRequest.k_MaxFaceCount];

{
public BaseInit baseInit; // the base class's initializer
public string shaderKeyword; // the global shader keyword to use when rendering the shadowmap
public int cascadeCount; // the number of cascades to use (these are global in ShadowSettings for now for some reason)
public Vector3 cascadeRatios; // cascade split ratios
}
// UI stuff

public void Initialize( AtlasInit init )
{
m_ShaderKeyword = init.shaderKeyword;
m_CascadeCount = init.cascadeCount;
m_CascadeRatios = init.cascadeRatios;
}
override public void ReserveSlots( ShadowContextStorage sc )

case LightType.Directional:
add = --m_MaxShadows[(int)GPUShadowType.Directional, 0] >= 0;
shadowType = GPUShadowType.Directional;
facecount = m_ShadowSettings.directionalLightCascadeCount;
facecount = ald.cascadeCount;
break;
case LightType.Point:
add = --m_MaxShadows[(int)GPUShadowType.Point, 0] >= 0;

42
Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs


namespace UnityEngine.Experimental.Rendering
{
// Class holding parameters for the initialization of the Shadow System
public class ShadowSettings
public class ShadowInitParameters
public bool enabled;
public int shadowAtlasWidth;
public int shadowAtlasHeight;
public const int kDefaultShadowAtlasSize = 4096;
public float maxShadowDistance;
public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
public float directionalLightNearPlaneOffset;
public int shadowAtlasWidth = kDefaultShadowAtlasSize;
public int shadowAtlasHeight = kDefaultShadowAtlasSize;
}
static ShadowSettings defaultShadowSettings = null;
// Class used to pass parameters to the shadow system on a per frame basis.
[Serializable]
public class ShadowSettings
{
public const float kDefaultMaxShadowDistance = 1000.0f;
public const float kDefaultDirectionalNearPlaneOffset = 5.0f;
public static ShadowSettings Default
{
get
{
if (defaultShadowSettings == null)
{
defaultShadowSettings = new ShadowSettings();
defaultShadowSettings.enabled = true;
defaultShadowSettings.shadowAtlasHeight = defaultShadowSettings.shadowAtlasWidth = 4096;
defaultShadowSettings.directionalLightCascadeCount = 1;
defaultShadowSettings.directionalLightCascades = new Vector3(0.05F, 0.2F, 0.3F);
defaultShadowSettings.directionalLightCascadeCount = 4;
defaultShadowSettings.directionalLightNearPlaneOffset = 5;
defaultShadowSettings.maxShadowDistance = 1000.0F;
}
return defaultShadowSettings;
}
}
public bool enabled = true;
public float maxShadowDistance = kDefaultMaxShadowDistance;
public float directionalLightNearPlaneOffset = kDefaultDirectionalNearPlaneOffset;
}
[GenerateHLSL]

22
Assets/ScriptableRenderPipeline/Core/TextureSettings.cs


namespace UnityEngine.Experimental.Rendering
{
[System.Serializable]
public struct TextureSettings
public class TextureSettings
public int spotCookieSize;
public int pointCookieSize;
public int reflectionCubemapSize;
public const int kDefaultSpotCookieSize = 128;
public const int kDefaultPointCookieSize = 512;
public const int kDefaultReflectionCubemapSize = 128;
public static TextureSettings Default
{
get
{
TextureSettings settings = new TextureSettings();
settings.spotCookieSize = 128;
settings.pointCookieSize = 512;
settings.reflectionCubemapSize = 128;
return settings;
}
}
public int spotCookieSize = kDefaultSpotCookieSize;
public int pointCookieSize = kDefaultPointCookieSize;
public int reflectionCubemapSize = kDefaultReflectionCubemapSize;
}
}

14
Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs


static ComputeBuffer s_ShadowDataBuffer;
static ComputeBuffer s_ShadowPayloadBuffer;
public ShadowSetup(ShadowSettings shadowSettings, out IShadowManager shadowManager)
public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSettings, out IShadowManager shadowManager)
atlasInit.baseInit.width = (uint)shadowSettings.shadowAtlasWidth;
atlasInit.baseInit.height = (uint)shadowSettings.shadowAtlasHeight;
atlasInit.baseInit.width = (uint)shadowInit.shadowAtlasWidth;
atlasInit.baseInit.height = (uint)shadowInit.shadowAtlasHeight;
atlasInit.baseInit.slices = 1;
atlasInit.baseInit.shadowmapBits = 32;
atlasInit.baseInit.shadowmapFormat = RenderTextureFormat.Shadowmap;

atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.baseInit.shadowSupport = ShadowmapBase.ShadowSupport.Directional | ShadowmapBase.ShadowSupport.Point | ShadowmapBase.ShadowSupport.Spot;
atlasInit.shaderKeyword = null;
atlasInit.cascadeCount = shadowSettings.directionalLightCascadeCount;
atlasInit.cascadeRatios = shadowSettings.directionalLightCascades;
m_Shadowmaps = new ShadowmapBase[] { new ShadowAtlas(ref atlasInit) };

}
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowSettings m_ShadowSettings = new ShadowSettings();
ShadowSetup m_ShadowSetup;
IShadowManager m_ShadowMgr;
FrameId m_FrameId = new FrameId();

void InitShadowSystem(ShadowSettings shadowSettings)
{
m_ShadowSetup = new ShadowSetup(shadowSettings, out m_ShadowMgr);
m_ShadowSetup = new ShadowSetup(new ShadowInitParameters(), shadowSettings, out m_ShadowMgr);
}
void DeinitShadowSystem()

[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
TextureSettings m_TextureSettings = new TextureSettings();
public Shader deferredShader;
public Shader deferredReflectionShader;

29
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


SerializedProperty m_Profiles = null;
SerializedProperty m_NumProfiles = null;
// Shadow Settings
SerializedProperty m_ShadowAtlasWidth = null;
SerializedProperty m_ShadowAtlasHeight = null;
// Texture Settings
SerializedProperty m_SpotCookieSize = null;
SerializedProperty m_PointCookieSize = null;
SerializedProperty m_ReflectionCubemapSize = null;
private void InitializeProperties()
{
m_DefaultDiffuseMaterial = serializedObject.FindProperty("m_DefaultDiffuseMaterial");

m_tileDebugByCategory = FindProperty(x => x.tileSettings.tileDebugByCategory);
// Shadow settings
m_ShadowAtlasWidth = FindProperty(x => x.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = FindProperty(x => x.shadowInitParams.shadowAtlasHeight);
//TODO!
// Texture settings
m_SpotCookieSize = FindProperty(x => x.textureSettings.spotCookieSize);
m_PointCookieSize = FindProperty(x => x.textureSettings.pointCookieSize);
m_ReflectionCubemapSize = FindProperty(x => x.textureSettings.reflectionCubemapSize);
// Rendering settings
m_RenderingUseForwardOnly = FindProperty(x => x.renderingSettings.useForwardRenderingOnly);

private void ShadowSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
var shadowSettings = renderContext.shadowSettings;
shadowSettings.shadowAtlasWidth = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasWidth, shadowSettings.shadowAtlasWidth));
shadowSettings.shadowAtlasHeight = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasHeight, shadowSettings.shadowAtlasHeight));
EditorGUILayout.PropertyField(m_ShadowAtlasWidth, styles.shadowsAtlasWidth);
EditorGUILayout.PropertyField(m_ShadowAtlasHeight, styles.shadowsAtlasHeight);
if (EditorGUI.EndChangeCheck())
{

private void TextureSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
var textureSettings = renderContext.textureSettings;
textureSettings.spotCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.spotCookieSize, textureSettings.spotCookieSize), 16, 1024));
textureSettings.pointCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.pointCookieSize, textureSettings.pointCookieSize), 16, 1024));
textureSettings.reflectionCubemapSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.reflectionCubemapSize, textureSettings.reflectionCubemapSize), 64, 1024));
EditorGUILayout.PropertyField(m_SpotCookieSize, styles.spotCookieSize);
EditorGUILayout.PropertyField(m_PointCookieSize, styles.pointCookieSize);
EditorGUILayout.PropertyField(m_ReflectionCubemapSize, styles.reflectionCubemapSize);
renderContext.textureSettings = textureSettings;
HackSetDirty(renderContext); // Repaint
}
EditorGUI.indentLevel--;

98
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


readonly SkyManager m_SkyManager = new SkyManager();
readonly LightLoop m_LightLoop = new LightLoop();
readonly ShadowSettings m_ShadowSettings = new ShadowSettings();
// Debugging
public DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings();
public SubsurfaceScatteringSettings sssSettings
{
get { return m_Asset.sssSettings; }
}
private CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
private SkySettings m_SkySettings;
private DebugDisplaySettings debugDisplaySettings
public CommonSettings.Settings commonSettingsToUse
get { return m_Asset.debugDisplaySettings; }
get
{
if (CommonSettingsSingleton.overrideSettings)
return CommonSettingsSingleton.overrideSettings.settings;
return m_CommonSettings;
}
public SubsurfaceScatteringSettings sssSettings
public SkySettings skySettingsToUse
get { return m_Asset.sssSettings; }
get
{
if (SkySettingsSingleton.overrideSettings)
return SkySettingsSingleton.overrideSettings;
return m_SkySettings;
}
public HDRenderPipeline(HDRenderPipelineAsset asset)
{
m_Asset = asset;

m_LitRenderLoop.Build(asset.renderPipelineResources);
m_LightLoop.Build(asset.renderPipelineResources, asset.tileSettings, asset.textureSettings);
m_LightLoop.Build(asset.renderPipelineResources, asset.tileSettings, asset.textureSettings, asset.shadowInitParams, m_ShadowSettings);
m_SkyManager.skySettings = asset.skySettingsToUse;
m_SkyManager.skySettings = skySettingsToUse;
m_DebugDisplaySettings.RegisterDebug();
}
void InitializeDebugMaterials()

// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager.skySettings = m_Asset.skySettingsToUse;
m_SkyManager.skySettings = skySettingsToUse;
m_SkyManager.Resize(camera.nearClipPlane, camera.farClipPlane); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (useful for lookdev)
bool resolutionChanged = camera.pixelWidth != m_CurrentWidth || camera.pixelHeight != m_CurrentHeight;

}
// Broadcast SSS parameters to all shaders.
Shader.SetGlobalInt( "_EnableSSS", debugDisplaySettings.renderingDebugSettings.enableSSS ? 1 : 0);
Shader.SetGlobalInt( "_EnableSSS", m_DebugDisplaySettings.renderingDebugSettings.enableSSS ? 1 : 0);
Shader.SetGlobalInt( "_TexturingModeFlags", (int)sssParameters.texturingModeFlags);
Shader.SetGlobalInt( "_TransmissionFlags", (int)sssParameters.transmissionFlags);
cmd.SetGlobalFloatArray( "_ThicknessRemaps", sssParameters.thicknessRemaps);

cmd.Dispose();
}
public void UpdateCommonSettings()
{
var commonSettings = commonSettingsToUse;
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
m_ShadowSettings.directionalLightNearPlaneOffset = commonSettings.shadowNearPlaneOffset;
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);

// Do anything we need to do upon a new frame.
m_LightLoop.NewFrame();
m_Asset.ApplyDebugDisplaySettings();
m_Asset.UpdateCommonSettings();
ApplyDebugDisplaySettings();
UpdateCommonSettings();
// Set Frame constant buffer
// TODO...

CopyDepthBufferIfNeeded(renderContext);
}
if (debugDisplaySettings.IsDebugMaterialDisplayEnabled())
if (m_DebugDisplaySettings.IsDebugMaterialDisplayEnabled())
{
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
}

{
// TODO: Everything here (SSAO, Shadow, Build light list, material and light classification can be parallelize with Async compute)
m_SsaoEffect.Render(m_Asset.ssaoSettingsToUse, hdCamera, renderContext, GetDepthTexture(), m_Asset.renderingSettings.useForwardRenderingOnly);
m_LightLoop.PrepareLightsForGPU(m_Asset.shadowSettings, cullResults, camera);
m_LightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera);
m_LightLoop.RenderShadows(renderContext, cullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_LightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthStencilBufferRT);

void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugDisplaySettings.renderingDebugSettings.displayOpaqueObjects)
if (!m_DebugDisplaySettings.renderingDebugSettings.displayOpaqueObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))

void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!debugDisplaySettings.renderingDebugSettings.displayTransparentObjects)
if (!m_DebugDisplaySettings.renderingDebugSettings.displayTransparentObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))

return;
}
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer";
string passName = m_DebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer";
using (new Utilities.ProfilingSample(passName, renderContext))
{

RenderTargetIdentifier[] colorRTs = { m_CameraColorBufferRT, m_CameraSubsurfaceBufferRT };
if (debugDisplaySettings.renderingDebugSettings.enableSSS)
if (m_DebugDisplaySettings.renderingDebugSettings.enableSSS)
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, debugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), true);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, m_DebugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), true);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, debugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), false);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, m_DebugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), false);
}
// Combines specular lighting and diffuse lighting with subsurface scattering.

if (m_Asset.renderingSettings.ShouldUseForwardRenderingOnly()) return;
if (!debugDisplaySettings.renderingDebugSettings.enableSSS) return;
if (!m_DebugDisplaySettings.renderingDebugSettings.enableSSS) return;
var cmd = new CommandBuffer() { name = "Subsurface Scattering" };

if (!m_Asset.renderingSettings.ShouldUseForwardRenderingOnly() && renderOpaque)
return;
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardDisplayDebug" : "Forward";
string passName = m_DebugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardDisplayDebug" : "Forward";
using (new Utilities.ProfilingSample(passName, renderContext))
{

// Render material that are forward opaque only (like eye), this include unlit material
void RenderForwardOnlyOpaque(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
string passName = debugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque";
string passName = m_DebugDisplaySettings.IsDebugDisplayEnabled() ? "ForwardOnlyOpaqueDisplayDebug" : "ForwardOnlyOpaque";
using (new Utilities.ProfilingSample(passName, renderContext))
{

void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
if (!debugDisplaySettings.renderingDebugSettings.enableDistortion)
if (!m_DebugDisplaySettings.renderingDebugSettings.enableDistortion)
return;
using (new Utilities.ProfilingSample("Distortion", renderContext))

}
}
public void ApplyDebugDisplaySettings()
{
m_ShadowSettings.enabled = m_DebugDisplaySettings.lightingDebugSettings.enableShadows;
LightingDebugSettings lightingDebugSettings = m_DebugDisplaySettings.lightingDebugSettings;
Vector4 debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);
Vector4 debugSmoothness = new Vector4(lightingDebugSettings.overrideSmoothness ? 1.0f : 0.0f, lightingDebugSettings.overrideSmoothnessValue, 0.0f, 0.0f);
Shader.SetGlobalInt("_DebugViewMaterial", (int)m_DebugDisplaySettings.GetDebugMaterialIndex());
Shader.SetGlobalInt("_DebugLightingMode", (int)m_DebugDisplaySettings.GetDebugLightingMode());
Shader.SetGlobalVector("_DebugLightingAlbedo", debugAlbedo);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
}
void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext)
{

debugCB.name = "Debug Overlay";
float x = 0;
float overlayRatio = debugDisplaySettings.debugOverlayRatio;
float overlayRatio = m_DebugDisplaySettings.debugOverlayRatio;
LightingDebugSettings lightingDebug = debugDisplaySettings.lightingDebugSettings;
LightingDebugSettings lightingDebug = m_DebugDisplaySettings.lightingDebugSettings;
if (lightingDebug.displaySkyReflection)
{

renderContext.ExecuteCommandBuffer(debugCB);
m_LightLoop.RenderDebugOverlay(camera, renderContext, debugDisplaySettings, ref x, ref y, overlaySize, camera.pixelWidth);
m_LightLoop.RenderDebugOverlay(camera, renderContext, m_DebugDisplaySettings, ref x, ref y, overlaySize, camera.pixelWidth);
}
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)

27
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset


- {fileID: 11400000, guid: d6ee4403015766f4093158d69216c0bf, type: 2}
- {fileID: 11400000, guid: 906339bac2066fc4aa22a3652e1283ef, type: 2}
tileSettings:
enableTileAndCluster: 1
enableTileAndCluster: 0
enableSplitLightEvaluation: 1
enableComputeLightEvaluation: 0
enableComputeFeatureVariants: 0

diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
tileDebugByCategory: 0
m_ShadowSettings:
enabled: 1
shadowAtlasWidth: 4096
shadowInitParams:
shadowAtlasWidth: 2048
maxShadowDistance: 1000
directionalLightCascadeCount: 4
directionalLightCascades: {x: 0.05, y: 0.2, z: 0.3}
directionalLightNearPlaneOffset: 5
m_TextureSettings:
textureSettings:
m_CommonSettings:
m_ShadowMaxDistance: 1000
m_ShadowCascadeCount: 4
m_ShadowCascadeSplit0: 0.05
m_ShadowCascadeSplit1: 0.2
m_ShadowCascadeSplit2: 0.3
m_ShadowNearPlaneOffset: 5
m_SkySettings: {fileID: 0}
m_SsaoSettings:
m_Enable: 0
m_Intensity: 1
m_Radius: 0.5
m_SampleCount: 8
m_Downsampling: 1
m_DefaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17,
type: 2}
m_DefaultShader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}

92
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


// NOTE: All those properties are public because of how HDRenderPipelineInspector retrieve those properties via serialization/reflection
// Doing it this way allow to change parameters name and still retrieve correct serialized value
// Debugging (Not persistent)
public DebugDisplaySettings debugDisplaySettings = new DebugDisplaySettings();
// Renderer Settings (per project)
// Renderer Settings
// TODO: Following two settings need to be update to the serialization/reflection way like above
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
public ShadowSettings shadowSettings
{
get { return m_ShadowSettings; }
}
public TextureSettings textureSettings
{
get { return m_TextureSettings; }
set { m_TextureSettings = value; }
}
// NOTE: Following settings are Asset so they need to be serialized as usual. no reflection/serialization here
// Renderer Settings (per "scene")
[SerializeField]
private CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
[SerializeField]
private SkySettings m_SkySettings;
public CommonSettings.Settings commonSettingsToUse
{
get
{
if (CommonSettingsSingleton.overrideSettings)
return CommonSettingsSingleton.overrideSettings.settings;
return m_CommonSettings;
}
}
/*
public SkySettings skySettings
{
get { return m_SkySettings; }
set { m_SkySettings = value; }
}
*/
// Shadow Settings
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
public SkySettings skySettingsToUse
{
get
{
if (SkySettingsSingleton.overrideSettings)
return SkySettingsSingleton.overrideSettings;
// Texture Settings
public TextureSettings textureSettings = new TextureSettings();
return m_SkySettings;
}
}
[SerializeField]
private ScreenSpaceAmbientOcclusionSettings.Settings m_SsaoSettings = ScreenSpaceAmbientOcclusionSettings.Settings.s_Defaultsettings;
public ScreenSpaceAmbientOcclusionSettings.Settings ssaoSettingsToUse

return null;
}
public void ApplyDebugDisplaySettings()
{
m_ShadowSettings.enabled = debugDisplaySettings.lightingDebugSettings.enableShadows;
LightingDebugSettings lightingDebugSettings = debugDisplaySettings.lightingDebugSettings;
Vector4 debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);
Vector4 debugSmoothness = new Vector4(lightingDebugSettings.overrideSmoothness ? 1.0f : 0.0f, lightingDebugSettings.overrideSmoothnessValue, 0.0f, 0.0f);
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugDisplaySettings.GetDebugMaterialIndex());
Shader.SetGlobalInt("_DebugLightingMode", (int)debugDisplaySettings.GetDebugLightingMode());
Shader.SetGlobalVector("_DebugLightingAlbedo", debugAlbedo);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
}
public void UpdateCommonSettings()
{
var commonSettings = commonSettingsToUse;
m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
m_ShadowSettings.directionalLightNearPlaneOffset = commonSettings.shadowNearPlaneOffset;
}
debugDisplaySettings.OnValidate();
}
void OnEnable()
{
debugDisplaySettings.RegisterDebug();
}
}
}

16
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


static ComputeBuffer s_ShadowDataBuffer;
static ComputeBuffer s_ShadowPayloadBuffer;
public ShadowSetup(ShadowSettings shadowSettings, out IShadowManager shadowManager)
public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSettings, out IShadowManager shadowManager)
atlasInit.baseInit.width = (uint)shadowSettings.shadowAtlasWidth;
atlasInit.baseInit.height = (uint)shadowSettings.shadowAtlasHeight;
atlasInit.baseInit.width = (uint)shadowInit.shadowAtlasWidth;
atlasInit.baseInit.height = (uint)shadowInit.shadowAtlasHeight;
atlasInit.baseInit.slices = 1;
atlasInit.baseInit.shadowmapBits = 32;
atlasInit.baseInit.shadowmapFormat = RenderTextureFormat.Shadowmap;

atlasInit.baseInit.maxPayloadCount = 0;
atlasInit.baseInit.shadowSupport = ShadowmapBase.ShadowSupport.Directional | ShadowmapBase.ShadowSupport.Point | ShadowmapBase.ShadowSupport.Spot;
atlasInit.shaderKeyword = null;
atlasInit.cascadeCount = shadowSettings.directionalLightCascadeCount;
atlasInit.cascadeRatios = shadowSettings.directionalLightCascades;
var varianceInit = atlasInit;
varianceInit.baseInit.shadowmapFormat = ShadowVariance.GetFormat( false, false, true );

List<int> m_ShadowRequests = new List<int>();
Dictionary<int, int> m_ShadowIndices = new Dictionary<int, int>();
void InitShadowSystem(ShadowSettings shadowSettings)
void InitShadowSystem(ShadowInitParameters initParam, ShadowSettings shadowSettings)
m_ShadowSetup = new ShadowSetup(shadowSettings, out m_ShadowMgr);
m_ShadowSetup = new ShadowSetup(initParam, shadowSettings, out m_ShadowMgr);
}
void DeinitShadowSystem()

public LightLoop()
{}
public void Build(RenderPipelineResources renderPipelineResources, TileSettings tileSettings, TextureSettings textureSettings)
public void Build(RenderPipelineResources renderPipelineResources, TileSettings tileSettings, TextureSettings textureSettings, ShadowInitParameters shadowInit, ShadowSettings shadowSettings)
{
m_Resources = renderPipelineResources;
m_TileSettings = tileSettings;

UnityEditor.SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
InitShadowSystem(ShadowSettings.Default);
InitShadowSystem(shadowInit, shadowSettings);
}
public void Cleanup()

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl


int shadowSplitIndex = EvalShadow_GetSplitSphereIndexForDirshadows(positionWS, dirShadowSplitSpheres);
if (shadowSplitIndex == -1)
{
}
}
#endif
}

24
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/CommonSettings.cs


[SerializeField]
float m_ShadowMaxDistance;
[SerializeField]
int m_ShadowCascadeCount;
[SerializeField]
float m_ShadowCascadeSplit0;
[SerializeField]
float m_ShadowCascadeSplit1;
[SerializeField]
float m_ShadowCascadeSplit2;
[SerializeField]
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }
public float shadowCascadeSplit0 { set { m_ShadowCascadeSplit0 = value; OnValidate(); } get { return m_ShadowCascadeSplit0; } }
public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
m_ShadowCascadeCount = Mathf.Min(4, Mathf.Max(1, m_ShadowCascadeCount));
m_ShadowCascadeSplit0 = Mathf.Clamp01(m_ShadowCascadeSplit0);
m_ShadowCascadeSplit1 = Mathf.Clamp01(m_ShadowCascadeSplit1);
m_ShadowCascadeSplit2 = Mathf.Clamp01(m_ShadowCascadeSplit2);
m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance,
m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount,
m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x,
m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y,
m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z,
m_ShadowNearPlaneOffset = ShadowSettings.Default.directionalLightNearPlaneOffset,
m_ShadowMaxDistance = ShadowSettings.kDefaultMaxShadowDistance,
m_ShadowNearPlaneOffset = ShadowSettings.kDefaultDirectionalNearPlaneOffset,
};
}

126
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs


{
private class Styles
{
public readonly GUIContent none = new GUIContent("None");
public readonly GUIContent sky = new GUIContent("Sky");
public readonly GUIContent skyRenderer = new GUIContent("Sky Renderer");
public readonly GUIContent shadows = new GUIContent("Shadows");
public readonly GUIContent shadowsDirectionalLightCascadeCount = new GUIContent("Directional cascade count");
public readonly GUIContent[] shadowsCascadeCounts = new GUIContent[] { new GUIContent("1"), new GUIContent("2"), new GUIContent("3"), new GUIContent("4") };
public readonly int[] shadowsCascadeCountValues = new int[] { 1, 2, 3, 4 };
public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent[] shadowSplits = new GUIContent[] { new GUIContent("Split 0"), new GUIContent("Split 1"), new GUIContent("Split 2") };
public readonly GUIContent nearPlaneOffset = new GUIContent("Near plane offset");
public readonly GUIContent nearPlaneOffset = new GUIContent("Shadow near plane offset");
}
private static Styles s_Styles = null;

}
}
// Sky renderer
List<Type> m_SkyRendererTypes = new List<Type>();
private List<GUIContent> m_SkyRendererTypeNames = new List<GUIContent>();
private List<string> m_SkyRendererFullTypeNames = new List<string>();
private List<int> m_SkyRendererTypeValues = new List<int>();
private bool multipleEditing { get { return targets.Length > 1; } }
private SerializedProperty m_SkyRenderer;
private SerializedProperty m_ShadowCascadeCount;
private SerializedProperty[] m_ShadowCascadeSplits = new SerializedProperty[3];
m_SkyRenderer = serializedObject.FindProperty("m_SkyRendererTypeName");
m_ShadowMaxDistance = serializedObject.FindProperty("m_ShadowMaxDistance");
m_ShadowCascadeCount = serializedObject.FindProperty("m_ShadowCascadeCount");
for (int i = 0; i < 3; ++i)
m_ShadowCascadeSplits[i] = serializedObject.FindProperty(string.Format("m_ShadowCascadeSplit{0}", i));
m_ShadowNearPlaneOffset = serializedObject.FindProperty("m_ShadowNearPlaneOffset");
m_SkyRendererTypes = Assembly.GetAssembly(typeof(SkyRenderer))
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(SkyRenderer)) && !t.IsGenericType)
.ToList();
// Prepare the list of available SkyRenderers for the IntPopup
m_SkyRendererTypeNames.Clear();
m_SkyRendererFullTypeNames.Clear();
m_SkyRendererTypeValues.Clear();
for (int i = 0; i < m_SkyRendererTypes.Count; ++i)
{
string longName = m_SkyRendererTypes[i].ToString();
m_SkyRendererFullTypeNames.Add(longName);
char[] separators = {'.'};
string[] tokens = longName.Split(separators);
m_SkyRendererTypeNames.Add(new GUIContent(tokens[tokens.Length - 1]));
m_SkyRendererTypeValues.Add(i);
}
// Add default null value.
m_SkyRendererTypeNames.Add(styles.none);
m_SkyRendererFullTypeNames.Add("");
m_SkyRendererTypeValues.Add(m_SkyRendererTypeValues.Count);
m_SkyRendererTypes.Add(null);
}
void OnSkyInspectorGUI()
{
EditorGUILayout.LabelField(styles.sky);
EditorGUI.indentLevel++;
// Retrieve the index of the current SkyRenderer. Won't be used in case of multiple editing with different values
int index = -1;
for (int i = 0; i < m_SkyRendererTypeNames.Count; ++i)
{
if (m_SkyRendererFullTypeNames[i] == m_SkyRenderer.stringValue)
{
index = i;
break;
}
}
EditorGUI.showMixedValue = m_SkyRenderer.hasMultipleDifferentValues;
EditorGUI.BeginChangeCheck();
int newValue = EditorGUILayout.IntPopup(styles.skyRenderer, index, m_SkyRendererTypeNames.ToArray(), m_SkyRendererTypeValues.ToArray());
if (EditorGUI.EndChangeCheck())
{
m_SkyRenderer.stringValue = m_SkyRendererFullTypeNames[newValue];
}
EditorGUI.showMixedValue = false;
EditorGUI.indentLevel--;
m_ShadowMaxDistance = serializedObject.FindProperty("m_Settings.m_ShadowMaxDistance");
m_ShadowNearPlaneOffset = serializedObject.FindProperty("m_Settings.m_ShadowNearPlaneOffset");
void OnShadowInspectorGUI()
{
EditorGUILayout.LabelField(styles.shadows);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_ShadowMaxDistance, styles.maxShadowDistance);
EditorGUI.BeginChangeCheck();
EditorGUI.showMixedValue = m_ShadowCascadeCount.hasMultipleDifferentValues;
int newCascadeCount = EditorGUILayout.IntPopup(styles.shadowsDirectionalLightCascadeCount, m_ShadowCascadeCount.intValue, styles.shadowsCascadeCounts, styles.shadowsCascadeCountValues);
if (EditorGUI.EndChangeCheck())
{
m_ShadowCascadeCount.intValue = newCascadeCount;
}
// Compute max cascade count.
int maxCascadeCount = 0;
for (int i = 0; i < targets.Length; ++i)
{
CommonSettings settings = targets[i] as CommonSettings;
maxCascadeCount = Math.Max(maxCascadeCount, settings.settings.shadowCascadeCount);
}
EditorGUI.indentLevel++;
for (int i = 0; i < maxCascadeCount - 1; i++)
{
EditorGUILayout.PropertyField(m_ShadowCascadeSplits[i], styles.shadowSplits[i]);
}
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(m_ShadowNearPlaneOffset, styles.nearPlaneOffset);
EditorGUI.indentLevel--;
}
/*
OnSkyInspectorGUI();
OnShadowInspectorGUI();
EditorGUILayout.PropertyField(m_ShadowMaxDistance, styles.maxShadowDistance);
EditorGUILayout.PropertyField(m_ShadowNearPlaneOffset, styles.nearPlaneOffset);
*/
}
}
正在加载...
取消
保存