// 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 ?
// Keep these settings safe to recover when leaving the render pipeline
boolpreviousLightsUseLinearIntensity;
boolpreviousLightsUseColorTemperature;
ShadowRenderPassm_ShadowPass;
// This must be allocate outside of Build() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
BaseLightLoopm_lightLoop;
readonlySkyManagerm_SkyManager=newSkyManager();
privatereadonlyBaseLightLoopm_LightLoop;
publicBaseLightLooplightLoop
privateDebugParametersdebugParameters
get{returnm_lightLoop;}
get{returnm_Owner.debugParameters;}
// 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 ?
// 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(camera.nearClipPlane,camera.farClipPlane);// TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
// 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.
m_LightLoop.BuildGPULightLists(camera,renderContext,m_CameraDepthBufferRT);// TODO: Use async compute here to run light culling during shadow
// END TEMP
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
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
// 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(camera.nearClipPlane,camera.farClipPlane);// TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
// 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.
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
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
// Disable all incompatible sky parameters and enable the compatible one
boolfound=false;
foreach(SkyParametersparaminresult)
{
if(param.GetType()==skyParamType)
{
// This is a workaround the fact that we can't control the order in which components are initialized.
// So it can happen that a given SkyParameter is OnEnabled before the CommonSettings and so fail the setup because the SkyRenderer is not yet initialized.
// So we disable it to for OnEnable to be called again.
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed direclty but the renderloop is not (so we need to wait for the sky texture to be rendered first)
if(m_NeedLowLevelUpdateEnvironment)
{
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
RenderSettings.skybox=m_StandardSkyboxMaterial;// Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity=1.0f;// fix this to 1, this parameter should not exist!
RenderSettings.ambientMode=UnityEngine.Rendering.AmbientMode.Skybox;// Force skybox for our HDRI
RenderSettings.reflectionIntensity=1.0f;
RenderSettings.customReflection=null;
DynamicGI.UpdateEnvironment();
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed direclty but the renderloop is not (so we need to wait for the sky texture to be rendered first)
if(m_NeedLowLevelUpdateEnvironment)
{
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
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.