Skip to content
Permalink
Browse files

Fix issue with MultiScaleVO and Single Pass Stereo

Fixes an issue with MultiScaleVO showing incorrectly if XR and single pass stereo is enabled for a project, but the current camera not actually doing stereo rendering, like the scene view or when the HMD isn't active, or for "social" camera views.
  • Loading branch information
bgolus committed Jun 4, 2019
1 parent 891a586 commit 743602d28803cb09ed891d0b04ebb1fa8906ca3b
Showing with 10 additions and 7 deletions.
  1. +10 −7 PostProcessing/Runtime/Effects/MultiScaleVO.cs
@@ -145,8 +145,10 @@ Vector3 GetSizeArray(MipLevel mip)

public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier? depthMap, bool invert, bool isMSAA)
{
bool isSinglePassStereo = camera.stereoEnabled && RuntimeUtilities.isSinglePassStereoEnabled;

// Base size
m_Widths[0] = camera.pixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
m_Widths[0] = camera.pixelWidth * (isSinglePassStereo ? 2 : 1);
m_Heights[0] = camera.pixelHeight;

// L1 -> L6 sizes
@@ -163,11 +165,12 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
// Render logic
PushDownsampleCommands(cmd, camera, depthMap, isMSAA);


float tanHalfFovH = CalculateTanHalfFovHeight(camera);
PushRenderCommands(cmd, ShaderIDs.TiledDepth1, ShaderIDs.Occlusion1, GetSizeArray(MipLevel.L3), tanHalfFovH, isMSAA);
PushRenderCommands(cmd, ShaderIDs.TiledDepth2, ShaderIDs.Occlusion2, GetSizeArray(MipLevel.L4), tanHalfFovH, isMSAA);
PushRenderCommands(cmd, ShaderIDs.TiledDepth3, ShaderIDs.Occlusion3, GetSizeArray(MipLevel.L5), tanHalfFovH, isMSAA);
PushRenderCommands(cmd, ShaderIDs.TiledDepth4, ShaderIDs.Occlusion4, GetSizeArray(MipLevel.L6), tanHalfFovH, isMSAA);
PushRenderCommands(cmd, ShaderIDs.TiledDepth1, ShaderIDs.Occlusion1, GetSizeArray(MipLevel.L3), tanHalfFovH, isMSAA, isSinglePassStereo);
PushRenderCommands(cmd, ShaderIDs.TiledDepth2, ShaderIDs.Occlusion2, GetSizeArray(MipLevel.L4), tanHalfFovH, isMSAA, isSinglePassStereo);
PushRenderCommands(cmd, ShaderIDs.TiledDepth3, ShaderIDs.Occlusion3, GetSizeArray(MipLevel.L5), tanHalfFovH, isMSAA, isSinglePassStereo);
PushRenderCommands(cmd, ShaderIDs.TiledDepth4, ShaderIDs.Occlusion4, GetSizeArray(MipLevel.L6), tanHalfFovH, isMSAA, isSinglePassStereo);

PushUpsampleCommands(cmd, ShaderIDs.LowDepth4, ShaderIDs.Occlusion4, ShaderIDs.LowDepth3, ShaderIDs.Occlusion3, ShaderIDs.Combined3, GetSize(MipLevel.L4), GetSize(MipLevel.L3), isMSAA);
PushUpsampleCommands(cmd, ShaderIDs.LowDepth3, ShaderIDs.Combined3, ShaderIDs.LowDepth2, ShaderIDs.Occlusion2, ShaderIDs.Combined2, GetSize(MipLevel.L3), GetSize(MipLevel.L2), isMSAA);
@@ -284,7 +287,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
cmd.DispatchCompute(cs, kernel, m_Widths[(int)MipLevel.L6], m_Heights[(int)MipLevel.L6], 1);
}

void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3 sourceSize, float tanHalfFovH, bool isMSAA)
void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3 sourceSize, float tanHalfFovH, bool isMSAA, bool isSinglePassStereo)
{
// Here we compute multipliers that convert the center depth value into (the reciprocal
// of) sphere thicknesses at each sample location. This assumes a maximum sample radius
@@ -303,7 +306,7 @@ void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3
// ScreenspaceDiameter: Diameter of sample sphere in pixel units
// ScreenspaceDiameter / BufferWidth: Ratio of the screen width that the sphere actually covers
float thicknessMultiplier = 2f * tanHalfFovH * kScreenspaceDiameter / sourceSize.x;
if (RuntimeUtilities.isSinglePassStereoEnabled)
if (isSinglePassStereo)
thicknessMultiplier *= 2f;

// This will transform a depth value from [0, thickness] to [0, 1].

0 comments on commit 743602d

Please sign in to comment.
You can’t perform that action at this time.