浏览代码

First step in removing the old shadow system. Stubbed out the old system in HDRenderloop.

/main
uygar 8 年前
当前提交
3043024a
共有 4 个文件被更改,包括 100 次插入54 次删除
  1. 25
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs
  3. 118
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  4. 4
      Assets/ScriptableRenderPipeline/RenderPasses/ShadowRenderPass.cs

25
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


//#define SHADOWS_OLD
using UnityEngine.Rendering;
using System;
using System.Linq;

int m_CurrentWidth;
int m_CurrentHeight;
#if SHADOWS_OLD
#else
public int GetCurrentShadowCount() { return m_LightLoop.GetCurrentShadowCount(); }
#endif
readonly SkyManager m_SkyManager = new SkyManager();
private readonly BaseLightLoop m_LightLoop;

InitializeDebugMaterials();
#if SHADOWS_OLD
#endif
// Init Gbuffer description
m_gbufferManager.gbufferCount = m_LitRenderLoop.GetMaterialGBufferCount();

if (!CullResults.GetCullingParameters(camera, out cullingParams))
return;
#if SHADOWS_OLD
#else
cullingParams.shadowDistance = Mathf.Min( 1000.0f, cullingParams.shadowDistance );
#endif
var cullResults = CullResults.Cull(ref cullingParams, renderContext);
Resize(camera);

}
else
{
#if SHADOWS_OLD
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{
m_ShadowPass.Render(renderContext, cullResults, out m_ShadowsResult);

#endif
#if SHADOWS_OLD
#else
m_LightLoop.PrepareLightsForGPU(m_Owner.shadowSettings, cullResults, camera);
#endif
m_LightLoop.RenderShadows(renderContext, cullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_LightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthStencilBufferRT); // TODO: Use async compute here to run light culling during shadow

if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeShadowMap)
{
uint visualizeShadowIndex = Math.Min(lightingDebug.shadowMapIndex, (uint)(GetCurrentShadowCount() - 1));
#if SHADOWS_OLD
ShadowLight shadowLight = m_ShadowsResult.shadowLights[visualizeShadowIndex];
for (int slice = 0; slice < shadowLight.shadowSliceCount; ++slice)
{

NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
}
#endif
}
else if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeAtlas)
{

renderContext.ExecuteCommandBuffer(debugCB);
}
#if SHADOWS_OLD
// Function to prepare light structure for GPU lighting
void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput)
{

}
#endif
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderContext))

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs


//#define SHADOWS_OLD
using UnityEngine;
using UnityEngine.Rendering;

public virtual void ReleaseResolutionDependentBuffers() {}
public virtual void NewFrame() {}
#if SHADOWS_OLD
#else
public virtual int GetCurrentShadowCount() { return 0; }
public virtual void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera) { }
#endif
public virtual void RenderShadows( ScriptableRenderContext renderContext, CullResults cullResults ) { }
// TODO: this should not be part of the interface but for now make something working

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


#define SHADOWS_ENABLED
#define SHADOWS_FIXSHADOWIDX
//#define SHADOWS_OLD
using UnityEngine.Rendering;
using System.Collections.Generic;
using System;

#if SHADOWS_ENABLED
#if !SHADOWS_OLD
using ShadowExp;
class ShadowSetup : IDisposable

var varianceInit3 = varianceInit;
varianceInit3.baseInit.shadowmapFormat = ShadowVariance.GetFormat( true, false, true );
m_Shadowmaps = new ShadowmapBase[] { new ShadowExp.ShadowVariance( ref varianceInit ), new ShadowExp.ShadowVariance( ref varianceInit2 ), new ShadowExp.ShadowVariance( ref varianceInit3 ), new ShadowExp.ShadowAtlas( ref atlasInit ) };
m_Shadowmaps = new ShadowmapBase[] { new ShadowExp.ShadowVariance( ref varianceInit ), new ShadowExp.ShadowVariance( ref varianceInit2 ), new ShadowExp.ShadowVariance( ref varianceInit3 ), new ShadowExp.ShadowAtlas( ref atlasInit ) };
ShadowContext.SyncDel syncer = (ShadowContext sc) =>
{

Material m_SingleDeferredMaterialSRT = null;
Material m_SingleDeferredMaterialMRT = null;
#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
// shadow related stuff
FrameId m_FrameId;
ShadowSetup m_ShadowSetup; // doesn't actually have to reside here, it would be enough to pass the IShadowManager in from the outside

UnityEditor.SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
InitShadowSystem(ShadowSettings.Default);
#endif
}

