浏览代码

[refactoring] HDLoop to do nice allocate / deallocate based on instantiation of loop instances.

/main
Tim Cooper 8 年前
当前提交
aa75277c
共有 11 个文件被更改,包括 447 次插入438 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  2. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset
  3. 744
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  4. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipelineSetup.cs
  5. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs
  6. 72
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  7. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  8. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  9. 31
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
  10. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs
  11. 2
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


EditorGUILayout.Space();
// TODO: we should call a virtual method or something similar to setup the UI, inspector should not know about it
TilePass.LightLoop tilePass = renderContext.lightLoop as TilePass.LightLoop;
var tilePass = renderContext.tileSettings;
if (tilePass != null)
{
EditorGUILayout.LabelField(styles.tileLightLoopSettings);

10
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset


spotCookieSize: 128
pointCookieSize: 512
reflectionCubemapSize: 128
m_TileSettings:
enableDrawLightBoundsDebug: 0
disableTileAndCluster: 0
disableDeferredShadingInCompute: 0
enableSplitLightEvaluation: 0
enableComputeLightEvaluation: 0
debugViewTilesFlags: 0
enableClustered: 0
disableFptlWhenClustered: 1
enableBigTilePrepass: 0

744
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


using UnityEngine.Rendering;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Experimental.Rendering.HDPipeline.TilePass;
public class HDRenderPipelineInstance : RenderPipeline
{
private readonly HDRenderPipeline m_Owner;
public HDRenderPipelineInstance(HDRenderPipeline owner)
{
m_Owner = owner;
if (m_Owner != null)
m_Owner.Build();
}
public override void Dispose()
{
base.Dispose();
if (m_Owner != null)
m_Owner.Cleanup();
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
m_Owner.Render(renderContext, cameras);
}
}
[ExecuteInEditMode]
// This HDRenderPipeline assume linear lighting. Don't work with gamma.
public class HDRenderPipeline : RenderPipelineAsset

[UnityEditor.MenuItem("RenderPipeline/CreateHDRenderPipeline")]
static void CreateHDRenderPipeline()
{
var instance = ScriptableObject.CreateInstance<HDRenderPipeline>();
UnityEditor.AssetDatabase.CreateAsset(instance, k_HDRenderPipelinePath);
var instance = CreateInstance<HDRenderPipeline>();
AssetDatabase.CreateAsset(instance, k_HDRenderPipelinePath);
instance.m_setup = UnityEditor.AssetDatabase.LoadAssetAtPath<HDRenderPipelineSetup>("Assets/HDRenderPipelineSetup.asset");
}

}
#endif
HDRenderPipeline()
{
m_lightLoop = new TilePass.LightLoop(this);
}
private HDRenderPipeline()
{ }
[SerializeField]
private HDRenderPipelineSetup m_setup;

