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

CameraComponent.ClearFlags is not properly refreshed on changed #10

Open
PolSpock opened this issue Dec 18, 2023 · 1 comment
Open

CameraComponent.ClearFlags is not properly refreshed on changed #10

PolSpock opened this issue Dec 18, 2023 · 1 comment

Comments

@PolSpock
Copy link

PolSpock commented Dec 18, 2023

Describe the bug

Hello,

I'm creating this issue in this project since i can't manage to get if it's an S&box Scene issue or a simple logical issue.

For my FPS Project, i have recently implemented the sbox-gunfight v2 ViewModel logic :

  • a main camera for displaying the scene
  • a secondary camera for displaying only the weapon ViewModel

By manipulating Render Tags / Render Exclude Tags for CameraComponent. And also, by manipulating Tags for Lights components & ViewModels, i obtain the desired result: a ViewModel that does not pass through facing walls.

Also inspired by the sbox-gunfight project, the Clear Flags of the secondary camera must be set to ClearFlags.Depth.

But let's discover 2 issues :

  1. Firstly, if you have any Screen Panel, they will be hidden by the second camera cause of his ClearFlags

  2. Secondly, setting ClearFlags toClearFlags.Depth only will create a spammy console error :

Error: View "Camera", Layer "Clear Color Depth Stencil", render target "output_depth_back_buffer....": 
	It is illegal for the first write to a non-scratch render target to not preserve, discard, or clear it!
	(This can often happen if you forget to clear both depth and stencil)
   at Sandbox.EngineLoop.Print(Int32 severity, String logger, String message)
   at Managed.SandboxEngine.Exports.Sandbox_EngineLoop_Print(Int32 severitty, IntPtr logger, IntPtr message)
   at Sandbox.EngineLoop.RunFrame(CMaterialSystem2AppSystemDict appDict, Boolean& wantsQuit)
   at Sandbox.SourceEngineApp.RunFrame() in C:\build\_work\sbox\sbox\engine\Launcher\SourceEngineApp.cs:line 48
   at Sandbox.SourceEngineApp.RunLoop() in C:\build\_work\sbox\sbox\engine\Launcher\SourceEngineApp.cs:line 39
   at Sandbox.Program.LaunchGame() in C:\build\_work\sbox\sbox\engine\Launcher\Launcher.cs:line 93
   at Sandbox.Program.Main() in C:\build\_work\sbox\sbox\engine\Launcher\Launcher.cs:line 58

To Reproduce

  1. Download sbox-gunfight

  2. Start gunfight.scene

  3. Play: you will get the spammy console errors (the Secondly mentioned issue)
    Stop. Now let's get the Firstly mentioned issue.

  4. To a GameObject, add Screen Panel component

  5. Then add a simple UI Razor Panel
    image

  6. Play: the UI panel will not appear

  7. Edit the Secondary camera Clear Flags : add Color then remove it.

  8. Constat the UI has started to appear correctly. This is the expected behavior.

Expected behavior

  1. No error
  2. Keep the UI

Media/Files

Here my reproduce step in video:

2023-12-18.19-35-18.mp4
@PolSpock
Copy link
Author

PolSpock commented Dec 18, 2023

Bonus

What i've tried on my own project :

  1. By adding ClearFlags = ClearFlags.Depth | ClearFlags.Stencil i can stop the spammy console errors
  2. By adding a delay between my ClearFlags, i can fix my UI issue, but it's very dirty :
// [Property] public CameraComponent ViewModelCamera { get; set; }
ViewModelCamera ??= GameObject.Components.Create<CameraComponent>();
ViewModelCamera.ClearFlags = ClearFlags.All;
ViewModelCamera.IsMainCamera = false;
ViewModelCamera.Priority = 2;
ViewModelCamera.FieldOfView = 90f;
ViewModelCamera.RenderTags.Add( "viewmodel" );
ViewModelCamera.RenderTags.Add( "light" );

await GameTask.DelayRealtimeSeconds( 2f );

ViewModelCamera.ClearFlags = ClearFlags.Depth | ClearFlags.Stencil;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant