Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Fix issue with MultiScaleVO and Single Pass Stereo #818

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions PostProcessing/Runtime/Effects/MultiScaleVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ Vector3 GetSizeArray(MipLevel mip)

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

// Base size
#if UNITY_2017_3_OR_NEWER
m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
m_ScaledWidths[0] = camera.scaledPixelWidth * (isSinglePassDoubleWide ? 2 : 1);
m_ScaledHeights[0] = camera.scaledPixelHeight;
#else
m_ScaledWidths[0] = camera.pixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
m_ScaledWidths[0] = camera.pixelWidth * (isSinglePassDoubleWide ? 2 : 1);
m_ScaledHeights[0] = camera.pixelHeight;
#endif

// L1 -> L6 sizes
for (int i = 1; i < 7; i++)
{
Expand All @@ -168,11 +170,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, isSinglePassDoubleWide);
PushRenderCommands(cmd, ShaderIDs.TiledDepth2, ShaderIDs.Occlusion2, GetSizeArray(MipLevel.L4), tanHalfFovH, isMSAA, isSinglePassDoubleWide);
PushRenderCommands(cmd, ShaderIDs.TiledDepth3, ShaderIDs.Occlusion3, GetSizeArray(MipLevel.L5), tanHalfFovH, isMSAA, isSinglePassDoubleWide);
PushRenderCommands(cmd, ShaderIDs.TiledDepth4, ShaderIDs.Occlusion4, GetSizeArray(MipLevel.L6), tanHalfFovH, isMSAA, isSinglePassDoubleWide);

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);
Expand Down Expand Up @@ -289,7 +292,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
cmd.DispatchCompute(cs, kernel, m_ScaledWidths[(int)MipLevel.L6], m_ScaledHeights[(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 isSinglePassDoubleWide)
{
// 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
Expand All @@ -308,7 +311,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 (isSinglePassDoubleWide)
thicknessMultiplier *= 2f;

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