get { return m_setup; }
}
SkyManager m_SkyManager = new SkyManager();
public SkyManager skyManager
readonly DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
get { return m_SkyManager; }
get { return m_DebugParameters; }
public void InstantiateSkyRenderer(Type skyRendererType)
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
public ShadowSettings shadowSettings
m_SkyManager.InstantiateSkyRenderer(skyRendererType);
get { return m_ShadowSettings; }
public class DebugParameters
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
public TextureSettings textureSettings
// Material Debugging
public int debugViewMaterial = 0;
get { return m_TextureSettings; }
set { m_TextureSettings = value; }
}
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
[SerializeField]
TileSettings m_TileSettings = new TileSettings();
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly () { return useForwardRenderingOnly || GL.wireframe; }
public TileSettings tileSettings
{
get { return m_TileSettings; }
DebugParameters m_DebugParameters = new DebugParameters();
public DebugParameters debugParameters
CommonSettings m_CommonSettings;
public CommonSettings commonSettings
get { return m_DebugParameters; }
set { m_CommonSettings = value; }
get { return m_CommonSettings; }
public class GBufferManager
public void UpdateCommonSettings()
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
if (commonSettings == null)
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
m_ShadowSettings.maxShadowDistance = ShadowSettings.Default.maxShadowDistance;
m_ShadowSettings.directionalLightCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
m_ShadowSettings.directionalLightCascades = ShadowSettings.Default.directionalLightCascades;
public void InitGBuffers(int width, int height, CommandBuffer cmd)
else
for (int index = 0; index < gbufferCount; index++)
{
/* RTs[index] = */ cmd.GetTemporaryRT(IDs[index], width, height, 0, FilterMode.Point, formats[index], sRGBWrites[index]);
}
m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
}
public void InstantiateSkyRenderer(Type skyRendererType)
{
var instances = CreatedInstances().OfType<HDRenderPipeline>();
foreach (var instance in instances)
instance.InstantiateSkyRenderer(skyRendererType);
}
public RenderTargetIdentifier[] GetGBuffers()
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
{
colorMRTs[index] = RTIDs[index];
}
public Type GetSkyParameterType()
{
var instance = CreatedInstances().OfType<HDRenderPipeline>().FirstOrDefault();
if (instance == null)
return null;
return instance.GetType();
}
}
return colorMRTs;
}
[Serializable]
public class TileSettings
{
public bool enableDrawLightBoundsDebug = false;
public bool disableTileAndCluster = true; // For debug / test
public bool disableDeferredShadingInCompute = true;
public bool enableSplitLightEvaluation = true;
public bool enableComputeLightEvaluation = false;
/*
public void BindBuffers(Material mat)
{
for (int index = 0; index < gbufferCount; index++)
{
mat.SetTexture(IDs[index], RTs[index]);
}
}
*/
// clustered light list specific buffers and data begin
public int debugViewTilesFlags = 0;
public bool enableClustered = false;
public bool disableFptlWhenClustered = true; // still useful on opaques. Should be false by default to force tile on opaque.
public bool enableBigTilePrepass = false;
}
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
public struct HDCamera
{
public Camera camera;
public Vector4 screenSize;
public Matrix4x4 viewProjectionMatrix;
public Matrix4x4 invViewProjectionMatrix;
}
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0;
GBufferManager m_gbufferManager = new GBufferManager();
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
public ShadowSettings shadowSettings
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly() { return useForwardRenderingOnly || GL.wireframe; }
}
public class GBufferManager
{
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
get { return m_ShadowSettings; }
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
ShadowRenderPass m_ShadowPass;
public void InitGBuffers(int width, int height, CommandBuffer cmd)
{
for (int index = 0; index < gbufferCount; index++)
{
/* RTs[index] = */
cmd.GetTemporaryRT(IDs[index], width, height, 0, FilterMode.Point, formats[index], sRGBWrites[index]);
}
}
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
public RenderTargetIdentifier[] GetGBuffers()
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
{
colorMRTs[index] = RTIDs[index];
}
return colorMRTs;
}
public TextureSettings textureSettings
/*
public void BindBuffers(Material mat)
get { return m_TextureSettings; }
set { m_TextureSettings = value; }
for (int index = 0; index < gbufferCount; index++)
{
mat.SetTexture(IDs[index], RTs[index]);
}
*/
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
public class HDRenderPipelineInstance : RenderPipeline
{
private readonly HDRenderPipeline m_Owner;
// TODO: Find a way to automatically create/iterate through deferred material
// TODO TO CHECK: SebL I move allocation from Build() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?
private readonly Lit.RenderLoop m_LitRenderLoop = new Lit.RenderLoop();
readonly GBufferManager m_gbufferManager = new GBufferManager();
Material m_DebugViewMaterialGBuffer;
readonly Material m_DebugViewMaterialGBuffer;
int m_CameraColorBuffer;
int m_CameraDepthBuffer;
int m_VelocityBuffer;
int m_DistortionBuffer;
readonly int m_CameraColorBuffer;
readonly int m_CameraDepthBuffer;
readonly int m_VelocityBuffer;
readonly int m_DistortionBuffer;
RenderTargetIdentifier m_CameraColorBufferRT;
RenderTargetIdentifier m_CameraDepthBufferRT;
RenderTargetIdentifier m_VelocityBufferRT;
RenderTargetIdentifier m_DistortionBufferRT;
readonly RenderTargetIdentifier m_CameraColorBufferRT;
readonly RenderTargetIdentifier m_CameraDepthBufferRT;
readonly RenderTargetIdentifier m_VelocityBufferRT;
readonly RenderTargetIdentifier m_DistortionBufferRT;
int m_currentWidth;
int m_currentHeight;
int m_CurrentWidth;
int m_CurrentHeight;
// Keep these settings safe to recover when leaving the render pipeline
bool previousLightsUseLinearIntensity;
bool previousLightsUseCCT;
ShadowRenderPass m_ShadowPass;
BaseLightLoop m_lightLoop;
//readonly BaseLightLoop m_lightLoop;
public BaseLightLoop lightLoop
SkyManager m_SkyManager;
public SkyManager skyManager
get { return m_lightLoop; }
get
{
if (m_SkyManager == null)
{
m_SkyManager = new SkyManager();
m_SkyManager.skyParameters = Object.FindObjectOfType<SkyParameters>();
}
return m_SkyManager;
}
// TODO: Find a way to automatically create/iterate through deferred material
// TODO TO CHECK: SebL I move allocation from Build() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?
Lit.RenderLoop m_LitRenderLoop = new Lit.RenderLoop();
private DebugParameters debugParameters
{
get { return m_Owner.debugParameters; }
}
public struct HDCamera
private CommonSettings commonSettings
public Camera camera;
public Vector4 screenSize;
public Matrix4x4 viewProjectionMatrix;
public Matrix4x4 invViewProjectionMatrix;
get { return m_Owner.commonSettings; }
CommonSettings m_CommonSettings = null;
public CommonSettings commonSettings
public void InstantiateSkyRenderer(Type skyRendererType)
set { m_CommonSettings = value; }
get { return m_CommonSettings; }
m_SkyManager.InstantiateSkyRenderer(skyRendererType);
public void Build()
public HDRenderPipelineInstance(HDRenderPipeline owner)
#if UNITY_EDITOR
UnityEditor.SupportedRenderingFeatures.active = new UnityEditor.SupportedRenderingFeatures
{
reflectionProbe = UnityEditor.SupportedRenderingFeatures.ReflectionProbe.Rotation
};
#endif
previousLightsUseLinearIntensity = UnityEngine.Rendering.GraphicsSettings.lightsUseLinearIntensity;
previousLightsUseCCT = UnityEngine.Rendering.GraphicsSettings.lightsUseCCT;
UnityEngine.Rendering.GraphicsSettings.lightsUseLinearIntensity = true;
UnityEngine.Rendering.GraphicsSettings.lightsUseCCT = true;
m_Owner = owner;
m_CameraDepthBuffer = Shader.PropertyToID("_CameraDepthTexture");
m_CameraDepthBuffer = Shader.PropertyToID("_CameraDepthTexture");
m_SkyManager.Build();
m_ShadowPass = new ShadowRenderPass(m_ShadowSettings);
m_ShadowPass = new ShadowRenderPass(owner.shadowSettings);
RenderTextureFormat[] RTFormat; RenderTextureReadWrite[] RTReadWrite;
RenderTextureFormat[] RTFormat;
RenderTextureReadWrite[] RTReadWrite;
m_LitRenderLoop.GetMaterialGBufferDescription(out RTFormat, out RTReadWrite);
for (int gbufferIndex = 0; gbufferIndex < m_gbufferManager.gbufferCount; ++gbufferIndex)

m_DistortionBufferRT = new RenderTargetIdentifier(m_DistortionBuffer);
m_LitRenderLoop.Build();
m_lightLoop.Build(m_TextureSettings);
m_lightLoop = new LightLoop(owner);
m_lightLoop.Build(owner.textureSettings);
public void Cleanup()
public override void Dispose()
base.Dispose();
UnityEditor.SupportedRenderingFeatures.active = UnityEditor.SupportedRenderingFeatures.Default;
SupportedRenderingFeatures.active = SupportedRenderingFeatures.Default;
UnityEngine.Rendering.GraphicsSettings.lightsUseLinearIntensity = previousLightsUseLinearIntensity;
UnityEngine.Rendering.GraphicsSettings.lightsUseCCT = previousLightsUseCCT;
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)
#if UNITY_EDITOR
private static readonly SupportedRenderingFeatures s_NeededFeatures = new SupportedRenderingFeatures()
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderContext))
reflectionProbe = SupportedRenderingFeatures.ReflectionProbe.Rotation
};
private LightLoop m_lightLoop;
#endif
void Resize(Camera camera)
{
// TODO: Detect if renderdoc just load and force a resize in this case, as often renderdoc require to realloc resource.
// 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.Resize(); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if (camera.pixelWidth != m_CurrentWidth || camera.pixelHeight != m_CurrentHeight || m_lightLoop.NeedResize())
// We clear only the depth buffer, no need to clear the various color buffer as we overwrite them.
// Clear depth/stencil and init buffers
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderContext))
if (m_CurrentWidth > 0 && m_CurrentHeight > 0)
var cmd = new CommandBuffer();
cmd.name = "";
m_lightLoop.ReleaseResolutionDependentBuffers();
}
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).
// Also we manage ourself the HDR format, here allocating fp16 directly.
// With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer
// These temporary surface are release automatically at the end of the scriptable render pipeline if not release explicitly
int w = camera.pixelWidth;
int h = camera.pixelHeight;
m_lightLoop.AllocResolutionDependentBuffers(camera.pixelWidth, camera.pixelHeight);
// update recorded window resolution
m_CurrentWidth = camera.pixelWidth;
m_CurrentHeight = camera.pixelHeight;
}
}
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (m_SkyManager.IsSkyValid())
{
m_SkyManager.SetGlobalSkyTexture();
Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else
{
Shader.SetGlobalInt("_EnvLightSkyEnabled", 0);
}
var cmd = new CommandBuffer { name = "Push Global Parameters" };
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
m_lightLoop.PushGlobalParams(hdCamera.camera, renderContext);
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);
#if UNITY_EDITOR
SupportedRenderingFeatures.active = s_NeededFeatures;
#endif
GraphicsSettings.lightsUseLinearIntensity = true;
GraphicsSettings.lightsUseCCT = true;
skyManager.Build();
if (!m_LitRenderLoop.isInit)
m_LitRenderLoop.RenderInit(renderContext);
cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
cmd.GetTemporaryRT(m_CameraDepthBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
if (!debugParameters.ShouldUseForwardRenderingOnly())
{
m_gbufferManager.InitGBuffers(w, h, cmd);
}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// Do anything we need to do upon a new frame.
m_lightLoop.NewFrame();
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth);
}
m_Owner.UpdateCommonSettings();
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Set Frame constant buffer
// TODO...
// Clear HDR target
using (new Utilities.ProfilingSample("Clear HDR target", renderContext))
{
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// we only want to render one camera for now
// select the most main camera!
Camera camera = cameras.OrderByDescending(x => x.tag == "MainCamera").FirstOrDefault();
if (camera == null)
return;
// Clear GBuffers
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
{
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// Set camera constant buffer
// TODO...
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))
return;
// END TEMP
m_ShadowPass.UpdateCullingParameters(ref cullingParams);
var cullResults = CullResults.Cull(ref cullingParams, renderContext);
Resize(camera);
renderContext.SetupCameraProperties(camera);
HDCamera hdCamera = Utilities.GetHDCamera(camera);
InitAndClearBuffer(camera, renderContext);
RenderDepthPrepass(cullResults, camera, renderContext);
// Forward opaque with deferred/cluster tile require that we fill the depth buffer
// correctly to build the light list.
// TODO: avoid double lighting by tagging stencil or gbuffer that we must not lit.
RenderForwardOnlyOpaqueDepthPrepass(cullResults, camera, renderContext);
RenderGBuffer(cullResults, camera, renderContext);
if (debugParameters.debugViewMaterial != 0)
{
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
return;
ShadowOutput shadows;
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{
m_ShadowPass.Render(renderContext, cullResults, out shadows);
}
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
using (new Utilities.ProfilingSample("Build Light list", renderContext))
{
m_lightLoop.PrepareLightsForGPU(m_Owner.shadowSettings, cullResults, camera, ref shadows);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
PushGlobalParams(hdCamera, renderContext);
}
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, renderContext);
RenderDeferredLighting(hdCamera, renderContext);
// For opaque forward we have split rendering in two categories
// Material that are always forward and material that can be deferred or forward depends on render pipeline options (like switch to rendering forward only mode)
// Material that are always forward are unlit and complex (Like Hair) and don't require sorting, so it is ok to split them.
RenderForward(cullResults, camera, renderContext, true); // Render deferred or forward opaque
RenderForwardOnlyOpaque(cullResults, camera, renderContext);
RenderSky(hdCamera, renderContext);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(cullResults, camera, renderContext, false);
RenderVelocity(cullResults, camera, renderContext); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
// TODO: Check with VFX team.
// Rendering distortion here have off course lot of artifact.
// But resolving at each objects that write in distortion is not possible (need to sort transparent, render those that do not distort, then resolve, then etc...)
// Instead we chose to apply distortion at the end after we cumulate distortion vector and desired blurriness. This
RenderDistortion(cullResults, camera, renderContext);
FinalPass(camera, renderContext);
// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)
{
var cmd = new CommandBuffer();
cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, m_CameraDepthBufferRT);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
renderContext.Submit();
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)