#if !SHADOWS_OLD
#endif
#if UNITY_EDITOR
UnityEditor.SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif

{
return new Vector3(light.finalColor.r, light.finalColor.g, light.finalColor.b);
}
#if SHADOWS_OLD
// Return number of added shadow
public int GetShadows(VisibleLight light, int lightIndex, ref ShadowOutput shadowOutput, ShadowSettings shadowSettings)
{

return shadowOutput.GetShadowSliceCountLightIndex(lightIndex);
}
#endif
#if SHADOWS_OLD
#else
public bool GetDirectionalLightData(ShadowSettings shadowSettings, GPULightType gpuLightType, VisibleLight light, AdditionalLightData additionalData, int lightIndex)
#endif
{
var directionalLightData = new DirectionalLightData();

directionalLightData.tileCookie = (light.light.cookie.wrapMode == TextureWrapMode.Repeat);
directionalLightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
}
#if SHADOWS_OLD
bool hasDirectionalShadows = light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;
bool hasDirectionalNotReachMaxLimit = directionalShadowcount == 0; // Only one cascade shadow allowed

m_lightList.directionalShadowSplitSphereSqr[s] = shadowOutput.directionalShadowSplitSphereSqr[s];
}
}
#else
// fix up shadow information
int shadowIdx;
if (m_ShadowIndices.TryGetValue(lightIndex, out shadowIdx))
{
directionalLightData.shadowIndex = shadowIdx;
m_CurrentSunLight = light.light;
}
m_CurrentSunLight = m_CurrentSunLight == null ? light.light : m_CurrentSunLight;
#endif
m_lightList.directionalLights.Add(directionalLightData);
return true;

return 1.0f - Mathf.Clamp01((distanceToCamera - distanceFadeNear) / (fadeDistance - distanceFadeNear));
}
#if SHADOWS_OLD
#else
public bool GetLightData(ShadowSettings shadowSettings, Camera camera, GPULightType gpuLightType, VisibleLight light, AdditionalLightData additionalData, int lightIndex)
#endif
{
var lightData = new LightData();

break;
}
}
#if SHADOWS_OLD
// Setup shadow data arrays
// In case lightData.shadowDimmer == 0.0 we need to avoid rendering the shadow map... see how it can be done with the culling (and more specifically, how can we do that BEFORE sending for shadows)
bool hasShadows = lightData.shadowDimmer > 0.0f && light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;

lightData.shadowIndex = m_lightList.shadows.Count;
shadowCount += GetShadows(light, lightIndex, ref shadowOutput, shadowSettings);
}
#else
// fix up shadow information
int shadowIdx;
if (m_ShadowIndices.TryGetValue(lightIndex, out shadowIdx))
{
lightData.shadowIndex = shadowIdx;
}
#endif
if (additionalData.archetype != LightArchetype.Punctual)
{
lightData.twoSided = additionalData.isDoubleSided;

m_lightList.bounds.Add(bound);
m_lightList.lightVolumes.Add(lightVolumeData);
}
#if SHADOWS_OLD
public override void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput)
#else
public override int GetCurrentShadowCount()
{
return m_ShadowRequests.Count;
}
public override void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput)
public override void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera)
#endif
{
m_lightList.Clear();

#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
// 0. deal with shadows
{
m_FrameId.frameCount++;

int lcnt = cullResults.visibleLights.Length;
for( int i = 0; i < lcnt; ++i )
{
if( cullResults.visibleLights[i].light.shadows != LightShadows.None )
VisibleLight vl = cullResults.visibleLights[i];
if( vl.light.shadows != LightShadows.None && vl.light.GetComponent<AdditionalLightData>().shadowDimmer > 0.0f )
m_ShadowRequests.Add( i );
}
// pass this list to a routine that assigns shadows based on some heuristic

}
}
#if (SHADOWS_ENABLED)
#if SHADOWS_OLD
// 5 bit (0x1F) light category, 5 bit (0x1F) GPULightType, 6 bit (0x3F) lightVolume, 16 bit index
sortKeys[sortCount++] = (uint)lightCategory << 27 | (uint)gpuLightType << 22 | (uint)lightVolumeType << 16 | (uint)lightIndex;
#else
#else
// 5 bit (0x1F) light category, 5 bit (0x1F) GPULightType, 6 bit (0x3F) lightVolume, 16 bit index
sortKeys[sortCount++] = (uint)lightCategory << 27 | (uint)gpuLightType << 22 | (uint)lightVolumeType << 16 | (uint)lightIndex;
#endif
}

