crest icon indicating copy to clipboard operation
crest copied to clipboard

Planar Reflection Error - Screen position out of view frustum

Open huwb opened this issue 4 years ago • 13 comments

Describe the bug

Error thrown when using the planar reflection feature.

Screen position out of view frustum (screen pos 256.000000, 0.000000, 10000.000000) (Camera rect 0 0 256 256)
UnityEngine.Rendering.LWRP.LightweightRenderPipeline:RenderSingleCamera(ScriptableRenderContext, Camera)
Crest.OceanPlanarReflection:BeginCameraRendering(ScriptableRenderContext, Camera) (at Assets/3rdLibrary/Crest/Scripts/Reflection/OceanPlanarReflection.cs:218)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Screenshots / video These are very helpful to understand and diagnose issues.

Log What is in the editor log? Clear before running and then provide any errors/warnings that appear. The log frequently provides the key hints.

Versions Crest URP 3.1 / Unity 2019.1.13f1 Crest URP / Unity 2019.3.2

To Reproduce How can the developers reproduce this bug? Are you able to reproduce the issue in the example content/scenes? Please include steps to reproduce the behaviour, with the example content ideally so we can follow the steps on our side.

Platform

  • Editor or standalone?
  • Platform (win/mac/...)

Hardware What hardware are you seeing the issue on? GPU model is particularly useful.

Additional context Add any other context about the problem here.

huwb avatar Mar 04 '20 08:03 huwb

image

Winux1062 avatar Mar 05 '20 09:03 Winux1062

I tried a few things to repro, mainly exploring different configurations of window layout/sizes in the editor, and different Texture Size settings on the planar reflection script. Have you tried messing with this setting - what value are you using at the moment?

I googled around and this has appeared in some hits, not sure how relevant they are:

  • https://issuetracker.unity3d.com/issues/screen-position-out-of-view-frustum-error-printed-non-stop
  • https://forum.unity.com/threads/screen-position-out-of-view-frustum.514453/

@Winux1062 just realised it says 'LWRP' in that callstack - so its on LWRP, not URP? The rate of change between LWRP/URP was massive with many bug fixes, so it would be worth upgrading to URP if that is an option?

One of the links above seems to talk about ARKit. Are you using any non-orthodox targets, such as VR?

There's too much missing from this bug and this is not actionable currently - could we please get help filling out the above template which has fields for target devices and etc. Thanks!

huwb avatar Mar 09 '20 13:03 huwb