{
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
return;
}
using (new Utilities.ProfilingSample("GBuffer Pass", renderContext))

{
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
return;
}
// Bind material data

void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
m_SkyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderContext);
skyManager.UpdateEnvironment(hdCamera, m_lightLoop.GetCurrentSunLight(), renderContext);
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
skyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)
{
// TODO: Currently we can't render opaque object forward when deferred is enabled

{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 0) || debugParameters.ShouldUseForwardRenderingOnly())
return ;
return;
int w = camera.pixelWidth;
int h = camera.pixelHeight;

void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
if (!debugParameters.useDistortion)
return ;
return;
using (new Utilities.ProfilingSample("Distortion Pass", renderContext))
{

m_lightLoop.PrepareLightsForGPU(shadowSettings, cullResults, camera, ref shadowOutput);
}
void Resize(Camera camera)
{
// TODO: Detect if renderdoc just load and force a resize in this case, as often renderdoc require to realloc resource.
// 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.Resize(); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if (camera.pixelWidth != m_currentWidth || camera.pixelHeight != m_currentHeight || m_lightLoop.NeedResize())
{
if (m_currentWidth > 0 && m_currentHeight > 0)
{
m_lightLoop.ReleaseResolutionDependentBuffers();
}
m_lightLoop.AllocResolutionDependentBuffers(camera.pixelWidth, camera.pixelHeight);
// update recorded window resolution
m_currentWidth = camera.pixelWidth;
m_currentHeight = camera.pixelHeight;
}
}
public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext)
void InitAndClearBuffer(Camera camera, ScriptableRenderContext renderContext)
if (m_SkyManager.IsSkyValid())
{
m_SkyManager.SetGlobalSkyTexture();
Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderContext))
Shader.SetGlobalInt("_EnvLightSkyEnabled", 0);
}
var cmd = new CommandBuffer { name = "Push Global Parameters" };
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);
cmd.SetGlobalMatrix("_InvViewProjMatrix", hdCamera.invViewProjectionMatrix);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
m_lightLoop.PushGlobalParams(hdCamera.camera, renderContext);
}
void UpdateCommonSettings()
{
if(m_CommonSettings == null)
{
m_ShadowSettings.maxShadowDistance = ShadowSettings.Default.maxShadowDistance;
m_ShadowSettings.directionalLightCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
m_ShadowSettings.directionalLightCascades = ShadowSettings.Default.directionalLightCascades;
}
else
{
m_ShadowSettings.directionalLightCascadeCount = m_CommonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(m_CommonSettings.shadowCascadeSplit0, m_CommonSettings.shadowCascadeSplit1, m_CommonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = m_CommonSettings.shadowMaxDistance;
}
}
public void Render(ScriptableRenderContext renderContext, IEnumerable<Camera> cameras)
{
if (!m_LitRenderLoop.isInit)
{
m_LitRenderLoop.RenderInit(renderContext);
}
// Do anything we need to do upon a new frame.
m_lightLoop.NewFrame();
UpdateCommonSettings();
// Set Frame constant buffer
// TODO...
foreach (var camera in cameras)
{
// Set camera constant buffer
// TODO...
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))
continue;
m_ShadowPass.UpdateCullingParameters(ref cullingParams);
var cullResults = CullResults.Cull(ref cullingParams, renderContext);
Resize(camera);
renderContext.SetupCameraProperties(camera);
HDCamera hdCamera = Utilities.GetHDCamera(camera);
InitAndClearBuffer(camera, renderContext);
RenderDepthPrepass(cullResults, camera, renderContext);
// Forward opaque with deferred/cluster tile require that we fill the depth buffer
// correctly to build the light list.
// TODO: avoid double lighting by tagging stencil or gbuffer that we must not lit.
RenderForwardOnlyOpaqueDepthPrepass(cullResults, camera, renderContext);
RenderGBuffer(cullResults, camera, renderContext);
if (debugParameters.debugViewMaterial != 0)
// We clear only the depth buffer, no need to clear the various color buffer as we overwrite them.
// Clear depth/stencil and init buffers
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderContext))
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
}
else
{
ShadowOutput shadows;
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{
m_ShadowPass.Render(renderContext, cullResults, out shadows);
}
var cmd = new CommandBuffer();
cmd.name = "";
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).
// Also we manage ourself the HDR format, here allocating fp16 directly.
// With scriptable render loop we can allocate temporary RT in a command buffer, they will not be release with ExecuteCommandBuffer
// These temporary surface are release automatically at the end of the scriptable render pipeline if not release explicitly
int w = camera.pixelWidth;
int h = camera.pixelHeight;
using (new Utilities.ProfilingSample("Build Light list", renderContext))
cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
cmd.GetTemporaryRT(m_CameraDepthBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
if (!m_Owner.debugParameters.ShouldUseForwardRenderingOnly())
m_lightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera, ref shadows);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
PushGlobalParams(hdCamera, renderContext);
m_gbufferManager.InitGBuffers(w, h, cmd);
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, renderContext);
RenderDeferredLighting(hdCamera, renderContext);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// For opaque forward we have split rendering in two categories
// Material that are always forward and material that can be deferred or forward depends on render pipeline options (like switch to rendering forward only mode)
// Material that are always forward are unlit and complex (Like Hair) and don't require sorting, so it is ok to split them.
RenderForward(cullResults, camera, renderContext, true); // Render deferred or forward opaque
RenderForwardOnlyOpaque(cullResults, camera, renderContext);
RenderSky(hdCamera, renderContext);
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward(cullResults, camera, renderContext, false);
RenderVelocity(cullResults, camera, renderContext); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth);
}
// TODO: Check with VFX team.
// Rendering distortion here have off course lot of artifact.
// But resolving at each objects that write in distortion is not possible (need to sort transparent, render those that do not distort, then resolve, then etc...)
// Instead we chose to apply distortion at the end after we cumulate distortion vector and desired blurriness. This
RenderDistortion(cullResults, camera, renderContext);
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
FinalPass(camera, renderContext);
// Clear HDR target
using (new Utilities.ProfilingSample("Clear HDR target", renderContext))
{
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)
// Clear GBuffers
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
var cmd = new CommandBuffer();
cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, m_CameraDepthBufferRT);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
renderContext.Submit();
// END TEMP
}
}
}

8
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipelineSetup.cs


using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class HDRenderPipelineSetup : ScriptableObject
{

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void PushGlobalParams(Camera camera, ScriptableRenderContext loop) {}
public virtual void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) {}

72
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

static ComputeBuffer s_BigTileLightList = null; // used for pre-pass coarse culling on 64x64 tiles
static int s_GenListPerBigTileKernel;
public bool enableDrawLightBoundsDebug = false;
public bool disableTileAndCluster = true; // For debug / test
public bool disableDeferredShadingInCompute = true;
public bool enableSplitLightEvaluation = true;
public bool enableComputeLightEvaluation = false;
// clustered light list specific buffers and data begin
public int debugViewTilesFlags = 0;
public bool enableClustered = false;
public bool disableFptlWhenClustered = true; // still useful on opaques. Should be false by default to force tile on opaque.
public bool enableBigTilePrepass = false;
const bool k_UseDepthBuffer = true; // only has an impact when EnableClustered is true (requires a depth-prepass)
const bool k_UseAsyncCompute = true; // should not use on mobile

get
{
bool isEnabledMSAA = false;
Debug.Assert(!isEnabledMSAA || enableClustered);
bool disableFptl = (disableFptlWhenClustered && enableClustered) || isEnabledMSAA;
var tileSettings = m_Parent.tileSettings;
Debug.Assert(!isEnabledMSAA || tileSettings.enableClustered);
bool disableFptl = (tileSettings.disableFptlWhenClustered && tileSettings.enableClustered) || isEnabledMSAA;
return !disableFptl;
}
}