// will be use...)
// The lightLoop is in charge, not the shadow pass.
// For now we will still apply the maximum of shadow here but we don't apply the sorting by priority + slot allocation yet
#if SHADOWS_OLD
#endif
m_CurrentSunLight = null;
// 2. Go thought all lights, convert them to GPU format.
// Create simultaneously data for culling (LigthVolumeData and rendering)

uint sortKey = sortKeys[sortIndex];
LightCategory lightCategory = (LightCategory)((sortKey >> 27) & 0x1F);
GPULightType gpuLightType = (GPULightType)((sortKey >> 22) & 0x1F);
#if (SHADOWS_ENABLED)
LightVolumeType lightVolumeType = (LightVolumeType)((sortKey >> 17) & 0x1F);
#if SHADOWS_OLD
LightVolumeType lightVolumeType = (LightVolumeType)((sortKey >> 16) & 0x3F);
LightVolumeType lightVolumeType = (LightVolumeType)((sortKey >> 16) & 0x3F);
LightVolumeType lightVolumeType = (LightVolumeType)((sortKey >> 17) & 0x1F);
#endif
int lightIndex = (int)(sortKey & 0xFFFF);

// Directional rendering side, it is separated as it is always visible so no volume to handle here
if (gpuLightType == GPULightType.Directional)
{
#if SHADOWS_OLD
#else
if (GetDirectionalLightData(shadowSettings, gpuLightType, light, additionalData, lightIndex))
#endif
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information
int shadowIdxDir;
if( m_ShadowIndices.TryGetValue( lightIndex, out shadowIdxDir ) )
{
var lightData = m_lightList.directionalLights[m_lightList.directionalLights.Count-1];
lightData.shadowIndex = shadowIdxDir;
m_lightList.directionalLights[m_lightList.directionalLights.Count-1] = lightData;
}
#endif
// Spot, point, rect, line light - Rendering side
#if SHADOWS_OLD
#else
if(GetLightData(shadowSettings, camera, gpuLightType, light, additionalData, lightIndex))
#endif
{
if (lightCategory == LightCategory.Punctual)
punctualLightcount++;

// Then culling side. Must be call in this order as we pass the created Light data to the function
GetLightVolumeDataAndBound(lightCategory, gpuLightType, lightVolumeType, light, m_lightList.lights[m_lightList.lights.Count - 1], worldToView);
}
#if (SHADOWS_ENABLED && SHADOWS_FIXSHADOWIDX)
// fix up shadow information
int shadowIdx;
if( m_ShadowIndices.TryGetValue( lightIndex, out shadowIdx ) )
{
var lightData = m_lightList.lights[m_lightList.lights.Count-1];
lightData.shadowIndex = shadowIdx;
m_lightList.lights[m_lightList.lights.Count-1] = lightData;
}
#endif
}
// Sanity check

private void BindGlobalParams(CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, Camera camera, ScriptableRenderContext loop)
{
#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
m_ShadowMgr.BindResources(loop);
#endif
SetGlobalBuffer("g_vLightListGlobal", !usingFptl ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)

{
var cmd = new CommandBuffer { name = "Push Global Parameters" };
#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
// Shadows
m_ShadowMgr.SyncData();
#endif

public override void RenderShadows( ScriptableRenderContext renderContext, CullResults cullResults )
{
#if (SHADOWS_ENABLED)
#if !SHADOWS_OLD
// kick off the shadow jobs here
m_ShadowMgr.RenderShadows( m_FrameId, renderContext, cullResults, cullResults.visibleLights );
#endif

4
Assets/ScriptableRenderPipeline/RenderPasses/ShadowRenderPass.cs


#define SHADOWS_OLD // can't disable this until fptl has moved over as well
using UnityEngine.Rendering;
using UnityEngine.Profiling;
using System.Collections.Generic;

}
}
}
#if SHADOWS_OLD
public struct InputShadowLightData
{
public int lightIndex;

loop.DrawShadows(ref settings);
}
}
#endif
}
正在加载...
取消
保存