From be5b87b3002f8be2c24e427ecdfb5f773bdf3490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Fri, 29 Sep 2023 09:14:27 +0200 Subject: [PATCH] new object flag: not visible in main camera --- Editor/ObjectWindow.cpp | 22 ++++++++++++++- Editor/ObjectWindow.h | 1 + WickedEngine/wiRenderPath3D.cpp | 47 +++++++++---------------------- WickedEngine/wiRenderer.cpp | 24 ++++++++++------ WickedEngine/wiRenderer.h | 1 + WickedEngine/wiScene_Components.h | 5 ++++ 6 files changed, 56 insertions(+), 44 deletions(-) diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 21bdc381b..0941b80c2 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -365,7 +365,7 @@ void ObjectWindow::Create(EditorComponent* _editor) AddWidget(&navmeshCheckBox); foregroundCheckBox.Create("Foreground: "); - foregroundCheckBox.SetTooltip("Set object to be rendered in the foreground. This is useful for first person hands or weapons."); + foregroundCheckBox.SetTooltip("Set object to be rendered in the foreground.\nThis is useful for first person hands or weapons, so that they not clip into walls and other objects."); foregroundCheckBox.SetSize(XMFLOAT2(hei, hei)); foregroundCheckBox.SetPos(XMFLOAT2(x, y += step)); foregroundCheckBox.SetCheck(true); @@ -382,6 +382,24 @@ void ObjectWindow::Create(EditorComponent* _editor) }); AddWidget(&foregroundCheckBox); + notVisibleInMainCameraCheckBox.Create("Not visible in main camera: "); + notVisibleInMainCameraCheckBox.SetTooltip("Set object to be not rendered in the main camera.\nThis is useful for first person character model, as the character will still be rendered in reflections and shadows."); + notVisibleInMainCameraCheckBox.SetSize(XMFLOAT2(hei, hei)); + notVisibleInMainCameraCheckBox.SetPos(XMFLOAT2(x, y += step)); + notVisibleInMainCameraCheckBox.SetCheck(true); + notVisibleInMainCameraCheckBox.OnClick([&](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + for (auto& x : editor->translator.selected) + { + ObjectComponent* object = scene.objects.GetComponent(x.entity); + if (object != nullptr) + { + object->SetNotVisibleInMainCamera(args.bValue); + } + } + }); + AddWidget(¬VisibleInMainCameraCheckBox); + ditherSlider.Create(0, 1, 0, 1000, "Transparency: "); ditherSlider.SetTooltip("Adjust transparency of the object. Opaque materials will use dithered transparency in this case!"); ditherSlider.SetSize(XMFLOAT2(wid, hei)); @@ -691,6 +709,7 @@ void ObjectWindow::SetEntity(Entity entity) renderableCheckBox.SetCheck(object->IsRenderable()); shadowCheckBox.SetCheck(object->IsCastingShadow()); foregroundCheckBox.SetCheck(object->IsForeground()); + notVisibleInMainCameraCheckBox.SetCheck(object->IsNotVisibleInMainCamera()); navmeshCheckBox.SetCheck(object->filterMask & wi::enums::FILTER_NAVIGATION_MESH); cascadeMaskSlider.SetValue((float)object->cascadeMask); ditherSlider.SetValue(object->GetTransparency()); @@ -767,6 +786,7 @@ void ObjectWindow::ResizeLayout() add_right(renderableCheckBox); add_right(shadowCheckBox); add_right(foregroundCheckBox); + add_right(notVisibleInMainCameraCheckBox); add_right(navmeshCheckBox); add(ditherSlider); add(cascadeMaskSlider); diff --git a/Editor/ObjectWindow.h b/Editor/ObjectWindow.h index 8a50b81f6..c311713da 100644 --- a/Editor/ObjectWindow.h +++ b/Editor/ObjectWindow.h @@ -15,6 +15,7 @@ public: wi::gui::CheckBox shadowCheckBox; wi::gui::CheckBox navmeshCheckBox; wi::gui::CheckBox foregroundCheckBox; + wi::gui::CheckBox notVisibleInMainCameraCheckBox; wi::gui::Slider ditherSlider; wi::gui::Slider cascadeMaskSlider; wi::gui::Slider lodSlider; diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index 7ce47612a..36df375a3 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -792,8 +792,9 @@ namespace wi wi::renderer::DRAWSCENE_IMPOSTOR | wi::renderer::DRAWSCENE_HAIRPARTICLE | wi::renderer::DRAWSCENE_TESSELLATION | - wi::renderer::DRAWSCENE_OCCLUSIONCULLING - ; + wi::renderer::DRAWSCENE_OCCLUSIONCULLING | + wi::renderer::DRAWSCENE_MAINCAMERA + ; // Main camera depth prepass + occlusion culling: cmd = device->BeginCommandList(); @@ -849,7 +850,8 @@ namespace wi RENDERPASS_PREPASS, cmd, wi::renderer::DRAWSCENE_OPAQUE | - wi::renderer::DRAWSCENE_FOREGROUND_ONLY + wi::renderer::DRAWSCENE_FOREGROUND_ONLY | + wi::renderer::DRAWSCENE_MAINCAMERA ); // Regular: @@ -1077,23 +1079,10 @@ namespace wi Viewport vp; vp.width = (float)depthBuffer_Reflection.GetDesc().width; vp.height = (float)depthBuffer_Reflection.GetDesc().height; - - // Foreground: - vp.min_depth = 1 - foreground_depth_range; - vp.max_depth = 1; - device->BindViewports(1, &vp, cmd); - wi::renderer::DrawScene( - visibility_reflection, - RENDERPASS_PREPASS, - cmd, - wi::renderer::DRAWSCENE_OPAQUE | - wi::renderer::DRAWSCENE_FOREGROUND_ONLY - ); - - // Regular: vp.min_depth = 0; vp.max_depth = 1; device->BindViewports(1, &vp, cmd); + wi::renderer::DrawScene( visibility_reflection, RENDERPASS_PREPASS, @@ -1174,23 +1163,10 @@ namespace wi Viewport vp; vp.width = (float)depthBuffer_Reflection.GetDesc().width; vp.height = (float)depthBuffer_Reflection.GetDesc().height; - - // Foreground: - vp.min_depth = 1 - foreground_depth_range; - vp.max_depth = 1; - device->BindViewports(1, &vp, cmd); - wi::renderer::DrawScene( - visibility_reflection, - RENDERPASS_MAIN, - cmd, - wi::renderer::DRAWSCENE_OPAQUE | - wi::renderer::DRAWSCENE_FOREGROUND_ONLY - ); - - // Regular: vp.min_depth = 0; vp.max_depth = 1; device->BindViewports(1, &vp, cmd); + wi::renderer::DrawScene( visibility_reflection, RENDERPASS_MAIN, @@ -1419,7 +1395,8 @@ namespace wi RENDERPASS_MAIN, cmd, wi::renderer::DRAWSCENE_OPAQUE | - wi::renderer::DRAWSCENE_FOREGROUND_ONLY + wi::renderer::DRAWSCENE_FOREGROUND_ONLY | + wi::renderer::DRAWSCENE_MAINCAMERA ); // Regular: @@ -1869,7 +1846,8 @@ namespace wi RENDERPASS_MAIN, cmd, wi::renderer::DRAWSCENE_TRANSPARENT | - wi::renderer::DRAWSCENE_FOREGROUND_ONLY + wi::renderer::DRAWSCENE_FOREGROUND_ONLY | + wi::renderer::DRAWSCENE_MAINCAMERA ); // Regular: @@ -1884,7 +1862,8 @@ namespace wi wi::renderer::DRAWSCENE_OCCLUSIONCULLING | wi::renderer::DRAWSCENE_HAIRPARTICLE | wi::renderer::DRAWSCENE_TESSELLATION | - wi::renderer::DRAWSCENE_OCEAN + wi::renderer::DRAWSCENE_OCEAN | + wi::renderer::DRAWSCENE_MAINCAMERA ); device->EventEnd(cmd); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 4b63b3e3b..9e4645d16 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -5696,6 +5696,7 @@ void DrawScene( const bool ocean = flags & DRAWSCENE_OCEAN; const bool skip_planar_reflection_objects = flags & DRAWSCENE_SKIP_PLANAR_REFLECTION_OBJECTS; const bool foreground_only = flags & DRAWSCENE_FOREGROUND_ONLY; + const bool maincamera = flags & DRAWSCENE_MAINCAMERA; device->EventBegin("DrawScene", cmd); device->BindShadingRate(ShadingRate::RATE_1X1, cmd); @@ -5734,15 +5735,20 @@ void DrawScene( continue; const ObjectComponent& object = vis.scene->objects[instanceIndex]; - if (object.IsRenderable() && object.IsForeground() == foreground_only && (object.GetFilterMask() & filterMask)) - { - const float distance = wi::math::Distance(vis.camera->Eye, object.center); - if (distance > object.fadeDistance + object.radius) - { - continue; - } - renderQueue.add(object.mesh_index, instanceIndex, distance, object.sort_bits); - } + if (!object.IsRenderable()) + continue; + if (foreground_only && !object.IsForeground()) + continue; + if (maincamera && object.IsNotVisibleInMainCamera()) + continue; + if ((object.GetFilterMask() & filterMask) == 0) + continue; + + const float distance = wi::math::Distance(vis.camera->Eye, object.center); + if (distance > object.fadeDistance + object.radius) + continue; + + renderQueue.add(object.mesh_index, instanceIndex, distance, object.sort_bits); } if (!renderQueue.empty()) { diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index a7c8f38b8..8e5dcf4f3 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -208,6 +208,7 @@ namespace wi::renderer DRAWSCENE_OCEAN = 1 << 6, // include ocean DRAWSCENE_SKIP_PLANAR_REFLECTION_OBJECTS = 1 << 7, // don't draw subsets which have planar reflection material DRAWSCENE_FOREGROUND_ONLY = 1 << 8, // only include objects that are tagged as foreground + DRAWSCENE_MAINCAMERA = 1 << 9, // If this is active, then ObjectComponent with SetNotVisibleInMainCamera(true) won't be drawn }; // Draw the world from a camera. You must call BindCameraCB() at least once in this frame prior to this diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 8aabfddb6..208c5a502 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -666,6 +666,7 @@ namespace wi::scene LIGHTMAP_RENDER_REQUEST = 1 << 5, LIGHTMAP_DISABLE_BLOCK_COMPRESSION = 1 << 6, FOREGROUND = 1 << 7, + NOT_VISIBLE_IN_MAIN_CAMERA = 1 << 8, }; uint32_t _flags = RENDERABLE | CAST_SHADOW; @@ -704,7 +705,10 @@ namespace wi::scene inline void SetRequestPlanarReflection(bool value) { if (value) { _flags |= REQUEST_PLANAR_REFLECTION; } else { _flags &= ~REQUEST_PLANAR_REFLECTION; } } inline void SetLightmapRenderRequest(bool value) { if (value) { _flags |= LIGHTMAP_RENDER_REQUEST; } else { _flags &= ~LIGHTMAP_RENDER_REQUEST; } } inline void SetLightmapDisableBlockCompression(bool value) { if (value) { _flags |= LIGHTMAP_DISABLE_BLOCK_COMPRESSION; } else { _flags &= ~LIGHTMAP_DISABLE_BLOCK_COMPRESSION; } } + // Foreground object will be rendered in front of regular objects inline void SetForeground(bool value) { if (value) { _flags |= FOREGROUND; } else { _flags &= ~FOREGROUND; } } + // With this you can disable object rendering for main camera (DRAWSCENE_MAINCAMERA) + inline void SetNotVisibleInMainCamera(bool value) { if (value) { _flags |= NOT_VISIBLE_IN_MAIN_CAMERA; } else { _flags &= ~NOT_VISIBLE_IN_MAIN_CAMERA; } } inline bool IsRenderable() const { return _flags & RENDERABLE; } inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; } @@ -713,6 +717,7 @@ namespace wi::scene inline bool IsLightmapRenderRequested() const { return _flags & LIGHTMAP_RENDER_REQUEST; } inline bool IsLightmapDisableBlockCompression() const { return _flags & LIGHTMAP_DISABLE_BLOCK_COMPRESSION; } inline bool IsForeground() const { return _flags & FOREGROUND; } + inline bool IsNotVisibleInMainCamera() const { return _flags & NOT_VISIBLE_IN_MAIN_CAMERA; } inline float GetTransparency() const { return 1 - color.w; } inline uint32_t GetFilterMask() const { return filterMask | filterMaskDynamic; }