m_lightList = new LightList();
m_lightList.Allocate();
var tileSettings = m_Parent.tileSettings;
s_DirectionalLightDatas = new ComputeBuffer(k_MaxDirectionalLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));
s_LightDatas = new ComputeBuffer(k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_EnvLightDatas = new ComputeBuffer(k_MaxEnvLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));

m_CubeReflTexArray.AllocTextureArray(32, textureSettings.reflectionCubemapSize, TextureFormat.BC6H, true);
s_GenAABBKernel = buildScreenAABBShader.FindKernel("ScreenBoundsAABB");
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(tileSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
s_AABBBoundsBuffer = new ComputeBuffer(2 * k_MaxLightsOnScreen, 3 * sizeof(float));
s_ConvexBoundsBuffer = new ComputeBuffer(k_MaxLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(SFiniteLightBound)));
s_LightVolumeDataBuffer = new ComputeBuffer(k_MaxLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightVolumeData)));

buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "_LightVolumeData", s_LightVolumeDataBuffer);
buildPerTileLightListShader.SetBuffer(s_GenListPerTileKernel, "g_data", s_ConvexBoundsBuffer);
if (enableClustered)
if (tileSettings.enableClustered)
var kernelName = enableBigTilePrepass ? (k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile") : (k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT");
var kernelName = tileSettings.enableBigTilePrepass ? (k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile") : (k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT");
s_GenListPerVoxelKernel = buildPerVoxelLightListShader.FindKernel(kernelName);
s_ClearVoxelAtomicKernel = buildPerVoxelLightListShader.FindKernel("ClearAtomic");
buildPerVoxelLightListShader.SetBuffer(s_GenListPerVoxelKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer);

