Skip to content

Commit

Permalink
Improve performance of OnDemand reflection probes [NEED C++] (#2775)
Browse files Browse the repository at this point in the history
* Removed some GCAlloc when creating probes

* Stop updating volume system for Lighting Override when not necessary.

Disabled ApplyMaterialPropertyDrawers when rendering HDRP to avoid unwanted perf spikes

* Removed C++ change dependency

* Used new API to disable terrain data deletion for reflection cameras.

* Fixed Render Graph immediate mode. (#3033)

Co-authored-by: Sebastien Lagarde <sebastien@unity3d.com>

* Fix issue with shadow mask and area lights (#3019)

* Not checking NdotL since it's not really valid for area lights (We have multiple valid light directions, not one)

* Changelog

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* Fix issue with capture callback (now includes post processing results) (#3035)

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* [HDRP] Fix decal draw order for ShaderGraph decal materials (#3018)

* Fixed ShaderGraph decal draw order

* Updated changelog

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>

* Fixed various Look Dev issues after exiting Playmode (#2956)

* Fixed access to invalid Contexts references after exiting playmode.

* Fixed comparison gizmo after playmode.

* Fixes from PR feedback

* StackLit: Fix SG surface option property block to only display energy conserving specular color option for the specular input parametrization (similar to case 1257050) (#3060)

* Fixed missing BeginCameraRendering call for custom render mode of a Camera (#3063)

* Fix wrong merge

* Fixed C++ API change

* Use new no alloc API to retrieve active terrain list.

* Fixed API change

Co-authored-by: Sebastien Lagarde <sebastien@unity3d.com>
Co-authored-by: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com>
Co-authored-by: Pavlos Mavridis <pavlos.mavridis@unity3d.com>
Co-authored-by: Antoine Lelievre <antoinel@unity3d.com>
Co-authored-by: slunity <37302815+slunity@users.noreply.github.com>
  • Loading branch information
6 people authored May 7, 2021
1 parent b241af4 commit f52392a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class IBLFilterGGX : IBLFilterBSDF
const int k_DefaultPlanarResolution = 512;
// Intermediate variables
Vector4 currentScreenSize = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
MaterialPropertyBlock m_MaterialPropertyBlock = new MaterialPropertyBlock();


public IBLFilterGGX(HDRenderPipelineRuntimeResources renderPipelineResources, MipGenerator mipGenerator)
{
Expand Down Expand Up @@ -138,23 +140,22 @@ void FilterCubemapCommon(CommandBuffer cmd,

m_convolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData);

var props = new MaterialPropertyBlock();
props.SetTexture("_MainTex", source);
props.SetFloat("_InvOmegaP", invOmegaP);
m_MaterialPropertyBlock.SetTexture("_MainTex", source);
m_MaterialPropertyBlock.SetFloat("_InvOmegaP", invOmegaP);

for (int mip = 1; mip < (int)EnvConstants.ConvolutionMipCount; ++mip)
{
props.SetFloat("_Level", mip);
m_MaterialPropertyBlock.SetFloat("_Level", mip);

for (int face = 0; face < 6; ++face)
{
var faceSize = new Vector4(source.width >> mip, source.height >> mip, 1.0f / (source.width >> mip), 1.0f / (source.height >> mip));
var transform = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, Vector2.zero, faceSize, worldToViewMatrices[face], true);

props.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform);
m_MaterialPropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, transform);

CoreUtils.SetRenderTarget(cmd, target, ClearFlag.None, mip, (CubemapFace)face);
CoreUtils.DrawFullScreen(cmd, m_convolveMaterial, props);
CoreUtils.DrawFullScreen(cmd, m_convolveMaterial, m_MaterialPropertyBlock);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,29 +1216,31 @@ internal void UpdateCurrentSky(SkyManager skyManager)
visualSky.skySettings = SkyManager.GetSkySetting(volumeStack);
visualSky.cloudSettings = SkyManager.GetCloudSetting(volumeStack);

// Now, see if we have a lighting override
// Update needs to happen before testing if the component is active other internal data structure are not properly updated yet.
VolumeManager.instance.Update(skyManager.lightingOverrideVolumeStack, volumeAnchor, skyManager.lightingOverrideLayerMask);
if (VolumeManager.instance.IsComponentActiveInMask<VisualEnvironment>(skyManager.lightingOverrideLayerMask))
lightingSky = visualSky;

if (skyManager.lightingOverrideLayerMask != 0)
{
SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack);
CloudSettings newCloudOverride = SkyManager.GetCloudSetting(skyManager.lightingOverrideVolumeStack);
// Now, see if we have a lighting override
// Update needs to happen before testing if the component is active other internal data structure are not properly updated yet.
VolumeManager.instance.Update(skyManager.lightingOverrideVolumeStack, volumeAnchor, skyManager.lightingOverrideLayerMask);

if ((m_LightingOverrideSky.skySettings != null && newSkyOverride == null) ||
(m_LightingOverrideSky.cloudSettings != null && newCloudOverride == null))
if (VolumeManager.instance.IsComponentActiveInMask<VisualEnvironment>(skyManager.lightingOverrideLayerMask))
{
// When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered.
// Resetting the visual sky hash will ensure that.
visualSky.skyParametersHash = -1;
}
SkySettings newSkyOverride = SkyManager.GetSkySetting(skyManager.lightingOverrideVolumeStack);
CloudSettings newCloudOverride = SkyManager.GetCloudSetting(skyManager.lightingOverrideVolumeStack);

m_LightingOverrideSky.skySettings = newSkyOverride;
m_LightingOverrideSky.cloudSettings = newCloudOverride;
lightingSky = m_LightingOverrideSky;
}
else
{
lightingSky = visualSky;
if ((m_LightingOverrideSky.skySettings != null && newSkyOverride == null) ||
(m_LightingOverrideSky.cloudSettings != null && newCloudOverride == null))
{
// When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered.
// Resetting the visual sky hash will ensure that.
visualSky.skyParametersHash = -1;

m_LightingOverrideSky.skySettings = newSkyOverride;
m_LightingOverrideSky.cloudSettings = newCloudOverride;
lightingSky = m_LightingOverrideSky;
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ internal static HDRenderPipeline currentPipeline
RenderStateBlock m_AlphaToMaskBlock;

readonly List<CustomPassVolume> m_ActivePassVolumes = new List<CustomPassVolume>(6);
readonly List<Terrain> m_ActiveTerrains = new List<Terrain>();

// Detect when windows size is changing
int m_MaxCameraWidth;
Expand Down Expand Up @@ -1081,13 +1082,13 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
if (newCount != m_FrameCount)
{
m_FrameCount = newCount;
m_ProbeCameraCache.ClearCamerasUnusedFor(2, Time.frameCount);
HDCamera.CleanUnused();
}

#if ENABLE_NVIDIA && ENABLE_NVIDIA_MODULE
m_DebugDisplaySettings.nvidiaDebugView.Update();
#endif
Terrain.GetActiveTerrains(m_ActiveTerrains);

// This syntax is awful and hostile to debugging, please don't use it...
using (ListPool<RenderRequest>.Get(out List<RenderRequest> renderRequests))
Expand Down Expand Up @@ -1453,15 +1454,19 @@ ref List<HDProbe.RenderData> renderDatas
for (int j = 0; j < cameraSettings.Count; ++j)
{
var camera = m_ProbeCameraCache.GetOrCreate((viewerTransform, visibleProbe, j), Time.frameCount, CameraType.Reflection);
var additionalCameraData = camera.GetComponent<HDAdditionalCameraData>();

var settingsCopy = m_Asset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings;
settingsCopy.forcedPercentage = 100.0f;
settingsCopy.forceResolution = true;
DynamicResolutionHandler.UpdateAndUseCamera(camera, settingsCopy);

if (additionalCameraData == null)
foreach (var terrain in m_ActiveTerrains)
terrain.SetKeepUnusedCameraRenderingResources(camera.GetInstanceID(), true);

if (!camera.TryGetComponent<HDAdditionalCameraData>(out var additionalCameraData))
{
additionalCameraData = camera.gameObject.AddComponent<HDAdditionalCameraData>();
}
additionalCameraData.hasPersistentHistory = true;

// We need to set a targetTexture with the right otherwise when setting pixelRect, it will be rescaled internally to the size of the screen
Expand Down

0 comments on commit f52392a

Please sign in to comment.