diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index df72542f..8aa7be3c 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -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++) { @@ -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); @@ -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 @@ -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].