s_GlobalLightListAtomic = new ComputeBuffer(1, sizeof(uint));
}
if (enableBigTilePrepass)
if (tileSettings.enableBigTilePrepass)
{
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
buildPerBigTileLightListShader.SetBuffer(s_GenListPerBigTileKernel, "g_vBoundsBuffer", s_AABBBoundsBuffer);

public override bool NeedResize()
{
var tileSettings = m_Parent.tileSettings;
(s_BigTileLightList == null && enableBigTilePrepass) ||
(s_PerVoxelLightLists == null && enableClustered);
(s_BigTileLightList == null && tileSettings.enableBigTilePrepass) ||
(s_PerVoxelLightLists == null && tileSettings.enableClustered);
}
public override void ReleaseResolutionDependentBuffers()

s_LightList = new ComputeBuffer((int)LightCategory.Count * dwordsPerTile * nrTiles, sizeof(uint)); // enough list memory for a 4k x 4k display
if (enableClustered)
var tileSettings = m_Parent.tileSettings;
if (tileSettings.enableClustered)
{
s_PerVoxelOffset = new ComputeBuffer((int)LightCategory.Count * (1 << k_Log2NumClusters) * nrTiles, sizeof(uint));
s_PerVoxelLightLists = new ComputeBuffer(NumLightIndicesPerClusteredTile() * nrTiles, sizeof(uint));

}
}
if (enableBigTilePrepass)
if (tileSettings.enableBigTilePrepass)
{
var nrBigTilesX = (width + 63) / 64;
var nrBigTilesY = (height + 63) / 64;

cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_vLayeredLightList", s_PerVoxelLightLists);
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_LayeredOffset", s_PerVoxelOffset);
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_LayeredSingleIdxBuffer", s_GlobalLightListAtomic);
if (enableBigTilePrepass)
if (m_Parent.tileSettings.enableBigTilePrepass)
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, "g_vBigTileLightList", s_BigTileLightList);
if (k_UseDepthBuffer)

