Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HDRP] Merge hd/bugfix #2787

Merged
merged 10 commits into from
Nov 30, 2020
54 changes: 40 additions & 14 deletions com.unity.render-pipelines.core/Editor/LookDev/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ enum Direction
bool m_InFlyMotion;

bool m_IsDragging;
ViewTool m_BehaviorState;
static TimeHelper s_Timer = new TimeHelper();

ViewTool m_BehaviorState;
ViewTool behaviorState
{
get { return m_BehaviorState; }
set
{
if (value != m_BehaviorState && m_BehaviorState == ViewTool.FPS)
{
isDragging = false;
inFlyMotion = false;
m_DirectionKeyPressed = Direction.None;
}
m_BehaviorState = value;
}
}

protected CameraState m_CameraState;
DisplayWindow m_Window;
protected Action m_Focused;
Expand Down Expand Up @@ -125,13 +140,13 @@ private void ResetCameraControl()
{
isDragging = false;
inFlyMotion = false;
m_BehaviorState = ViewTool.None;
behaviorState = ViewTool.None;
}

protected virtual void OnScrollWheel(WheelEvent evt)
{
// See UnityEditor.SceneViewMotion.HandleScrollWheel
switch (m_BehaviorState)
switch (behaviorState)
{
case ViewTool.FPS: OnChangeFPSCameraSpeed(evt); break;
default: OnZoom(evt); break;
Expand All @@ -140,7 +155,7 @@ protected virtual void OnScrollWheel(WheelEvent evt)

void OnMouseDrag(MouseMoveEvent evt)
{
switch (m_BehaviorState)
switch (behaviorState)
{
case ViewTool.Orbit: OnMouseDragOrbit(evt); break;
case ViewTool.FPS: OnMouseDragFPS(evt); break;
Expand Down Expand Up @@ -241,7 +256,7 @@ void OnKeyDownReset(KeyDownEvent evt)
void OnKeyUpOrDownFPS<T>(KeyboardEventBase<T> evt)
where T : KeyboardEventBase<T>, new()
{
if (m_BehaviorState != ViewTool.FPS)
if (behaviorState != ViewTool.FPS)
return;

//Note: Keydown is called in loop but between first occurence of the
Expand Down Expand Up @@ -319,29 +334,40 @@ bool GetKeyCombinationByID(string ID, out KeyCombination combination)
}
}

ViewTool GetBehaviorTool<T>(MouseEventBase<T> evt, bool onMac) where T : MouseEventBase<T>, new()
{
if (evt.button == 2)
return ViewTool.Pan;
else if (evt.button == 0 && evt.ctrlKey && onMac || evt.button == 1 && evt.altKey)
return ViewTool.Zoom;
else if (evt.button == 0)
return ViewTool.Orbit;
else if (evt.button == 1 && !evt.altKey)
return ViewTool.FPS;
return ViewTool.None;
}

void OnMouseUp(MouseUpEvent evt)
{
ResetCameraControl();
bool onMac = Application.platform == RuntimePlatform.OSXEditor;
var state = GetBehaviorTool(evt, onMac);

if (state == behaviorState)
ResetCameraControl();
evt.StopPropagation();
}

void OnMouseDown(MouseDownEvent evt)
{
bool onMac = Application.platform == RuntimePlatform.OSXEditor;
behaviorState = GetBehaviorTool(evt, onMac);

if (evt.button == 2)
m_BehaviorState = ViewTool.Pan;
else if (evt.button == 0 && evt.ctrlKey && onMac || evt.button == 1 && evt.altKey)
if (behaviorState == ViewTool.Zoom)
{
m_BehaviorState = ViewTool.Zoom;
m_StartZoom = m_CameraState.viewSize;
m_ZoomSpeed = Mathf.Max(Mathf.Abs(m_StartZoom), .3f);
m_TotalMotion = 0;
}
else if (evt.button == 0)
m_BehaviorState = ViewTool.Orbit;
else if (evt.button == 1 && !evt.altKey)
m_BehaviorState = ViewTool.FPS;

// see also SceneView.HandleClickAndDragToFocus()
if (evt.button == 1 && onMac)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ protected SerializedDataParameter Unpack(SerializedProperty property)
/// <param name="property">The property to draw in the editor</param>
protected void PropertyField(SerializedDataParameter property)
{
var title = EditorGUIUtility.TrTextContent(property.displayName);
var title = EditorGUIUtility.TrTextContent(property.displayName, property.GetAttribute<TooltipAttribute>()?.tooltip);
PropertyField(property, title);
}

Expand Down
7 changes: 7 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Fixed probe volumes debug views.
- Fixed lookdev movement.
- Fixed volume component tooltips using the same parameter name.
- Fixed issue with saving some quality settings in volume overrides (case 1293747)
- Fixed NullReferenceException in HDRenderPipeline.UpgradeResourcesIfNeeded (case 1292524)
- Fixed SSGI texture allocation when not using the RenderGraph.
- Fixed NullReference Exception when setting Max Shadows On Screen to 0 in the HDRP asset.

### Changed
- Removed the material pass probe volumes evaluation mode.
Expand Down Expand Up @@ -43,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed the clear coat not being handled properly for SSR and RTR (case 1291654).
- Fixed ghosting in RTGI and RTAO when denoising is enabled and the RTHandle size is not equal to the Viewport size (case 1291654).
- Fixed alpha output when atmospheric scattering is enabled.
- Fixed issue with TAA history sharpening when view is downsampled.

### Changed
- Volume Manager now always tests scene culling masks. This was required to fix hybrid workflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,22 @@ public override void OnEnable()

void RayTracingQualityModeGUI()
{
PropertyField(m_MinSmoothness, k_MinimumSmoothnessText);
PropertyField(m_SmoothnessFadeStart, k_SmoothnessFadeStartText);
m_SmoothnessFadeStart.value.floatValue = Mathf.Max(m_MinSmoothness.value.floatValue, m_SmoothnessFadeStart.value.floatValue);
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue, k_ClampValueText);
PropertyField(m_SampleCount, k_SampleCountText);
PropertyField(m_BounceCount, k_BounceCountText);
PropertyField(m_Denoise, k_DenoiseText);
base.OnInspectorGUI();
using (new HDEditorUtils.IndentScope())
using (new QualityScope(this))
{
PropertyField(m_DenoiserRadius, k_DenoiseRadiusText);
PropertyField(m_MinSmoothness, k_MinimumSmoothnessText);
PropertyField(m_SmoothnessFadeStart, k_SmoothnessFadeStartText);
m_SmoothnessFadeStart.value.floatValue = Mathf.Max(m_MinSmoothness.value.floatValue, m_SmoothnessFadeStart.value.floatValue);
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue, k_ClampValueText);
PropertyField(m_SampleCount, k_SampleCountText);
PropertyField(m_BounceCount, k_BounceCountText);
PropertyField(m_Denoise, k_DenoiseText);
using (new HDEditorUtils.IndentScope())
{
PropertyField(m_DenoiserRadius, k_DenoiseRadiusText);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace UnityEditor.Rendering.HighDefinition
{
static class DiffusionProfileMaterialUI
{
static GUIContent diffusionProfileNotInHDRPAsset = new GUIContent("You must make sure that this diffusion profile is either referenced in the HDRP asset or in the Diffusion Profile Override to make it work.", EditorGUIUtility.IconContent("console.infoicon").image);
static GUIContent diffusionProfileNotInHDRPAsset = new GUIContent("Make sure this Diffusion Profile is referenced in either a Diffusion Profile Override or the HDRP Default Settings. If the Diffusion Profile is not referenced in either, HDRP cannot use it. To add a reference to the Diffusion Profile in the HDRP Default Settings, press Fix.", EditorGUIUtility.IconContent("console.infoicon").image);

public static bool IsSupported(MaterialEditor materialEditor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,17 @@ public override void OnInspectorGUI()
break;
case RayTracingMode.Quality:
{
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue);
PropertyField(m_SampleCount);
PropertyField(m_BounceCount);
DenoiserGUI();
base.OnInspectorGUI(); // Quality Setting

using (new HDEditorUtils.IndentScope())
using (new QualityScope(this))
{
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue);
PropertyField(m_SampleCount);
PropertyField(m_BounceCount);
DenoiserGUI();
}
}
break;
}
Expand All @@ -158,11 +164,16 @@ public override void OnInspectorGUI()
else if (currentAsset.currentPlatformRenderPipelineSettings.supportedRayTracingMode ==
RenderPipelineSettings.SupportedRayTracingMode.Quality)
{
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue);
PropertyField(m_SampleCount);
PropertyField(m_BounceCount);
DenoiserGUI();
base.OnInspectorGUI(); // Quality Setting
EditorGUI.indentLevel++;
using (new QualityScope(this))
{
PropertyField(m_RayLength, k_RayLengthText);
PropertyField(m_ClampValue);
PropertyField(m_SampleCount);
PropertyField(m_BounceCount);
DenoiserGUI();
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4208,6 +4208,9 @@ LightLoopDebugOverlayParameters PrepareLightLoopDebugOverlayParameters()

static void RenderShadowsDebugOverlay(in DebugParameters debugParameters, in HDShadowManager.ShadowDebugAtlasTextures atlasTextures, CommandBuffer cmd, MaterialPropertyBlock mpb)
{
if (HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxShadowRequests == 0)
return;

LightingDebugSettings lightingDebug = debugParameters.debugDisplaySettings.data.lightingDebugSettings;
if (lightingDebug.shadowDebugMode != ShadowMapDebugMode.None)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ void LIGHTLISTGEN(uint threadID : SV_GroupIndex, uint3 u3GroupID : SV_GroupID)
for(int i=0; i<g_iNumSamplesMSAA; i++)
{
const float fDpth = FetchDepthMSAA(uPixCrd, i);
#if defined(SHADER_API_METAL) // GetSamplePosition isn't supported on Metal yet in Unity. TODO: remove when support is added
#if defined(SHADER_API_METAL) // GetSamplePosition isn't supported on Metal yet in Unity. TODO: remove when support is added
const float2 fracSampleCoord = float2(0.0, 0.0);
#else
const float2 fracSampleCoord = g_depth_tex.GetSamplePosition(i).xy; // this is optimized away when USE_OBLIQUE_MODE is NOT set.
#endif
#else
const float2 fracSampleCoord = g_depth_tex.GetSamplePosition(i).xy; // this is optimized away when USE_OBLIQUE_MODE is NOT set.
#endif
#else
const float fDpth = FetchDepth(uPixCrd);
const float2 fracSampleCoord = float2(0.5,0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ private HDShadowManager()

public void InitShadowManager(RenderPipelineResources renderPipelineResources, HDShadowInitParameters initParams, Shader clearShader)
{
// Even when shadows are disabled (maxShadowRequests == 0) we need to allocate compute buffers to avoid having
// resource not bound errors when dispatching a compute shader.
m_ShadowDataBuffer = new ComputeBuffer(Mathf.Max(initParams.maxShadowRequests, 1), System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));
m_MaxShadowRequests = initParams.maxShadowRequests;
m_ShadowRequestCount = 0;

if (initParams.maxShadowRequests == 0)
return;

m_ClearShadowMaterial = CoreUtils.CreateEngineMaterial(clearShader);
m_BlitShadowMaterial = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.shadowBlitPS);

Expand All @@ -332,11 +342,6 @@ public void InitShadowManager(RenderPipelineResources renderPipelineResources, H
m_AreaLightShadowAtlas = new HDDynamicShadowAtlas(renderPipelineResources, initParams.areaLightShadowAtlas.shadowAtlasResolution, initParams.areaLightShadowAtlas.shadowAtlasResolution,
HDShaderIDs._ShadowmapAreaAtlas, m_ClearShadowMaterial, initParams.maxShadowRequests, initParams, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: initParams.areaLightShadowAtlas.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas");

m_ShadowDataBuffer = new ComputeBuffer(initParams.maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

m_MaxShadowRequests = initParams.maxShadowRequests;

cachedShadowManager.InitPunctualShadowAtlas(renderPipelineResources, initParams.cachedPunctualLightShadowAtlas, initParams.cachedPunctualLightShadowAtlas,
HDShaderIDs._CachedShadowmapAtlas, m_ClearShadowMaterial, initParams.maxShadowRequests, initParams: initParams, depthBufferBits: initParams.punctualLightShadowAtlas.shadowAtlasDepthBits, name: "Cached Shadow Map Atlas");
if (ShaderConfig.s_AreaLights == 1)
Expand Down Expand Up @@ -392,6 +397,9 @@ public static DirectionalShadowAlgorithm GetDirectionalShadowAlgorithm()

public void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb)
{
if (m_MaxShadowRequests == 0)
return;

cb._CascadeShadowCount = (uint)(m_CascadeCount + 1);
cb._ShadowAtlasSize = new Vector4(m_Atlas.width, m_Atlas.height, 1.0f / m_Atlas.width, 1.0f / m_Atlas.height);
cb._CascadeShadowAtlasSize = new Vector4(m_CascadeAtlas.width, m_CascadeAtlas.height, 1.0f / m_CascadeAtlas.width, 1.0f / m_CascadeAtlas.height);
Expand Down Expand Up @@ -596,6 +604,9 @@ public void UpdateCullingParameters(ref ScriptableCullingParameters cullingParam

public void LayoutShadowMaps(LightingDebugSettings lightingDebugSettings)
{
if (m_MaxShadowRequests == 0)
return;

cachedShadowManager.UpdateDebugSettings(lightingDebugSettings);

m_Atlas.UpdateDebugSettings(lightingDebugSettings);
Expand Down Expand Up @@ -627,6 +638,9 @@ public void LayoutShadowMaps(LightingDebugSettings lightingDebugSettings)

unsafe public void PrepareGPUShadowDatas(CullingResults cullResults, HDCamera camera)
{
if (m_MaxShadowRequests == 0)
return;

int shadowIndex = 0;

m_ShadowDatas.Clear();
Expand Down Expand Up @@ -787,6 +801,9 @@ public int GetShadowRequestCount()

public void Clear()
{
if (m_MaxShadowRequests == 0)
return;

// Clear the shadows atlas infos and requests
m_Atlas.Clear();
m_CascadeAtlas.Clear();
Expand Down Expand Up @@ -897,6 +914,10 @@ public void Dispose()
{
m_ShadowDataBuffer.Dispose();
m_DirectionalShadowDataBuffer.Dispose();

if (m_MaxShadowRequests == 0)
return;

m_Atlas.Release();
if (ShaderConfig.s_AreaLights == 1)
m_AreaLightShadowAtlas.Release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,7 @@ struct TemporalAntiAliasingParameters
public MaterialPropertyBlock taaPropertyBlock;
public bool resetPostProcessingHistory;

public Vector4 previousScreenSize;
public Vector4 taaParameters;
public Vector4 taaFilterWeights;
public bool motionVectorRejection;
Expand Down Expand Up @@ -1681,6 +1682,8 @@ TemporalAntiAliasingParameters PrepareTAAParameters(HDCamera camera, bool PostDO

parameters.taaHistoryPropertyBlock = m_TAAHistoryBlitPropertyBlock;
parameters.taaPropertyBlock = m_TAAPropertyBlock;
Vector2Int prevViewPort = camera.historyRTHandleProperties.previousViewportSize;
parameters.previousScreenSize = new Vector4(prevViewPort.x, prevViewPort.y, 1.0f / prevViewPort.x, 1.0f / prevViewPort.y);

return parameters;
}
Expand Down Expand Up @@ -1719,9 +1722,7 @@ TemporalAntiAliasingParameters PrepareTAAParameters(HDCamera camera, bool PostDO

taaParams.taaPropertyBlock.SetTexture(HDShaderIDs._DepthTexture, depthMipChain);

Vector2 historySize = new Vector2(prevHistory.referenceSize.x * prevHistory.scaleFactor.x,
prevHistory.referenceSize.y * prevHistory.scaleFactor.y);
var taaHistorySize = new Vector4(historySize.x, historySize.y, 1.0f / historySize.x, 1.0f / historySize.y);
var taaHistorySize = taaParams.previousScreenSize;

taaParams.taaPropertyBlock.SetVector(HDShaderIDs._TaaPostParameters, taaParams.taaParameters);
taaParams.taaPropertyBlock.SetVector(HDShaderIDs._TaaHistorySize, taaHistorySize);
Expand Down