Thanks for your patience!I run crest in editor mode(https://github.com/crest-ocean/crest/commits/feature/ocean-in-edit-mode), this mode does not support Planar Reflection. Then I added this support, it works good!. Occasionally this error occurs when roaming in editormode, or it changes when the scene size is changed. Operating platform:PC & Crest Ocean System 3.1 for LWRP

Winux1062 avatar Mar 13 '20 08:03 Winux1062

Bump. Same here. Unity 2021.1.2f1 Crest 4.10

cemkoker avatar Apr 29 '21 15:04 cemkoker

@cemkoker Can you provide more details? @Winux1062 modified the script to run in edit mode. Have you done the same or are experiencing this error in play mode?

daleeidd avatar Apr 29 '21 19:04 daleeidd

I am encountering the same issue very inconsistently. It logs an error in the editor but causes a full-on crash of the game on Stadia. I can reproduce the error by setting one of the elements m00, m11 or m23 to 0 in _camReflections.projectionMatrix before it gets sent off to UniversalRenderPipeline.RenderSingleCamera(context, _camReflections);

A cheap workaround could be to clamp those values maybe but I am sure that someone with more insight in the matrix multiplication can maybe find the source of the issue.

EliGould avatar Jul 12 '21 17:07 EliGould

@EliGould Thanks. We'll look at adding that in. It is hard to say if that is the cause of the issue, but looks like we might need to catch as many cases as we can.

I've created a reproducible here and submitted a bug report to Unity: test/planar-reflections-frustum-error. The case is different as the reproducible is caused by precision issues from very large coordinates, but hopefully Unity will see to solve the problem generally. The test case can be fixed by changing the clip plane or clip plane offset, but that probably only pushes the error to a different coordinate.

I'll update this thread with their reply.

daleeidd avatar Jul 13 '21 00:07 daleeidd

For my particular setting, it seems like only the values m00, m11 and m23 seem to matter, all other values can be 0 without causing issues. The near plane is at 0.1 and the far plane 5000. This is the workaround I will go with for now but it is good to know that I should not touch the clipping planes anymore then, to not move the issue around.

Will be interesting to see what Unity says.

EliGould avatar Jul 13 '21 10:07 EliGould

I could repro in BoatAttack but with fairly extreme values.

  • Open demo_island, press play
  • Select Player 1 GO, set Z to 10,000,000
  • Select FollowCam GO below Player 1, set near plane to 0.001, far plane to 10,000,000
  • Resume and it should spew them after some seconds

Something about the reflection camera matrices makes Camera::ScreenToWorldPoint fail. Understandable that this is failing, but this crashes the game on @EliGould 's platform.

Screen position out of view frustum (screen pos 0.000000, 0.000000, 10000000.000000) (Camera rect 0 0 376 171)
0x00007ff7ab0897ac (Unity) StackWalker::GetCurrentCallstack
0x00007ff7ab091b89 (Unity) StackWalker::ShowCallstack
0x00007ff7ac57752c (Unity) GetStacktrace
0x00007ff7ad67ae03 (Unity) DebugStringToFile
0x00007ff7aa18b759 (Unity) Camera::ScreenToWorldPoint
0x00007ff7aa173892 (Unity) Camera::CalculateFarPlaneWorldSpaceLength
0x00007ff7aa68d236 (Unity) GetScriptableCullingParameters
0x00007ff7ab218589 (Unity) Camera_CUSTOM_GetCullingParameters_Internal
0x000002a332b6ee8b (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Camera:GetCullingParameters_Internal (UnityEngine.Camera,bool,UnityEngine.Rendering.ScriptableCullingParameters&,int)
0x000002a332b6ece3 (Mono JIT Code) UnityEngine.Camera:TryGetCullingParameters (bool,UnityEngine.Rendering.ScriptableCullingParameters&)
0x000002a332b6eb5b (Mono JIT Code) [UniversalRenderPipeline.cs:318] UnityEngine.Rendering.Universal.UniversalRenderPipeline:TryGetCullingParameters (UnityEngine.Rendering.Universal.CameraData,UnityEngine.Rendering.ScriptableCullingParameters&) 
0x000002a332b6d6d3 (Mono JIT Code) [UniversalRenderPipeline.cs:337] UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Rendering.Universal.CameraData,bool) 
0x000002a332b6c733 (Mono JIT Code) [UniversalRenderPipeline.cs:300] UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera) 
0x000002a332b603f3 (Mono JIT Code) [PlanarReflections.cs:252] UnityEngine.Rendering.Universal.PlanarReflections:ExecutePlanarReflections (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera) 
0x000002a332b3fc09 (Mono JIT Code) (wrapper delegate-invoke) System.Action`2<UnityEngine.Rendering.ScriptableRenderContext, UnityEngine.Camera>:invoke_void_T1_T2 (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera)
0x000002a332b3f772 (Mono JIT Code) UnityEngine.Rendering.RenderPipelineManager:BeginCameraRendering (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera)
0x000002a332b3f5e3 (Mono JIT Code) UnityEngine.Rendering.RenderPipeline:BeginCameraRendering (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera)
0x000002a332b41e8b (Mono JIT Code) [UniversalRenderPipeline.cs:509] UnityEngine.Rendering.Universal.UniversalRenderPipeline:RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera) 
0x000002a332b35973 (Mono JIT Code) [UniversalRenderPipeline.cs:241] UnityEngine.Rendering.Universal.UniversalRenderPipeline:Render (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera[]) 
0x000002a332b34719 (Mono JIT Code) UnityEngine.Rendering.RenderPipeline:InternalRender (UnityEngine.Rendering.ScriptableRenderContext,UnityEngine.Camera[])
0x000002a332b1046b (Mono JIT Code) UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset,intptr,System.Collections.Generic.List`1<UnityEngine.Camera/RenderRequest>,Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle)
0x000002a332b108b4 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object_intptr_object_AtomicSafetyHandle (object,intptr,intptr,intptr)
0x00007ff8a47be630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke 
0x00007ff8a4742ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke 
0x00007ff8a474bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke 
0x00007ff7aaf01af4 (Unity) scripting_method_invoke
0x00007ff7aaefa445 (Unity) ScriptingInvocation::Invoke
0x00007ff7aa672009 (Unity) ScriptableRenderContext::ExtractAndExecuteRenderPipeline
0x00007ff7aa18664f (Unity) RenderManager::RenderCamerasWithScriptableRenderLoop
0x00007ff7aa185dd8 (Unity) RenderManager::RenderCameras
0x00007ff7aba28ef2 (Unity) RepaintController::RenderPlayModeViewCameras
0x00007ff7ac3c1b9e (Unity) EditorGUIUtility::RenderPlayModeViewCamerasInternal
0x00007ff7acc6ba99 (Unity) EditorGUIUtility_CUSTOM_RenderPlayModeViewCamerasInternal_Injected
0x000002a332b0caf7 (Mono JIT Code) (wrapper managed-to-native) UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal_Injected (UnityEngine.RenderTexture,int,UnityEngine.Vector2&,bool,bool)
0x000002a332b0c9a3 (Mono JIT Code) UnityEditor.EditorGUIUtility:RenderPlayModeViewCamerasInternal (UnityEngine.RenderTexture,int,UnityEngine.Vector2,bool,bool)
0x000002a332b092d3 (Mono JIT Code) UnityEditor.PlayModeView:RenderView (UnityEngine.Vector2,bool)
0x000002a33268d313 (Mono JIT Code) UnityEditor.GameView:OnGUI ()
0x000002a332686504 (Mono JIT Code) UnityEditor.HostView:InvokeOnGUI (UnityEngine.Rect,UnityEngine.Rect)
0x000002a332685ed3 (Mono JIT Code) UnityEditor.DockArea:DrawView (UnityEngine.Rect,UnityEngine.Rect)
0x000002a332668a3b (Mono JIT Code) UnityEditor.DockArea:OldOnGUI ()
0x000002a3326319c2 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:DoOnGUI (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,bool,UnityEngine.Rect,System.Action,bool)
0x000002a33262d0b3 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:HandleIMGUIEvent (UnityEngine.Event,UnityEngine.Matrix4x4,UnityEngine.Rect,System.Action,bool)
0x000002a3329aca53 (Mono JIT Code) UnityEngine.UIElements.IMGUIContainer:DoIMGUIRepaint ()
0x000002a3329a860e (Mono JIT Code) UnityEngine.UIElements.UIR.RenderChainCommand:ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams,single,System.Exception&)
0x000002a3329a4b6b (Mono JIT Code) UnityEngine.UIElements.UIR.UIRenderDevice:EvaluateChain (UnityEngine.UIElements.UIR.RenderChainCommand,UnityEngine.Material,UnityEngine.Material,UnityEngine.Texture,UnityEngine.Texture,UnityEngine.Texture,single,Unity.Collections.NativeSlice`1<UnityEngine.UIElements.UIR.Transform3x4>,Unity.Collections.NativeSlice`1<UnityEngine.Vector4>,UnityEngine.MaterialPropertyBlock,bool,System.Exception&)
0x000002a33299ad8b (Mono JIT Code) UnityEngine.UIElements.UIR.RenderChain:Render ()
0x000002a33286945b (Mono JIT Code) UnityEngine.UIElements.UIRRepaintUpdater:Update ()
0x000002a3325bf46a (Mono JIT Code) UnityEngine.UIElements.VisualTreeUpdater:UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase)
0x000002a332867123 (Mono JIT Code) UnityEngine.UIElements.Panel:UpdateForRepaint ()
0x000002a3328665a3 (Mono JIT Code) UnityEngine.UIElements.Panel:Repaint (UnityEngine.Event)
0x000002a3325be0e1 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel)
0x000002a3325bda83 (Mono JIT Code) UnityEngine.UIElements.UIElementsUtility:UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (int,intptr,bool&)
0x000002a3325bd46f (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration:ProcessEvent (int,intptr)
0x000002a3325bd17b (Mono JIT Code) UnityEngine.UIElements.UIEventRegistration/<>c:<.cctor>b__1_2 (int,intptr)
0x000002a3325bcc75 (Mono JIT Code) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
0x000002a3325bce96 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_int_intptr_intptr& (object,intptr,intptr,intptr)
0x00007ff8a47be630 (mono-2.0-bdwgc) [mini-runtime.c:2812] mono_jit_runtime_invoke 
0x00007ff8a4742ac2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke 
0x00007ff8a474bb1f (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke 
0x00007ff7aaf01af4 (Unity) scripting_method_invoke
0x00007ff7aaefa445 (Unity) ScriptingInvocation::Invoke
0x00007ff7aaef35a5 (Unity) ScriptingInvocation::Invoke<void>
0x00007ff7a95a7eed (Unity) Scripting::UnityEngine::GUIUtilityProxy::ProcessEvent
0x00007ff7abb2c596 (Unity) GUIView::ProcessRetainedMode
0x00007ff7ac5b91ea (Unity) GUIView::OnInputEvent
0x00007ff7abb2c488 (Unity) GUIView::ProcessInputEvent
0x00007ff7ac5aff02 (Unity) GUIView::DoPaint
0x00007ff7ac5bc20d (Unity) GUIView::RepaintAll
0x00007ff7abc128b1 (Unity) PlayerLoopController::UpdateScene
0x00007ff7abc10356 (Unity) Application::TickTimer
0x00007ff7ac580d21 (Unity) MainMessageLoop
0x00007ff7ac584d61 (Unity) WinMain
0x00007ff7ae3d62b6 (Unity) __scrt_common_main_seh
0x00007ff929ac7034 (KERNEL32) BaseThreadInitThunk
0x00007ff92ac02651 (ntdll) RtlUserThreadStart

huwb avatar Jul 15 '21 08:07 huwb

A little update on my end: The initial clamping approach of three values did not fully prevent crashes but clamping all values of the matrix against 0 (though that feels wrong for a projection matrix) seems to work. No reported crash eversince and visible difference in the reflections. Maybe that's an okay work around until the core issue is found.

EliGould avatar Jul 16 '21 19:07 EliGould

So you just ensure all elements are >= 0 ? Interesting, we could try this on our side as well

huwb avatar Jul 19 '21 06:07 huwb

I am making sure nothing is too close to zero. In the end I actually don't have any zero which feels very strange for a projection matrix. This is very much a hack but its been keeping me afloat so far.

I am using the method you suggested the other day, @huwb. Value = sign(value) * max(abs(value), 0.001)

EliGould avatar Jul 19 '21 21:07 EliGould

I have heard back from Unity and they created an issue for it.

daleeidd avatar Aug 04 '21 18:08 daleeidd