|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
ShadowSettings m_ShadowSettings = ShadowSettings.Default; |
|
|
|
|
|
|
|
public ShadowSettings shadowSettings |
|
|
|
{ |
|
|
|
get { return m_ShadowSettings; } |
|
|
|
} |
|
|
|
|
|
|
|
ShadowRenderPass m_ShadowPass; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitAndClearBuffer(Camera camera, RenderLoop renderLoop) |
|
|
|
{ |
|
|
|
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderLoop)) |
|
|
|
{ |
|
|
|
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderLoop)) |
|
|
|
cmd.name = "InitGBuffers and clear Depth/Stencil"; |
|
|
|
cmd.name = ""; |
|
|
|
|
|
|
|
// 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).
|
|
|
|
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearDepth); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using (new Utilities.ProfilingSample("Clear HDR target", renderLoop)) |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black, "Clear HDR target"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black); |
|
|
|
using (new Utilities.ProfilingSample("Clear GBuffer", renderLoop)) |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black, "Clear GBuffer"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName, RendererConfiguration rendererConfiguration = 0) |
|
|
|
|
|
|
if (!debugParameters.useDepthPrepass) |
|
|
|
return; |
|
|
|
|
|
|
|
using (new Utilities.ProfilingSample("Depth Prepass", renderLoop)) |
|
|
|
{ |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT, "Depth Prepass"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop) |
|
|
|
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
using (new Utilities.ProfilingSample("GBuffer Pass", renderLoop)) |
|
|
|
{ |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, "GBuffer Pass"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// This pass is use in case of forward opaque and deferred rendering. We need to render forward objects before tile lighting pass
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
// TODO: Use the render queue index to only send the forward opaque!
|
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT, "Clear HDR target"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT, "Depth Prepass"); |
|
|
|
using (new Utilities.ProfilingSample("DebugView Material Mode Pass", renderLoop)) |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, Utilities.kClearAll, Color.black, "DebugView Material Mode Pass"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, Utilities.kClearAll, Color.black); |
|
|
|
|
|
|
|
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugParameters.debugViewMaterial); |
|
|
|
|
|
|
|
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
using (new Utilities.ProfilingSample("Single Pass - Deferred Lighting Pass", renderLoop)) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void RenderSky(Camera camera, RenderLoop renderLoop) |
|
|
|
|
|
|
|
|
|
|
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop) |
|
|
|
{ |
|
|
|
using (new Utilities.ProfilingSample("Forward Pass", renderLoop)) |
|
|
|
{ |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, "Forward Pass"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT); |
|
|
|
|
|
|
|
if (debugParameters.useForwardRenderingOnly) |
|
|
|
{ |
|
|
|
|
|
|
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward", Utilities.kRendererConfigurationBakedLighting); |
|
|
|
} |
|
|
|
} |
|
|
|
using (new Utilities.ProfilingSample("Forward Unlit Pass", renderLoop)) |
|
|
|
{ |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, "Forward Unlit Pass"); |
|
|
|
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT); |
|
|
|
} |
|
|
|
using (new Utilities.ProfilingSample("Velocity Pass", renderLoop)) |
|
|
|
{ |
|
|
|
// warning CS0162: Unreachable code detected // warning CS0429: Unreachable expression code detected
|
|
|
|
#pragma warning disable 162, 429
|
|
|
|
// If opaque velocity have been render during GBuffer no need to render it here
|
|
|
|
|
|
|
int w = camera.pixelWidth; |
|
|
|
int h = camera.pixelHeight; |
|
|
|
|
|
|
|
var cmd = new CommandBuffer { name = "Velocity Pass" }; |
|
|
|
var cmd = new CommandBuffer { name = "" }; |
|
|
|
cmd.GetTemporaryRT(m_VelocityBuffer, w, h, 0, FilterMode.Point, Builtin.RenderLoop.GetVelocityBufferFormat(), Builtin.RenderLoop.GetVelocityBufferReadWrite()); |
|
|
|
cmd.SetRenderTarget(m_VelocityBufferRT, m_CameraDepthBufferRT); |
|
|
|
renderLoop.ExecuteCommandBuffer(cmd); |
|
|
|
|
|
|
#pragma warning restore 162, 429
|
|
|
|
} |
|
|
|
} |
|
|
|
using (new Utilities.ProfilingSample("Distortion Pass", renderLoop)) |
|
|
|
{ |
|
|
|
var cmd = new CommandBuffer { name = "Distortion Pass" }; |
|
|
|
var cmd = new CommandBuffer { name = "" }; |
|
|
|
cmd.GetTemporaryRT(m_DistortionBuffer, w, h, 0, FilterMode.Point, Builtin.RenderLoop.GetDistortionBufferFormat(), Builtin.RenderLoop.GetDistortionBufferReadWrite()); |
|
|
|
cmd.SetRenderTarget(m_DistortionBufferRT, m_CameraDepthBufferRT); |
|
|
|
renderLoop.ExecuteCommandBuffer(cmd); |
|
|
|
|
|
|
RenderTransparentRenderList(cullResults, camera, renderLoop, "DistortionVectors"); |
|
|
|
} |
|
|
|
} |
|
|
|
using (new Utilities.ProfilingSample("Final Pass", renderLoop)) |
|
|
|
{ |
|
|
|
// Those could be tweakable for the neutral tonemapper, but in the case of the LookDev we don't need that
|
|
|
|
const float blackIn = 0.02f; |
|
|
|
const float whiteIn = 10.0f; |
|
|
|
|
|
|
m_FinalPassMaterial.SetFloat("_EnableToneMap", debugParameters.enableTonemap ? 1.0f : 0.0f); |
|
|
|
m_FinalPassMaterial.SetFloat("_Exposure", debugParameters.exposure); |
|
|
|
|
|
|
|
var cmd = new CommandBuffer { name = "FinalPass" }; |
|
|
|
var cmd = new CommandBuffer { name = "" }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Function to prepare light structure for GPU lighting
|
|
|
|
|
|
|
else |
|
|
|
{ |
|
|
|
ShadowOutput shadows; |
|
|
|
using (new Utilities.ProfilingSample("Shadow Pass", renderLoop)) |
|
|
|
{ |
|
|
|
} |
|
|
|
PrepareLightsForGPU(cullResults, camera, ref shadows, ref m_lightList); |
|
|
|
//m_TilePassLightLoop.BuildGPULightLists(camera, renderLoop, m_lightList, m_CameraDepthBuffer);
|
|
|
|
using (new Utilities.ProfilingSample("Build Light list", renderLoop)) |
|
|
|
{ |
|
|
|
PrepareLightsForGPU(cullResults, camera, ref shadows, ref m_lightList); |
|
|
|
//m_TilePassLightLoop.BuildGPULightLists(camera, renderLoop, m_lightList, m_CameraDepthBuffer);
|
|
|
|
PushGlobalParams(camera, renderLoop, m_lightList); |
|
|
|
|
|
|
|
PushGlobalParams(camera, renderLoop, m_lightList); |
|
|
|
} |
|
|
|
RenderDeferredLighting(camera, renderLoop); |
|
|
|
|
|
|
|
RenderSky(camera, renderLoop); |
|
|
|