cmd.DispatchCompute(buildScreenAABBShader, s_GenAABBKernel, (m_lightCount + 7) / 8, 1, 1);
}
var tileSettings = m_Parent.tileSettings;
if (enableBigTilePrepass)
if (tileSettings.enableBigTilePrepass)
{
cmd.SetComputeIntParams(buildPerBigTileLightListShader, "g_viDimensions", new int[2] { w, h });
cmd.SetComputeIntParam(buildPerBigTileLightListShader, "_EnvLightIndexShift", m_lightList.lights.Count);

Utilities.SetMatrixCS(cmd, buildPerTileLightListShader, "g_mInvScrProjection", invProjscr);
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_depth_tex", cameraDepthBufferRT);
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, "g_vLightList", s_LightList);
if (enableBigTilePrepass)
if (tileSettings.enableBigTilePrepass)
if (enableClustered) // works for transparencies too.
if (tileSettings.enableClustered) // works for transparencies too.
{
VoxelLightListGeneration(cmd, camera, projscr, invProjscr, cameraDepthBufferRT);
}

SetGlobalInt("_NumTileX", GetNumTileX(camera));
SetGlobalInt("_NumTileY", GetNumTileY(camera));
if (enableBigTilePrepass)
var tileSettings = m_Parent.tileSettings;
if (tileSettings.enableBigTilePrepass)
if (enableClustered)
if (tileSettings.enableClustered)
{
SetGlobalFloat("g_fClustScale", m_ClustScale);
SetGlobalFloat("g_fClustBase", k_ClustLogBase);

}
#endif
public override void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT)
public override void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier cameraColorBufferRT)
{
var bUseClusteredForDeferred = !usingFptl;

mousePixelCoord.y = (hdCamera.screenSize.y - 1.0f) - mousePixelCoord.y;
}
#endif
var tileSettings = m_Parent.tileSettings;
using (new Utilities.ProfilingSample(disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderContext))
using (new Utilities.ProfilingSample(tileSettings.disableTileAndCluster ? "SinglePass - Deferred Lighting Pass" : "TilePass - Deferred Lighting Pass", renderContext))
{
var cmd = new CommandBuffer();

SetGlobalFloat("_UseTileLightList", 0);
}
if (disableTileAndCluster)
if (tileSettings.disableTileAndCluster)
{
Utilities.SetupMaterialHDCamera(hdCamera, m_SingleDeferredMaterial);
m_SingleDeferredMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);

}
else
{
if (!disableDeferredShadingInCompute)
if (!tileSettings.disableDeferredShadingInCompute)
{
// Compute shader evaluation
int kernel = bUseClusteredForDeferred ? s_shadeOpaqueClusteredKernel : s_shadeOpaqueFptlKernel;

else
{
// Pixel shader evaluation
if (enableSplitLightEvaluation)
if (tileSettings.enableSplitLightEvaluation)
{
Utilities.SetupMaterialHDCamera(hdCamera, m_DeferredDirectMaterial);
m_DeferredDirectMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);

}
// Draw tile debugging
if (debugViewTilesFlags != 0)
if (tileSettings.debugViewTilesFlags != 0)
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", debugViewTilesFlags);
m_DebugViewTilesMaterial.SetInt("_ViewTilesFlags", tileSettings.debugViewTilesFlags);
m_DebugViewTilesMaterial.SetVector("_MousePixelCoord", mousePixelCoord);
m_DebugViewTilesMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DebugViewTilesMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");

var cmd = new CommandBuffer();
if (disableTileAndCluster)
if (m_Parent.tileSettings.disableTileAndCluster)
{
cmd.name = "Forward pass";
cmd.EnableShaderKeyword("LIGHTLOOP_SINGLE_PASS");

2
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


List<SkyParameters> result = new List<SkyParameters>();
gameObject.GetComponents<SkyParameters>(result);
Type skyParamType = renderPipeline.skyManager.GetSkyParameterType();
Type skyParamType = renderPipeline.GetSkyParameterType();
// Disable all incompatible sky parameters and enable the compatible one
bool found = false;

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


m_UpdateRequired = true;
}
public void UpdateEnvironment(HDRenderPipeline.HDCamera camera, Light sunLight, ScriptableRenderContext renderContext)
public void UpdateEnvironment(HDCamera camera, Light sunLight, ScriptableRenderContext renderContext)
{
{
using (new Utilities.ProfilingSample("Sky Environment Pass", renderContext))

}
}
public void RenderSky(HDRenderPipeline.HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ScriptableRenderContext renderContext)
public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("Sky Pass", renderContext))
{

31
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs


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

protected void OnEnable()
{
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
{
return;
}
if (renderPipeline.skyManager.skyParameters == null || renderPipeline.skyManager.skyParameters.GetType() != this.GetType()) // We allow override of parameters only if the type is different. It means that we changed the Sky Renderer and might need a new set of parameters.
renderPipeline.skyManager.skyParameters = this;
else if (renderPipeline.skyManager.skyParameters != this && renderPipeline.skyManager.skyParameters.GetType() == this.GetType())
Debug.LogWarning("Tried to setup another SkyParameters component although there is already one enabled.");
protected void OnDisable()
{
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
{
return;
}
// Reset the current sky parameter on the render loop
if (renderPipeline.skyManager.skyParameters == this)
renderPipeline.skyManager.skyParameters = null;
}
public int GetHash()
{
unchecked

{
bool unhashedAttribute = p.GetCustomAttributes(typeof(Unhashed), true).Length != 0;
System.Object obj = p.GetValue(this);
object obj = p.GetValue(this);
if (obj != null && !unhashedAttribute) // Sometimes it can be a null reference.
hash = hash * 23 + obj.GetHashCode();
}

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


return gpuVP;
}
public static HDRenderPipeline.HDCamera GetHDCamera(Camera camera)
public static HDCamera GetHDCamera(Camera camera)
HDRenderPipeline.HDCamera hdCamera = new HDRenderPipeline.HDCamera();
HDCamera hdCamera = new HDCamera();
hdCamera.camera = camera;
hdCamera.screenSize = new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight);

return hdCamera;
}
public static void SetupMaterialHDCamera(HDRenderPipeline.HDCamera hdCamera, Material material)
public static void SetupMaterialHDCamera(HDCamera hdCamera, Material material)
{
material.SetVector("_ScreenSize", hdCamera.screenSize);
material.SetMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);

public static HDRenderPipeline GetHDRenderPipeline()
{
HDRenderPipeline renderContext = UnityEngine.Rendering.GraphicsSettings.renderPipeline as HDRenderPipeline;
HDRenderPipeline renderContext = GraphicsSettings.renderPipeline as HDRenderPipeline;
if (renderContext == null)
{
Debug.LogWarning("SkyParameters component can only be used with HDRenderPipeline custom RenderPipeline.");

2
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


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

public float maxShadowDistance;
public int directionalLightCascadeCount;
public Vector3 directionalLightCascades;
public static ShadowSettings Default
{

正在加载...
取消
保存