diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 4748c97ad..b59dec004 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -110,7 +110,6 @@ You can use the Renderer with the following functions, all of which are in the g - GetCamera() : Camera result -- returns the main camera - AttachCamera(Entity entity) -- attaches camera to an entity in the current frame - HairParticleSettings(opt int lod0, opt int lod1, opt int lod2) -- SetAlphaCompositionEnabled(opt bool enabled) - SetShadowProps2D(int resolution, int count, int softShadowQuality) - SetShadowPropsCube(int resolution, int count) - SetDebugPartitionTreeEnabled(bool enabled) diff --git a/Documentation/WickedEngine-Documentation.md b/Documentation/WickedEngine-Documentation.md index a298aee7d..db8f4480f 100644 --- a/Documentation/WickedEngine-Documentation.md +++ b/Documentation/WickedEngine-Documentation.md @@ -7,10 +7,6 @@ This is a reference for the C++ features of Wicked Engine 2. [RenderPath](#renderpath) 3. [RenderPath2D](#renderpath2d) 4. [RenderPath3D](#renderpath3d) - 5. [RenderPath3D_Forward](#renderpath3d_forward) - 6. [RenderPath3D_Deferred](#renderpath3d_deferred) - 7. [RenderPath3D_TiledForward](#renderpath3d_tiledforward) - 8. [RenderPath3D_TiledDeferred](#renderpath3d_tileddeferred) 9. [RenderPath3D_Pathtracing](#renderpath3d_pathtracing) 10. [LoadingScreen](#loadingscreen) 2. [System](#system) @@ -93,6 +89,7 @@ This is a reference for the C++ features of Wicked Engine 15. [Loading Shaders](#loading-shaders) 16. [Debug Draw](#debug-draw) 17. [Animation Skinning](#animation-skinning) + 18. [Custom Shaders](#custom-shaders) 3. [wiEnums](#wienums) 4. [wiImage](#wiimage) 5. [wiFont](#wifont) @@ -208,7 +205,7 @@ Capable of handling 2D rendering to offscreen buffer in Render() function, or ju ### RenderPath3D [[Header]](../WickedEngine/RenderPath3D.h) [[Cpp]](../WickedEngine/RenderPath3D.cpp) -Base class for implementing 3D rendering paths. It supports everything that the Renderpath2D does. It is a base class that doesn't implement a particular 3D scene rendering algorithm, so it can't be used by itself. For specific algorithm, the user can choose between using [RenderPath3D_Forward](#renderpath3d_forward), [RenderPath3D_Deferred](#renderpath3d_deferred), [RenderPath3D_TiledForward](#renderpath3d_tiledforward), [RenderPath3D_TiledDeferred](#renderpath3d_tileddeferred) and [RenderPath3D_PathTracing](#renderpath3d_pathtracing), each with their own strengths and weaknesses. +Base class for implementing 3D rendering paths. It also supports everything that the Renderpath2D does. The post process chain is also implemented here. This means that the order of the post processes and the resources that they use are defined here, but the individual post process rendering on a lower level is implemented in the `wiRenderer` as core engine features. Read more about post process implementation in the [wiRenderer section](#post-processing). @@ -222,22 +219,6 @@ These are running in more specific locations, depending on the render path. For The HDR and LDR post process chain are using the "ping-ponging" technique, which means when the first post process consumes texture1 and produces texture2, then the following post process will consume texture2 and produce texture1, until all post processes are rendered. -### RenderPath3D_Forward -[[Header]](../WickedEngine/RenderPath3D_Forward.h) [[Cpp]](../WickedEngine/RenderPath3D_Forward.cpp) -Implements simple Forward rendering. It uses few render targets, small memory footprint, but not very efficient with many lights. - -### RenderPath3D_Defered -[[Header]](../WickedEngine/RenderPath3D_Deferred.h) [[Cpp]](../WickedEngine/RenderPath3D_Deferred.cpp) -Implements "old school" Deferred rendering. It uses many render targets, capable of advanced post processing effects, and good to render many lights. - -### RenderPath3D_TiledForward -[[Header]](../WickedEngine/RenderPath3D_TiledForward.h) [[Cpp]](../WickedEngine/RenderPath3D_TiledForward.cpp) -Implements an advanced method of Forward rendering to be able to render many lights efficiently. It uses fewer render targets, and less memory than deferred. One downside is that it is not capable of Subsurface scattering, because light buffers are not separated from rendering result. - -### RenderPath3D_TiledDeferred -[[Header]](../WickedEngine/RenderPath3D_TiledDeferred.h) [[Cpp]](../WickedEngine/RenderPath3D_TiledDeferred.cpp) -Implements an advanced method of Deferred rendering to be able to render many lights with reduced memory bandwidth requirements. This has the largest memory footprint overall, but less bandwidth consummation than old school deferred approach, because lighting is computed in a single pass instead of additive blending. - ### RenderPath3D_PathTracing [[Header]](../WickedEngine/RenderPath3D_PathTracing.h) [[Cpp]](../WickedEngine/RenderPath3D_PathTracing.cpp) Implements a compute shader based path tracing solution. In a static scene, the rendering will converge to ground truth. When something changes in the scene (something moves, ot material changes, etc...), the convergence will be restarted from the beginning. The raytracing is implemented in [wiRenderer](#wirenderer) and multiple [shaders](#shaders). The ray tracing is available on any GPU that supports compute shaders. @@ -839,6 +820,11 @@ Configuring other debug rendering functionality: If the [ArmatureComponent](#armaturecomponent) has less than `SKINNING_COMPUTE_THREADCOUNT` amount of bones, an optimized version of the skinning will be performed that uses shared memory. The user can disable this with the `wiRenderer::SetLDSSkinningEnabled()` function if the optimization proves to be worse on the target platform. +#### Custom Shaders +Apart from the built in material shaders, the developer can create a library of custom shaders from the application side and assign them to materials. The `wiRenderer::RegisterCustomShader()` function is used to register a custom shader from the application. The function returns the ID of the custom shader that can be input to the `MaterialComponent::SetCustomShaderID()` function. + +The custom shader is essentially the combination of a [Pipeline State Object](#pipeline-states-and-shaders) for each `RENDERPASS` and a `RENDERTYPE` flag that specifies whether it is to be drawn in a transparent or opaque, or other kind of pass within a `RENDERPASS`. The developer is responsible of creating a fully valid pipeline state to render a mesh. If a pipeline state is left as empty for a combination of `RENDERPASS` and `RENDERTYPE`, then the material will simply be skipped and not rendered. + ### wiEnums [[Header]](../WickedEngine/wiEnums.h) @@ -957,7 +943,7 @@ Supports item selection from a list of text. Can set the maximum number of visib #### wiWindow [[Header]](../WickedEngine/wiWidget.h) [[Cpp]](../WickedEngine/wiWidget.cpp) -A window widget is able to hold any number of other widgets. It can be moved across the screen, minimized and resized by the user. If a window holds a widget, it will manage its lifetime, so if the window is destroyed, all its children will be destroyed as well. +A window widget is able to hold any number of other widgets. It can be moved across the screen, minimized and resized by the user. The window does not manage lifetime of attached widgets since 0.49.0! #### wiColorPicker [[Header]](../WickedEngine/wiWidget.h) [[Cpp]](../WickedEngine/wiWidget.cpp) diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index 8495e6488..d16cdcf21 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -7,13 +7,10 @@ using namespace wiECS; using namespace wiScene; -AnimationWindow::AnimationWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void AnimationWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - animWindow = new wiWindow(GUI, "Animation Window"); - animWindow->SetSize(XMFLOAT2(520, 140)); - GUI->AddWidget(animWindow); + wiWindow::Create("Animation Window"); + SetSize(XMFLOAT2(520, 140)); float x = 140; float y = 10; @@ -21,34 +18,34 @@ AnimationWindow::AnimationWindow(EditorComponent* editor) : GUI(&editor->GetGUI( float step = hei + 2; - animationsComboBox = new wiComboBox("Animation: "); - animationsComboBox->SetSize(XMFLOAT2(300, hei)); - animationsComboBox->SetPos(XMFLOAT2(x, y += step)); - animationsComboBox->SetEnabled(false); - animationsComboBox->OnSelect([&](wiEventArgs args) { + animationsComboBox.Create("Animation: "); + animationsComboBox.SetSize(XMFLOAT2(300, hei)); + animationsComboBox.SetPos(XMFLOAT2(x, y += step)); + animationsComboBox.SetEnabled(false); + animationsComboBox.OnSelect([&](wiEventArgs args) { entity = wiScene::GetScene().animations.GetEntity(args.iValue); }); - animationsComboBox->SetTooltip("Choose an animation clip..."); - animWindow->AddWidget(animationsComboBox); + animationsComboBox.SetTooltip("Choose an animation clip..."); + AddWidget(&animationsComboBox); - loopedCheckBox = new wiCheckBox("Looped: "); - loopedCheckBox->SetTooltip("Toggle animation looping behaviour."); - loopedCheckBox->SetSize(XMFLOAT2(hei, hei)); - loopedCheckBox->SetPos(XMFLOAT2(150, y += step)); - loopedCheckBox->OnClick([&](wiEventArgs args) { + loopedCheckBox.Create("Looped: "); + loopedCheckBox.SetTooltip("Toggle animation looping behaviour."); + loopedCheckBox.SetSize(XMFLOAT2(hei, hei)); + loopedCheckBox.SetPos(XMFLOAT2(150, y += step)); + loopedCheckBox.OnClick([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->SetLooped(args.bValue); } }); - animWindow->AddWidget(loopedCheckBox); + AddWidget(&loopedCheckBox); - playButton = new wiButton("Play"); - playButton->SetTooltip("Play/Pause animation."); - playButton->SetSize(XMFLOAT2(100, hei)); - playButton->SetPos(XMFLOAT2(200, y)); - playButton->OnClick([&](wiEventArgs args) { + playButton.Create("Play"); + playButton.SetTooltip("Play/Pause animation."); + playButton.SetSize(XMFLOAT2(100, hei)); + playButton.SetPos(XMFLOAT2(200, y)); + playButton.OnClick([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { @@ -63,82 +60,73 @@ AnimationWindow::AnimationWindow(EditorComponent* editor) : GUI(&editor->GetGUI( } } }); - animWindow->AddWidget(playButton); + AddWidget(&playButton); - stopButton = new wiButton("Stop"); - stopButton->SetTooltip("Stop animation."); - stopButton->SetSize(XMFLOAT2(100, hei)); - stopButton->SetPos(XMFLOAT2(310, y)); - stopButton->OnClick([&](wiEventArgs args) { + stopButton.Create("Stop"); + stopButton.SetTooltip("Stop animation."); + stopButton.SetSize(XMFLOAT2(100, hei)); + stopButton.SetPos(XMFLOAT2(310, y)); + stopButton.OnClick([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->Stop(); } }); - animWindow->AddWidget(stopButton); + AddWidget(&stopButton); - timerSlider = new wiSlider(0, 1, 0, 100000, "Timer: "); - timerSlider->SetSize(XMFLOAT2(250, hei)); - timerSlider->SetPos(XMFLOAT2(x, y += step)); - timerSlider->OnSlide([&](wiEventArgs args) { + timerSlider.Create(0, 1, 0, 100000, "Timer: "); + timerSlider.SetSize(XMFLOAT2(250, hei)); + timerSlider.SetPos(XMFLOAT2(x, y += step)); + timerSlider.OnSlide([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->timer = args.fValue; } }); - timerSlider->SetEnabled(false); - timerSlider->SetTooltip("Set the animation timer by hand."); - animWindow->AddWidget(timerSlider); + timerSlider.SetEnabled(false); + timerSlider.SetTooltip("Set the animation timer by hand."); + AddWidget(&timerSlider); - amountSlider = new wiSlider(0, 1, 0, 100000, "Amount: "); - amountSlider->SetSize(XMFLOAT2(250, hei)); - amountSlider->SetPos(XMFLOAT2(x, y += step)); - amountSlider->OnSlide([&](wiEventArgs args) { + amountSlider.Create(0, 1, 0, 100000, "Amount: "); + amountSlider.SetSize(XMFLOAT2(250, hei)); + amountSlider.SetPos(XMFLOAT2(x, y += step)); + amountSlider.OnSlide([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->amount = args.fValue; } }); - amountSlider->SetEnabled(false); - amountSlider->SetTooltip("Set the animation blending amount by hand."); - animWindow->AddWidget(amountSlider); + amountSlider.SetEnabled(false); + amountSlider.SetTooltip("Set the animation blending amount by hand."); + AddWidget(&amountSlider); - speedSlider = new wiSlider(0, 4, 1, 100000, "Speed: "); - speedSlider->SetSize(XMFLOAT2(250, hei)); - speedSlider->SetPos(XMFLOAT2(x, y += step)); - speedSlider->OnSlide([&](wiEventArgs args) { + speedSlider.Create(0, 4, 1, 100000, "Speed: "); + speedSlider.SetSize(XMFLOAT2(250, hei)); + speedSlider.SetPos(XMFLOAT2(x, y += step)); + speedSlider.OnSlide([&](wiEventArgs args) { AnimationComponent* animation = wiScene::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->speed = args.fValue; } }); - speedSlider->SetEnabled(false); - speedSlider->SetTooltip("Set the animation speed."); - animWindow->AddWidget(speedSlider); + speedSlider.SetEnabled(false); + speedSlider.SetTooltip("Set the animation speed."); + AddWidget(&speedSlider); - animWindow->Translate(XMFLOAT3(100, 50, 0)); - animWindow->SetVisible(false); + Translate(XMFLOAT3(100, 50, 0)); + SetVisible(false); } - -AnimationWindow::~AnimationWindow() -{ - animWindow->RemoveWidgets(true); - - GUI->RemoveWidget(animWindow); - delete animWindow; -} - void AnimationWindow::Update() { - animationsComboBox->ClearItems(); + animationsComboBox.ClearItems(); Scene& scene = wiScene::GetScene(); @@ -149,52 +137,52 @@ void AnimationWindow::Update() if (scene.animations.GetCount() == 0) { - animWindow->SetEnabled(false); + SetEnabled(false); return; } else { - animWindow->SetEnabled(true); + SetEnabled(true); } for (size_t i = 0; i < scene.animations.GetCount(); ++i) { Entity e = scene.animations.GetEntity(i); NameComponent& name = *scene.names.GetComponent(e); - animationsComboBox->AddItem(name.name.empty() ? std::to_string(e) : name.name); + animationsComboBox.AddItem(name.name.empty() ? std::to_string(e) : name.name); if (e == entity) { - animationsComboBox->SetSelected((int)i); + animationsComboBox.SetSelected((int)i); } } if (entity == INVALID_ENTITY && scene.animations.GetCount() > 0) { entity = scene.animations.GetEntity(0); - animationsComboBox->SetSelected(0); + animationsComboBox.SetSelected(0); } - int selected = animationsComboBox->GetSelected(); + int selected = animationsComboBox.GetSelected(); if (selected >= 0 && selected < (int)scene.animations.GetCount()) { AnimationComponent& animation = scene.animations[selected]; if (animation.IsPlaying()) { - playButton->SetText("Pause"); + playButton.SetText("Pause"); animation.amount = wiMath::Lerp(animation.amount, 1, 0.1f); } else { - playButton->SetText("Play"); + playButton.SetText("Play"); } - loopedCheckBox->SetCheck(animation.IsLooped()); + loopedCheckBox.SetCheck(animation.IsLooped()); - timerSlider->SetRange(0, animation.GetLength()); - timerSlider->SetValue(animation.timer); - amountSlider->SetValue(animation.amount); - speedSlider->SetValue(animation.speed); + timerSlider.SetRange(0, animation.GetLength()); + timerSlider.SetValue(animation.timer); + amountSlider.SetValue(animation.amount); + speedSlider.SetValue(animation.speed); } } diff --git a/Editor/AnimationWindow.h b/Editor/AnimationWindow.h index 164733d73..d431be363 100644 --- a/Editor/AnimationWindow.h +++ b/Editor/AnimationWindow.h @@ -1,33 +1,22 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiButton; +#include "WickedEngine.h" class EditorComponent; -class AnimationWindow +class AnimationWindow : public wiWindow { public: - AnimationWindow(EditorComponent* editor); - ~AnimationWindow(); - - wiGUI* GUI; + void Create(EditorComponent* editor); wiECS::Entity entity = wiECS::INVALID_ENTITY; - wiWindow* animWindow; - wiComboBox* animationsComboBox; - wiCheckBox* loopedCheckBox; - wiButton* playButton; - wiButton* stopButton; - wiSlider* timerSlider; - wiSlider* amountSlider; - wiSlider* speedSlider; + wiComboBox animationsComboBox; + wiCheckBox loopedCheckBox; + wiButton playButton; + wiButton stopButton; + wiSlider timerSlider; + wiSlider amountSlider; + wiSlider speedSlider; void Update(); }; diff --git a/Editor/CameraWindow.cpp b/Editor/CameraWindow.cpp index cd824ee4b..db7b19551 100644 --- a/Editor/CameraWindow.cpp +++ b/Editor/CameraWindow.cpp @@ -18,126 +18,122 @@ void CameraWindow::ResetCam() camera_target.UpdateTransform(); } -CameraWindow::CameraWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void CameraWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - + wiWindow::Create("Camera Window"); camera_transform.MatrixTransform(wiRenderer::GetCamera().GetInvView()); camera_transform.UpdateTransform(); - cameraWindow = new wiWindow(GUI, "Camera Window"); - cameraWindow->SetSize(XMFLOAT2(380, 260)); - GUI->AddWidget(cameraWindow); + SetSize(XMFLOAT2(380, 260)); float x = 200; float y = 10; float hei = 18; float step = hei + 2; - farPlaneSlider = new wiSlider(1, 5000, 1000, 100000, "Far Plane: "); - farPlaneSlider->SetSize(XMFLOAT2(100, hei)); - farPlaneSlider->SetPos(XMFLOAT2(x, y += step)); - farPlaneSlider->SetValue(wiRenderer::GetCamera().zFarP); - farPlaneSlider->OnSlide([&](wiEventArgs args) { + farPlaneSlider.Create(1, 5000, 1000, 100000, "Far Plane: "); + farPlaneSlider.SetSize(XMFLOAT2(100, hei)); + farPlaneSlider.SetPos(XMFLOAT2(x, y += step)); + farPlaneSlider.SetValue(wiRenderer::GetCamera().zFarP); + farPlaneSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.zFarP = args.fValue; camera.UpdateCamera(); }); - cameraWindow->AddWidget(farPlaneSlider); + AddWidget(&farPlaneSlider); - nearPlaneSlider = new wiSlider(0.01f, 10, 0.1f, 10000, "Near Plane: "); - nearPlaneSlider->SetSize(XMFLOAT2(100, hei)); - nearPlaneSlider->SetPos(XMFLOAT2(x, y += step)); - nearPlaneSlider->SetValue(wiRenderer::GetCamera().zNearP); - nearPlaneSlider->OnSlide([&](wiEventArgs args) { + nearPlaneSlider.Create(0.01f, 10, 0.1f, 10000, "Near Plane: "); + nearPlaneSlider.SetSize(XMFLOAT2(100, hei)); + nearPlaneSlider.SetPos(XMFLOAT2(x, y += step)); + nearPlaneSlider.SetValue(wiRenderer::GetCamera().zNearP); + nearPlaneSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.zNearP = args.fValue; camera.UpdateCamera(); }); - cameraWindow->AddWidget(nearPlaneSlider); + AddWidget(&nearPlaneSlider); - fovSlider = new wiSlider(1, 179, 60, 10000, "FOV: "); - fovSlider->SetSize(XMFLOAT2(100, hei)); - fovSlider->SetPos(XMFLOAT2(x, y += step)); - fovSlider->OnSlide([&](wiEventArgs args) { + fovSlider.Create(1, 179, 60, 10000, "FOV: "); + fovSlider.SetSize(XMFLOAT2(100, hei)); + fovSlider.SetPos(XMFLOAT2(x, y += step)); + fovSlider.OnSlide([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.fov = args.fValue / 180.f * XM_PI; camera.UpdateCamera(); }); - cameraWindow->AddWidget(fovSlider); + AddWidget(&fovSlider); - movespeedSlider = new wiSlider(1, 100, 10, 10000, "Movement Speed: "); - movespeedSlider->SetSize(XMFLOAT2(100, hei)); - movespeedSlider->SetPos(XMFLOAT2(x, y += step)); - cameraWindow->AddWidget(movespeedSlider); + movespeedSlider.Create(1, 100, 10, 10000, "Movement Speed: "); + movespeedSlider.SetSize(XMFLOAT2(100, hei)); + movespeedSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&movespeedSlider); - rotationspeedSlider = new wiSlider(0.1f, 2, 1, 10000, "Rotation Speed: "); - rotationspeedSlider->SetSize(XMFLOAT2(100, hei)); - rotationspeedSlider->SetPos(XMFLOAT2(x, y += step)); - cameraWindow->AddWidget(rotationspeedSlider); + rotationspeedSlider.Create(0.1f, 2, 1, 10000, "Rotation Speed: "); + rotationspeedSlider.SetSize(XMFLOAT2(100, hei)); + rotationspeedSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&rotationspeedSlider); - resetButton = new wiButton("Reset Camera"); - resetButton->SetSize(XMFLOAT2(140, hei)); - resetButton->SetPos(XMFLOAT2(x, y += step)); - resetButton->OnClick([&](wiEventArgs args) { + resetButton.Create("Reset Camera"); + resetButton.SetSize(XMFLOAT2(140, hei)); + resetButton.SetPos(XMFLOAT2(x, y += step)); + resetButton.OnClick([&](wiEventArgs args) { ResetCam(); }); - cameraWindow->AddWidget(resetButton); + AddWidget(&resetButton); - fpsCheckBox = new wiCheckBox("FPS Camera: "); - fpsCheckBox->SetSize(XMFLOAT2(hei, hei)); - fpsCheckBox->SetPos(XMFLOAT2(x, y += step)); - fpsCheckBox->SetCheck(true); - cameraWindow->AddWidget(fpsCheckBox); + fpsCheckBox.Create("FPS Camera: "); + fpsCheckBox.SetSize(XMFLOAT2(hei, hei)); + fpsCheckBox.SetPos(XMFLOAT2(x, y += step)); + fpsCheckBox.SetCheck(true); + AddWidget(&fpsCheckBox); - proxyButton = new wiButton("Place Proxy"); - proxyButton->SetTooltip("Copy the current camera and place a proxy of it in the world."); - proxyButton->SetSize(XMFLOAT2(140, hei)); - proxyButton->SetPos(XMFLOAT2(x, y += step * 2)); - proxyButton->OnClick([&](wiEventArgs args) { + proxyButton.Create("Place Proxy"); + proxyButton.SetTooltip("Copy the current camera and place a proxy of it in the world."); + proxyButton.SetSize(XMFLOAT2(140, hei)); + proxyButton.SetPos(XMFLOAT2(x, y += step * 2)); + proxyButton.OnClick([=](wiEventArgs args) { const CameraComponent& camera = wiRenderer::GetCamera(); Scene& scene = wiScene::GetScene(); - Entity entity = scene.Entity_CreateCamera("cam", camera.width, camera.height, camera.zNearP, camera.zFarP, camera.fov); + static int camcounter = 0; + Entity entity = scene.Entity_CreateCamera("cam" + std::to_string(camcounter), camera.width, camera.height, camera.zNearP, camera.zFarP, camera.fov); + camcounter++; TransformComponent& transform = *scene.transforms.GetComponent(entity); transform.MatrixTransform(camera.InvView); + + editor->ClearSelected(); + editor->AddSelected(entity); + editor->RefreshSceneGraphView(); + SetEntity(entity); }); - cameraWindow->AddWidget(proxyButton); + AddWidget(&proxyButton); - followCheckBox = new wiCheckBox("Follow Proxy: "); - followCheckBox->SetSize(XMFLOAT2(hei, hei)); - followCheckBox->SetPos(XMFLOAT2(x, y += step)); - followCheckBox->SetCheck(false); - cameraWindow->AddWidget(followCheckBox); + followCheckBox.Create("Follow Proxy: "); + followCheckBox.SetSize(XMFLOAT2(hei, hei)); + followCheckBox.SetPos(XMFLOAT2(x, y += step)); + followCheckBox.SetCheck(false); + AddWidget(&followCheckBox); - followSlider = new wiSlider(0.0f, 0.999f, 0.0f, 1000.0f, "Follow Proxy Delay: "); - followSlider->SetSize(XMFLOAT2(100, hei)); - followSlider->SetPos(XMFLOAT2(x, y += step)); - cameraWindow->AddWidget(followSlider); + followSlider.Create(0.0f, 0.999f, 0.0f, 1000.0f, "Follow Proxy Delay: "); + followSlider.SetSize(XMFLOAT2(100, hei)); + followSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&followSlider); SetEntity(INVALID_ENTITY); - cameraWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 100, 0)); - cameraWindow->SetVisible(false); -} - - -CameraWindow::~CameraWindow() -{ - cameraWindow->RemoveWidgets(true); - GUI->RemoveWidget(cameraWindow); - delete cameraWindow; + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 100, 0)); + SetVisible(false); } void CameraWindow::SetEntity(Entity entity) @@ -148,13 +144,13 @@ void CameraWindow::SetEntity(Entity entity) if (scene.cameras.GetComponent(entity) != nullptr) { - followCheckBox->SetEnabled(true); - followSlider->SetEnabled(true); + followCheckBox.SetEnabled(true); + followSlider.SetEnabled(true); } else { - followCheckBox->SetCheck(false); - followCheckBox->SetEnabled(false); - followSlider->SetEnabled(false); + followCheckBox.SetCheck(false); + followCheckBox.SetEnabled(false); + followSlider.SetEnabled(false); } } diff --git a/Editor/CameraWindow.h b/Editor/CameraWindow.h index f833f0814..30f58c643 100644 --- a/Editor/CameraWindow.h +++ b/Editor/CameraWindow.h @@ -1,19 +1,12 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class CameraWindow +class CameraWindow : public wiWindow { public: - CameraWindow(EditorComponent* editor); - ~CameraWindow(); + void Create(EditorComponent* editor); void ResetCam(); @@ -24,19 +17,16 @@ public: wiScene::TransformComponent camera_transform; wiScene::TransformComponent camera_target; - wiGUI* GUI; + wiSlider farPlaneSlider; + wiSlider nearPlaneSlider; + wiSlider fovSlider; + wiSlider movespeedSlider; + wiSlider rotationspeedSlider; + wiButton resetButton; + wiCheckBox fpsCheckBox; - wiWindow* cameraWindow; - wiSlider* farPlaneSlider; - wiSlider* nearPlaneSlider; - wiSlider* fovSlider; - wiSlider* movespeedSlider; - wiSlider* rotationspeedSlider; - wiButton* resetButton; - wiCheckBox* fpsCheckBox; - - wiButton* proxyButton; - wiCheckBox* followCheckBox; - wiSlider* followSlider; + wiButton proxyButton; + wiCheckBox followCheckBox; + wiSlider followSlider; }; diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index 8c3e51fb7..6d8acbdd4 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -6,62 +6,51 @@ using namespace wiECS; using namespace wiScene; -DecalWindow::DecalWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void DecalWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - decalWindow = new wiWindow(GUI, "Decal Window"); - decalWindow->SetSize(XMFLOAT2(400, 200)); - GUI->AddWidget(decalWindow); + wiWindow::Create("Decal Window"); + SetSize(XMFLOAT2(400, 200)); float x = 200; float y = 5; float hei = 18; float step = hei + 2; - placementCheckBox = new wiCheckBox("Decal Placement Enabled: "); - placementCheckBox->SetPos(XMFLOAT2(x, y += step)); - placementCheckBox->SetSize(XMFLOAT2(hei, hei)); - placementCheckBox->SetCheck(false); - placementCheckBox->SetTooltip("Enable decal placement. Use the left mouse button to place decals to the scene."); - decalWindow->AddWidget(placementCheckBox); + placementCheckBox.Create("Decal Placement Enabled: "); + placementCheckBox.SetPos(XMFLOAT2(x, y += step)); + placementCheckBox.SetSize(XMFLOAT2(hei, hei)); + placementCheckBox.SetCheck(false); + placementCheckBox.SetTooltip("Enable decal placement. Use the left mouse button to place decals to the scene."); + AddWidget(&placementCheckBox); y += step; - infoLabel = new wiLabel(""); - infoLabel->SetText("Selecting decals will select the according material. Set decal properties (texture, color, etc.) in the Material window."); - infoLabel->SetSize(XMFLOAT2(400 - 20, 100)); - infoLabel->SetPos(XMFLOAT2(10, y)); - infoLabel->SetColor(wiColor::Transparent()); - decalWindow->AddWidget(infoLabel); - y += infoLabel->GetScale().y - step + 5; + infoLabel.Create(""); + infoLabel.SetText("Selecting decals will select the according material. Set decal properties (texture, color, etc.) in the Material window."); + infoLabel.SetSize(XMFLOAT2(400 - 20, 100)); + infoLabel.SetPos(XMFLOAT2(10, y)); + infoLabel.SetColor(wiColor::Transparent()); + AddWidget(&infoLabel); + y += infoLabel.GetScale().y - step + 5; - decalNameField = new wiTextInputField("Decal Name"); - decalNameField->SetPos(XMFLOAT2(10, y+=step)); - decalNameField->SetSize(XMFLOAT2(300, hei)); - decalNameField->OnInputAccepted([&](wiEventArgs args) { + decalNameField.Create("Decal Name"); + decalNameField.SetPos(XMFLOAT2(10, y+=step)); + decalNameField.SetSize(XMFLOAT2(300, hei)); + decalNameField.OnInputAccepted([&](wiEventArgs args) { NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; } }); - decalWindow->AddWidget(decalNameField); + AddWidget(&decalNameField); - decalWindow->Translate(XMFLOAT3(30, 30, 0)); - decalWindow->SetVisible(false); + Translate(XMFLOAT3(30, 30, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -DecalWindow::~DecalWindow() -{ - decalWindow->RemoveWidgets(true); - GUI->RemoveWidget(decalWindow); - delete decalWindow; -} - void DecalWindow::SetEntity(Entity entity) { this->entity = entity; @@ -73,12 +62,12 @@ void DecalWindow::SetEntity(Entity entity) { const NameComponent& name = *scene.names.GetComponent(entity); - decalNameField->SetValue(name.name); - decalNameField->SetEnabled(true); + decalNameField.SetValue(name.name); + decalNameField.SetEnabled(true); } else { - decalNameField->SetValue("No decal selected"); - decalNameField->SetEnabled(false); + decalNameField.SetValue("No decal selected"); + decalNameField.SetEnabled(false); } } diff --git a/Editor/DecalWindow.h b/Editor/DecalWindow.h index 5afe80171..6b421b971 100644 --- a/Editor/DecalWindow.h +++ b/Editor/DecalWindow.h @@ -1,28 +1,18 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; +#include "WickedEngine.h" class EditorComponent; -class DecalWindow +class DecalWindow : public wiWindow { public: - DecalWindow(EditorComponent* editor); - ~DecalWindow(); - - wiGUI* GUI; + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiCheckBox* placementCheckBox; - wiLabel* infoLabel; - wiTextInputField* decalNameField; - - wiWindow* decalWindow; + wiCheckBox placementCheckBox; + wiLabel infoLabel; + wiTextInputField decalNameField; }; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 301759003..ee732daf8 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -66,15 +66,13 @@ void Editor::Initialize() wiRenderer::GetDevice()->SetVSyncEnabled(true); wiRenderer::SetOcclusionCullingEnabled(true); - renderComponent = std::make_unique(); - loader = std::make_unique(); - loader->Load(); + loader.Load(); - renderComponent->main = this; + renderComponent.main = this; - loader->addLoadingComponent(renderComponent.get(), this, 0.2f); + loader.addLoadingComponent(&renderComponent, this, 0.2f); - ActivatePath(loader.get(), 0.2f); + ActivatePath(&loader, 0.2f); } @@ -110,17 +108,8 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path) { switch (path) { - case EditorComponent::RENDERPATH_FORWARD: - renderPath = std::make_unique(); - break; - case EditorComponent::RENDERPATH_DEFERRED: - renderPath = std::make_unique(); - break; - case EditorComponent::RENDERPATH_TILEDFORWARD: - renderPath = std::make_unique(); - break; - case EditorComponent::RENDERPATH_TILEDDEFERRED: - renderPath = std::make_unique(); + case EditorComponent::RENDERPATH_DEFAULT: + renderPath = std::make_unique(); break; case EditorComponent::RENDERPATH_PATHTRACING: renderPath = std::make_unique(); @@ -143,27 +132,19 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path) renderPath->Load(); - materialWnd = std::make_unique(this); - postprocessWnd = std::make_unique(this); - weatherWnd = std::make_unique(this); - objectWnd = std::make_unique(this); - meshWnd = std::make_unique(this); - cameraWnd = std::make_unique(this); - rendererWnd = std::make_unique(this); - envProbeWnd = std::make_unique(this); - soundWnd = std::make_unique(this); - decalWnd = std::make_unique(this); - lightWnd = std::make_unique(this); - animWnd = std::make_unique(this); - emitterWnd = std::make_unique(this); - hairWnd = std::make_unique(this); - forceFieldWnd = std::make_unique(this); - paintToolWnd = std::make_unique(this); - springWnd = std::make_unique(this); - ikWnd = std::make_unique(this); - transformWnd = std::make_unique(this); - layerWnd = std::make_unique(this); - nameWnd = std::make_unique(this); + wiGUI& gui = GetGUI(); + + // Destroy and recreate renderer and postprocess windows: + + gui.RemoveWidget(&rendererWnd); + rendererWnd = RendererWindow(); + rendererWnd.Create(this); + gui.AddWidget(&rendererWnd); + + gui.RemoveWidget(&postprocessWnd); + postprocessWnd = PostprocessWindow(); + postprocessWnd.Create(this); + gui.AddWidget(&postprocessWnd); ResizeBuffers(); } @@ -245,14 +226,14 @@ void EditorComponent::ResizeLayout() float step = (option_size.y + 2) * -1; float hstep = (option_size.x + 2) * -1; - rendererWnd_Toggle->SetPos(XMFLOAT2(x += hstep, y)); - rendererWnd_Toggle->SetSize(option_size); + rendererWnd_Toggle.SetPos(XMFLOAT2(x += hstep, y)); + rendererWnd_Toggle.SetSize(option_size); - postprocessWnd_Toggle->SetPos(XMFLOAT2(x += hstep, y)); - postprocessWnd_Toggle->SetSize(option_size); + postprocessWnd_Toggle.SetPos(XMFLOAT2(x += hstep, y)); + postprocessWnd_Toggle.SetSize(option_size); - paintToolWnd_Toggle->SetPos(XMFLOAT2(x += hstep, y)); - paintToolWnd_Toggle->SetSize(option_size); + paintToolWnd_Toggle.SetPos(XMFLOAT2(x += hstep, y)); + paintToolWnd_Toggle.SetSize(option_size); ///////////////////////// @@ -261,112 +242,112 @@ void EditorComponent::ResizeLayout() x = screenW - option_size.x; y = screenH - option_size.y; - weatherWnd_Toggle->SetPos(XMFLOAT2(x, y)); - weatherWnd_Toggle->SetSize(option_size); + weatherWnd_Toggle.SetPos(XMFLOAT2(x, y)); + weatherWnd_Toggle.SetSize(option_size); - objectWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - objectWnd_Toggle->SetSize(option_size); + objectWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + objectWnd_Toggle.SetSize(option_size); - meshWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - meshWnd_Toggle->SetSize(option_size); + meshWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + meshWnd_Toggle.SetSize(option_size); - materialWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - materialWnd_Toggle->SetSize(option_size); + materialWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + materialWnd_Toggle.SetSize(option_size); - cameraWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - cameraWnd_Toggle->SetSize(option_size); + cameraWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + cameraWnd_Toggle.SetSize(option_size); - envProbeWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - envProbeWnd_Toggle->SetSize(option_size); + envProbeWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + envProbeWnd_Toggle.SetSize(option_size); - decalWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - decalWnd_Toggle->SetSize(option_size); + decalWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + decalWnd_Toggle.SetSize(option_size); - soundWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - soundWnd_Toggle->SetSize(option_size); + soundWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + soundWnd_Toggle.SetSize(option_size); - lightWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - lightWnd_Toggle->SetSize(option_size); + lightWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + lightWnd_Toggle.SetSize(option_size); - animWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - animWnd_Toggle->SetSize(option_size); + animWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + animWnd_Toggle.SetSize(option_size); - emitterWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - emitterWnd_Toggle->SetSize(option_size); + emitterWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + emitterWnd_Toggle.SetSize(option_size); - hairWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - hairWnd_Toggle->SetSize(option_size); + hairWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + hairWnd_Toggle.SetSize(option_size); - forceFieldWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - forceFieldWnd_Toggle->SetSize(option_size); + forceFieldWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + forceFieldWnd_Toggle.SetSize(option_size); - springWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - springWnd_Toggle->SetSize(option_size); + springWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + springWnd_Toggle.SetSize(option_size); - ikWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - ikWnd_Toggle->SetSize(option_size); + ikWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + ikWnd_Toggle.SetSize(option_size); - transformWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - transformWnd_Toggle->SetSize(option_size); + transformWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + transformWnd_Toggle.SetSize(option_size); - layerWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - layerWnd_Toggle->SetSize(option_size); + layerWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + layerWnd_Toggle.SetSize(option_size); - nameWnd_Toggle->SetPos(XMFLOAT2(x, y += step)); - nameWnd_Toggle->SetSize(option_size); + nameWnd_Toggle.SetPos(XMFLOAT2(x, y += step)); + nameWnd_Toggle.SetSize(option_size); //////////////////////////////////////////////////////////////////////////////////// - translatorCheckBox->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25, 0)); - translatorCheckBox->SetSize(XMFLOAT2(18, 18)); + translatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25, 0)); + translatorCheckBox.SetSize(XMFLOAT2(18, 18)); - isScalatorCheckBox->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25 - 40 * 2, 22)); - isScalatorCheckBox->SetSize(XMFLOAT2(18, 18)); + isScalatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25 - 40 * 2, 22)); + isScalatorCheckBox.SetSize(XMFLOAT2(18, 18)); - isRotatorCheckBox->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25 - 40 * 1, 22)); - isRotatorCheckBox->SetSize(XMFLOAT2(18, 18)); + isRotatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25 - 40 * 1, 22)); + isRotatorCheckBox.SetSize(XMFLOAT2(18, 18)); - isTranslatorCheckBox->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25, 22)); - isTranslatorCheckBox->SetSize(XMFLOAT2(18, 18)); + isTranslatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5 - 25, 22)); + isTranslatorCheckBox.SetSize(XMFLOAT2(18, 18)); - saveButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5, 0)); - saveButton->SetSize(XMFLOAT2(100, 40)); + saveButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 5, 0)); + saveButton.SetSize(XMFLOAT2(100, 40)); - modelButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4, 0)); - modelButton->SetSize(XMFLOAT2(100, 40)); + modelButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4, 0)); + modelButton.SetSize(XMFLOAT2(100, 40)); - scriptButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3, 0)); - scriptButton->SetSize(XMFLOAT2(100, 40)); + scriptButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3, 0)); + scriptButton.SetSize(XMFLOAT2(100, 40)); - shaderButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 2, 0)); - shaderButton->SetSize(XMFLOAT2(100, 40)); + shaderButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 2, 0)); + shaderButton.SetSize(XMFLOAT2(100, 40)); - clearButton->SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 1, 0)); - clearButton->SetSize(XMFLOAT2(100, 40)); + clearButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 1, 0)); + clearButton.SetSize(XMFLOAT2(100, 40)); - helpButton->SetPos(XMFLOAT2(screenW - 50 - 55, 0)); - helpButton->SetSize(XMFLOAT2(50, 40)); + helpButton.SetPos(XMFLOAT2(screenW - 50 - 55, 0)); + helpButton.SetSize(XMFLOAT2(50, 40)); - helpLabel->SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f)); - helpLabel->SetPos(XMFLOAT2(screenW / 2.0f - helpLabel->scale.x / 2.0f, screenH / 2.0f - helpLabel->scale.y / 2.0f)); + helpLabel.SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f)); + helpLabel.SetPos(XMFLOAT2(screenW / 2.0f - helpLabel.scale.x / 2.0f, screenH / 2.0f - helpLabel.scale.y / 2.0f)); - exitButton->SetPos(XMFLOAT2(screenW - 50, 0)); - exitButton->SetSize(XMFLOAT2(50, 40)); + exitButton.SetPos(XMFLOAT2(screenW - 50, 0)); + exitButton.SetSize(XMFLOAT2(50, 40)); - profilerEnabledCheckBox->SetSize(XMFLOAT2(20, 20)); - profilerEnabledCheckBox->SetPos(XMFLOAT2(screenW - 520, 45)); + profilerEnabledCheckBox.SetSize(XMFLOAT2(20, 20)); + profilerEnabledCheckBox.SetPos(XMFLOAT2(screenW - 520, 45)); - physicsEnabledCheckBox->SetSize(XMFLOAT2(20, 20)); - physicsEnabledCheckBox->SetPos(XMFLOAT2(screenW - 370, 45)); + physicsEnabledCheckBox.SetSize(XMFLOAT2(20, 20)); + physicsEnabledCheckBox.SetPos(XMFLOAT2(screenW - 370, 45)); - cinemaModeCheckBox->SetSize(XMFLOAT2(20, 20)); - cinemaModeCheckBox->SetPos(XMFLOAT2(screenW - 240, 45)); + cinemaModeCheckBox.SetSize(XMFLOAT2(20, 20)); + cinemaModeCheckBox.SetPos(XMFLOAT2(screenW - 240, 45)); - renderPathComboBox->SetSize(XMFLOAT2(100, 20)); - renderPathComboBox->SetPos(XMFLOAT2(screenW - 120, 45)); + renderPathComboBox.SetSize(XMFLOAT2(100, 20)); + renderPathComboBox.SetPos(XMFLOAT2(screenW - 120, 45)); - sceneGraphView->SetSize(XMFLOAT2(260, 300)); - sceneGraphView->SetPos(XMFLOAT2(0, screenH - sceneGraphView->scale_local.y)); + sceneGraphView.SetSize(XMFLOAT2(260, 300)); + sceneGraphView.SetPos(XMFLOAT2(0, screenH - sceneGraphView.scale_local.y)); } void EditorComponent::Load() { @@ -440,30 +421,31 @@ void EditorComponent::Load() wiJobSystem::Execute(ctx, [this](wiJobArgs args) { soundTex = wiResourceManager::Load("images/sound.dds"); }); // wait for ctx is at the end of this function! + translator.Create(); translator.enabled = false; - rendererWnd_Toggle = new wiButton("Renderer"); - rendererWnd_Toggle->SetTooltip("Renderer settings window"); - rendererWnd_Toggle->OnClick([=](wiEventArgs args) { - rendererWnd->rendererWindow->SetVisible(!rendererWnd->rendererWindow->IsVisible()); + rendererWnd_Toggle.Create("Renderer"); + rendererWnd_Toggle.SetTooltip("Renderer settings window"); + rendererWnd_Toggle.OnClick([&](wiEventArgs args) { + rendererWnd.SetVisible(!rendererWnd.IsVisible()); }); - GetGUI().AddWidget(rendererWnd_Toggle); + GetGUI().AddWidget(&rendererWnd_Toggle); - postprocessWnd_Toggle = new wiButton("PostProcess"); - postprocessWnd_Toggle->SetTooltip("Postprocess settings window"); - postprocessWnd_Toggle->OnClick([=](wiEventArgs args) { - postprocessWnd->ppWindow->SetVisible(!postprocessWnd->ppWindow->IsVisible()); + postprocessWnd_Toggle.Create("PostProcess"); + postprocessWnd_Toggle.SetTooltip("Postprocess settings window"); + postprocessWnd_Toggle.OnClick([&](wiEventArgs args) { + postprocessWnd.SetVisible(!postprocessWnd.IsVisible()); }); - GetGUI().AddWidget(postprocessWnd_Toggle); + GetGUI().AddWidget(&postprocessWnd_Toggle); - paintToolWnd_Toggle = new wiButton("Paint Tool"); - paintToolWnd_Toggle->SetTooltip("Paint tool window"); - paintToolWnd_Toggle->OnClick([=](wiEventArgs args) { - paintToolWnd->window->SetVisible(!paintToolWnd->window->IsVisible()); + paintToolWnd_Toggle.Create("Paint Tool"); + paintToolWnd_Toggle.SetTooltip("Paint tool window"); + paintToolWnd_Toggle.OnClick([&](wiEventArgs args) { + paintToolWnd.SetVisible(!paintToolWnd.IsVisible()); }); - GetGUI().AddWidget(paintToolWnd_Toggle); + GetGUI().AddWidget(&paintToolWnd_Toggle); /////////////////////// @@ -471,223 +453,223 @@ void EditorComponent::Load() wiColor option_color_focus = wiColor(255, 197, 193, 200); - weatherWnd_Toggle = new wiButton("Weather"); - weatherWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - weatherWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - weatherWnd_Toggle->SetTooltip("Weather settings window"); - weatherWnd_Toggle->OnClick([=](wiEventArgs args) { - weatherWnd->weatherWindow->SetVisible(!weatherWnd->weatherWindow->IsVisible()); + weatherWnd_Toggle.Create("Weather"); + weatherWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + weatherWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + weatherWnd_Toggle.SetTooltip("Weather settings window"); + weatherWnd_Toggle.OnClick([&](wiEventArgs args) { + weatherWnd.SetVisible(!weatherWnd.IsVisible()); }); - GetGUI().AddWidget(weatherWnd_Toggle); + GetGUI().AddWidget(&weatherWnd_Toggle); - objectWnd_Toggle = new wiButton("Object"); - objectWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - objectWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - objectWnd_Toggle->SetTooltip("Object settings window"); - objectWnd_Toggle->OnClick([=](wiEventArgs args) { - objectWnd->objectWindow->SetVisible(!objectWnd->objectWindow->IsVisible()); + objectWnd_Toggle.Create("Object"); + objectWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + objectWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + objectWnd_Toggle.SetTooltip("Object settings window"); + objectWnd_Toggle.OnClick([&](wiEventArgs args) { + objectWnd.SetVisible(!objectWnd.IsVisible()); }); - GetGUI().AddWidget(objectWnd_Toggle); + GetGUI().AddWidget(&objectWnd_Toggle); - meshWnd_Toggle = new wiButton("Mesh"); - meshWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - meshWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - meshWnd_Toggle->SetTooltip("Mesh settings window"); - meshWnd_Toggle->OnClick([=](wiEventArgs args) { - meshWnd->meshWindow->SetVisible(!meshWnd->meshWindow->IsVisible()); + meshWnd_Toggle.Create("Mesh"); + meshWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + meshWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + meshWnd_Toggle.SetTooltip("Mesh settings window"); + meshWnd_Toggle.OnClick([&](wiEventArgs args) { + meshWnd.SetVisible(!meshWnd.IsVisible()); }); - GetGUI().AddWidget(meshWnd_Toggle); + GetGUI().AddWidget(&meshWnd_Toggle); - materialWnd_Toggle = new wiButton("Material"); - materialWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - materialWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - materialWnd_Toggle->SetTooltip("Material settings window"); - materialWnd_Toggle->OnClick([=](wiEventArgs args) { - materialWnd->materialWindow->SetVisible(!materialWnd->materialWindow->IsVisible()); + materialWnd_Toggle.Create("Material"); + materialWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + materialWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + materialWnd_Toggle.SetTooltip("Material settings window"); + materialWnd_Toggle.OnClick([&](wiEventArgs args) { + materialWnd.SetVisible(!materialWnd.IsVisible()); }); - GetGUI().AddWidget(materialWnd_Toggle); + GetGUI().AddWidget(&materialWnd_Toggle); - cameraWnd_Toggle = new wiButton("Camera"); - cameraWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - cameraWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - cameraWnd_Toggle->SetTooltip("Camera settings window"); - cameraWnd_Toggle->OnClick([=](wiEventArgs args) { - cameraWnd->cameraWindow->SetVisible(!cameraWnd->cameraWindow->IsVisible()); + cameraWnd_Toggle.Create("Camera"); + cameraWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + cameraWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + cameraWnd_Toggle.SetTooltip("Camera settings window"); + cameraWnd_Toggle.OnClick([&](wiEventArgs args) { + cameraWnd.SetVisible(!cameraWnd.IsVisible()); }); - GetGUI().AddWidget(cameraWnd_Toggle); + GetGUI().AddWidget(&cameraWnd_Toggle); - envProbeWnd_Toggle = new wiButton("EnvProbe"); - envProbeWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - envProbeWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - envProbeWnd_Toggle->SetTooltip("Environment probe settings window"); - envProbeWnd_Toggle->OnClick([=](wiEventArgs args) { - envProbeWnd->envProbeWindow->SetVisible(!envProbeWnd->envProbeWindow->IsVisible()); + envProbeWnd_Toggle.Create("EnvProbe"); + envProbeWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + envProbeWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + envProbeWnd_Toggle.SetTooltip("Environment probe settings window"); + envProbeWnd_Toggle.OnClick([&](wiEventArgs args) { + envProbeWnd.SetVisible(!envProbeWnd.IsVisible()); }); - GetGUI().AddWidget(envProbeWnd_Toggle); + GetGUI().AddWidget(&envProbeWnd_Toggle); - decalWnd_Toggle = new wiButton("Decal"); - decalWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - decalWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - decalWnd_Toggle->SetTooltip("Decal settings window"); - decalWnd_Toggle->OnClick([=](wiEventArgs args) { - decalWnd->decalWindow->SetVisible(!decalWnd->decalWindow->IsVisible()); + decalWnd_Toggle.Create("Decal"); + decalWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + decalWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + decalWnd_Toggle.SetTooltip("Decal settings window"); + decalWnd_Toggle.OnClick([&](wiEventArgs args) { + decalWnd.SetVisible(!decalWnd.IsVisible()); }); - GetGUI().AddWidget(decalWnd_Toggle); + GetGUI().AddWidget(&decalWnd_Toggle); - soundWnd_Toggle = new wiButton("Sound"); - soundWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - soundWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - soundWnd_Toggle->SetTooltip("Sound settings window"); - soundWnd_Toggle->OnClick([=](wiEventArgs args) { - soundWnd->soundWindow->SetVisible(!soundWnd->soundWindow->IsVisible()); + soundWnd_Toggle.Create("Sound"); + soundWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + soundWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + soundWnd_Toggle.SetTooltip("Sound settings window"); + soundWnd_Toggle.OnClick([&](wiEventArgs args) { + soundWnd.SetVisible(!soundWnd.IsVisible()); }); - GetGUI().AddWidget(soundWnd_Toggle); + GetGUI().AddWidget(&soundWnd_Toggle); - lightWnd_Toggle = new wiButton("Light"); - lightWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - lightWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - lightWnd_Toggle->SetTooltip("Light settings window"); - lightWnd_Toggle->OnClick([=](wiEventArgs args) { - lightWnd->lightWindow->SetVisible(!lightWnd->lightWindow->IsVisible()); + lightWnd_Toggle.Create("Light"); + lightWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + lightWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + lightWnd_Toggle.SetTooltip("Light settings window"); + lightWnd_Toggle.OnClick([&](wiEventArgs args) { + lightWnd.SetVisible(!lightWnd.IsVisible()); }); - GetGUI().AddWidget(lightWnd_Toggle); + GetGUI().AddWidget(&lightWnd_Toggle); - animWnd_Toggle = new wiButton("Animation"); - animWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - animWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - animWnd_Toggle->SetTooltip("Animation inspector window"); - animWnd_Toggle->OnClick([=](wiEventArgs args) { - animWnd->animWindow->SetVisible(!animWnd->animWindow->IsVisible()); + animWnd_Toggle.Create("Animation"); + animWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + animWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + animWnd_Toggle.SetTooltip("Animation inspector window"); + animWnd_Toggle.OnClick([&](wiEventArgs args) { + animWnd.SetVisible(!animWnd.IsVisible()); }); - GetGUI().AddWidget(animWnd_Toggle); + GetGUI().AddWidget(&animWnd_Toggle); - emitterWnd_Toggle = new wiButton("Emitter"); - emitterWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - emitterWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - emitterWnd_Toggle->SetTooltip("Emitter Particle System properties"); - emitterWnd_Toggle->OnClick([=](wiEventArgs args) { - emitterWnd->emitterWindow->SetVisible(!emitterWnd->emitterWindow->IsVisible()); + emitterWnd_Toggle.Create("Emitter"); + emitterWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + emitterWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + emitterWnd_Toggle.SetTooltip("Emitter Particle System properties"); + emitterWnd_Toggle.OnClick([&](wiEventArgs args) { + emitterWnd.SetVisible(!emitterWnd.IsVisible()); }); - GetGUI().AddWidget(emitterWnd_Toggle); + GetGUI().AddWidget(&emitterWnd_Toggle); - hairWnd_Toggle = new wiButton("HairParticle"); - hairWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - hairWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - hairWnd_Toggle->SetTooltip("Hair Particle System properties"); - hairWnd_Toggle->OnClick([=](wiEventArgs args) { - hairWnd->hairWindow->SetVisible(!hairWnd->hairWindow->IsVisible()); + hairWnd_Toggle.Create("HairParticle"); + hairWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + hairWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + hairWnd_Toggle.SetTooltip("Hair Particle System properties"); + hairWnd_Toggle.OnClick([&](wiEventArgs args) { + hairWnd.SetVisible(!hairWnd.IsVisible()); }); - GetGUI().AddWidget(hairWnd_Toggle); + GetGUI().AddWidget(&hairWnd_Toggle); - forceFieldWnd_Toggle = new wiButton("ForceField"); - forceFieldWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - forceFieldWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - forceFieldWnd_Toggle->SetTooltip("Force Field properties"); - forceFieldWnd_Toggle->OnClick([=](wiEventArgs args) { - forceFieldWnd->forceFieldWindow->SetVisible(!forceFieldWnd->forceFieldWindow->IsVisible()); + forceFieldWnd_Toggle.Create("ForceField"); + forceFieldWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + forceFieldWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + forceFieldWnd_Toggle.SetTooltip("Force Field properties"); + forceFieldWnd_Toggle.OnClick([&](wiEventArgs args) { + forceFieldWnd.SetVisible(!forceFieldWnd.IsVisible()); }); - GetGUI().AddWidget(forceFieldWnd_Toggle); + GetGUI().AddWidget(&forceFieldWnd_Toggle); - springWnd_Toggle = new wiButton("Spring"); - springWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - springWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - springWnd_Toggle->SetTooltip("Spring properties"); - springWnd_Toggle->OnClick([=](wiEventArgs args) { - springWnd->window->SetVisible(!springWnd->window->IsVisible()); + springWnd_Toggle.Create("Spring"); + springWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + springWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + springWnd_Toggle.SetTooltip("Spring properties"); + springWnd_Toggle.OnClick([&](wiEventArgs args) { + springWnd.SetVisible(!springWnd.IsVisible()); }); - GetGUI().AddWidget(springWnd_Toggle); + GetGUI().AddWidget(&springWnd_Toggle); - ikWnd_Toggle = new wiButton("IK"); - ikWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - ikWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - ikWnd_Toggle->SetTooltip("Inverse Kinematics properties"); - ikWnd_Toggle->OnClick([=](wiEventArgs args) { - ikWnd->window->SetVisible(!ikWnd->window->IsVisible()); + ikWnd_Toggle.Create("IK"); + ikWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + ikWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + ikWnd_Toggle.SetTooltip("Inverse Kinematics properties"); + ikWnd_Toggle.OnClick([&](wiEventArgs args) { + ikWnd.SetVisible(!ikWnd.IsVisible()); }); - GetGUI().AddWidget(ikWnd_Toggle); + GetGUI().AddWidget(&ikWnd_Toggle); - transformWnd_Toggle = new wiButton("Transform"); - transformWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - transformWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - transformWnd_Toggle->SetTooltip("Transform properties"); - transformWnd_Toggle->OnClick([=](wiEventArgs args) { - transformWnd->window->SetVisible(!transformWnd->window->IsVisible()); + transformWnd_Toggle.Create("Transform"); + transformWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + transformWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + transformWnd_Toggle.SetTooltip("Transform properties"); + transformWnd_Toggle.OnClick([&](wiEventArgs args) { + transformWnd.SetVisible(!transformWnd.IsVisible()); }); - GetGUI().AddWidget(transformWnd_Toggle); + GetGUI().AddWidget(&transformWnd_Toggle); - layerWnd_Toggle = new wiButton("Layer"); - layerWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - layerWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - layerWnd_Toggle->SetTooltip("Layer Component"); - layerWnd_Toggle->OnClick([=](wiEventArgs args) { - layerWnd->window->SetVisible(!layerWnd->window->IsVisible()); + layerWnd_Toggle.Create("Layer"); + layerWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + layerWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + layerWnd_Toggle.SetTooltip("Layer Component"); + layerWnd_Toggle.OnClick([&](wiEventArgs args) { + layerWnd.SetVisible(!layerWnd.IsVisible()); }); - GetGUI().AddWidget(layerWnd_Toggle); + GetGUI().AddWidget(&layerWnd_Toggle); - nameWnd_Toggle = new wiButton("Name"); - nameWnd_Toggle->SetColor(option_color_idle, wiWidget::IDLE); - nameWnd_Toggle->SetColor(option_color_focus, wiWidget::FOCUS); - nameWnd_Toggle->SetTooltip("Name Component"); - nameWnd_Toggle->OnClick([=](wiEventArgs args) { - nameWnd->window->SetVisible(!nameWnd->window->IsVisible()); + nameWnd_Toggle.Create("Name"); + nameWnd_Toggle.SetColor(option_color_idle, wiWidget::IDLE); + nameWnd_Toggle.SetColor(option_color_focus, wiWidget::FOCUS); + nameWnd_Toggle.SetTooltip("Name Component"); + nameWnd_Toggle.OnClick([&](wiEventArgs args) { + nameWnd.SetVisible(!nameWnd.IsVisible()); }); - GetGUI().AddWidget(nameWnd_Toggle); + GetGUI().AddWidget(&nameWnd_Toggle); //////////////////////////////////////////////////////////////////////////////////// - translatorCheckBox = new wiCheckBox("Translator: "); - translatorCheckBox->SetTooltip("Enable the translator tool"); - translatorCheckBox->OnClick([&](wiEventArgs args) { + translatorCheckBox.Create("Translator: "); + translatorCheckBox.SetTooltip("Enable the translator tool"); + translatorCheckBox.OnClick([&](wiEventArgs args) { translator.enabled = args.bValue; }); - GetGUI().AddWidget(translatorCheckBox); + GetGUI().AddWidget(&translatorCheckBox); - isScalatorCheckBox = new wiCheckBox("S: "); - isRotatorCheckBox = new wiCheckBox("R: "); - isTranslatorCheckBox = new wiCheckBox("T: "); + isScalatorCheckBox.Create("S: "); + isRotatorCheckBox.Create("R: "); + isTranslatorCheckBox.Create("T: "); { - isScalatorCheckBox->SetTooltip("Scale"); - isScalatorCheckBox->OnClick([&](wiEventArgs args) { + isScalatorCheckBox.SetTooltip("Scale"); + isScalatorCheckBox.OnClick([&](wiEventArgs args) { translator.isScalator = args.bValue; translator.isTranslator = false; translator.isRotator = false; - isTranslatorCheckBox->SetCheck(false); - isRotatorCheckBox->SetCheck(false); + isTranslatorCheckBox.SetCheck(false); + isRotatorCheckBox.SetCheck(false); }); - isScalatorCheckBox->SetCheck(translator.isScalator); - GetGUI().AddWidget(isScalatorCheckBox); + isScalatorCheckBox.SetCheck(translator.isScalator); + GetGUI().AddWidget(&isScalatorCheckBox); - isRotatorCheckBox->SetTooltip("Rotate"); - isRotatorCheckBox->OnClick([&](wiEventArgs args) { + isRotatorCheckBox.SetTooltip("Rotate"); + isRotatorCheckBox.OnClick([&](wiEventArgs args) { translator.isRotator = args.bValue; translator.isScalator = false; translator.isTranslator = false; - isScalatorCheckBox->SetCheck(false); - isTranslatorCheckBox->SetCheck(false); + isScalatorCheckBox.SetCheck(false); + isTranslatorCheckBox.SetCheck(false); }); - isRotatorCheckBox->SetCheck(translator.isRotator); - GetGUI().AddWidget(isRotatorCheckBox); + isRotatorCheckBox.SetCheck(translator.isRotator); + GetGUI().AddWidget(&isRotatorCheckBox); - isTranslatorCheckBox->SetTooltip("Translate"); - isTranslatorCheckBox->OnClick([&](wiEventArgs args) { + isTranslatorCheckBox.SetTooltip("Translate"); + isTranslatorCheckBox.OnClick([&](wiEventArgs args) { translator.isTranslator = args.bValue; translator.isScalator = false; translator.isRotator = false; - isScalatorCheckBox->SetCheck(false); - isRotatorCheckBox->SetCheck(false); + isScalatorCheckBox.SetCheck(false); + isRotatorCheckBox.SetCheck(false); }); - isTranslatorCheckBox->SetCheck(translator.isTranslator); - GetGUI().AddWidget(isTranslatorCheckBox); + isTranslatorCheckBox.SetCheck(translator.isTranslator); + GetGUI().AddWidget(&isTranslatorCheckBox); } - saveButton = new wiButton("Save"); - saveButton->SetTooltip("Save the current scene"); - saveButton->SetColor(wiColor(0, 198, 101, 180), wiWidget::WIDGETSTATE::IDLE); - saveButton->SetColor(wiColor(0, 255, 140, 255), wiWidget::WIDGETSTATE::FOCUS); - saveButton->OnClick([=](wiEventArgs args) { + saveButton.Create("Save"); + saveButton.SetTooltip("Save the current scene"); + saveButton.SetColor(wiColor(0, 198, 101, 180), wiWidget::WIDGETSTATE::IDLE); + saveButton.SetColor(wiColor(0, 255, 140, 255), wiWidget::WIDGETSTATE::FOCUS); + saveButton.OnClick([&](wiEventArgs args) { wiHelper::FileDialogParams params; params.type = wiHelper::FileDialogParams::SAVE; @@ -716,14 +698,14 @@ void EditorComponent::Load() }); }); }); - GetGUI().AddWidget(saveButton); + GetGUI().AddWidget(&saveButton); - modelButton = new wiButton("Load Model"); - modelButton->SetTooltip("Load a scene / import model into the editor..."); - modelButton->SetColor(wiColor(0, 89, 255, 180), wiWidget::WIDGETSTATE::IDLE); - modelButton->SetColor(wiColor(112, 155, 255, 255), wiWidget::WIDGETSTATE::FOCUS); - modelButton->OnClick([=](wiEventArgs args) { + modelButton.Create("Load Model"); + modelButton.SetTooltip("Load a scene / import model into the editor..."); + modelButton.SetColor(wiColor(0, 89, 255, 180), wiWidget::WIDGETSTATE::IDLE); + modelButton.SetColor(wiColor(112, 155, 255, 255), wiWidget::WIDGETSTATE::FOCUS); + modelButton.OnClick([&](wiEventArgs args) { wiHelper::FileDialogParams params; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Model formats (.wiscene, .obj, .gltf, .glb)"; @@ -733,7 +715,7 @@ void EditorComponent::Load() params.extensions.push_back("glb"); wiHelper::FileDialog(params, [&](std::string fileName) { wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - main->loader->addLoadingFunction([=](wiJobArgs args) { + main->loader.addLoadingFunction([=](wiJobArgs args) { string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); if (!extension.compare("WISCENE")) // engine-serialized @@ -759,23 +741,24 @@ void EditorComponent::Load() wiScene::GetScene().Merge(scene); } }); - main->loader->onFinished([=] { + main->loader.onFinished([=] { main->ActivatePath(this, 0.2f, wiColor::Black()); - weatherWnd->Update(); + weatherWnd.Update(); + RefreshSceneGraphView(); }); - main->ActivatePath(main->loader.get(), 0.2f, wiColor::Black()); + main->ActivatePath(&main->loader, 0.2f, wiColor::Black()); ResetHistory(); }); }); }); - GetGUI().AddWidget(modelButton); + GetGUI().AddWidget(&modelButton); - scriptButton = new wiButton("Load Script"); - scriptButton->SetTooltip("Load a Lua script..."); - scriptButton->SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); - scriptButton->SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); - scriptButton->OnClick([=](wiEventArgs args) { + scriptButton.Create("Load Script"); + scriptButton.SetTooltip("Load a Lua script..."); + scriptButton.SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); + scriptButton.SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); + scriptButton.OnClick([&](wiEventArgs args) { wiHelper::FileDialogParams params; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Lua script"; @@ -786,58 +769,60 @@ void EditorComponent::Load() }); }); }); - GetGUI().AddWidget(scriptButton); + GetGUI().AddWidget(&scriptButton); - shaderButton = new wiButton("Reload Shaders"); - shaderButton->SetTooltip("Reload shaders from the default directory..."); - shaderButton->SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); - shaderButton->SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); - shaderButton->font.params.size -= 2; - shaderButton->OnClick([=](wiEventArgs args) { + shaderButton.Create("Reload Shaders"); + shaderButton.SetTooltip("Reload shaders from the default directory..."); + shaderButton.SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); + shaderButton.SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); + shaderButton.font.params.size -= 2; + shaderButton.OnClick([](wiEventArgs args) { wiRenderer::ReloadShaders(); }); - GetGUI().AddWidget(shaderButton); + GetGUI().AddWidget(&shaderButton); - clearButton = new wiButton("Clear World"); - clearButton->SetTooltip("Delete every model from the scene"); - clearButton->SetColor(wiColor(255, 205, 43, 180), wiWidget::WIDGETSTATE::IDLE); - clearButton->SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); - clearButton->OnClick([&](wiEventArgs args) { + clearButton.Create("Clear World"); + clearButton.SetTooltip("Delete every model from the scene"); + clearButton.SetColor(wiColor(255, 173, 43, 180), wiWidget::WIDGETSTATE::IDLE); + clearButton.SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); + clearButton.OnClick([&](wiEventArgs args) { translator.selected.clear(); wiRenderer::ClearWorld(); - objectWnd->SetEntity(INVALID_ENTITY); - meshWnd->SetEntity(INVALID_ENTITY); - lightWnd->SetEntity(INVALID_ENTITY); - soundWnd->SetEntity(INVALID_ENTITY); - decalWnd->SetEntity(INVALID_ENTITY); - envProbeWnd->SetEntity(INVALID_ENTITY); - materialWnd->SetEntity(INVALID_ENTITY); - emitterWnd->SetEntity(INVALID_ENTITY); - hairWnd->SetEntity(INVALID_ENTITY); - forceFieldWnd->SetEntity(INVALID_ENTITY); - cameraWnd->SetEntity(INVALID_ENTITY); - paintToolWnd->SetEntity(INVALID_ENTITY); - springWnd->SetEntity(INVALID_ENTITY); - ikWnd->SetEntity(INVALID_ENTITY); - transformWnd->SetEntity(INVALID_ENTITY); - layerWnd->SetEntity(INVALID_ENTITY); - nameWnd->SetEntity(INVALID_ENTITY); + objectWnd.SetEntity(INVALID_ENTITY); + meshWnd.SetEntity(INVALID_ENTITY); + lightWnd.SetEntity(INVALID_ENTITY); + soundWnd.SetEntity(INVALID_ENTITY); + decalWnd.SetEntity(INVALID_ENTITY); + envProbeWnd.SetEntity(INVALID_ENTITY); + materialWnd.SetEntity(INVALID_ENTITY); + emitterWnd.SetEntity(INVALID_ENTITY); + hairWnd.SetEntity(INVALID_ENTITY); + forceFieldWnd.SetEntity(INVALID_ENTITY); + cameraWnd.SetEntity(INVALID_ENTITY); + paintToolWnd.SetEntity(INVALID_ENTITY); + springWnd.SetEntity(INVALID_ENTITY); + ikWnd.SetEntity(INVALID_ENTITY); + transformWnd.SetEntity(INVALID_ENTITY); + layerWnd.SetEntity(INVALID_ENTITY); + nameWnd.SetEntity(INVALID_ENTITY); + + RefreshSceneGraphView(); }); - GetGUI().AddWidget(clearButton); + GetGUI().AddWidget(&clearButton); - helpButton = new wiButton("?"); - helpButton->SetTooltip("Help"); - helpButton->SetColor(wiColor(34, 158, 214, 180), wiWidget::WIDGETSTATE::IDLE); - helpButton->SetColor(wiColor(113, 183, 214, 255), wiWidget::WIDGETSTATE::FOCUS); - helpButton->OnClick([=](wiEventArgs args) { - helpLabel->SetVisible(!helpLabel->IsVisible()); + helpButton.Create("?"); + helpButton.SetTooltip("Help"); + helpButton.SetColor(wiColor(34, 158, 214, 180), wiWidget::WIDGETSTATE::IDLE); + helpButton.SetColor(wiColor(113, 183, 214, 255), wiWidget::WIDGETSTATE::FOCUS); + helpButton.OnClick([&](wiEventArgs args) { + helpLabel.SetVisible(!helpLabel.IsVisible()); }); - GetGUI().AddWidget(helpButton); + GetGUI().AddWidget(&helpButton); { stringstream ss(""); @@ -868,41 +853,41 @@ void EditorComponent::Load() ss << endl << "Devblog: https://wickedengine.net/" << endl; ss << "Discord: https://discord.gg/CFjRYmE" << endl; - helpLabel = new wiLabel("HelpLabel"); - helpLabel->SetText(ss.str()); - helpLabel->SetVisible(false); - GetGUI().AddWidget(helpLabel); + helpLabel.Create("HelpLabel"); + helpLabel.SetText(ss.str()); + helpLabel.SetVisible(false); + GetGUI().AddWidget(&helpLabel); } - exitButton = new wiButton("X"); - exitButton->SetTooltip("Exit"); - exitButton->SetColor(wiColor(190, 0, 0, 180), wiWidget::WIDGETSTATE::IDLE); - exitButton->SetColor(wiColor(255, 0, 0, 255), wiWidget::WIDGETSTATE::FOCUS); - exitButton->OnClick([this](wiEventArgs args) { + exitButton.Create("X"); + exitButton.SetTooltip("Exit"); + exitButton.SetColor(wiColor(190, 0, 0, 180), wiWidget::WIDGETSTATE::IDLE); + exitButton.SetColor(wiColor(255, 0, 0, 255), wiWidget::WIDGETSTATE::FOCUS); + exitButton.OnClick([this](wiEventArgs args) { wiPlatform::Exit(); }); - GetGUI().AddWidget(exitButton); + GetGUI().AddWidget(&exitButton); - profilerEnabledCheckBox = new wiCheckBox("Profiler Enabled: "); - profilerEnabledCheckBox->SetTooltip("Toggle Profiler On/Off"); - profilerEnabledCheckBox->OnClick([&](wiEventArgs args) { + profilerEnabledCheckBox.Create("Profiler Enabled: "); + profilerEnabledCheckBox.SetTooltip("Toggle Profiler On/Off"); + profilerEnabledCheckBox.OnClick([&](wiEventArgs args) { wiProfiler::SetEnabled(args.bValue); }); - profilerEnabledCheckBox->SetCheck(wiProfiler::IsEnabled()); - GetGUI().AddWidget(profilerEnabledCheckBox); + profilerEnabledCheckBox.SetCheck(wiProfiler::IsEnabled()); + GetGUI().AddWidget(&profilerEnabledCheckBox); - physicsEnabledCheckBox = new wiCheckBox("Physics Enabled: "); - physicsEnabledCheckBox->SetTooltip("Toggle Physics Engine On/Off"); - physicsEnabledCheckBox->OnClick([&](wiEventArgs args) { + physicsEnabledCheckBox.Create("Physics Enabled: "); + physicsEnabledCheckBox.SetTooltip("Toggle Physics Engine On/Off"); + physicsEnabledCheckBox.OnClick([&](wiEventArgs args) { wiPhysicsEngine::SetEnabled(args.bValue); }); - physicsEnabledCheckBox->SetCheck(wiPhysicsEngine::IsEnabled()); - GetGUI().AddWidget(physicsEnabledCheckBox); + physicsEnabledCheckBox.SetCheck(wiPhysicsEngine::IsEnabled()); + GetGUI().AddWidget(&physicsEnabledCheckBox); - cinemaModeCheckBox = new wiCheckBox("Cinema Mode: "); - cinemaModeCheckBox->SetTooltip("Toggle Cinema Mode (All HUD disabled). Press ESC to exit."); - cinemaModeCheckBox->OnClick([&](wiEventArgs args) { + cinemaModeCheckBox.Create("Cinema Mode: "); + cinemaModeCheckBox.SetTooltip("Toggle Cinema Mode (All HUD disabled). Press ESC to exit."); + cinemaModeCheckBox.OnClick([&](wiEventArgs args) { if (renderPath != nullptr) { renderPath->GetGUI().SetVisible(false); @@ -911,17 +896,17 @@ void EditorComponent::Load() wiProfiler::SetEnabled(false); main->infoDisplay.active = false; }); - GetGUI().AddWidget(cinemaModeCheckBox); + GetGUI().AddWidget(&cinemaModeCheckBox); - sceneGraphView = new wiTreeList("Scene graph view"); - sceneGraphView->OnSelect([this](wiEventArgs args) { + sceneGraphView.Create("Scene graph view"); + sceneGraphView.OnSelect([this](wiEventArgs args) { translator.selected.clear(); - for (int i = 0; i < sceneGraphView->GetItemCount(); ++i) + for (int i = 0; i < sceneGraphView.GetItemCount(); ++i) { - const wiTreeList::Item& item = sceneGraphView->GetItem(i); + const wiTreeList::Item& item = sceneGraphView.GetItem(i); if (item.selected) { wiScene::PickResult pick; @@ -931,44 +916,67 @@ void EditorComponent::Load() } }); - GetGUI().AddWidget(sceneGraphView); + sceneGraphView.SetColor(wiColor(100, 100, 100, 100), wiWidget::IDLE); + GetGUI().AddWidget(&sceneGraphView); - renderPathComboBox = new wiComboBox("Render Path: "); - renderPathComboBox->AddItem("Forward"); - renderPathComboBox->AddItem("Deferred"); - renderPathComboBox->AddItem("Tiled Forward"); - renderPathComboBox->AddItem("Tiled Deferred"); - renderPathComboBox->AddItem("Path Tracing"); - renderPathComboBox->OnSelect([&](wiEventArgs args) { - switch (args.iValue) - { - case 0: - ChangeRenderPath(RENDERPATH_FORWARD); - break; - case 1: - ChangeRenderPath(RENDERPATH_DEFERRED); - break; - case 2: - ChangeRenderPath(RENDERPATH_TILEDFORWARD); - break; - case 3: - ChangeRenderPath(RENDERPATH_TILEDDEFERRED); - break; - case 4: - ChangeRenderPath(RENDERPATH_PATHTRACING); - break; - default: - break; - } + renderPathComboBox.Create("Render Path: "); + renderPathComboBox.AddItem("Default"); + renderPathComboBox.AddItem("Path Tracing"); + renderPathComboBox.OnSelect([&](wiEventArgs args) { + ChangeRenderPath((RENDERPATH)args.iValue); }); - renderPathComboBox->SetSelected(2); - renderPathComboBox->SetEnabled(true); - renderPathComboBox->SetTooltip("Choose a render path..."); - GetGUI().AddWidget(renderPathComboBox); + renderPathComboBox.SetSelected(RENDERPATH_DEFAULT); + renderPathComboBox.SetEnabled(true); + renderPathComboBox.SetTooltip("Choose a render path..."); + GetGUI().AddWidget(&renderPathComboBox); - cameraWnd->ResetCam(); + // Renderer and Postprocess windows are created in ChangeRenderPath(), because they deal with + // RenderPath related information as well, so it's easier to reset them when changing + + materialWnd.Create(this); + weatherWnd.Create(this); + objectWnd.Create(this); + meshWnd.Create(this); + cameraWnd.Create(this); + envProbeWnd.Create(this); + soundWnd.Create(this); + decalWnd.Create(this); + lightWnd.Create(this); + animWnd.Create(this); + emitterWnd.Create(this); + hairWnd.Create(this); + forceFieldWnd.Create(this); + paintToolWnd.Create(this); + springWnd.Create(this); + ikWnd.Create(this); + transformWnd.Create(this); + layerWnd.Create(this); + nameWnd.Create(this); + + wiGUI& gui = GetGUI(); + gui.AddWidget(&materialWnd); + gui.AddWidget(&weatherWnd); + gui.AddWidget(&objectWnd); + gui.AddWidget(&meshWnd); + gui.AddWidget(&cameraWnd); + gui.AddWidget(&envProbeWnd); + gui.AddWidget(&soundWnd); + gui.AddWidget(&decalWnd); + gui.AddWidget(&lightWnd); + gui.AddWidget(&animWnd); + gui.AddWidget(&emitterWnd); + gui.AddWidget(&hairWnd); + gui.AddWidget(&forceFieldWnd); + gui.AddWidget(&paintToolWnd); + gui.AddWidget(&springWnd); + gui.AddWidget(&ikWnd); + gui.AddWidget(&transformWnd); + gui.AddWidget(&layerWnd); + gui.AddWidget(&nameWnd); + + cameraWnd.ResetCam(); wiJobSystem::Wait(ctx); @@ -985,33 +993,6 @@ void EditorComponent::FixedUpdate() renderPath->FixedUpdate(); } -void EditorComponent::PushToSceneGraphView(wiECS::Entity entity, int level) -{ - if (scenegraphview_added_items.count(entity) != 0) - { - return; - } - const Scene& scene = wiScene::GetScene(); - - wiTreeList::Item item; - item.level = level; - item.userdata = entity; - item.selected = IsSelected(entity); - item.open = scenegraphview_opened_items.count(entity) != 0; - const NameComponent* name = scene.names.GetComponent(entity); - item.name = name == nullptr ? std::to_string(entity) : name->name; - sceneGraphView->AddItem(item); - - scenegraphview_added_items.insert(entity); - - for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i) - { - if (scene.hierarchy[i].parentID == entity) - { - PushToSceneGraphView(scene.hierarchy.GetEntity(i), level + 1); - } - } -} void EditorComponent::Update(float dt) { wiProfiler::range_id profrange = wiProfiler::BeginRangeCPU("Editor Update"); @@ -1019,82 +1000,12 @@ void EditorComponent::Update(float dt) Scene& scene = wiScene::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); - animWnd->Update(); - weatherWnd->Update(); - paintToolWnd->Update(dt); + animWnd.Update(); + weatherWnd.Update(); + paintToolWnd.Update(dt); selectionOutlineTimer += dt; - // Update scene graph view: - if(sceneGraphView != nullptr) - { - for (int i = 0; i < sceneGraphView->GetItemCount(); ++i) - { - const wiTreeList::Item& item = sceneGraphView->GetItem(i); - if (item.open) - { - scenegraphview_opened_items.insert((Entity)item.userdata); - } - } - - sceneGraphView->ClearItems(); - - // Add hierarchy: - for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i) - { - PushToSceneGraphView(scene.hierarchy[i].parentID, 0); - } - - // Any transform left that is not part of a hierarchy: - for (size_t i = 0; i < scene.transforms.GetCount(); ++i) - { - PushToSceneGraphView(scene.transforms.GetEntity(i), 0); - } - - // Add materials: - for (size_t i = 0; i < scene.materials.GetCount(); ++i) - { - Entity entity = scene.materials.GetEntity(i); - if (scenegraphview_added_items.count(entity) != 0) - { - continue; - } - - wiTreeList::Item item; - item.userdata = entity; - item.selected = IsSelected(entity); - item.open = scenegraphview_opened_items.count(entity) != 0; - const NameComponent* name = scene.names.GetComponent(entity); - item.name = name == nullptr ? std::to_string(entity) : name->name; - sceneGraphView->AddItem(item); - - scenegraphview_added_items.insert(entity); - } - - // Add meshes: - for (size_t i = 0; i < scene.meshes.GetCount(); ++i) - { - Entity entity = scene.meshes.GetEntity(i); - if (scenegraphview_added_items.count(entity) != 0) - { - continue; - } - - wiTreeList::Item item; - item.userdata = entity; - item.selected = IsSelected(entity); - item.open = scenegraphview_opened_items.count(entity) != 0; - const NameComponent* name = scene.names.GetComponent(entity); - item.name = name == nullptr ? std::to_string(entity) : name->name; - sceneGraphView->AddItem(item); - - scenegraphview_added_items.insert(entity); - } - - scenegraphview_added_items.clear(); - scenegraphview_opened_items.clear(); - } - // Exit cinema mode: if (wiInput::Down(wiInput::KEYBOARD_BUTTON_ESCAPE)) { @@ -1105,7 +1016,7 @@ void EditorComponent::Update(float dt) GetGUI().SetVisible(true); main->infoDisplay.active = true; - cinemaModeCheckBox->SetCheck(false); + cinemaModeCheckBox.SetCheck(false); } // Camera control: @@ -1168,16 +1079,16 @@ void EditorComponent::Update(float dt) xDif += rightStick.x * jostickrotspeed; yDif += rightStick.y * jostickrotspeed; - xDif *= cameraWnd->rotationspeedSlider->GetValue(); - yDif *= cameraWnd->rotationspeedSlider->GetValue(); + xDif *= cameraWnd.rotationspeedSlider.GetValue(); + yDif *= cameraWnd.rotationspeedSlider.GetValue(); - if (cameraWnd->fpsCheckBox->GetCheck()) + if (cameraWnd.fpsCheckBox.GetCheck()) { // FPS Camera const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far... - const float speed = ((wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; + const float speed = ((wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd.movespeedSlider.GetValue() * clampedDT; static XMVECTOR move = XMVectorSet(0, 0, 0, 0); XMVECTOR moveNew = XMVectorSet(leftStick.x, 0, leftStick.y, 0); @@ -1204,16 +1115,16 @@ void EditorComponent::Update(float dt) if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f) { - XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&cameraWnd->camera_transform.rotation_local)); + XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&cameraWnd.camera_transform.rotation_local)); XMVECTOR move_rot = XMVector3TransformNormal(move, camRot); XMFLOAT3 _move; XMStoreFloat3(&_move, move_rot); - cameraWnd->camera_transform.Translate(_move); - cameraWnd->camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0)); + cameraWnd.camera_transform.Translate(_move); + cameraWnd.camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0)); camera.SetDirty(); } - cameraWnd->camera_transform.UpdateTransform(); + cameraWnd.camera_transform.UpdateTransform(); } else { @@ -1224,28 +1135,28 @@ void EditorComponent::Update(float dt) XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10; XMFLOAT3 vec; XMStoreFloat3(&vec, V); - cameraWnd->camera_target.Translate(vec); + cameraWnd.camera_target.Translate(vec); } else if (wiInput::Down(wiInput::KEYBOARD_BUTTON_LCONTROL) || currentMouse.z != 0.0f) { - cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z)); - cameraWnd->camera_transform.translation_local.z = std::min(0.0f, cameraWnd->camera_transform.translation_local.z); + cameraWnd.camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z)); + cameraWnd.camera_transform.translation_local.z = std::min(0.0f, cameraWnd.camera_transform.translation_local.z); camera.SetDirty(); } else if (abs(xDif) + abs(yDif) > 0) { - cameraWnd->camera_target.RotateRollPitchYaw(XMFLOAT3(yDif * 2, xDif * 2, 0)); + cameraWnd.camera_target.RotateRollPitchYaw(XMFLOAT3(yDif * 2, xDif * 2, 0)); camera.SetDirty(); } - cameraWnd->camera_target.UpdateTransform(); - cameraWnd->camera_transform.UpdateTransform_Parented(cameraWnd->camera_target); + cameraWnd.camera_target.UpdateTransform(); + cameraWnd.camera_transform.UpdateTransform_Parented(cameraWnd.camera_target); } if (!wiBackLog::isActive() && !GetGUI().HasFocus()) { // Begin picking: - unsigned int pickMask = rendererWnd->GetPickType(); + unsigned int pickMask = rendererWnd.GetPickType(); RAY pickRay = wiRenderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y); { hovered = wiScene::PickResult(); @@ -1416,7 +1327,7 @@ void EditorComponent::Update(float dt) } // Interactions only when paint tool is disabled: - if (paintToolWnd->GetMode() == PaintToolWindow::MODE_DISABLED) + if (paintToolWnd.GetMode() == PaintToolWindow::MODE_DISABLED) { // Interact: if (hovered.entity != INVALID_ENTITY) @@ -1432,7 +1343,7 @@ void EditorComponent::Update(float dt) wiRenderer::PutWaterRipple(wiHelper::GetOriginalWorkingDirectory() + "images/ripple.png", hovered.position); } } - else if (decalWnd->placementCheckBox->GetCheck() && wiInput::Press(wiInput::MOUSE_BUTTON_LEFT)) + else if (decalWnd.placementCheckBox.GetCheck() && wiInput::Press(wiInput::MOUSE_BUTTON_LEFT)) { // if not water or softbody, put a decal on it: static int decalselector = 0; @@ -1443,6 +1354,8 @@ void EditorComponent::Update(float dt) transform.RotateRollPitchYaw(XMFLOAT3(XM_PIDIV2, 0, 0)); transform.Scale(XMFLOAT3(2, 2, 2)); scene.Component_Attach(entity, hovered.entity); + + RefreshSceneGraphView(); } } @@ -1525,6 +1438,8 @@ void EditorComponent::Update(float dt) archive << x.subsetIndex; archive << x.distance; } + + RefreshSceneGraphView(); } // Control operations... @@ -1574,6 +1489,8 @@ void EditorComponent::Update(float dt) picked.entity = scene.Entity_Duplicate(x.entity); AddSelected(picked); } + + RefreshSceneGraphView(); } // Put Instances if (clipboard.IsOpen() && hovered.subsetIndex >= 0 && wiInput::Down(wiInput::KEYBOARD_BUTTON_LSHIFT) && wiInput::Press(wiInput::MOUSE_BUTTON_LEFT)) @@ -1594,6 +1511,8 @@ void EditorComponent::Update(float dt) transform->UpdateTransform_Parented(parent_transform); } } + + RefreshSceneGraphView(); } // Undo if (wiInput::Press((wiInput::BUTTON)'Z')) @@ -1636,23 +1555,23 @@ void EditorComponent::Update(float dt) // Update window data bindings... if (translator.selected.empty()) { - objectWnd->SetEntity(INVALID_ENTITY); - emitterWnd->SetEntity(INVALID_ENTITY); - hairWnd->SetEntity(INVALID_ENTITY); - meshWnd->SetEntity(INVALID_ENTITY); - materialWnd->SetEntity(INVALID_ENTITY); - lightWnd->SetEntity(INVALID_ENTITY); - soundWnd->SetEntity(INVALID_ENTITY); - decalWnd->SetEntity(INVALID_ENTITY); - envProbeWnd->SetEntity(INVALID_ENTITY); - forceFieldWnd->SetEntity(INVALID_ENTITY); - cameraWnd->SetEntity(INVALID_ENTITY); - paintToolWnd->SetEntity(INVALID_ENTITY); - springWnd->SetEntity(INVALID_ENTITY); - ikWnd->SetEntity(INVALID_ENTITY); - transformWnd->SetEntity(INVALID_ENTITY); - layerWnd->SetEntity(INVALID_ENTITY); - nameWnd->SetEntity(INVALID_ENTITY); + objectWnd.SetEntity(INVALID_ENTITY); + emitterWnd.SetEntity(INVALID_ENTITY); + hairWnd.SetEntity(INVALID_ENTITY); + meshWnd.SetEntity(INVALID_ENTITY); + materialWnd.SetEntity(INVALID_ENTITY); + lightWnd.SetEntity(INVALID_ENTITY); + soundWnd.SetEntity(INVALID_ENTITY); + decalWnd.SetEntity(INVALID_ENTITY); + envProbeWnd.SetEntity(INVALID_ENTITY); + forceFieldWnd.SetEntity(INVALID_ENTITY); + cameraWnd.SetEntity(INVALID_ENTITY); + paintToolWnd.SetEntity(INVALID_ENTITY); + springWnd.SetEntity(INVALID_ENTITY); + ikWnd.SetEntity(INVALID_ENTITY); + transformWnd.SetEntity(INVALID_ENTITY); + layerWnd.SetEntity(INVALID_ENTITY); + nameWnd.SetEntity(INVALID_ENTITY); } else { @@ -1660,49 +1579,48 @@ void EditorComponent::Update(float dt) assert(picked.entity != INVALID_ENTITY); - objectWnd->SetEntity(INVALID_ENTITY); for (auto& x : translator.selected) { if (scene.objects.GetComponent(x.entity) != nullptr) { - objectWnd->SetEntity(x.entity); + objectWnd.SetEntity(x.entity); break; } } - emitterWnd->SetEntity(picked.entity); - hairWnd->SetEntity(picked.entity); - lightWnd->SetEntity(picked.entity); - soundWnd->SetEntity(picked.entity); - decalWnd->SetEntity(picked.entity); - envProbeWnd->SetEntity(picked.entity); - forceFieldWnd->SetEntity(picked.entity); - cameraWnd->SetEntity(picked.entity); - paintToolWnd->SetEntity(picked.entity, picked.subsetIndex); - springWnd->SetEntity(picked.entity); - ikWnd->SetEntity(picked.entity); - transformWnd->SetEntity(picked.entity); - layerWnd->SetEntity(picked.entity); - nameWnd->SetEntity(picked.entity); + emitterWnd.SetEntity(picked.entity); + hairWnd.SetEntity(picked.entity); + lightWnd.SetEntity(picked.entity); + soundWnd.SetEntity(picked.entity); + decalWnd.SetEntity(picked.entity); + envProbeWnd.SetEntity(picked.entity); + forceFieldWnd.SetEntity(picked.entity); + cameraWnd.SetEntity(picked.entity); + paintToolWnd.SetEntity(picked.entity, picked.subsetIndex); + springWnd.SetEntity(picked.entity); + ikWnd.SetEntity(picked.entity); + transformWnd.SetEntity(picked.entity); + layerWnd.SetEntity(picked.entity); + nameWnd.SetEntity(picked.entity); if (picked.subsetIndex >= 0) { const ObjectComponent* object = scene.objects.GetComponent(picked.entity); if (object != nullptr) // maybe it was deleted... { - meshWnd->SetEntity(object->meshID); + meshWnd.SetEntity(object->meshID); const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID); if (mesh != nullptr && (int)mesh->subsets.size() > picked.subsetIndex) { - materialWnd->SetEntity(mesh->subsets[picked.subsetIndex].materialID); + materialWnd.SetEntity(mesh->subsets[picked.subsetIndex].materialID); } } } else { - meshWnd->SetEntity(picked.entity); - materialWnd->SetEntity(picked.entity); + meshWnd.SetEntity(picked.entity); + materialWnd.SetEntity(picked.entity); } } @@ -1746,21 +1664,21 @@ void EditorComponent::Update(float dt) archive << translator.GetDragDeltaMatrix(); } - emitterWnd->UpdateData(); - hairWnd->UpdateData(); + emitterWnd.UpdateData(); + hairWnd.UpdateData(); // Follow camera proxy: - if (cameraWnd->followCheckBox->IsEnabled() && cameraWnd->followCheckBox->GetCheck()) + if (cameraWnd.followCheckBox.IsEnabled() && cameraWnd.followCheckBox.GetCheck()) { - TransformComponent* proxy = scene.transforms.GetComponent(cameraWnd->proxy); + TransformComponent* proxy = scene.transforms.GetComponent(cameraWnd.proxy); if (proxy != nullptr) { - cameraWnd->camera_transform.Lerp(cameraWnd->camera_transform, *proxy, 1.0f - cameraWnd->followSlider->GetValue()); - cameraWnd->camera_transform.UpdateTransform(); + cameraWnd.camera_transform.Lerp(cameraWnd.camera_transform, *proxy, 1.0f - cameraWnd.followSlider.GetValue()); + cameraWnd.camera_transform.UpdateTransform(); } } - camera.TransformCamera(cameraWnd->camera_transform); + camera.TransformCamera(cameraWnd.camera_transform); camera.UpdateCamera(); wiProfiler::EndRange(profrange); @@ -1774,7 +1692,7 @@ void EditorComponent::Render() const Scene& scene = wiScene::GetScene(); // Hovered item boxes: - if (!cinemaModeCheckBox->GetCheck()) + if (!cinemaModeCheckBox.GetCheck()) { if (hovered.entity != INVALID_ENTITY) { @@ -1824,7 +1742,7 @@ void EditorComponent::Render() const } // Spring visualizer: - if (springWnd->debugCheckBox->GetCheck()) + if (springWnd.debugCheckBox.GetCheck()) { for (size_t i = 0; i < scene.springs.GetCount(); ++i) { @@ -1839,7 +1757,7 @@ void EditorComponent::Render() const } // Selected items box: - if (!cinemaModeCheckBox->GetCheck() && !translator.selected.empty()) + if (!cinemaModeCheckBox.GetCheck() && !translator.selected.empty()) { AABB selectedAABB = AABB(XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX), XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX)); for (auto& picked : translator.selected) @@ -1893,7 +1811,7 @@ void EditorComponent::Render() const wiRenderer::DrawBox(selectionBox, XMFLOAT4(1, 1, 1, 1)); } - paintToolWnd->DrawBrush(); + paintToolWnd.DrawBrush(); renderPath->Render(); @@ -1951,7 +1869,7 @@ void EditorComponent::Compose(CommandList cmd) const { renderPath->Compose(cmd); - if (cinemaModeCheckBox->GetCheck()) + if (cinemaModeCheckBox.GetCheck()) { return; } @@ -1982,7 +1900,7 @@ void EditorComponent::Compose(CommandList cmd) const const XMFLOAT4 glow = wiMath::Lerp(wiMath::Lerp(XMFLOAT4(1, 1, 1, 1), selectionColor, 0.4f), selectionColor, selectionColorIntensity); const wiColor selectedEntityColor = wiColor::fromFloat4(glow); - if (rendererWnd->GetPickType() & PICK_LIGHT) + if (rendererWnd.GetPickType() & PICK_LIGHT) { for (size_t i = 0; i < scene.lights.GetCount(); ++i) { @@ -2031,7 +1949,7 @@ void EditorComponent::Compose(CommandList cmd) const } - if (rendererWnd->GetPickType() & PICK_DECAL) + if (rendererWnd.GetPickType() & PICK_DECAL) { for (size_t i = 0; i < scene.decals.GetCount(); ++i) { @@ -2066,7 +1984,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_FORCEFIELD) + if (rendererWnd.GetPickType() & PICK_FORCEFIELD) { for (size_t i = 0; i < scene.forces.GetCount(); ++i) { @@ -2100,7 +2018,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_CAMERA) + if (rendererWnd.GetPickType() & PICK_CAMERA) { for (size_t i = 0; i < scene.cameras.GetCount(); ++i) { @@ -2135,7 +2053,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_ARMATURE) + if (rendererWnd.GetPickType() & PICK_ARMATURE) { for (size_t i = 0; i < scene.armatures.GetCount(); ++i) { @@ -2169,7 +2087,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_EMITTER) + if (rendererWnd.GetPickType() & PICK_EMITTER) { for (size_t i = 0; i < scene.emitters.GetCount(); ++i) { @@ -2203,7 +2121,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_HAIR) + if (rendererWnd.GetPickType() & PICK_HAIR) { for (size_t i = 0; i < scene.hairs.GetCount(); ++i) { @@ -2237,7 +2155,7 @@ void EditorComponent::Compose(CommandList cmd) const } } - if (rendererWnd->GetPickType() & PICK_SOUND) + if (rendererWnd.GetPickType() & PICK_SOUND) { for (size_t i = 0; i < scene.sounds.GetCount(); ++i) { @@ -2280,6 +2198,104 @@ void EditorComponent::Compose(CommandList cmd) const RenderPath2D::Compose(cmd); } +void EditorComponent::PushToSceneGraphView(wiECS::Entity entity, int level) +{ + if (scenegraphview_added_items.count(entity) != 0) + { + return; + } + const Scene& scene = wiScene::GetScene(); + + wiTreeList::Item item; + item.level = level; + item.userdata = entity; + item.selected = IsSelected(entity); + item.open = scenegraphview_opened_items.count(entity) != 0; + const NameComponent* name = scene.names.GetComponent(entity); + item.name = name == nullptr ? std::to_string(entity) : name->name; + sceneGraphView.AddItem(item); + + scenegraphview_added_items.insert(entity); + + for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i) + { + if (scene.hierarchy[i].parentID == entity) + { + PushToSceneGraphView(scene.hierarchy.GetEntity(i), level + 1); + } + } +} +void EditorComponent::RefreshSceneGraphView() +{ + const Scene& scene = wiScene::GetScene(); + + for (int i = 0; i < sceneGraphView.GetItemCount(); ++i) + { + const wiTreeList::Item& item = sceneGraphView.GetItem(i); + if (item.open) + { + scenegraphview_opened_items.insert((Entity)item.userdata); + } + } + + sceneGraphView.ClearItems(); + + // Add hierarchy: + for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i) + { + PushToSceneGraphView(scene.hierarchy[i].parentID, 0); + } + + // Any transform left that is not part of a hierarchy: + for (size_t i = 0; i < scene.transforms.GetCount(); ++i) + { + PushToSceneGraphView(scene.transforms.GetEntity(i), 0); + } + + // Add materials: + for (size_t i = 0; i < scene.materials.GetCount(); ++i) + { + Entity entity = scene.materials.GetEntity(i); + if (scenegraphview_added_items.count(entity) != 0) + { + continue; + } + + wiTreeList::Item item; + item.userdata = entity; + item.selected = IsSelected(entity); + item.open = scenegraphview_opened_items.count(entity) != 0; + const NameComponent* name = scene.names.GetComponent(entity); + item.name = name == nullptr ? std::to_string(entity) : name->name; + sceneGraphView.AddItem(item); + + scenegraphview_added_items.insert(entity); + } + + // Add meshes: + for (size_t i = 0; i < scene.meshes.GetCount(); ++i) + { + Entity entity = scene.meshes.GetEntity(i); + if (scenegraphview_added_items.count(entity) != 0) + { + continue; + } + + wiTreeList::Item item; + item.userdata = entity; + item.selected = IsSelected(entity); + item.open = scenegraphview_opened_items.count(entity) != 0; + const NameComponent* name = scene.names.GetComponent(entity); + item.name = name == nullptr ? std::to_string(entity) : name->name; + sceneGraphView.AddItem(item); + + scenegraphview_added_items.insert(entity); + } + + scenegraphview_added_items.clear(); + scenegraphview_opened_items.clear(); +} + void EditorComponent::ClearSelected() { translator.selected.clear(); @@ -2446,7 +2462,7 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) } break; case HISTORYOP_PAINTTOOL: - paintToolWnd->ConsumeHistoryOperation(archive, undo); + paintToolWnd.ConsumeHistoryOperation(archive, undo); break; case HISTORYOP_NONE: assert(0); @@ -2460,4 +2476,6 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) historyPos--; } } + + RefreshSceneGraphView(); } diff --git a/Editor/Editor.h b/Editor/Editor.h index e0213c892..de981e2fe 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -40,80 +40,78 @@ class EditorComponent : public RenderPath2D private: std::shared_ptr pointLightTex, spotLightTex, dirLightTex, areaLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex, soundTex; public: - std::unique_ptr materialWnd; - std::unique_ptr postprocessWnd; - std::unique_ptr weatherWnd; - std::unique_ptr objectWnd; - std::unique_ptr meshWnd; - std::unique_ptr cameraWnd; - std::unique_ptr rendererWnd; - std::unique_ptr envProbeWnd; - std::unique_ptr decalWnd; - std::unique_ptr soundWnd; - std::unique_ptr lightWnd; - std::unique_ptr animWnd; - std::unique_ptr emitterWnd; - std::unique_ptr hairWnd; - std::unique_ptr forceFieldWnd; - std::unique_ptr paintToolWnd; - std::unique_ptr springWnd; - std::unique_ptr ikWnd; - std::unique_ptr transformWnd; - std::unique_ptr layerWnd; - std::unique_ptr nameWnd; + MaterialWindow materialWnd; + PostprocessWindow postprocessWnd; + WeatherWindow weatherWnd; + ObjectWindow objectWnd; + MeshWindow meshWnd; + CameraWindow cameraWnd; + RendererWindow rendererWnd; + EnvProbeWindow envProbeWnd; + DecalWindow decalWnd; + SoundWindow soundWnd; + LightWindow lightWnd; + AnimationWindow animWnd; + EmitterWindow emitterWnd; + HairParticleWindow hairWnd; + ForceFieldWindow forceFieldWnd; + PaintToolWindow paintToolWnd; + SpringWindow springWnd; + IKWindow ikWnd; + TransformWindow transformWnd; + LayerWindow layerWnd; + NameWindow nameWnd; Editor* main = nullptr; - wiButton* rendererWnd_Toggle = nullptr; - wiButton* postprocessWnd_Toggle = nullptr; - wiButton* paintToolWnd_Toggle = nullptr; - wiButton* weatherWnd_Toggle = nullptr; - wiButton* objectWnd_Toggle = nullptr; - wiButton* meshWnd_Toggle = nullptr; - wiButton* materialWnd_Toggle = nullptr; - wiButton* cameraWnd_Toggle = nullptr; - wiButton* envProbeWnd_Toggle = nullptr; - wiButton* decalWnd_Toggle = nullptr; - wiButton* soundWnd_Toggle = nullptr; - wiButton* lightWnd_Toggle = nullptr; - wiButton* animWnd_Toggle = nullptr; - wiButton* emitterWnd_Toggle = nullptr; - wiButton* hairWnd_Toggle = nullptr; - wiButton* forceFieldWnd_Toggle = nullptr; - wiButton* springWnd_Toggle = nullptr; - wiButton* ikWnd_Toggle = nullptr; - wiButton* transformWnd_Toggle = nullptr; - wiButton* layerWnd_Toggle = nullptr; - wiButton* nameWnd_Toggle = nullptr; - wiCheckBox* translatorCheckBox = nullptr; - wiCheckBox* isScalatorCheckBox = nullptr; - wiCheckBox* isRotatorCheckBox = nullptr; - wiCheckBox* isTranslatorCheckBox = nullptr; - wiButton* saveButton = nullptr; - wiButton* modelButton = nullptr; - wiButton* scriptButton = nullptr; - wiButton* shaderButton = nullptr; - wiButton* clearButton = nullptr; - wiButton* helpButton = nullptr; - wiButton* exitButton = nullptr; - wiCheckBox* profilerEnabledCheckBox = nullptr; - wiCheckBox* physicsEnabledCheckBox = nullptr; - wiCheckBox* cinemaModeCheckBox = nullptr; - wiComboBox* renderPathComboBox = nullptr; - wiLabel* helpLabel = nullptr; + wiButton rendererWnd_Toggle; + wiButton postprocessWnd_Toggle; + wiButton paintToolWnd_Toggle; + wiButton weatherWnd_Toggle; + wiButton objectWnd_Toggle; + wiButton meshWnd_Toggle; + wiButton materialWnd_Toggle; + wiButton cameraWnd_Toggle; + wiButton envProbeWnd_Toggle; + wiButton decalWnd_Toggle; + wiButton soundWnd_Toggle; + wiButton lightWnd_Toggle; + wiButton animWnd_Toggle; + wiButton emitterWnd_Toggle; + wiButton hairWnd_Toggle; + wiButton forceFieldWnd_Toggle; + wiButton springWnd_Toggle; + wiButton ikWnd_Toggle; + wiButton transformWnd_Toggle; + wiButton layerWnd_Toggle; + wiButton nameWnd_Toggle; + wiCheckBox translatorCheckBox; + wiCheckBox isScalatorCheckBox; + wiCheckBox isRotatorCheckBox; + wiCheckBox isTranslatorCheckBox; + wiButton saveButton; + wiButton modelButton; + wiButton scriptButton; + wiButton shaderButton; + wiButton clearButton; + wiButton helpButton; + wiButton exitButton; + wiCheckBox profilerEnabledCheckBox; + wiCheckBox physicsEnabledCheckBox; + wiCheckBox cinemaModeCheckBox; + wiComboBox renderPathComboBox; + wiLabel helpLabel; - wiTreeList* sceneGraphView = nullptr; + wiTreeList sceneGraphView; std::unordered_set scenegraphview_added_items; std::unordered_set scenegraphview_opened_items; void PushToSceneGraphView(wiECS::Entity entity, int level); + void RefreshSceneGraphView(); std::unique_ptr renderPath; enum RENDERPATH { - RENDERPATH_FORWARD, - RENDERPATH_DEFERRED, - RENDERPATH_TILEDFORWARD, - RENDERPATH_TILEDDEFERRED, + RENDERPATH_DEFAULT, RENDERPATH_PATHTRACING, }; void ChangeRenderPath(RENDERPATH path); @@ -153,7 +151,6 @@ public: - wiArchive clipboard; std::vector history; @@ -175,8 +172,8 @@ public: class Editor : public MainComponent { public: - std::unique_ptr renderComponent; - std::unique_ptr loader; + EditorComponent renderComponent; + EditorLoadingScreen loader; void Initialize() override; }; diff --git a/Editor/Editor_UWP.vcxproj b/Editor/Editor_UWP.vcxproj index e7a870d84..6cf2156a4 100644 --- a/Editor/Editor_UWP.vcxproj +++ b/Editor/Editor_UWP.vcxproj @@ -445,6 +445,39 @@ + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + Document diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index 6b57d0718..587ddddac 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -8,13 +8,10 @@ using namespace std; using namespace wiECS; using namespace wiScene; -EmitterWindow::EmitterWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void EmitterWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - emitterWindow = new wiWindow(GUI, "Emitter Window"); - emitterWindow->SetSize(XMFLOAT2(680, 660)); - GUI->AddWidget(emitterWindow); + wiWindow::Create("Emitter Window"); + SetSize(XMFLOAT2(680, 660)); float x = 200; float y = 5; @@ -22,49 +19,50 @@ EmitterWindow::EmitterWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) float step = itemheight + 2; - emitterNameField = new wiTextInputField("EmitterName"); - emitterNameField->SetPos(XMFLOAT2(x, y += step)); - emitterNameField->SetSize(XMFLOAT2(300, itemheight)); - emitterNameField->OnInputAccepted([&](wiEventArgs args) { + emitterNameField.Create("EmitterName"); + emitterNameField.SetPos(XMFLOAT2(x, y += step)); + emitterNameField.SetSize(XMFLOAT2(300, itemheight)); + emitterNameField.OnInputAccepted([&](wiEventArgs args) { NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; } }); - emitterWindow->AddWidget(emitterNameField); + AddWidget(&emitterNameField); - addButton = new wiButton("Add Emitter"); - addButton->SetPos(XMFLOAT2(x, y += step)); - addButton->SetSize(XMFLOAT2(150, itemheight)); - addButton->OnClick([=](wiEventArgs args) { + addButton.Create("Add Emitter"); + addButton.SetPos(XMFLOAT2(x, y += step)); + addButton.SetSize(XMFLOAT2(150, itemheight)); + addButton.OnClick([=](wiEventArgs args) { Scene& scene = wiScene::GetScene(); Entity entity = scene.Entity_CreateEmitter("editorEmitter"); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); - addButton->SetTooltip("Add new emitter particle system."); - emitterWindow->AddWidget(addButton); + addButton.SetTooltip("Add new emitter particle system."); + AddWidget(&addButton); - restartButton = new wiButton("Restart Emitter"); - restartButton->SetPos(XMFLOAT2(x + 160, y)); - restartButton->SetSize(XMFLOAT2(150, itemheight)); - restartButton->OnClick([&](wiEventArgs args) { + restartButton.Create("Restart Emitter"); + restartButton.SetPos(XMFLOAT2(x + 160, y)); + restartButton.SetSize(XMFLOAT2(150, itemheight)); + restartButton.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->Restart(); } }); - restartButton->SetTooltip("Restart particle system emitter"); - emitterWindow->AddWidget(restartButton); + restartButton.SetTooltip("Restart particle system emitter"); + AddWidget(&restartButton); - meshComboBox = new wiComboBox("Mesh: "); - meshComboBox->SetSize(XMFLOAT2(300, itemheight)); - meshComboBox->SetPos(XMFLOAT2(x, y += step)); - meshComboBox->SetEnabled(false); - meshComboBox->OnSelect([&](wiEventArgs args) { + meshComboBox.Create("Mesh: "); + meshComboBox.SetSize(XMFLOAT2(300, itemheight)); + meshComboBox.SetPos(XMFLOAT2(x, y += step)); + meshComboBox.SetEnabled(false); + meshComboBox.OnSelect([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { @@ -79,386 +77,386 @@ EmitterWindow::EmitterWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - meshComboBox->SetTooltip("Choose an mesh that particles will be emitted from..."); - emitterWindow->AddWidget(meshComboBox); + meshComboBox.SetTooltip("Choose an mesh that particles will be emitted from..."); + AddWidget(&meshComboBox); - shaderTypeComboBox = new wiComboBox("ShaderType: "); - shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); - shaderTypeComboBox->SetSize(XMFLOAT2(300, itemheight)); - shaderTypeComboBox->AddItem("SOFT"); - shaderTypeComboBox->AddItem("SOFT + DISTORTION"); - shaderTypeComboBox->AddItem("SIMPLEST"); - shaderTypeComboBox->AddItem("SOFT + LIGHTING"); - shaderTypeComboBox->OnSelect([&](wiEventArgs args) { + shaderTypeComboBox.Create("ShaderType: "); + shaderTypeComboBox.SetPos(XMFLOAT2(x, y += step)); + shaderTypeComboBox.SetSize(XMFLOAT2(300, itemheight)); + shaderTypeComboBox.AddItem("SOFT"); + shaderTypeComboBox.AddItem("SOFT + DISTORTION"); + shaderTypeComboBox.AddItem("SIMPLEST"); + shaderTypeComboBox.AddItem("SOFT + LIGHTING"); + shaderTypeComboBox.OnSelect([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->shaderType = (wiEmittedParticle::PARTICLESHADERTYPE)args.iValue; } }); - shaderTypeComboBox->SetEnabled(false); - shaderTypeComboBox->SetTooltip("Choose a shader type for the particles. This is responsible of how they will be rendered."); - emitterWindow->AddWidget(shaderTypeComboBox); + shaderTypeComboBox.SetEnabled(false); + shaderTypeComboBox.SetTooltip("Choose a shader type for the particles. This is responsible of how they will be rendered."); + AddWidget(&shaderTypeComboBox); - sortCheckBox = new wiCheckBox("Sorting Enabled: "); - sortCheckBox->SetPos(XMFLOAT2(x, y += step)); - sortCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - sortCheckBox->OnClick([&](wiEventArgs args) { + sortCheckBox.Create("Sorting Enabled: "); + sortCheckBox.SetPos(XMFLOAT2(x, y += step)); + sortCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + sortCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetSorted(args.bValue); } }); - sortCheckBox->SetCheck(false); - sortCheckBox->SetTooltip("Enable sorting of the particles. This might slow down performance."); - emitterWindow->AddWidget(sortCheckBox); + sortCheckBox.SetCheck(false); + sortCheckBox.SetTooltip("Enable sorting of the particles. This might slow down performance."); + AddWidget(&sortCheckBox); - depthCollisionsCheckBox = new wiCheckBox("Depth Buffer Collisions Enabled: "); - depthCollisionsCheckBox->SetPos(XMFLOAT2(x + 250, y)); - depthCollisionsCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - depthCollisionsCheckBox->OnClick([&](wiEventArgs args) { + depthCollisionsCheckBox.Create("Depth Buffer Collisions Enabled: "); + depthCollisionsCheckBox.SetPos(XMFLOAT2(x + 250, y)); + depthCollisionsCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + depthCollisionsCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetDepthCollisionEnabled(args.bValue); } }); - depthCollisionsCheckBox->SetCheck(false); - depthCollisionsCheckBox->SetTooltip("Enable particle collisions with the depth buffer."); - emitterWindow->AddWidget(depthCollisionsCheckBox); + depthCollisionsCheckBox.SetCheck(false); + depthCollisionsCheckBox.SetTooltip("Enable particle collisions with the depth buffer."); + AddWidget(&depthCollisionsCheckBox); - sphCheckBox = new wiCheckBox("SPH - FluidSim: "); - sphCheckBox->SetPos(XMFLOAT2(x + 400, y)); - sphCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - sphCheckBox->OnClick([&](wiEventArgs args) { + sphCheckBox.Create("SPH - FluidSim: "); + sphCheckBox.SetPos(XMFLOAT2(x + 400, y)); + sphCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + sphCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetSPHEnabled(args.bValue); } }); - sphCheckBox->SetCheck(false); - sphCheckBox->SetTooltip("Enable particle collisions with each other. Simulate with Smooth Particle Hydrodynamics (SPH) solver."); - emitterWindow->AddWidget(sphCheckBox); + sphCheckBox.SetCheck(false); + sphCheckBox.SetTooltip("Enable particle collisions with each other. Simulate with Smooth Particle Hydrodynamics (SPH) solver."); + AddWidget(&sphCheckBox); - pauseCheckBox = new wiCheckBox("PAUSE: "); - pauseCheckBox->SetPos(XMFLOAT2(x, y += step)); - pauseCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pauseCheckBox->OnClick([&](wiEventArgs args) { + pauseCheckBox.Create("PAUSE: "); + pauseCheckBox.SetPos(XMFLOAT2(x, y += step)); + pauseCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pauseCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetPaused(args.bValue); } }); - pauseCheckBox->SetCheck(false); - pauseCheckBox->SetTooltip("Stop simulation update."); - emitterWindow->AddWidget(pauseCheckBox); + pauseCheckBox.SetCheck(false); + pauseCheckBox.SetTooltip("Stop simulation update."); + AddWidget(&pauseCheckBox); - debugCheckBox = new wiCheckBox("DEBUG: "); - debugCheckBox->SetPos(XMFLOAT2(x + 120, y)); - debugCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - debugCheckBox->OnClick([&](wiEventArgs args) { + debugCheckBox.Create("DEBUG: "); + debugCheckBox.SetPos(XMFLOAT2(x + 120, y)); + debugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + debugCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetDebug(args.bValue); } }); - debugCheckBox->SetCheck(false); - debugCheckBox->SetTooltip("Currently this has no functionality."); - emitterWindow->AddWidget(debugCheckBox); + debugCheckBox.SetCheck(false); + debugCheckBox.SetTooltip("Currently this has no functionality."); + AddWidget(&debugCheckBox); - volumeCheckBox = new wiCheckBox("Volume: "); - volumeCheckBox->SetPos(XMFLOAT2(x + 250, y)); - volumeCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - volumeCheckBox->OnClick([&](wiEventArgs args) { + volumeCheckBox.Create("Volume: "); + volumeCheckBox.SetPos(XMFLOAT2(x + 250, y)); + volumeCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + volumeCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetVolumeEnabled(args.bValue); } }); - volumeCheckBox->SetCheck(false); - volumeCheckBox->SetTooltip("Enable volume for the emitter. Particles will be emitted inside volume."); - emitterWindow->AddWidget(volumeCheckBox); + volumeCheckBox.SetCheck(false); + volumeCheckBox.SetTooltip("Enable volume for the emitter. Particles will be emitted inside volume."); + AddWidget(&volumeCheckBox); - frameBlendingCheckBox = new wiCheckBox("Frame Blending: "); - frameBlendingCheckBox->SetPos(XMFLOAT2(x + 400, y)); - frameBlendingCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - frameBlendingCheckBox->OnClick([&](wiEventArgs args) { + frameBlendingCheckBox.Create("Frame Blending: "); + frameBlendingCheckBox.SetPos(XMFLOAT2(x + 400, y)); + frameBlendingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + frameBlendingCheckBox.OnClick([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetFrameBlendingEnabled(args.bValue); } }); - frameBlendingCheckBox->SetCheck(false); - frameBlendingCheckBox->SetTooltip("If sprite sheet animation is in effect, frames will be smoothly blended."); - emitterWindow->AddWidget(frameBlendingCheckBox); + frameBlendingCheckBox.SetCheck(false); + frameBlendingCheckBox.SetTooltip("If sprite sheet animation is in effect, frames will be smoothly blended."); + AddWidget(&frameBlendingCheckBox); - infoLabel = new wiLabel("EmitterInfo"); - infoLabel->SetSize(XMFLOAT2(380, 120)); - infoLabel->SetPos(XMFLOAT2(x, y += step)); - emitterWindow->AddWidget(infoLabel); + infoLabel.Create("EmitterInfo"); + infoLabel.SetSize(XMFLOAT2(380, 120)); + infoLabel.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&infoLabel); y += 125; - frameRateInput = new wiTextInputField(""); - frameRateInput->SetPos(XMFLOAT2(x, y)); - frameRateInput->SetSize(XMFLOAT2(40, 18)); - frameRateInput->SetText(""); - frameRateInput->SetTooltip("Enter a value to enable looping sprite sheet animation (frames per second). Set 0 for animation along paritcle lifetime."); - frameRateInput->SetDescription("Frame Rate: "); - frameRateInput->OnInputAccepted([this](wiEventArgs args) { + frameRateInput.Create(""); + frameRateInput.SetPos(XMFLOAT2(x, y)); + frameRateInput.SetSize(XMFLOAT2(40, 18)); + frameRateInput.SetText(""); + frameRateInput.SetTooltip("Enter a value to enable looping sprite sheet animation (frames per second). Set 0 for animation along paritcle lifetime."); + frameRateInput.SetDescription("Frame Rate: "); + frameRateInput.OnInputAccepted([this](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->frameRate = args.fValue; } }); - emitterWindow->AddWidget(frameRateInput); + AddWidget(&frameRateInput); - framesXInput = new wiTextInputField(""); - framesXInput->SetPos(XMFLOAT2(x + 150, y)); - framesXInput->SetSize(XMFLOAT2(40, 18)); - framesXInput->SetText(""); - framesXInput->SetTooltip("How many horizontal frames there are in the spritesheet."); - framesXInput->SetDescription("Frames X: "); - framesXInput->OnInputAccepted([this](wiEventArgs args) { + framesXInput.Create(""); + framesXInput.SetPos(XMFLOAT2(x + 150, y)); + framesXInput.SetSize(XMFLOAT2(40, 18)); + framesXInput.SetText(""); + framesXInput.SetTooltip("How many horizontal frames there are in the spritesheet."); + framesXInput.SetDescription("Frames X: "); + framesXInput.OnInputAccepted([this](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->framesX = (uint32_t)args.iValue; } }); - emitterWindow->AddWidget(framesXInput); + AddWidget(&framesXInput); - framesYInput = new wiTextInputField(""); - framesYInput->SetPos(XMFLOAT2(x + 300, y)); - framesYInput->SetSize(XMFLOAT2(40, 18)); - framesYInput->SetText(""); - framesYInput->SetTooltip("How many vertical frames there are in the spritesheet."); - framesYInput->SetDescription("Frames Y: "); - framesYInput->OnInputAccepted([this](wiEventArgs args) { + framesYInput.Create(""); + framesYInput.SetPos(XMFLOAT2(x + 300, y)); + framesYInput.SetSize(XMFLOAT2(40, 18)); + framesYInput.SetText(""); + framesYInput.SetTooltip("How many vertical frames there are in the spritesheet."); + framesYInput.SetDescription("Frames Y: "); + framesYInput.OnInputAccepted([this](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->framesY = (uint32_t)args.iValue; } }); - emitterWindow->AddWidget(framesYInput); + AddWidget(&framesYInput); - frameCountInput = new wiTextInputField(""); - frameCountInput->SetPos(XMFLOAT2(x, y += step)); - frameCountInput->SetSize(XMFLOAT2(40, 18)); - frameCountInput->SetText(""); - frameCountInput->SetTooltip("Enter a value to enable the random sprite sheet frame selection's max frame number."); - frameCountInput->SetDescription("Frame Count: "); - frameCountInput->OnInputAccepted([this](wiEventArgs args) { + frameCountInput.Create(""); + frameCountInput.SetPos(XMFLOAT2(x, y += step)); + frameCountInput.SetSize(XMFLOAT2(40, 18)); + frameCountInput.SetText(""); + frameCountInput.SetTooltip("Enter a value to enable the random sprite sheet frame selection's max frame number."); + frameCountInput.SetDescription("Frame Count: "); + frameCountInput.OnInputAccepted([this](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->frameCount = (uint32_t)args.iValue; } }); - emitterWindow->AddWidget(frameCountInput); + AddWidget(&frameCountInput); - frameStartInput = new wiTextInputField(""); - frameStartInput->SetPos(XMFLOAT2(x + 300, y)); - frameStartInput->SetSize(XMFLOAT2(40, 18)); - frameStartInput->SetText(""); - frameStartInput->SetTooltip("Specifies the starting frame of the animation."); - frameStartInput->SetDescription("Start Frame: "); - frameStartInput->OnInputAccepted([this](wiEventArgs args) { + frameStartInput.Create(""); + frameStartInput.SetPos(XMFLOAT2(x + 300, y)); + frameStartInput.SetSize(XMFLOAT2(40, 18)); + frameStartInput.SetText(""); + frameStartInput.SetTooltip("Specifies the starting frame of the animation."); + frameStartInput.SetDescription("Start Frame: "); + frameStartInput.OnInputAccepted([this](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->frameStart = (uint32_t)args.iValue; } }); - emitterWindow->AddWidget(frameStartInput); + AddWidget(&frameStartInput); - maxParticlesSlider = new wiSlider(100.0f, 1000000.0f, 10000, 100000, "Max particle count: "); - maxParticlesSlider->SetSize(XMFLOAT2(360, itemheight)); - maxParticlesSlider->SetPos(XMFLOAT2(x, y += step)); - maxParticlesSlider->OnSlide([&](wiEventArgs args) { + maxParticlesSlider.Create(100.0f, 1000000.0f, 10000, 100000, "Max particle count: "); + maxParticlesSlider.SetSize(XMFLOAT2(360, itemheight)); + maxParticlesSlider.SetPos(XMFLOAT2(x, y += step)); + maxParticlesSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SetMaxParticleCount((uint32_t)args.iValue); } }); - maxParticlesSlider->SetEnabled(false); - maxParticlesSlider->SetTooltip("Set the maximum amount of particles this system can handle. This has an effect on the memory budget."); - emitterWindow->AddWidget(maxParticlesSlider); + maxParticlesSlider.SetEnabled(false); + maxParticlesSlider.SetTooltip("Set the maximum amount of particles this system can handle. This has an effect on the memory budget."); + AddWidget(&maxParticlesSlider); - emitCountSlider = new wiSlider(0.0f, 10000.0f, 1.0f, 100000, "Emit count per sec: "); - emitCountSlider->SetSize(XMFLOAT2(360, itemheight)); - emitCountSlider->SetPos(XMFLOAT2(x, y += step)); - emitCountSlider->OnSlide([&](wiEventArgs args) { + emitCountSlider.Create(0.0f, 10000.0f, 1.0f, 100000, "Emit count per sec: "); + emitCountSlider.SetSize(XMFLOAT2(360, itemheight)); + emitCountSlider.SetPos(XMFLOAT2(x, y += step)); + emitCountSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->count = args.fValue; } }); - emitCountSlider->SetEnabled(false); - emitCountSlider->SetTooltip("Set the number of particles to emit per second."); - emitterWindow->AddWidget(emitCountSlider); + emitCountSlider.SetEnabled(false); + emitCountSlider.SetTooltip("Set the number of particles to emit per second."); + AddWidget(&emitCountSlider); - emitSizeSlider = new wiSlider(0.01f, 10.0f, 1.0f, 100000, "Size: "); - emitSizeSlider->SetSize(XMFLOAT2(360, itemheight)); - emitSizeSlider->SetPos(XMFLOAT2(x, y += step)); - emitSizeSlider->OnSlide([&](wiEventArgs args) { + emitSizeSlider.Create(0.01f, 10.0f, 1.0f, 100000, "Size: "); + emitSizeSlider.SetSize(XMFLOAT2(360, itemheight)); + emitSizeSlider.SetPos(XMFLOAT2(x, y += step)); + emitSizeSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->size = args.fValue; } }); - emitSizeSlider->SetEnabled(false); - emitSizeSlider->SetTooltip("Set the size of the emitted particles."); - emitterWindow->AddWidget(emitSizeSlider); + emitSizeSlider.SetEnabled(false); + emitSizeSlider.SetTooltip("Set the size of the emitted particles."); + AddWidget(&emitSizeSlider); - emitRotationSlider = new wiSlider(0.0f, 1.0f, 0.0f, 100000, "Rotation: "); - emitRotationSlider->SetSize(XMFLOAT2(360, itemheight)); - emitRotationSlider->SetPos(XMFLOAT2(x, y += step)); - emitRotationSlider->OnSlide([&](wiEventArgs args) { + emitRotationSlider.Create(0.0f, 1.0f, 0.0f, 100000, "Rotation: "); + emitRotationSlider.SetSize(XMFLOAT2(360, itemheight)); + emitRotationSlider.SetPos(XMFLOAT2(x, y += step)); + emitRotationSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->rotation = args.fValue; } }); - emitRotationSlider->SetEnabled(false); - emitRotationSlider->SetTooltip("Set the rotation velocity of the emitted particles."); - emitterWindow->AddWidget(emitRotationSlider); + emitRotationSlider.SetEnabled(false); + emitRotationSlider.SetTooltip("Set the rotation velocity of the emitted particles."); + AddWidget(&emitRotationSlider); - emitNormalSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Normal factor: "); - emitNormalSlider->SetSize(XMFLOAT2(360, itemheight)); - emitNormalSlider->SetPos(XMFLOAT2(x, y += step)); - emitNormalSlider->OnSlide([&](wiEventArgs args) { + emitNormalSlider.Create(0.0f, 100.0f, 1.0f, 100000, "Normal factor: "); + emitNormalSlider.SetSize(XMFLOAT2(360, itemheight)); + emitNormalSlider.SetPos(XMFLOAT2(x, y += step)); + emitNormalSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->normal_factor = args.fValue; } }); - emitNormalSlider->SetEnabled(false); - emitNormalSlider->SetTooltip("Set the velocity of the emitted particles based on the normal vector of the emitter surface."); - emitterWindow->AddWidget(emitNormalSlider); + emitNormalSlider.SetEnabled(false); + emitNormalSlider.SetTooltip("Set the velocity of the emitted particles based on the normal vector of the emitter surface."); + AddWidget(&emitNormalSlider); - emitScalingSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Scaling: "); - emitScalingSlider->SetSize(XMFLOAT2(360, itemheight)); - emitScalingSlider->SetPos(XMFLOAT2(x, y += step)); - emitScalingSlider->OnSlide([&](wiEventArgs args) { + emitScalingSlider.Create(0.0f, 100.0f, 1.0f, 100000, "Scaling: "); + emitScalingSlider.SetSize(XMFLOAT2(360, itemheight)); + emitScalingSlider.SetPos(XMFLOAT2(x, y += step)); + emitScalingSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->scaleX = args.fValue; } }); - emitScalingSlider->SetEnabled(false); - emitScalingSlider->SetTooltip("Set the scaling of the particles based on their lifetime."); - emitterWindow->AddWidget(emitScalingSlider); + emitScalingSlider.SetEnabled(false); + emitScalingSlider.SetTooltip("Set the scaling of the particles based on their lifetime."); + AddWidget(&emitScalingSlider); - emitLifeSlider = new wiSlider(0.0f, 100.0f, 1.0f, 10000, "Life span: "); - emitLifeSlider->SetSize(XMFLOAT2(360, itemheight)); - emitLifeSlider->SetPos(XMFLOAT2(x, y += step)); - emitLifeSlider->OnSlide([&](wiEventArgs args) { + emitLifeSlider.Create(0.0f, 100.0f, 1.0f, 10000, "Life span: "); + emitLifeSlider.SetSize(XMFLOAT2(360, itemheight)); + emitLifeSlider.SetPos(XMFLOAT2(x, y += step)); + emitLifeSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->life = args.fValue; } }); - emitLifeSlider->SetEnabled(false); - emitLifeSlider->SetTooltip("Set the lifespan of the emitted particles (in seconds)."); - emitterWindow->AddWidget(emitLifeSlider); + emitLifeSlider.SetEnabled(false); + emitLifeSlider.SetTooltip("Set the lifespan of the emitted particles (in seconds)."); + AddWidget(&emitLifeSlider); - emitRandomnessSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Randomness: "); - emitRandomnessSlider->SetSize(XMFLOAT2(360, itemheight)); - emitRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); - emitRandomnessSlider->OnSlide([&](wiEventArgs args) { + emitRandomnessSlider.Create(0.0f, 1.0f, 1.0f, 100000, "Randomness: "); + emitRandomnessSlider.SetSize(XMFLOAT2(360, itemheight)); + emitRandomnessSlider.SetPos(XMFLOAT2(x, y += step)); + emitRandomnessSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->random_factor = args.fValue; } }); - emitRandomnessSlider->SetEnabled(false); - emitRandomnessSlider->SetTooltip("Set the general randomness of the emitter."); - emitterWindow->AddWidget(emitRandomnessSlider); + emitRandomnessSlider.SetEnabled(false); + emitRandomnessSlider.SetTooltip("Set the general randomness of the emitter."); + AddWidget(&emitRandomnessSlider); - emitLifeRandomnessSlider = new wiSlider(0.0f, 2.0f, 0.0f, 100000, "Life randomness: "); - emitLifeRandomnessSlider->SetSize(XMFLOAT2(360, itemheight)); - emitLifeRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); - emitLifeRandomnessSlider->OnSlide([&](wiEventArgs args) { + emitLifeRandomnessSlider.Create(0.0f, 2.0f, 0.0f, 100000, "Life randomness: "); + emitLifeRandomnessSlider.SetSize(XMFLOAT2(360, itemheight)); + emitLifeRandomnessSlider.SetPos(XMFLOAT2(x, y += step)); + emitLifeRandomnessSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->random_life = args.fValue; } }); - emitLifeRandomnessSlider->SetEnabled(false); - emitLifeRandomnessSlider->SetTooltip("Set the randomness of lifespans for the emitted particles."); - emitterWindow->AddWidget(emitLifeRandomnessSlider); + emitLifeRandomnessSlider.SetEnabled(false); + emitLifeRandomnessSlider.SetTooltip("Set the randomness of lifespans for the emitted particles."); + AddWidget(&emitLifeRandomnessSlider); - emitMotionBlurSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Motion blur: "); - emitMotionBlurSlider->SetSize(XMFLOAT2(360, itemheight)); - emitMotionBlurSlider->SetPos(XMFLOAT2(x, y += step)); - emitMotionBlurSlider->OnSlide([&](wiEventArgs args) { + emitMotionBlurSlider.Create(0.0f, 1.0f, 1.0f, 100000, "Motion blur: "); + emitMotionBlurSlider.SetSize(XMFLOAT2(360, itemheight)); + emitMotionBlurSlider.SetPos(XMFLOAT2(x, y += step)); + emitMotionBlurSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->motionBlurAmount = args.fValue; } }); - emitMotionBlurSlider->SetEnabled(false); - emitMotionBlurSlider->SetTooltip("Set the motion blur amount for the particle system."); - emitterWindow->AddWidget(emitMotionBlurSlider); + emitMotionBlurSlider.SetEnabled(false); + emitMotionBlurSlider.SetTooltip("Set the motion blur amount for the particle system."); + AddWidget(&emitMotionBlurSlider); - emitMassSlider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "Mass: "); - emitMassSlider->SetSize(XMFLOAT2(360, itemheight)); - emitMassSlider->SetPos(XMFLOAT2(x, y += step)); - emitMassSlider->OnSlide([&](wiEventArgs args) { + emitMassSlider.Create(0.1f, 100.0f, 1.0f, 100000, "Mass: "); + emitMassSlider.SetSize(XMFLOAT2(360, itemheight)); + emitMassSlider.SetPos(XMFLOAT2(x, y += step)); + emitMassSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->mass = args.fValue; } }); - emitMassSlider->SetEnabled(false); - emitMassSlider->SetTooltip("Set the mass per particle."); - emitterWindow->AddWidget(emitMassSlider); + emitMassSlider.SetEnabled(false); + emitMassSlider.SetTooltip("Set the mass per particle."); + AddWidget(&emitMassSlider); - timestepSlider = new wiSlider(-1, 0.016f, -1, 100000, "Timestep: "); - timestepSlider->SetSize(XMFLOAT2(360, itemheight)); - timestepSlider->SetPos(XMFLOAT2(x, y += step)); - timestepSlider->OnSlide([&](wiEventArgs args) { + timestepSlider.Create(-1, 0.016f, -1, 100000, "Timestep: "); + timestepSlider.SetSize(XMFLOAT2(360, itemheight)); + timestepSlider.SetPos(XMFLOAT2(x, y += step)); + timestepSlider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->FIXED_TIMESTEP = args.fValue; } }); - timestepSlider->SetEnabled(false); - timestepSlider->SetTooltip("Adjust timestep for emitter simulation. -1 means variable timestep, positive means fixed timestep."); - emitterWindow->AddWidget(timestepSlider); + timestepSlider.SetEnabled(false); + timestepSlider.SetTooltip("Adjust timestep for emitter simulation. -1 means variable timestep, positive means fixed timestep."); + AddWidget(×tepSlider); @@ -466,80 +464,73 @@ EmitterWindow::EmitterWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) //////////////// SPH //////////////////////////// - sph_h_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Smoothing Radius (h): "); - sph_h_Slider->SetSize(XMFLOAT2(360, itemheight)); - sph_h_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_h_Slider->OnSlide([&](wiEventArgs args) { + sph_h_Slider.Create(0.1f, 100.0f, 1.0f, 100000, "SPH Smoothing Radius (h): "); + sph_h_Slider.SetSize(XMFLOAT2(360, itemheight)); + sph_h_Slider.SetPos(XMFLOAT2(x, y += step)); + sph_h_Slider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SPH_h = args.fValue; } }); - sph_h_Slider->SetEnabled(false); - sph_h_Slider->SetTooltip("Set the SPH parameter: smoothing radius"); - emitterWindow->AddWidget(sph_h_Slider); + sph_h_Slider.SetEnabled(false); + sph_h_Slider.SetTooltip("Set the SPH parameter: smoothing radius"); + AddWidget(&sph_h_Slider); - sph_K_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Pressure Constant (K): "); - sph_K_Slider->SetSize(XMFLOAT2(360, itemheight)); - sph_K_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_K_Slider->OnSlide([&](wiEventArgs args) { + sph_K_Slider.Create(0.1f, 100.0f, 1.0f, 100000, "SPH Pressure Constant (K): "); + sph_K_Slider.SetSize(XMFLOAT2(360, itemheight)); + sph_K_Slider.SetPos(XMFLOAT2(x, y += step)); + sph_K_Slider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SPH_K = args.fValue; } }); - sph_K_Slider->SetEnabled(false); - sph_K_Slider->SetTooltip("Set the SPH parameter: pressure constant"); - emitterWindow->AddWidget(sph_K_Slider); + sph_K_Slider.SetEnabled(false); + sph_K_Slider.SetTooltip("Set the SPH parameter: pressure constant"); + AddWidget(&sph_K_Slider); - sph_p0_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Reference Density (p0): "); - sph_p0_Slider->SetSize(XMFLOAT2(360, itemheight)); - sph_p0_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_p0_Slider->OnSlide([&](wiEventArgs args) { + sph_p0_Slider.Create(0.1f, 100.0f, 1.0f, 100000, "SPH Reference Density (p0): "); + sph_p0_Slider.SetSize(XMFLOAT2(360, itemheight)); + sph_p0_Slider.SetPos(XMFLOAT2(x, y += step)); + sph_p0_Slider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SPH_p0 = args.fValue; } }); - sph_p0_Slider->SetEnabled(false); - sph_p0_Slider->SetTooltip("Set the SPH parameter: reference density"); - emitterWindow->AddWidget(sph_p0_Slider); + sph_p0_Slider.SetEnabled(false); + sph_p0_Slider.SetTooltip("Set the SPH parameter: reference density"); + AddWidget(&sph_p0_Slider); - sph_e_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Viscosity (e): "); - sph_e_Slider->SetSize(XMFLOAT2(360, itemheight)); - sph_e_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_e_Slider->OnSlide([&](wiEventArgs args) { + sph_e_Slider.Create(0.1f, 100.0f, 1.0f, 100000, "SPH Viscosity (e): "); + sph_e_Slider.SetSize(XMFLOAT2(360, itemheight)); + sph_e_Slider.SetPos(XMFLOAT2(x, y += step)); + sph_e_Slider.OnSlide([&](wiEventArgs args) { auto emitter = GetEmitter(); if (emitter != nullptr) { emitter->SPH_e = args.fValue; } }); - sph_e_Slider->SetEnabled(false); - sph_e_Slider->SetTooltip("Set the SPH parameter: viscosity constant"); - emitterWindow->AddWidget(sph_e_Slider); + sph_e_Slider.SetEnabled(false); + sph_e_Slider.SetTooltip("Set the SPH parameter: viscosity constant"); + AddWidget(&sph_e_Slider); - emitterWindow->Translate(XMFLOAT3(200, 50, 0)); - emitterWindow->SetVisible(false); + Translate(XMFLOAT3(200, 50, 0)); + SetVisible(false); SetEntity(entity); } -EmitterWindow::~EmitterWindow() -{ - emitterWindow->RemoveWidgets(true); - GUI->RemoveWidget(emitterWindow); - delete emitterWindow; -} - void EmitterWindow::SetEntity(Entity entity) { this->entity = entity; @@ -548,100 +539,100 @@ void EmitterWindow::SetEntity(Entity entity) if (emitter != nullptr) { - emitterNameField->SetEnabled(true); - restartButton->SetEnabled(true); - shaderTypeComboBox->SetEnabled(true); - meshComboBox->SetEnabled(true); - debugCheckBox->SetEnabled(true); - volumeCheckBox->SetEnabled(true); - frameBlendingCheckBox->SetEnabled(true); - sortCheckBox->SetEnabled(true); - depthCollisionsCheckBox->SetEnabled(true); - sphCheckBox->SetEnabled(true); - pauseCheckBox->SetEnabled(true); - maxParticlesSlider->SetEnabled(true); - emitCountSlider->SetEnabled(true); - emitSizeSlider->SetEnabled(true); - emitRotationSlider->SetEnabled(true); - emitNormalSlider->SetEnabled(true); - emitScalingSlider->SetEnabled(true); - emitLifeSlider->SetEnabled(true); - emitRandomnessSlider->SetEnabled(true); - emitLifeRandomnessSlider->SetEnabled(true); - emitMotionBlurSlider->SetEnabled(true); - emitMassSlider->SetEnabled(true); - timestepSlider->SetEnabled(true); - sph_h_Slider->SetEnabled(true); - sph_K_Slider->SetEnabled(true); - sph_p0_Slider->SetEnabled(true); - sph_e_Slider->SetEnabled(true); + emitterNameField.SetEnabled(true); + restartButton.SetEnabled(true); + shaderTypeComboBox.SetEnabled(true); + meshComboBox.SetEnabled(true); + debugCheckBox.SetEnabled(true); + volumeCheckBox.SetEnabled(true); + frameBlendingCheckBox.SetEnabled(true); + sortCheckBox.SetEnabled(true); + depthCollisionsCheckBox.SetEnabled(true); + sphCheckBox.SetEnabled(true); + pauseCheckBox.SetEnabled(true); + maxParticlesSlider.SetEnabled(true); + emitCountSlider.SetEnabled(true); + emitSizeSlider.SetEnabled(true); + emitRotationSlider.SetEnabled(true); + emitNormalSlider.SetEnabled(true); + emitScalingSlider.SetEnabled(true); + emitLifeSlider.SetEnabled(true); + emitRandomnessSlider.SetEnabled(true); + emitLifeRandomnessSlider.SetEnabled(true); + emitMotionBlurSlider.SetEnabled(true); + emitMassSlider.SetEnabled(true); + timestepSlider.SetEnabled(true); + sph_h_Slider.SetEnabled(true); + sph_K_Slider.SetEnabled(true); + sph_p0_Slider.SetEnabled(true); + sph_e_Slider.SetEnabled(true); - shaderTypeComboBox->SetSelected((int)emitter->shaderType); + shaderTypeComboBox.SetSelected((int)emitter->shaderType); - sortCheckBox->SetCheck(emitter->IsSorted()); - depthCollisionsCheckBox->SetCheck(emitter->IsDepthCollisionEnabled()); - sphCheckBox->SetCheck(emitter->IsSPHEnabled()); - pauseCheckBox->SetCheck(emitter->IsPaused()); - volumeCheckBox->SetCheck(emitter->IsVolumeEnabled()); - frameBlendingCheckBox->SetCheck(emitter->IsFrameBlendingEnabled()); - maxParticlesSlider->SetValue((float)emitter->GetMaxParticleCount()); + sortCheckBox.SetCheck(emitter->IsSorted()); + depthCollisionsCheckBox.SetCheck(emitter->IsDepthCollisionEnabled()); + sphCheckBox.SetCheck(emitter->IsSPHEnabled()); + pauseCheckBox.SetCheck(emitter->IsPaused()); + volumeCheckBox.SetCheck(emitter->IsVolumeEnabled()); + frameBlendingCheckBox.SetCheck(emitter->IsFrameBlendingEnabled()); + maxParticlesSlider.SetValue((float)emitter->GetMaxParticleCount()); - frameRateInput->SetValue(emitter->frameRate); - framesXInput->SetValue((int)emitter->framesX); - framesYInput->SetValue((int)emitter->framesY); - frameCountInput->SetValue((int)emitter->frameCount); - frameStartInput->SetValue((int)emitter->frameStart); + frameRateInput.SetValue(emitter->frameRate); + framesXInput.SetValue((int)emitter->framesX); + framesYInput.SetValue((int)emitter->framesY); + frameCountInput.SetValue((int)emitter->frameCount); + frameStartInput.SetValue((int)emitter->frameStart); - emitCountSlider->SetValue(emitter->count); - emitSizeSlider->SetValue(emitter->size); - emitRotationSlider->SetValue(emitter->rotation); - emitNormalSlider->SetValue(emitter->normal_factor); - emitScalingSlider->SetValue(emitter->scaleX); - emitLifeSlider->SetValue(emitter->life); - emitRandomnessSlider->SetValue(emitter->random_factor); - emitLifeRandomnessSlider->SetValue(emitter->random_life); - emitMotionBlurSlider->SetValue(emitter->motionBlurAmount); - emitMassSlider->SetValue(emitter->mass); - timestepSlider->SetValue(emitter->FIXED_TIMESTEP); + emitCountSlider.SetValue(emitter->count); + emitSizeSlider.SetValue(emitter->size); + emitRotationSlider.SetValue(emitter->rotation); + emitNormalSlider.SetValue(emitter->normal_factor); + emitScalingSlider.SetValue(emitter->scaleX); + emitLifeSlider.SetValue(emitter->life); + emitRandomnessSlider.SetValue(emitter->random_factor); + emitLifeRandomnessSlider.SetValue(emitter->random_life); + emitMotionBlurSlider.SetValue(emitter->motionBlurAmount); + emitMassSlider.SetValue(emitter->mass); + timestepSlider.SetValue(emitter->FIXED_TIMESTEP); - sph_h_Slider->SetValue(emitter->SPH_h); - sph_K_Slider->SetValue(emitter->SPH_K); - sph_p0_Slider->SetValue(emitter->SPH_p0); - sph_e_Slider->SetValue(emitter->SPH_e); + sph_h_Slider.SetValue(emitter->SPH_h); + sph_K_Slider.SetValue(emitter->SPH_K); + sph_p0_Slider.SetValue(emitter->SPH_p0); + sph_e_Slider.SetValue(emitter->SPH_e); - debugCheckBox->SetCheck(emitter->IsDebug()); + debugCheckBox.SetCheck(emitter->IsDebug()); } else { - infoLabel->SetText("No emitter object selected."); + infoLabel.SetText("No emitter object selected."); - emitterNameField->SetEnabled(false); - restartButton->SetEnabled(false); - shaderTypeComboBox->SetEnabled(false); - meshComboBox->SetEnabled(false); - debugCheckBox->SetEnabled(false); - volumeCheckBox->SetEnabled(false); - frameBlendingCheckBox->SetEnabled(false); - sortCheckBox->SetEnabled(false); - depthCollisionsCheckBox->SetEnabled(false); - sphCheckBox->SetEnabled(false); - pauseCheckBox->SetEnabled(false); - maxParticlesSlider->SetEnabled(false); - emitCountSlider->SetEnabled(false); - emitSizeSlider->SetEnabled(false); - emitRotationSlider->SetEnabled(false); - emitNormalSlider->SetEnabled(false); - emitScalingSlider->SetEnabled(false); - emitLifeSlider->SetEnabled(false); - emitRandomnessSlider->SetEnabled(false); - emitLifeRandomnessSlider->SetEnabled(false); - emitMotionBlurSlider->SetEnabled(false); - emitMassSlider->SetEnabled(false); - timestepSlider->SetEnabled(false); - sph_h_Slider->SetEnabled(false); - sph_K_Slider->SetEnabled(false); - sph_p0_Slider->SetEnabled(false); - sph_e_Slider->SetEnabled(false); + emitterNameField.SetEnabled(false); + restartButton.SetEnabled(false); + shaderTypeComboBox.SetEnabled(false); + meshComboBox.SetEnabled(false); + debugCheckBox.SetEnabled(false); + volumeCheckBox.SetEnabled(false); + frameBlendingCheckBox.SetEnabled(false); + sortCheckBox.SetEnabled(false); + depthCollisionsCheckBox.SetEnabled(false); + sphCheckBox.SetEnabled(false); + pauseCheckBox.SetEnabled(false); + maxParticlesSlider.SetEnabled(false); + emitCountSlider.SetEnabled(false); + emitSizeSlider.SetEnabled(false); + emitRotationSlider.SetEnabled(false); + emitNormalSlider.SetEnabled(false); + emitScalingSlider.SetEnabled(false); + emitLifeSlider.SetEnabled(false); + emitRandomnessSlider.SetEnabled(false); + emitLifeRandomnessSlider.SetEnabled(false); + emitMotionBlurSlider.SetEnabled(false); + emitMassSlider.SetEnabled(false); + timestepSlider.SetEnabled(false); + sph_h_Slider.SetEnabled(false); + sph_K_Slider.SetEnabled(false); + sph_p0_Slider.SetEnabled(false); + sph_e_Slider.SetEnabled(false); } } @@ -669,17 +660,17 @@ void EmitterWindow::UpdateData() Scene& scene = wiScene::GetScene(); - meshComboBox->ClearItems(); - meshComboBox->AddItem("NO MESH"); + meshComboBox.ClearItems(); + meshComboBox.AddItem("NO MESH"); for (size_t i = 0; i < scene.meshes.GetCount(); ++i) { Entity entity = scene.meshes.GetEntity(i); const NameComponent& name = *scene.names.GetComponent(entity); - meshComboBox->AddItem(name.name); + meshComboBox.AddItem(name.name); if (emitter->meshID == entity) { - meshComboBox->SetSelected((int)i + 1); + meshComboBox.SetSelected((int)i + 1); } } @@ -697,7 +688,7 @@ void EmitterWindow::UpdateData() ss << "Dead Particle Count = " << data.deadCount << endl; ss << "GPU Emit count = " << data.realEmitCount << endl; - infoLabel->SetText(ss.str()); + infoLabel.SetText(ss.str()); - emitterNameField->SetText(name->name); + emitterNameField.SetText(name->name); } diff --git a/Editor/EmitterWindow.h b/Editor/EmitterWindow.h index 65cfc5b66..fc0ac69d7 100644 --- a/Editor/EmitterWindow.h +++ b/Editor/EmitterWindow.h @@ -1,23 +1,14 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiButton; +#include "WickedEngine.h" class EditorComponent; class MaterialWindow; -class EmitterWindow +class EmitterWindow : public wiWindow { public: - EmitterWindow(EditorComponent* editor); - ~EmitterWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); @@ -26,45 +17,41 @@ public: wiScene::wiEmittedParticle* GetEmitter(); - wiGUI* GUI; + wiTextInputField emitterNameField; + wiButton addButton; + wiButton restartButton; + wiComboBox meshComboBox; + wiComboBox shaderTypeComboBox; + wiLabel infoLabel; + wiSlider maxParticlesSlider; + wiCheckBox sortCheckBox; + wiCheckBox depthCollisionsCheckBox; + wiCheckBox sphCheckBox; + wiCheckBox pauseCheckBox; + wiCheckBox debugCheckBox; + wiCheckBox volumeCheckBox; + wiCheckBox frameBlendingCheckBox; + wiSlider emitCountSlider; + wiSlider emitSizeSlider; + wiSlider emitRotationSlider; + wiSlider emitNormalSlider; + wiSlider emitScalingSlider; + wiSlider emitLifeSlider; + wiSlider emitRandomnessSlider; + wiSlider emitLifeRandomnessSlider; + wiSlider emitMotionBlurSlider; + wiSlider emitMassSlider; + wiSlider timestepSlider; + wiSlider sph_h_Slider; + wiSlider sph_K_Slider; + wiSlider sph_p0_Slider; + wiSlider sph_e_Slider; - wiWindow* emitterWindow; - - wiTextInputField* emitterNameField; - wiButton* addButton; - wiButton* restartButton; - wiComboBox* meshComboBox; - wiComboBox* shaderTypeComboBox; - wiLabel* infoLabel; - wiSlider* maxParticlesSlider; - wiCheckBox* sortCheckBox; - wiCheckBox* depthCollisionsCheckBox; - wiCheckBox* sphCheckBox; - wiCheckBox* pauseCheckBox; - wiCheckBox* debugCheckBox; - wiCheckBox* volumeCheckBox; - wiCheckBox* frameBlendingCheckBox; - wiSlider* emitCountSlider; - wiSlider* emitSizeSlider; - wiSlider* emitRotationSlider; - wiSlider* emitNormalSlider; - wiSlider* emitScalingSlider; - wiSlider* emitLifeSlider; - wiSlider* emitRandomnessSlider; - wiSlider* emitLifeRandomnessSlider; - wiSlider* emitMotionBlurSlider; - wiSlider* emitMassSlider; - wiSlider* timestepSlider; - wiSlider* sph_h_Slider; - wiSlider* sph_K_Slider; - wiSlider* sph_p0_Slider; - wiSlider* sph_e_Slider; - - wiTextInputField* frameRateInput; - wiTextInputField* framesXInput; - wiTextInputField* framesYInput; - wiTextInputField* frameCountInput; - wiTextInputField* frameStartInput; + wiTextInputField frameRateInput; + wiTextInputField framesXInput; + wiTextInputField framesYInput; + wiTextInputField frameCountInput; + wiTextInputField frameStartInput; }; diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp index d79ed1de9..a4d97fc99 100644 --- a/Editor/EnvProbeWindow.cpp +++ b/Editor/EnvProbeWindow.cpp @@ -5,20 +5,17 @@ using namespace wiECS; using namespace wiScene; -EnvProbeWindow::EnvProbeWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void EnvProbeWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - envProbeWindow = new wiWindow(GUI, "Environment Probe Window"); - envProbeWindow->SetSize(XMFLOAT2(300, 200)); - GUI->AddWidget(envProbeWindow); + wiWindow::Create("Environment Probe Window"); + SetSize(XMFLOAT2(300, 200)); float x = 100, y = 5, step = 35; - realTimeCheckBox = new wiCheckBox("RealTime: "); - realTimeCheckBox->SetPos(XMFLOAT2(x, y += step)); - realTimeCheckBox->SetEnabled(false); - realTimeCheckBox->OnClick([&](wiEventArgs args) { + realTimeCheckBox.Create("RealTime: "); + realTimeCheckBox.SetPos(XMFLOAT2(x, y += step)); + realTimeCheckBox.SetEnabled(false); + realTimeCheckBox.OnClick([&](wiEventArgs args) { EnvironmentProbeComponent* probe = wiScene::GetScene().probes.GetComponent(entity); if (probe != nullptr) { @@ -26,36 +23,37 @@ EnvProbeWindow::EnvProbeWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) probe->SetDirty(); } }); - envProbeWindow->AddWidget(realTimeCheckBox); + AddWidget(&realTimeCheckBox); - generateButton = new wiButton("Put"); - generateButton->SetPos(XMFLOAT2(x, y += step)); - generateButton->OnClick([=](wiEventArgs args) { + generateButton.Create("Put"); + generateButton.SetPos(XMFLOAT2(x, y += step)); + generateButton.OnClick([=](wiEventArgs args) { XMFLOAT3 pos; XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::GetCamera().GetEye(), wiRenderer::GetCamera().GetAt() * 4)); Entity entity = wiScene::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); - envProbeWindow->AddWidget(generateButton); + AddWidget(&generateButton); - refreshButton = new wiButton("Refresh"); - refreshButton->SetPos(XMFLOAT2(x, y += step)); - refreshButton->SetEnabled(false); - refreshButton->OnClick([&](wiEventArgs args) { + refreshButton.Create("Refresh"); + refreshButton.SetPos(XMFLOAT2(x, y += step)); + refreshButton.SetEnabled(false); + refreshButton.OnClick([&](wiEventArgs args) { EnvironmentProbeComponent* probe = wiScene::GetScene().probes.GetComponent(entity); if (probe != nullptr) { probe->SetDirty(); } }); - envProbeWindow->AddWidget(refreshButton); + AddWidget(&refreshButton); - refreshAllButton = new wiButton("Refresh All"); - refreshAllButton->SetPos(XMFLOAT2(x, y += step)); - refreshAllButton->SetEnabled(true); - refreshAllButton->OnClick([&](wiEventArgs args) { + refreshAllButton.Create("Refresh All"); + refreshAllButton.SetPos(XMFLOAT2(x, y += step)); + refreshAllButton.SetEnabled(true); + refreshAllButton.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); for (size_t i = 0; i < scene.probes.GetCount(); ++i) { @@ -63,25 +61,17 @@ EnvProbeWindow::EnvProbeWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) probe.SetDirty(); } }); - envProbeWindow->AddWidget(refreshAllButton); + AddWidget(&refreshAllButton); - envProbeWindow->Translate(XMFLOAT3(100, 100, 0)); - envProbeWindow->SetVisible(false); + Translate(XMFLOAT3(100, 100, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -EnvProbeWindow::~EnvProbeWindow() -{ - envProbeWindow->RemoveWidgets(true); - GUI->RemoveWidget(envProbeWindow); - delete envProbeWindow; -} - void EnvProbeWindow::SetEntity(Entity entity) { this->entity = entity; @@ -90,14 +80,14 @@ void EnvProbeWindow::SetEntity(Entity entity) if (probe == nullptr) { - realTimeCheckBox->SetEnabled(false); - refreshButton->SetEnabled(false); + realTimeCheckBox.SetEnabled(false); + refreshButton.SetEnabled(false); } else { - realTimeCheckBox->SetCheck(probe->IsRealTime()); - realTimeCheckBox->SetEnabled(true); - refreshButton->SetEnabled(true); + realTimeCheckBox.SetCheck(probe->IsRealTime()); + realTimeCheckBox.SetEnabled(true); + refreshButton.SetEnabled(true); } } diff --git a/Editor/EnvProbeWindow.h b/Editor/EnvProbeWindow.h index ea2d5c8e9..aa2b44313 100644 --- a/Editor/EnvProbeWindow.h +++ b/Editor/EnvProbeWindow.h @@ -1,29 +1,19 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; +#include "WickedEngine.h" class EditorComponent; -class EnvProbeWindow +class EnvProbeWindow : public wiWindow { public: - EnvProbeWindow(EditorComponent* editor); - ~EnvProbeWindow(); - - wiGUI* GUI; + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiWindow* envProbeWindow; - - wiCheckBox* realTimeCheckBox; - wiButton* generateButton; - wiButton* refreshButton; - wiButton* refreshAllButton; + wiCheckBox realTimeCheckBox; + wiButton generateButton; + wiButton refreshButton; + wiButton refreshAllButton; }; diff --git a/Editor/ForceFieldWindow.cpp b/Editor/ForceFieldWindow.cpp index d8d44a2f3..9f08cc4ac 100644 --- a/Editor/ForceFieldWindow.cpp +++ b/Editor/ForceFieldWindow.cpp @@ -6,28 +6,25 @@ using namespace wiECS; using namespace wiScene; -ForceFieldWindow::ForceFieldWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void ForceFieldWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - forceFieldWindow = new wiWindow(GUI, "Force Field Window"); - forceFieldWindow->SetSize(XMFLOAT2(420, 120)); - GUI->AddWidget(forceFieldWindow); + wiWindow::Create("Force Field Window"); + SetSize(XMFLOAT2(420, 120)); float x = 150; float y = 10; float hei = 18; float step = hei + 2; - addButton = new wiButton("Add Force Field"); - addButton->SetSize(XMFLOAT2(150, hei)); - addButton->SetPos(XMFLOAT2(x, y += step)); - addButton->OnClick([=](wiEventArgs args) { + addButton.Create("Add Force Field"); + addButton.SetSize(XMFLOAT2(150, hei)); + addButton.SetPos(XMFLOAT2(x, y += step)); + addButton.OnClick([=](wiEventArgs args) { Entity entity = wiScene::GetScene().Entity_CreateForce("editorForce"); ForceFieldComponent* force = wiScene::GetScene().forces.GetComponent(entity); if (force != nullptr) { - switch (typeComboBox->GetSelected()) + switch (typeComboBox.GetSelected()) { case 0: force->type = ENTITY_TYPE_FORCEFIELD_POINT; @@ -41,6 +38,7 @@ ForceFieldWindow::ForceFieldWindow(EditorComponent* editor) : GUI(&editor->GetGU } editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); } else @@ -48,14 +46,14 @@ ForceFieldWindow::ForceFieldWindow(EditorComponent* editor) : GUI(&editor->GetGU assert(0); } }); - addButton->SetEnabled(true); - addButton->SetTooltip("Add new Force Field to the simulation."); - forceFieldWindow->AddWidget(addButton); + addButton.SetEnabled(true); + addButton.SetTooltip("Add new Force Field to the simulation."); + AddWidget(&addButton); - typeComboBox = new wiComboBox("Force Field type: "); - typeComboBox->SetPos(XMFLOAT2(x, y += step)); - typeComboBox->SetSize(XMFLOAT2(200, hei)); - typeComboBox->OnSelect([&](wiEventArgs args) { + typeComboBox.Create("Force Field type: "); + typeComboBox.SetPos(XMFLOAT2(x, y += step)); + typeComboBox.SetSize(XMFLOAT2(200, hei)); + typeComboBox.OnSelect([&](wiEventArgs args) { ForceFieldComponent* force = wiScene::GetScene().forces.GetComponent(entity); if (force != nullptr && args.iValue >= 0) { @@ -73,58 +71,50 @@ ForceFieldWindow::ForceFieldWindow(EditorComponent* editor) : GUI(&editor->GetGU } } }); - typeComboBox->AddItem("Point"); - typeComboBox->AddItem("Plane"); - typeComboBox->SetEnabled(false); - typeComboBox->SetTooltip("Choose the force field type."); - forceFieldWindow->AddWidget(typeComboBox); + typeComboBox.AddItem("Point"); + typeComboBox.AddItem("Plane"); + typeComboBox.SetEnabled(false); + typeComboBox.SetTooltip("Choose the force field type."); + AddWidget(&typeComboBox); - gravitySlider = new wiSlider(-10, 10, 0, 100000, "Gravity: "); - gravitySlider->SetSize(XMFLOAT2(200, hei)); - gravitySlider->SetPos(XMFLOAT2(x, y += step)); - gravitySlider->OnSlide([&](wiEventArgs args) { + gravitySlider.Create(-10, 10, 0, 100000, "Gravity: "); + gravitySlider.SetSize(XMFLOAT2(200, hei)); + gravitySlider.SetPos(XMFLOAT2(x, y += step)); + gravitySlider.OnSlide([&](wiEventArgs args) { ForceFieldComponent* force = wiScene::GetScene().forces.GetComponent(entity); if (force != nullptr) { force->gravity = args.fValue; } }); - gravitySlider->SetEnabled(false); - gravitySlider->SetTooltip("Set the amount of gravity. Positive values attract, negatives deflect."); - forceFieldWindow->AddWidget(gravitySlider); + gravitySlider.SetEnabled(false); + gravitySlider.SetTooltip("Set the amount of gravity. Positive values attract, negatives deflect."); + AddWidget(&gravitySlider); - rangeSlider = new wiSlider(0.0f, 100.0f, 10, 100000, "Range: "); - rangeSlider->SetSize(XMFLOAT2(200, hei)); - rangeSlider->SetPos(XMFLOAT2(x, y += step)); - rangeSlider->OnSlide([&](wiEventArgs args) { + rangeSlider.Create(0.0f, 100.0f, 10, 100000, "Range: "); + rangeSlider.SetSize(XMFLOAT2(200, hei)); + rangeSlider.SetPos(XMFLOAT2(x, y += step)); + rangeSlider.OnSlide([&](wiEventArgs args) { ForceFieldComponent* force = wiScene::GetScene().forces.GetComponent(entity); if (force != nullptr) { force->range_local = args.fValue; } }); - rangeSlider->SetEnabled(false); - rangeSlider->SetTooltip("Set the range of affection."); - forceFieldWindow->AddWidget(rangeSlider); + rangeSlider.SetEnabled(false); + rangeSlider.SetTooltip("Set the range of affection."); + AddWidget(&rangeSlider); - forceFieldWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 50, 0)); - forceFieldWindow->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 50, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -ForceFieldWindow::~ForceFieldWindow() -{ - forceFieldWindow->RemoveWidgets(true); - GUI->RemoveWidget(forceFieldWindow); - delete forceFieldWindow; -} - void ForceFieldWindow::SetEntity(Entity entity) { this->entity = entity; @@ -133,19 +123,19 @@ void ForceFieldWindow::SetEntity(Entity entity) if (force != nullptr) { - typeComboBox->SetSelected(force->type == ENTITY_TYPE_FORCEFIELD_POINT ? 0 : 1); - gravitySlider->SetValue(force->gravity); - rangeSlider->SetValue(force->range_local); + typeComboBox.SetSelected(force->type == ENTITY_TYPE_FORCEFIELD_POINT ? 0 : 1); + gravitySlider.SetValue(force->gravity); + rangeSlider.SetValue(force->range_local); - gravitySlider->SetEnabled(true); - rangeSlider->SetEnabled(true); + gravitySlider.SetEnabled(true); + rangeSlider.SetEnabled(true); } else { - gravitySlider->SetEnabled(false); - rangeSlider->SetEnabled(false); + gravitySlider.SetEnabled(false); + rangeSlider.SetEnabled(false); } - addButton->SetEnabled(true); + addButton.SetEnabled(true); } diff --git a/Editor/ForceFieldWindow.h b/Editor/ForceFieldWindow.h index 24a2fe300..06491e967 100644 --- a/Editor/ForceFieldWindow.h +++ b/Editor/ForceFieldWindow.h @@ -1,31 +1,19 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; +#include "WickedEngine.h" class EditorComponent; -class ForceFieldWindow +class ForceFieldWindow : public wiWindow { public: - ForceFieldWindow(EditorComponent* editor); - ~ForceFieldWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* forceFieldWindow; - - wiComboBox* typeComboBox; - wiSlider* gravitySlider; - wiSlider* rangeSlider; - wiButton* addButton; + wiComboBox typeComboBox; + wiSlider gravitySlider; + wiSlider rangeSlider; + wiButton addButton; }; diff --git a/Editor/HairParticleWindow.cpp b/Editor/HairParticleWindow.cpp index fc1e96c1c..87bc59b63 100644 --- a/Editor/HairParticleWindow.cpp +++ b/Editor/HairParticleWindow.cpp @@ -6,13 +6,10 @@ using namespace std; using namespace wiECS; using namespace wiScene; -HairParticleWindow::HairParticleWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void HairParticleWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - hairWindow = new wiWindow(GUI, "Hair Particle System Window"); - hairWindow->SetSize(XMFLOAT2(600, 260)); - GUI->AddWidget(hairWindow); + wiWindow::Create("Hair Particle System Window"); + SetSize(XMFLOAT2(600, 260)); float x = 160; float y = 10; @@ -20,24 +17,25 @@ HairParticleWindow::HairParticleWindow(EditorComponent* editor) : GUI(&editor->G float step = hei + 2; - addButton = new wiButton("Add Hair Particle System"); - addButton->SetPos(XMFLOAT2(x, y += step)); - addButton->SetSize(XMFLOAT2(200, hei)); - addButton->OnClick([=](wiEventArgs args) { + addButton.Create("Add Hair Particle System"); + addButton.SetPos(XMFLOAT2(x, y += step)); + addButton.SetSize(XMFLOAT2(200, hei)); + addButton.OnClick([=](wiEventArgs args) { Scene& scene = wiScene::GetScene(); Entity entity = scene.Entity_CreateHair("editorHair"); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); - addButton->SetTooltip("Add new hair particle system."); - hairWindow->AddWidget(addButton); + addButton.SetTooltip("Add new hair particle system."); + AddWidget(&addButton); - meshComboBox = new wiComboBox("Mesh: "); - meshComboBox->SetSize(XMFLOAT2(300, hei)); - meshComboBox->SetPos(XMFLOAT2(x, y += step)); - meshComboBox->SetEnabled(false); - meshComboBox->OnSelect([&](wiEventArgs args) { + meshComboBox.Create("Mesh: "); + meshComboBox.SetSize(XMFLOAT2(300, hei)); + meshComboBox.SetPos(XMFLOAT2(x, y += step)); + meshComboBox.SetEnabled(false); + meshComboBox.OnSelect([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { @@ -52,185 +50,178 @@ HairParticleWindow::HairParticleWindow(EditorComponent* editor) : GUI(&editor->G } } }); - meshComboBox->SetTooltip("Choose a mesh where hair will grow from..."); - hairWindow->AddWidget(meshComboBox); + meshComboBox.SetTooltip("Choose a mesh where hair will grow from..."); + AddWidget(&meshComboBox); - countSlider = new wiSlider(0, 100000, 1000, 100000, "Strand Count: "); - countSlider->SetSize(XMFLOAT2(360, hei)); - countSlider->SetPos(XMFLOAT2(x, y += step)); - countSlider->OnSlide([&](wiEventArgs args) { + countSlider.Create(0, 100000, 1000, 100000, "Strand Count: "); + countSlider.SetSize(XMFLOAT2(360, hei)); + countSlider.SetPos(XMFLOAT2(x, y += step)); + countSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->strandCount = (uint32_t)args.iValue; } }); - countSlider->SetEnabled(false); - countSlider->SetTooltip("Set hair strand count"); - hairWindow->AddWidget(countSlider); + countSlider.SetEnabled(false); + countSlider.SetTooltip("Set hair strand count"); + AddWidget(&countSlider); - lengthSlider = new wiSlider(0, 4, 1, 100000, "Particle Length: "); - lengthSlider->SetSize(XMFLOAT2(360, hei)); - lengthSlider->SetPos(XMFLOAT2(x, y += step)); - lengthSlider->OnSlide([&](wiEventArgs args) { + lengthSlider.Create(0, 4, 1, 100000, "Particle Length: "); + lengthSlider.SetSize(XMFLOAT2(360, hei)); + lengthSlider.SetPos(XMFLOAT2(x, y += step)); + lengthSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->length = args.fValue; } }); - lengthSlider->SetEnabled(false); - lengthSlider->SetTooltip("Set hair strand length"); - hairWindow->AddWidget(lengthSlider); + lengthSlider.SetEnabled(false); + lengthSlider.SetTooltip("Set hair strand length"); + AddWidget(&lengthSlider); - stiffnessSlider = new wiSlider(0, 20, 5, 100000, "Particle Stiffness: "); - stiffnessSlider->SetSize(XMFLOAT2(360, hei)); - stiffnessSlider->SetPos(XMFLOAT2(x, y += step)); - stiffnessSlider->OnSlide([&](wiEventArgs args) { + stiffnessSlider.Create(0, 20, 5, 100000, "Particle Stiffness: "); + stiffnessSlider.SetSize(XMFLOAT2(360, hei)); + stiffnessSlider.SetPos(XMFLOAT2(x, y += step)); + stiffnessSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->stiffness = args.fValue; } }); - stiffnessSlider->SetEnabled(false); - stiffnessSlider->SetTooltip("Set hair strand stiffness, how much it tries to get back to rest position."); - hairWindow->AddWidget(stiffnessSlider); + stiffnessSlider.SetEnabled(false); + stiffnessSlider.SetTooltip("Set hair strand stiffness, how much it tries to get back to rest position."); + AddWidget(&stiffnessSlider); - randomnessSlider = new wiSlider(0, 1, 0.2f, 100000, "Particle Randomness: "); - randomnessSlider->SetSize(XMFLOAT2(360, hei)); - randomnessSlider->SetPos(XMFLOAT2(x, y += step)); - randomnessSlider->OnSlide([&](wiEventArgs args) { + randomnessSlider.Create(0, 1, 0.2f, 100000, "Particle Randomness: "); + randomnessSlider.SetSize(XMFLOAT2(360, hei)); + randomnessSlider.SetPos(XMFLOAT2(x, y += step)); + randomnessSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->randomness = args.fValue; } }); - randomnessSlider->SetEnabled(false); - randomnessSlider->SetTooltip("Set hair length randomization factor. This will affect randomness of hair lengths."); - hairWindow->AddWidget(randomnessSlider); + randomnessSlider.SetEnabled(false); + randomnessSlider.SetTooltip("Set hair length randomization factor. This will affect randomness of hair lengths."); + AddWidget(&randomnessSlider); - segmentcountSlider = new wiSlider(1, 10, 1, 9, "Segment Count: "); - segmentcountSlider->SetSize(XMFLOAT2(360, hei)); - segmentcountSlider->SetPos(XMFLOAT2(x, y += step)); - segmentcountSlider->OnSlide([&](wiEventArgs args) { + segmentcountSlider.Create(1, 10, 1, 9, "Segment Count: "); + segmentcountSlider.SetSize(XMFLOAT2(360, hei)); + segmentcountSlider.SetPos(XMFLOAT2(x, y += step)); + segmentcountSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->segmentCount = (uint32_t)args.iValue; } }); - segmentcountSlider->SetEnabled(false); - segmentcountSlider->SetTooltip("Set hair strand segment count. This will affect simulation quality and performance."); - hairWindow->AddWidget(segmentcountSlider); + segmentcountSlider.SetEnabled(false); + segmentcountSlider.SetTooltip("Set hair strand segment count. This will affect simulation quality and performance."); + AddWidget(&segmentcountSlider); - randomSeedSlider = new wiSlider(1, 12345, 1, 12344, "Random seed: "); - randomSeedSlider->SetSize(XMFLOAT2(360, hei)); - randomSeedSlider->SetPos(XMFLOAT2(x, y += step)); - randomSeedSlider->OnSlide([&](wiEventArgs args) { + randomSeedSlider.Create(1, 12345, 1, 12344, "Random seed: "); + randomSeedSlider.SetSize(XMFLOAT2(360, hei)); + randomSeedSlider.SetPos(XMFLOAT2(x, y += step)); + randomSeedSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->randomSeed = (uint32_t)args.iValue; } }); - randomSeedSlider->SetEnabled(false); - randomSeedSlider->SetTooltip("Set hair system-wide random seed value. This will affect hair patch placement randomization."); - hairWindow->AddWidget(randomSeedSlider); + randomSeedSlider.SetEnabled(false); + randomSeedSlider.SetTooltip("Set hair system-wide random seed value. This will affect hair patch placement randomization."); + AddWidget(&randomSeedSlider); - viewDistanceSlider = new wiSlider(0, 1000, 100, 10000, "View distance: "); - viewDistanceSlider->SetSize(XMFLOAT2(360, hei)); - viewDistanceSlider->SetPos(XMFLOAT2(x, y += step)); - viewDistanceSlider->OnSlide([&](wiEventArgs args) { + viewDistanceSlider.Create(0, 1000, 100, 10000, "View distance: "); + viewDistanceSlider.SetSize(XMFLOAT2(360, hei)); + viewDistanceSlider.SetPos(XMFLOAT2(x, y += step)); + viewDistanceSlider.OnSlide([&](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->viewDistance = args.fValue; } }); - viewDistanceSlider->SetEnabled(false); - viewDistanceSlider->SetTooltip("Set view distance. After this, particles will be faded out."); - hairWindow->AddWidget(viewDistanceSlider); + viewDistanceSlider.SetEnabled(false); + viewDistanceSlider.SetTooltip("Set view distance. After this, particles will be faded out."); + AddWidget(&viewDistanceSlider); - framesXInput = new wiTextInputField(""); - framesXInput->SetPos(XMFLOAT2(x, y += step)); - framesXInput->SetSize(XMFLOAT2(40, hei)); - framesXInput->SetText(""); - framesXInput->SetTooltip("How many horizontal frames there are in the spritesheet."); - framesXInput->SetDescription("Frames X: "); - framesXInput->OnInputAccepted([this](wiEventArgs args) { + framesXInput.Create(""); + framesXInput.SetPos(XMFLOAT2(x, y += step)); + framesXInput.SetSize(XMFLOAT2(40, hei)); + framesXInput.SetText(""); + framesXInput.SetTooltip("How many horizontal frames there are in the spritesheet."); + framesXInput.SetDescription("Frames X: "); + framesXInput.OnInputAccepted([this](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->framesX = (uint32_t)args.iValue; } }); - hairWindow->AddWidget(framesXInput); + AddWidget(&framesXInput); - framesYInput = new wiTextInputField(""); - framesYInput->SetPos(XMFLOAT2(x + 250, y)); - framesYInput->SetSize(XMFLOAT2(40, hei)); - framesYInput->SetText(""); - framesYInput->SetTooltip("How many vertical frames there are in the spritesheet."); - framesYInput->SetDescription("Frames Y: "); - framesYInput->OnInputAccepted([this](wiEventArgs args) { + framesYInput.Create(""); + framesYInput.SetPos(XMFLOAT2(x + 250, y)); + framesYInput.SetSize(XMFLOAT2(40, hei)); + framesYInput.SetText(""); + framesYInput.SetTooltip("How many vertical frames there are in the spritesheet."); + framesYInput.SetDescription("Frames Y: "); + framesYInput.OnInputAccepted([this](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->framesY = (uint32_t)args.iValue; } }); - hairWindow->AddWidget(framesYInput); + AddWidget(&framesYInput); step = 20; - frameCountInput = new wiTextInputField(""); - frameCountInput->SetPos(XMFLOAT2(x, y += step)); - frameCountInput->SetSize(XMFLOAT2(40, hei)); - frameCountInput->SetText(""); - frameCountInput->SetTooltip("Enter a value to enable the random sprite sheet frame selection's max frame number."); - frameCountInput->SetDescription("Frame Count: "); - frameCountInput->OnInputAccepted([this](wiEventArgs args) { + frameCountInput.Create(""); + frameCountInput.SetPos(XMFLOAT2(x, y += step)); + frameCountInput.SetSize(XMFLOAT2(40, hei)); + frameCountInput.SetText(""); + frameCountInput.SetTooltip("Enter a value to enable the random sprite sheet frame selection's max frame number."); + frameCountInput.SetDescription("Frame Count: "); + frameCountInput.OnInputAccepted([this](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->frameCount = (uint32_t)args.iValue; } }); - hairWindow->AddWidget(frameCountInput); + AddWidget(&frameCountInput); - frameStartInput = new wiTextInputField(""); - frameStartInput->SetPos(XMFLOAT2(x + 250, y)); - frameStartInput->SetSize(XMFLOAT2(40, hei)); - frameStartInput->SetText(""); - frameStartInput->SetTooltip("Specifies the first frame of the sheet that can be used."); - frameStartInput->SetDescription("First Frame: "); - frameStartInput->OnInputAccepted([this](wiEventArgs args) { + frameStartInput.Create(""); + frameStartInput.SetPos(XMFLOAT2(x + 250, y)); + frameStartInput.SetSize(XMFLOAT2(40, hei)); + frameStartInput.SetText(""); + frameStartInput.SetTooltip("Specifies the first frame of the sheet that can be used."); + frameStartInput.SetDescription("First Frame: "); + frameStartInput.OnInputAccepted([this](wiEventArgs args) { auto hair = GetHair(); if (hair != nullptr) { hair->frameStart = (uint32_t)args.iValue; } }); - hairWindow->AddWidget(frameStartInput); + AddWidget(&frameStartInput); - hairWindow->Translate(XMFLOAT3(200, 50, 0)); - hairWindow->SetVisible(false); + Translate(XMFLOAT3(200, 50, 0)); + SetVisible(false); SetEntity(entity); } -HairParticleWindow::~HairParticleWindow() -{ - hairWindow->RemoveWidgets(true); - GUI->RemoveWidget(hairWindow); - delete hairWindow; -} - void HairParticleWindow::SetEntity(Entity entity) { this->entity = entity; @@ -239,26 +230,26 @@ void HairParticleWindow::SetEntity(Entity entity) if (hair != nullptr) { - lengthSlider->SetValue(hair->length); - stiffnessSlider->SetValue(hair->stiffness); - randomnessSlider->SetValue(hair->randomness); - countSlider->SetValue((float)hair->strandCount); - segmentcountSlider->SetValue((float)hair->segmentCount); - randomSeedSlider->SetValue((float)hair->randomSeed); - viewDistanceSlider->SetValue(hair->viewDistance); - framesXInput->SetValue((int)hair->framesX); - framesYInput->SetValue((int)hair->framesY); - frameCountInput->SetValue((int)hair->frameCount); - frameStartInput->SetValue((int)hair->frameStart); + lengthSlider.SetValue(hair->length); + stiffnessSlider.SetValue(hair->stiffness); + randomnessSlider.SetValue(hair->randomness); + countSlider.SetValue((float)hair->strandCount); + segmentcountSlider.SetValue((float)hair->segmentCount); + randomSeedSlider.SetValue((float)hair->randomSeed); + viewDistanceSlider.SetValue(hair->viewDistance); + framesXInput.SetValue((int)hair->framesX); + framesYInput.SetValue((int)hair->framesY); + frameCountInput.SetValue((int)hair->frameCount); + frameStartInput.SetValue((int)hair->frameStart); - hairWindow->SetEnabled(true); + SetEnabled(true); } else { - hairWindow->SetEnabled(false); + SetEnabled(false); } - addButton->SetEnabled(true); + addButton.SetEnabled(true); } wiHairParticle* HairParticleWindow::GetHair() @@ -284,17 +275,17 @@ void HairParticleWindow::UpdateData() Scene& scene = wiScene::GetScene(); - meshComboBox->ClearItems(); - meshComboBox->AddItem("NO MESH"); + meshComboBox.ClearItems(); + meshComboBox.AddItem("NO MESH"); for (size_t i = 0; i < scene.meshes.GetCount(); ++i) { Entity entity = scene.meshes.GetEntity(i); const NameComponent& name = *scene.names.GetComponent(entity); - meshComboBox->AddItem(name.name); + meshComboBox.AddItem(name.name); if (emitter->meshID == entity) { - meshComboBox->SetSelected((int)i + 1); + meshComboBox.SetSelected((int)i + 1); } } } diff --git a/Editor/HairParticleWindow.h b/Editor/HairParticleWindow.h index e4b424733..dc12a70e9 100644 --- a/Editor/HairParticleWindow.h +++ b/Editor/HairParticleWindow.h @@ -1,24 +1,14 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiButton; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; class MaterialWindow; -class HairParticleWindow +class HairParticleWindow : public wiWindow { public: - HairParticleWindow(EditorComponent* editor); - ~HairParticleWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); @@ -27,23 +17,19 @@ public: wiScene::wiHairParticle* GetHair(); - wiGUI* GUI; - - wiWindow* hairWindow; - - wiButton* addButton; - wiComboBox* meshComboBox; - wiSlider* lengthSlider; - wiSlider* stiffnessSlider; - wiSlider* randomnessSlider; - wiSlider* countSlider; - wiSlider* segmentcountSlider; - wiSlider* randomSeedSlider; - wiSlider* viewDistanceSlider; - wiTextInputField* framesXInput; - wiTextInputField* framesYInput; - wiTextInputField* frameCountInput; - wiTextInputField* frameStartInput; + wiButton addButton; + wiComboBox meshComboBox; + wiSlider lengthSlider; + wiSlider stiffnessSlider; + wiSlider randomnessSlider; + wiSlider countSlider; + wiSlider segmentcountSlider; + wiSlider randomSeedSlider; + wiSlider viewDistanceSlider; + wiTextInputField framesXInput; + wiTextInputField framesYInput; + wiTextInputField frameCountInput; + wiTextInputField frameStartInput; }; diff --git a/Editor/IKWindow.cpp b/Editor/IKWindow.cpp index 769fd969b..cdfa39624 100644 --- a/Editor/IKWindow.cpp +++ b/Editor/IKWindow.cpp @@ -6,13 +6,10 @@ using namespace wiECS; using namespace wiScene; -IKWindow::IKWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void IKWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - window = new wiWindow(GUI, "Inverse Kinematics (IK) Window"); - window->SetSize(XMFLOAT2(400, 150)); - GUI->AddWidget(window); + wiWindow::Create("Inverse Kinematics (IK) Window"); + SetSize(XMFLOAT2(400, 150)); float x = 120; float y = 10; @@ -20,17 +17,17 @@ IKWindow::IKWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) float hei = 18; float step = hei + 2; - createButton = new wiButton("Create"); - createButton->SetTooltip("Create/Remove IK Component to selected entity"); - createButton->SetPos(XMFLOAT2(x, y += step)); - createButton->SetSize(XMFLOAT2(siz, hei)); - window->AddWidget(createButton); + createButton.Create("Create"); + createButton.SetTooltip("Create/Remove IK Component to selected entity"); + createButton.SetPos(XMFLOAT2(x, y += step)); + createButton.SetSize(XMFLOAT2(siz, hei)); + AddWidget(&createButton); - targetCombo = new wiComboBox("Target: "); - targetCombo->SetSize(XMFLOAT2(siz, hei)); - targetCombo->SetPos(XMFLOAT2(x, y += step)); - targetCombo->SetEnabled(false); - targetCombo->OnSelect([&](wiEventArgs args) { + targetCombo.Create("Target: "); + targetCombo.SetSize(XMFLOAT2(siz, hei)); + targetCombo.SetPos(XMFLOAT2(x, y += step)); + targetCombo.SetEnabled(false); + targetCombo.OnSelect([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); InverseKinematicsComponent* ik = scene.inverse_kinematics.GetComponent(entity); if (ik != nullptr) @@ -45,50 +42,42 @@ IKWindow::IKWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - targetCombo->SetTooltip("Choose a target entity (with transform) that the IK will follow"); - window->AddWidget(targetCombo); + targetCombo.SetTooltip("Choose a target entity (with transform) that the IK will follow"); + AddWidget(&targetCombo); - disabledCheckBox = new wiCheckBox("Disabled: "); - disabledCheckBox->SetTooltip("Disable simulation."); - disabledCheckBox->SetPos(XMFLOAT2(x, y += step)); - disabledCheckBox->SetSize(XMFLOAT2(hei, hei)); - disabledCheckBox->OnClick([=](wiEventArgs args) { + disabledCheckBox.Create("Disabled: "); + disabledCheckBox.SetTooltip("Disable simulation."); + disabledCheckBox.SetPos(XMFLOAT2(x, y += step)); + disabledCheckBox.SetSize(XMFLOAT2(hei, hei)); + disabledCheckBox.OnClick([=](wiEventArgs args) { wiScene::GetScene().inverse_kinematics.GetComponent(entity)->SetDisabled(args.bValue); }); - window->AddWidget(disabledCheckBox); + AddWidget(&disabledCheckBox); - chainLengthSlider = new wiSlider(0, 10, 0, 10, "Chain Length: "); - chainLengthSlider->SetTooltip("How far the hierarchy chain is simulated backwards from this entity"); - chainLengthSlider->SetPos(XMFLOAT2(x, y += step)); - chainLengthSlider->SetSize(XMFLOAT2(siz, hei)); - chainLengthSlider->OnSlide([&](wiEventArgs args) { + chainLengthSlider.Create(0, 10, 0, 10, "Chain Length: "); + chainLengthSlider.SetTooltip("How far the hierarchy chain is simulated backwards from this entity"); + chainLengthSlider.SetPos(XMFLOAT2(x, y += step)); + chainLengthSlider.SetSize(XMFLOAT2(siz, hei)); + chainLengthSlider.OnSlide([&](wiEventArgs args) { wiScene::GetScene().inverse_kinematics.GetComponent(entity)->chain_length = args.iValue; }); - window->AddWidget(chainLengthSlider); + AddWidget(&chainLengthSlider); - iterationCountSlider = new wiSlider(0, 10, 1, 10, "Iteration Count: "); - iterationCountSlider->SetTooltip("How many iterations to compute the inverse kinematics for. Higher values are slower but more accurate."); - iterationCountSlider->SetPos(XMFLOAT2(x, y += step)); - iterationCountSlider->SetSize(XMFLOAT2(siz, hei)); - iterationCountSlider->OnSlide([&](wiEventArgs args) { + iterationCountSlider.Create(0, 10, 1, 10, "Iteration Count: "); + iterationCountSlider.SetTooltip("How many iterations to compute the inverse kinematics for. Higher values are slower but more accurate."); + iterationCountSlider.SetPos(XMFLOAT2(x, y += step)); + iterationCountSlider.SetSize(XMFLOAT2(siz, hei)); + iterationCountSlider.OnSlide([&](wiEventArgs args) { wiScene::GetScene().inverse_kinematics.GetComponent(entity)->iteration_count = args.iValue; }); - window->AddWidget(iterationCountSlider); + AddWidget(&iterationCountSlider); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 740, 150, 0)); - window->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 740, 150, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -IKWindow::~IKWindow() -{ - window->RemoveWidgets(true); - GUI->RemoveWidget(window); - delete window; -} - void IKWindow::SetEntity(Entity entity) { this->entity = entity; @@ -98,48 +87,48 @@ void IKWindow::SetEntity(Entity entity) if (ik != nullptr) { - window->SetEnabled(true); + SetEnabled(true); - disabledCheckBox->SetCheck(ik->IsDisabled()); - chainLengthSlider->SetValue((float)ik->chain_length); - iterationCountSlider->SetValue((float)ik->iteration_count); + disabledCheckBox.SetCheck(ik->IsDisabled()); + chainLengthSlider.SetValue((float)ik->chain_length); + iterationCountSlider.SetValue((float)ik->iteration_count); - targetCombo->ClearItems(); - targetCombo->AddItem("NO TARGET"); + targetCombo.ClearItems(); + targetCombo.AddItem("NO TARGET"); for (size_t i = 0; i < scene.transforms.GetCount(); ++i) { Entity entity = scene.transforms.GetEntity(i); const NameComponent* name = scene.names.GetComponent(entity); - targetCombo->AddItem(name == nullptr ? std::to_string(entity) : name->name); + targetCombo.AddItem(name == nullptr ? std::to_string(entity) : name->name); if (ik->target == entity) { - targetCombo->SetSelected((int)i + 1); + targetCombo.SetSelected((int)i + 1); } } } else { - window->SetEnabled(false); + SetEnabled(false); } const TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { - createButton->SetEnabled(true); + createButton.SetEnabled(true); if (ik == nullptr) { - createButton->SetText("Create"); - createButton->OnClick([=](wiEventArgs args) { + createButton.SetText("Create"); + createButton.OnClick([=](wiEventArgs args) { wiScene::GetScene().inverse_kinematics.Create(entity).chain_length = 1; SetEntity(entity); }); } else { - createButton->SetText("Remove"); - createButton->OnClick([=](wiEventArgs args) { + createButton.SetText("Remove"); + createButton.OnClick([=](wiEventArgs args) { wiScene::GetScene().inverse_kinematics.Remove_KeepSorted(entity); SetEntity(entity); }); diff --git a/Editor/IKWindow.h b/Editor/IKWindow.h index 195b7bbe7..5ae99cef0 100644 --- a/Editor/IKWindow.h +++ b/Editor/IKWindow.h @@ -1,32 +1,20 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; +#include "WickedEngine.h" class EditorComponent; -class IKWindow +class IKWindow : public wiWindow { public: - IKWindow(EditorComponent* editor); - ~IKWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* window; - - wiButton* createButton; - wiComboBox* targetCombo; - wiCheckBox* disabledCheckBox; - wiSlider* chainLengthSlider; - wiSlider* iterationCountSlider; + wiButton createButton; + wiComboBox targetCombo; + wiCheckBox disabledCheckBox; + wiSlider chainLengthSlider; + wiSlider iterationCountSlider; }; diff --git a/Editor/LayerWindow.cpp b/Editor/LayerWindow.cpp index eff487a71..b7b5fbae9 100644 --- a/Editor/LayerWindow.cpp +++ b/Editor/LayerWindow.cpp @@ -6,13 +6,10 @@ using namespace wiECS; using namespace wiScene; -LayerWindow::LayerWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void LayerWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - window = new wiWindow(GUI, "Layer Window"); - window->SetSize(XMFLOAT2(410, 160)); - GUI->AddWidget(window); + wiWindow::Create("Layer Window"); + SetSize(XMFLOAT2(410, 160)); float x = 30; float y = 0; @@ -21,10 +18,10 @@ LayerWindow::LayerWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) for (uint32_t i = 0; i < arraysize(layers); ++i) { - layers[i] = new wiCheckBox(""); - layers[i]->SetText(std::to_string(i) + ": "); - layers[i]->SetPos(XMFLOAT2(x + (i % 8) * 50, y + (i / 8 + 1) * step)); - layers[i]->OnClick([=](wiEventArgs args) { + layers[i].Create(""); + layers[i].SetText(std::to_string(i) + ": "); + layers[i].SetPos(XMFLOAT2(x + (i % 8) * 50, y + (i / 8 + 1) * step)); + layers[i].OnClick([=](wiEventArgs args) { LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); if (layer == nullptr) @@ -42,70 +39,63 @@ LayerWindow::LayerWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } }); - window->AddWidget(layers[i]); + AddWidget(&layers[i]); } y += step * 5; - enableAllButton = new wiButton("Enable ALL"); - enableAllButton->SetPos(XMFLOAT2(x, y)); - enableAllButton->OnClick([this](wiEventArgs args) { + enableAllButton.Create("Enable ALL"); + enableAllButton.SetPos(XMFLOAT2(x, y)); + enableAllButton.OnClick([this](wiEventArgs args) { LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); if (layer == nullptr) return; layer->layerMask = ~0; }); - window->AddWidget(enableAllButton); + AddWidget(&enableAllButton); - enableNoneButton = new wiButton("Enable NONE"); - enableNoneButton->SetPos(XMFLOAT2(x + 120, y)); - enableNoneButton->OnClick([this](wiEventArgs args) { + enableNoneButton.Create("Enable NONE"); + enableNoneButton.SetPos(XMFLOAT2(x + 120, y)); + enableNoneButton.OnClick([this](wiEventArgs args) { LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); if (layer == nullptr) return; layer->layerMask = 0; }); - window->AddWidget(enableNoneButton); + AddWidget(&enableNoneButton); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 450, 300, 0)); - window->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 450, 300, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } -LayerWindow::~LayerWindow() -{ - window->RemoveWidgets(true); - GUI->RemoveWidget(window); - delete window; -} - void LayerWindow::SetEntity(Entity entity) { this->entity = entity; if (entity != INVALID_ENTITY) { - window->SetEnabled(true); + SetEnabled(true); LayerComponent* layer = wiScene::GetScene().layers.GetComponent(entity); if (layer == nullptr) { for (uint32_t i = 0; i < 32; ++i) { - layers[i]->SetCheck(true); + layers[i].SetCheck(true); } } else { for (uint32_t i = 0; i < 32; ++i) { - layers[i]->SetCheck(layer->GetLayerMask() & 1 << i); + layers[i].SetCheck(layer->GetLayerMask() & 1 << i); } } } else { - window->SetEnabled(false); + SetEnabled(false); } } diff --git a/Editor/LayerWindow.h b/Editor/LayerWindow.h index 57b82f34c..97d009316 100644 --- a/Editor/LayerWindow.h +++ b/Editor/LayerWindow.h @@ -1,31 +1,18 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class LayerWindow +class LayerWindow : public wiWindow { public: - LayerWindow(EditorComponent* editor); - ~LayerWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* window; - - wiCheckBox* layers[32]; - wiButton* enableAllButton; - wiButton* enableNoneButton; + wiCheckBox layers[32]; + wiButton enableAllButton; + wiButton enableNoneButton; }; diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 353f5895c..5c6736afd 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -9,184 +9,182 @@ using namespace wiGraphics; using namespace wiScene; -LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void LightWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - lightWindow = new wiWindow(GUI, "Light Window"); - lightWindow->SetSize(XMFLOAT2(650, 500)); - GUI->AddWidget(lightWindow); + wiWindow::Create("Light Window"); + SetSize(XMFLOAT2(650, 500)); float x = 450; float y = 0; float hei = 18; float step = hei + 2; - energySlider = new wiSlider(0.1f, 64, 0, 100000, "Energy: "); - energySlider->SetSize(XMFLOAT2(100, hei)); - energySlider->SetPos(XMFLOAT2(x, y += step)); - energySlider->OnSlide([&](wiEventArgs args) { + energySlider.Create(0.1f, 64, 0, 100000, "Energy: "); + energySlider.SetSize(XMFLOAT2(100, hei)); + energySlider.SetPos(XMFLOAT2(x, y += step)); + energySlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->energy = args.fValue; } }); - energySlider->SetEnabled(false); - energySlider->SetTooltip("Adjust the light radiation amount inside the maximum range"); - lightWindow->AddWidget(energySlider); + energySlider.SetEnabled(false); + energySlider.SetTooltip("Adjust the light radiation amount inside the maximum range"); + AddWidget(&energySlider); - rangeSlider = new wiSlider(1, 1000, 0, 100000, "Range: "); - rangeSlider->SetSize(XMFLOAT2(100, hei)); - rangeSlider->SetPos(XMFLOAT2(x, y += step)); - rangeSlider->OnSlide([&](wiEventArgs args) { + rangeSlider.Create(1, 1000, 0, 100000, "Range: "); + rangeSlider.SetSize(XMFLOAT2(100, hei)); + rangeSlider.SetPos(XMFLOAT2(x, y += step)); + rangeSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->range_local = args.fValue; } }); - rangeSlider->SetEnabled(false); - rangeSlider->SetTooltip("Adjust the maximum range the light can affect."); - lightWindow->AddWidget(rangeSlider); + rangeSlider.SetEnabled(false); + rangeSlider.SetTooltip("Adjust the maximum range the light can affect."); + AddWidget(&rangeSlider); - radiusSlider = new wiSlider(0.01f, 10, 0, 100000, "Radius: "); - radiusSlider->SetSize(XMFLOAT2(100, hei)); - radiusSlider->SetPos(XMFLOAT2(x, y += step)); - radiusSlider->OnSlide([&](wiEventArgs args) { + radiusSlider.Create(0.01f, 10, 0, 100000, "Radius: "); + radiusSlider.SetSize(XMFLOAT2(100, hei)); + radiusSlider.SetPos(XMFLOAT2(x, y += step)); + radiusSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->radius = args.fValue; } }); - radiusSlider->SetEnabled(false); - radiusSlider->SetTooltip("Adjust the radius of an area light."); - lightWindow->AddWidget(radiusSlider); + radiusSlider.SetEnabled(false); + radiusSlider.SetTooltip("Adjust the radius of an area light."); + AddWidget(&radiusSlider); - widthSlider = new wiSlider(1, 10, 0, 100000, "Width: "); - widthSlider->SetSize(XMFLOAT2(100, hei)); - widthSlider->SetPos(XMFLOAT2(x, y += step)); - widthSlider->OnSlide([&](wiEventArgs args) { + widthSlider.Create(1, 10, 0, 100000, "Width: "); + widthSlider.SetSize(XMFLOAT2(100, hei)); + widthSlider.SetPos(XMFLOAT2(x, y += step)); + widthSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->width = args.fValue; } }); - widthSlider->SetEnabled(false); - widthSlider->SetTooltip("Adjust the width of an area light."); - lightWindow->AddWidget(widthSlider); + widthSlider.SetEnabled(false); + widthSlider.SetTooltip("Adjust the width of an area light."); + AddWidget(&widthSlider); - heightSlider = new wiSlider(1, 10, 0, 100000, "Height: "); - heightSlider->SetSize(XMFLOAT2(100, hei)); - heightSlider->SetPos(XMFLOAT2(x, y += step)); - heightSlider->OnSlide([&](wiEventArgs args) { + heightSlider.Create(1, 10, 0, 100000, "Height: "); + heightSlider.SetSize(XMFLOAT2(100, hei)); + heightSlider.SetPos(XMFLOAT2(x, y += step)); + heightSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->height = args.fValue; } }); - heightSlider->SetEnabled(false); - heightSlider->SetTooltip("Adjust the height of an area light."); - lightWindow->AddWidget(heightSlider); + heightSlider.SetEnabled(false); + heightSlider.SetTooltip("Adjust the height of an area light."); + AddWidget(&heightSlider); - fovSlider = new wiSlider(0.1f, XM_PI - 0.01f, 0, 100000, "FOV: "); - fovSlider->SetSize(XMFLOAT2(100, hei)); - fovSlider->SetPos(XMFLOAT2(x, y += step)); - fovSlider->OnSlide([&](wiEventArgs args) { + fovSlider.Create(0.1f, XM_PI - 0.01f, 0, 100000, "FOV: "); + fovSlider.SetSize(XMFLOAT2(100, hei)); + fovSlider.SetPos(XMFLOAT2(x, y += step)); + fovSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->fov = args.fValue; } }); - fovSlider->SetEnabled(false); - fovSlider->SetTooltip("Adjust the cone aperture for spotlight."); - lightWindow->AddWidget(fovSlider); + fovSlider.SetEnabled(false); + fovSlider.SetTooltip("Adjust the cone aperture for spotlight."); + AddWidget(&fovSlider); - biasSlider = new wiSlider(0.0f, 0.2f, 0, 100000, "ShadowBias: "); - biasSlider->SetSize(XMFLOAT2(100, hei)); - biasSlider->SetPos(XMFLOAT2(x, y += step)); - biasSlider->OnSlide([&](wiEventArgs args) { + biasSlider.Create(0.0f, 0.2f, 0, 100000, "ShadowBias: "); + biasSlider.SetSize(XMFLOAT2(100, hei)); + biasSlider.SetPos(XMFLOAT2(x, y += step)); + biasSlider.OnSlide([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->shadowBias = args.fValue; } }); - biasSlider->SetEnabled(false); - biasSlider->SetTooltip("Adjust the shadow bias if shadow artifacts occur."); - lightWindow->AddWidget(biasSlider); + biasSlider.SetEnabled(false); + biasSlider.SetTooltip("Adjust the shadow bias if shadow artifacts occur."); + AddWidget(&biasSlider); - shadowCheckBox = new wiCheckBox("Shadow: "); - shadowCheckBox->SetSize(XMFLOAT2(hei, hei)); - shadowCheckBox->SetPos(XMFLOAT2(x, y += step)); - shadowCheckBox->OnClick([&](wiEventArgs args) { + shadowCheckBox.Create("Shadow: "); + shadowCheckBox.SetSize(XMFLOAT2(hei, hei)); + shadowCheckBox.SetPos(XMFLOAT2(x, y += step)); + shadowCheckBox.OnClick([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetCastShadow(args.bValue); } }); - shadowCheckBox->SetEnabled(false); - shadowCheckBox->SetTooltip("Set light as shadow caster. Many shadow casters can affect performance!"); - lightWindow->AddWidget(shadowCheckBox); + shadowCheckBox.SetEnabled(false); + shadowCheckBox.SetTooltip("Set light as shadow caster. Many shadow casters can affect performance!"); + AddWidget(&shadowCheckBox); - volumetricsCheckBox = new wiCheckBox("Volumetric: "); - volumetricsCheckBox->SetSize(XMFLOAT2(hei, hei)); - volumetricsCheckBox->SetPos(XMFLOAT2(x, y += step)); - volumetricsCheckBox->OnClick([&](wiEventArgs args) { + volumetricsCheckBox.Create("Volumetric: "); + volumetricsCheckBox.SetSize(XMFLOAT2(hei, hei)); + volumetricsCheckBox.SetPos(XMFLOAT2(x, y += step)); + volumetricsCheckBox.OnClick([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetVolumetricsEnabled(args.bValue); } }); - volumetricsCheckBox->SetEnabled(false); - volumetricsCheckBox->SetTooltip("Compute volumetric light scattering effect. \nThe fog settings affect scattering (see Weather window). If there is no fog, there is no scattering."); - lightWindow->AddWidget(volumetricsCheckBox); + volumetricsCheckBox.SetEnabled(false); + volumetricsCheckBox.SetTooltip("Compute volumetric light scattering effect. \nThe fog settings affect scattering (see Weather window). If there is no fog, there is no scattering."); + AddWidget(&volumetricsCheckBox); - haloCheckBox = new wiCheckBox("Visualizer: "); - haloCheckBox->SetSize(XMFLOAT2(hei, hei)); - haloCheckBox->SetPos(XMFLOAT2(x, y += step)); - haloCheckBox->OnClick([&](wiEventArgs args) { + haloCheckBox.Create("Visualizer: "); + haloCheckBox.SetSize(XMFLOAT2(hei, hei)); + haloCheckBox.SetPos(XMFLOAT2(x, y += step)); + haloCheckBox.OnClick([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetVisualizerEnabled(args.bValue); } }); - haloCheckBox->SetEnabled(false); - haloCheckBox->SetTooltip("Visualize light source emission"); - lightWindow->AddWidget(haloCheckBox); + haloCheckBox.SetEnabled(false); + haloCheckBox.SetTooltip("Visualize light source emission"); + AddWidget(&haloCheckBox); - staticCheckBox = new wiCheckBox("Static: "); - staticCheckBox->SetSize(XMFLOAT2(hei, hei)); - staticCheckBox->SetPos(XMFLOAT2(x, y += step)); - staticCheckBox->OnClick([&](wiEventArgs args) { + staticCheckBox.Create("Static: "); + staticCheckBox.SetSize(XMFLOAT2(hei, hei)); + staticCheckBox.SetPos(XMFLOAT2(x, y += step)); + staticCheckBox.OnClick([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetStatic(args.bValue); } }); - staticCheckBox->SetEnabled(false); - staticCheckBox->SetTooltip("Static lights will only be used for baking into lightmaps."); - lightWindow->AddWidget(staticCheckBox); + staticCheckBox.SetEnabled(false); + staticCheckBox.SetTooltip("Static lights will only be used for baking into lightmaps."); + AddWidget(&staticCheckBox); - addLightButton = new wiButton("Add Light"); - addLightButton->SetPos(XMFLOAT2(x, y += step)); - addLightButton->SetSize(XMFLOAT2(150, hei)); - addLightButton->OnClick([=](wiEventArgs args) { + addLightButton.Create("Add Light"); + addLightButton.SetPos(XMFLOAT2(x, y += step)); + addLightButton.SetSize(XMFLOAT2(150, hei)); + addLightButton.OnClick([=](wiEventArgs args) { Entity entity = wiScene::GetScene().Entity_CreateLight("editorLight", XMFLOAT3(0, 3, 0), XMFLOAT3(1, 1, 1), 2, 60); LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { - light->type = (LightComponent::LightType)typeSelectorComboBox->GetSelected(); + light->type = (LightComponent::LightType)typeSelectorComboBox.GetSelected(); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); } else @@ -194,45 +192,45 @@ LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) assert(0); } }); - addLightButton->SetTooltip("Add a light to the scene."); - lightWindow->AddWidget(addLightButton); + addLightButton.SetTooltip("Add a light to the scene."); + AddWidget(&addLightButton); - colorPicker = new wiColorPicker(GUI, "Light Color", false); - colorPicker->SetPos(XMFLOAT2(10, 30)); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(false); - colorPicker->OnColorChanged([&](wiEventArgs args) { + colorPicker.Create("Light Color", false); + colorPicker.SetPos(XMFLOAT2(10, 30)); + colorPicker.SetVisible(true); + colorPicker.SetEnabled(false); + colorPicker.OnColorChanged([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->color = args.color.toFloat3(); } }); - lightWindow->AddWidget(colorPicker); + AddWidget(&colorPicker); - typeSelectorComboBox = new wiComboBox("Type: "); - typeSelectorComboBox->SetSize(XMFLOAT2(150, hei)); - typeSelectorComboBox->SetPos(XMFLOAT2(x, y += step)); - typeSelectorComboBox->OnSelect([&](wiEventArgs args) { + typeSelectorComboBox.Create("Type: "); + typeSelectorComboBox.SetSize(XMFLOAT2(150, hei)); + typeSelectorComboBox.SetPos(XMFLOAT2(x, y += step)); + typeSelectorComboBox.OnSelect([&](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light != nullptr && args.iValue >= 0) { light->SetType((LightComponent::LightType)args.iValue); SetLightType(light->GetType()); - biasSlider->SetValue(light->shadowBias); + biasSlider.SetValue(light->shadowBias); } }); - typeSelectorComboBox->AddItem("Directional"); - typeSelectorComboBox->AddItem("Point"); - typeSelectorComboBox->AddItem("Spot"); - typeSelectorComboBox->AddItem("Sphere"); - typeSelectorComboBox->AddItem("Disc"); - typeSelectorComboBox->AddItem("Rectangle"); - typeSelectorComboBox->AddItem("Tube"); - typeSelectorComboBox->SetTooltip("Choose the light source type..."); - typeSelectorComboBox->SetSelected((int)LightComponent::POINT); - lightWindow->AddWidget(typeSelectorComboBox); + typeSelectorComboBox.AddItem("Directional"); + typeSelectorComboBox.AddItem("Point"); + typeSelectorComboBox.AddItem("Spot"); + typeSelectorComboBox.AddItem("Sphere"); + typeSelectorComboBox.AddItem("Disc"); + typeSelectorComboBox.AddItem("Rectangle"); + typeSelectorComboBox.AddItem("Tube"); + typeSelectorComboBox.SetTooltip("Choose the light source type..."); + typeSelectorComboBox.SetSelected((int)LightComponent::POINT); + AddWidget(&typeSelectorComboBox); @@ -241,19 +239,19 @@ LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) hei = 20; step = hei + 2; - lensflare_Label = new wiLabel("Lens flare textures: "); - lensflare_Label->SetPos(XMFLOAT2(x, y += step)); - lensflare_Label->SetSize(XMFLOAT2(140, hei)); - lightWindow->AddWidget(lensflare_Label); + lensflare_Label.Create("Lens flare textures: "); + lensflare_Label.SetPos(XMFLOAT2(x, y += step)); + lensflare_Label.SetSize(XMFLOAT2(140, hei)); + AddWidget(&lensflare_Label); for (size_t i = 0; i < arraysize(lensflare_Button); ++i) { - lensflare_Button[i] = new wiButton("LensFlareSlot"); - lensflare_Button[i]->SetText(""); - lensflare_Button[i]->SetTooltip("Load a lensflare texture to this slot"); - lensflare_Button[i]->SetPos(XMFLOAT2(x, y += step)); - lensflare_Button[i]->SetSize(XMFLOAT2(260, hei)); - lensflare_Button[i]->OnClick([=](wiEventArgs args) { + lensflare_Button[i].Create("LensFlareSlot"); + lensflare_Button[i].SetText(""); + lensflare_Button[i].SetTooltip("Load a lensflare texture to this slot"); + lensflare_Button[i].SetPos(XMFLOAT2(x, y += step)); + lensflare_Button[i].SetSize(XMFLOAT2(260, hei)); + lensflare_Button[i].OnClick([=](wiEventArgs args) { LightComponent* light = wiScene::GetScene().lights.GetComponent(entity); if (light == nullptr) return; @@ -268,7 +266,7 @@ LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) { light->lensFlareNames[i] = ""; light->lensFlareRimTextures[i] = nullptr; - lensflare_Button[i]->SetText(""); + lensflare_Button[i].SetText(""); } else { @@ -283,29 +281,21 @@ LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { light->lensFlareRimTextures[i] = wiResourceManager::Load(fileName); light->lensFlareNames[i] = fileName; - lensflare_Button[i]->SetText(wiHelper::GetFileNameFromPath(fileName)); + lensflare_Button[i].SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - lightWindow->AddWidget(lensflare_Button[i]); + AddWidget(&lensflare_Button[i]); } - lightWindow->Translate(XMFLOAT3(120, 30, 0)); - lightWindow->SetVisible(false); + Translate(XMFLOAT3(120, 30, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -LightWindow::~LightWindow() -{ - lightWindow->RemoveWidgets(true); - GUI->RemoveWidget(lightWindow); - delete lightWindow; -} - void LightWindow::SetEntity(Entity entity) { this->entity = entity; @@ -314,26 +304,26 @@ void LightWindow::SetEntity(Entity entity) if (light != nullptr) { - energySlider->SetEnabled(true); - energySlider->SetValue(light->energy); - rangeSlider->SetValue(light->range_local); - radiusSlider->SetValue(light->radius); - widthSlider->SetValue(light->width); - heightSlider->SetValue(light->height); - fovSlider->SetValue(light->fov); - biasSlider->SetEnabled(true); - biasSlider->SetValue(light->shadowBias); - shadowCheckBox->SetEnabled(true); - shadowCheckBox->SetCheck(light->IsCastingShadow()); - haloCheckBox->SetEnabled(true); - haloCheckBox->SetCheck(light->IsVisualizerEnabled()); - volumetricsCheckBox->SetEnabled(true); - volumetricsCheckBox->SetCheck(light->IsVolumetricsEnabled()); - staticCheckBox->SetEnabled(true); - staticCheckBox->SetCheck(light->IsStatic()); - colorPicker->SetEnabled(true); - colorPicker->SetPickColor(wiColor::fromFloat3(light->color)); - typeSelectorComboBox->SetSelected((int)light->GetType()); + energySlider.SetEnabled(true); + energySlider.SetValue(light->energy); + rangeSlider.SetValue(light->range_local); + radiusSlider.SetValue(light->radius); + widthSlider.SetValue(light->width); + heightSlider.SetValue(light->height); + fovSlider.SetValue(light->fov); + biasSlider.SetEnabled(true); + biasSlider.SetValue(light->shadowBias); + shadowCheckBox.SetEnabled(true); + shadowCheckBox.SetCheck(light->IsCastingShadow()); + haloCheckBox.SetEnabled(true); + haloCheckBox.SetCheck(light->IsVisualizerEnabled()); + volumetricsCheckBox.SetEnabled(true); + volumetricsCheckBox.SetCheck(light->IsVolumetricsEnabled()); + staticCheckBox.SetEnabled(true); + staticCheckBox.SetCheck(light->IsStatic()); + colorPicker.SetEnabled(true); + colorPicker.SetPickColor(wiColor::fromFloat3(light->color)); + typeSelectorComboBox.SetSelected((int)light->GetType()); SetLightType(light->GetType()); @@ -341,33 +331,33 @@ void LightWindow::SetEntity(Entity entity) { if (light->lensFlareRimTextures.size() > i && light->lensFlareRimTextures[i] && !light->lensFlareNames[i].empty()) { - lensflare_Button[i]->SetText(light->lensFlareNames[i]); + lensflare_Button[i].SetText(light->lensFlareNames[i]); } else { - lensflare_Button[i]->SetText(""); + lensflare_Button[i].SetText(""); } - lensflare_Button[i]->SetEnabled(true); + lensflare_Button[i].SetEnabled(true); } } else { - rangeSlider->SetEnabled(false); - radiusSlider->SetEnabled(false); - widthSlider->SetEnabled(false); - heightSlider->SetEnabled(false); - fovSlider->SetEnabled(false); - biasSlider->SetEnabled(false); - shadowCheckBox->SetEnabled(false); - haloCheckBox->SetEnabled(false); - volumetricsCheckBox->SetEnabled(false); - staticCheckBox->SetEnabled(false); - energySlider->SetEnabled(false); - colorPicker->SetEnabled(false); + rangeSlider.SetEnabled(false); + radiusSlider.SetEnabled(false); + widthSlider.SetEnabled(false); + heightSlider.SetEnabled(false); + fovSlider.SetEnabled(false); + biasSlider.SetEnabled(false); + shadowCheckBox.SetEnabled(false); + haloCheckBox.SetEnabled(false); + volumetricsCheckBox.SetEnabled(false); + staticCheckBox.SetEnabled(false); + energySlider.SetEnabled(false); + colorPicker.SetEnabled(false); for (size_t i = 0; i < arraysize(lensflare_Button); ++i) { - lensflare_Button[i]->SetEnabled(false); + lensflare_Button[i].SetEnabled(false); } } } @@ -375,32 +365,32 @@ void LightWindow::SetLightType(LightComponent::LightType type) { if (type == LightComponent::DIRECTIONAL) { - rangeSlider->SetEnabled(false); - fovSlider->SetEnabled(false); + rangeSlider.SetEnabled(false); + fovSlider.SetEnabled(false); } else { if (type == LightComponent::SPHERE || type == LightComponent::DISC || type == LightComponent::RECTANGLE || type == LightComponent::TUBE) { - rangeSlider->SetEnabled(false); - radiusSlider->SetEnabled(true); - widthSlider->SetEnabled(true); - heightSlider->SetEnabled(true); - fovSlider->SetEnabled(false); + rangeSlider.SetEnabled(false); + radiusSlider.SetEnabled(true); + widthSlider.SetEnabled(true); + heightSlider.SetEnabled(true); + fovSlider.SetEnabled(false); } else { - rangeSlider->SetEnabled(true); - radiusSlider->SetEnabled(false); - widthSlider->SetEnabled(false); - heightSlider->SetEnabled(false); + rangeSlider.SetEnabled(true); + radiusSlider.SetEnabled(false); + widthSlider.SetEnabled(false); + heightSlider.SetEnabled(false); if (type == LightComponent::SPOT) { - fovSlider->SetEnabled(true); + fovSlider.SetEnabled(true); } else { - fovSlider->SetEnabled(false); + fovSlider.SetEnabled(false); } } } diff --git a/Editor/LightWindow.h b/Editor/LightWindow.h index 0c94a6b68..71ad9d156 100644 --- a/Editor/LightWindow.h +++ b/Editor/LightWindow.h @@ -1,46 +1,34 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiButton; -class wiColorPicker; -class wiComboBox; +#include "WickedEngine.h" class EditorComponent; -class LightWindow +class LightWindow : public wiWindow { public: - LightWindow(EditorComponent* editor); - ~LightWindow(); - - wiGUI* GUI; + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); void SetLightType(wiScene::LightComponent::LightType type); - wiWindow* lightWindow; - wiSlider* energySlider; - wiSlider* rangeSlider; - wiSlider* radiusSlider; - wiSlider* widthSlider; - wiSlider* heightSlider; - wiSlider* fovSlider; - wiSlider* biasSlider; - wiCheckBox* shadowCheckBox; - wiCheckBox* haloCheckBox; - wiCheckBox* volumetricsCheckBox; - wiCheckBox* staticCheckBox; - wiButton* addLightButton; - wiColorPicker* colorPicker; - wiComboBox* typeSelectorComboBox; + wiSlider energySlider; + wiSlider rangeSlider; + wiSlider radiusSlider; + wiSlider widthSlider; + wiSlider heightSlider; + wiSlider fovSlider; + wiSlider biasSlider; + wiCheckBox shadowCheckBox; + wiCheckBox haloCheckBox; + wiCheckBox volumetricsCheckBox; + wiCheckBox staticCheckBox; + wiButton addLightButton; + wiColorPicker colorPicker; + wiComboBox typeSelectorComboBox; - wiLabel* lensflare_Label; - wiButton* lensflare_Button[7]; + wiLabel lensflare_Label; + wiButton lensflare_Button[7]; }; diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index 3693dc4de..a7f408ac9 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -9,274 +9,329 @@ using namespace wiGraphics; using namespace wiECS; using namespace wiScene; -MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void MaterialWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - materialWindow = new wiWindow(GUI, "Material Window"); - materialWindow->SetSize(XMFLOAT2(700, 580)); - GUI->AddWidget(materialWindow); + wiWindow::Create("Material Window"); + SetSize(XMFLOAT2(720, 520)); float x = 670, y = 0; float hei = 18; float step = hei + 2; - waterCheckBox = new wiCheckBox("Water: "); - waterCheckBox->SetTooltip("Set material as special water material."); - waterCheckBox->SetPos(XMFLOAT2(670, y += step)); - waterCheckBox->SetSize(XMFLOAT2(hei, hei)); - waterCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - material->SetWater(args.bValue); - }); - materialWindow->AddWidget(waterCheckBox); - - planarReflCheckBox = new wiCheckBox("Planar Reflections: "); - planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); - planarReflCheckBox->SetPos(XMFLOAT2(670, y += step)); - planarReflCheckBox->SetSize(XMFLOAT2(hei, hei)); - planarReflCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - material->SetPlanarReflections(args.bValue); - }); - materialWindow->AddWidget(planarReflCheckBox); - - shadowCasterCheckBox = new wiCheckBox("Cast Shadow: "); - shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); - shadowCasterCheckBox->SetPos(XMFLOAT2(670, y += step)); - shadowCasterCheckBox->SetSize(XMFLOAT2(hei, hei)); - shadowCasterCheckBox->OnClick([&](wiEventArgs args) { + shadowCasterCheckBox.Create("Cast Shadow: "); + shadowCasterCheckBox.SetTooltip("The subset will contribute to the scene shadows if enabled."); + shadowCasterCheckBox.SetPos(XMFLOAT2(670, y += step)); + shadowCasterCheckBox.SetSize(XMFLOAT2(hei, hei)); + shadowCasterCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetCastShadow(args.bValue); }); - materialWindow->AddWidget(shadowCasterCheckBox); + AddWidget(&shadowCasterCheckBox); - flipNormalMapCheckBox = new wiCheckBox("Flip Normal Map: "); - flipNormalMapCheckBox->SetTooltip("The normal map green channel will be inverted. Useful for imported models coming from OpenGL space (such as GLTF)."); - flipNormalMapCheckBox->SetPos(XMFLOAT2(670, y += step)); - flipNormalMapCheckBox->SetSize(XMFLOAT2(hei, hei)); - flipNormalMapCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - material->SetFlipNormalMap(args.bValue); - }); - materialWindow->AddWidget(flipNormalMapCheckBox); - - useVertexColorsCheckBox = new wiCheckBox("Use vertex colors: "); - useVertexColorsCheckBox->SetTooltip("Enable if you want to render the mesh with vertex colors (must have appropriate vertex buffer)"); - useVertexColorsCheckBox->SetPos(XMFLOAT2(670, y += step)); - useVertexColorsCheckBox->SetSize(XMFLOAT2(hei, hei)); - useVertexColorsCheckBox->OnClick([&](wiEventArgs args) { + useVertexColorsCheckBox.Create("Use vertex colors: "); + useVertexColorsCheckBox.SetTooltip("Enable if you want to render the mesh with vertex colors (must have appropriate vertex buffer)"); + useVertexColorsCheckBox.SetPos(XMFLOAT2(670, y += step)); + useVertexColorsCheckBox.SetSize(XMFLOAT2(hei, hei)); + useVertexColorsCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetUseVertexColors(args.bValue); }); - materialWindow->AddWidget(useVertexColorsCheckBox); + AddWidget(&useVertexColorsCheckBox); - specularGlossinessCheckBox = new wiCheckBox("Specular-glossiness workflow: "); - specularGlossinessCheckBox->SetTooltip("If enabled, surface map will be viewed like it contains specular color (RGB) and smoothness (A)"); - specularGlossinessCheckBox->SetPos(XMFLOAT2(670, y += step)); - specularGlossinessCheckBox->SetSize(XMFLOAT2(hei, hei)); - specularGlossinessCheckBox->OnClick([&](wiEventArgs args) { + specularGlossinessCheckBox.Create("Specular-glossiness workflow: "); + specularGlossinessCheckBox.SetTooltip("If enabled, surface map will be viewed like it contains specular color (RGB) and smoothness (A)"); + specularGlossinessCheckBox.SetPos(XMFLOAT2(670, y += step)); + specularGlossinessCheckBox.SetSize(XMFLOAT2(hei, hei)); + specularGlossinessCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetUseSpecularGlossinessWorkflow(args.bValue); }); - materialWindow->AddWidget(specularGlossinessCheckBox); + AddWidget(&specularGlossinessCheckBox); - occlusionPrimaryCheckBox = new wiCheckBox("Occlusion - Primary: "); - occlusionPrimaryCheckBox->SetTooltip("If enabled, surface map's RED channel will be used as occlusion map"); - occlusionPrimaryCheckBox->SetPos(XMFLOAT2(670, y += step)); - occlusionPrimaryCheckBox->SetSize(XMFLOAT2(hei, hei)); - occlusionPrimaryCheckBox->OnClick([&](wiEventArgs args) { + occlusionPrimaryCheckBox.Create("Occlusion - Primary: "); + occlusionPrimaryCheckBox.SetTooltip("If enabled, surface map's RED channel will be used as occlusion map"); + occlusionPrimaryCheckBox.SetPos(XMFLOAT2(670, y += step)); + occlusionPrimaryCheckBox.SetSize(XMFLOAT2(hei, hei)); + occlusionPrimaryCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetOcclusionEnabled_Primary(args.bValue); }); - materialWindow->AddWidget(occlusionPrimaryCheckBox); + AddWidget(&occlusionPrimaryCheckBox); - occlusionSecondaryCheckBox = new wiCheckBox("Occlusion - Secondary: "); - occlusionSecondaryCheckBox->SetTooltip("If enabled, occlusion map's RED channel will be used as occlusion map"); - occlusionSecondaryCheckBox->SetPos(XMFLOAT2(670, y += step)); - occlusionSecondaryCheckBox->SetSize(XMFLOAT2(hei, hei)); - occlusionSecondaryCheckBox->OnClick([&](wiEventArgs args) { + occlusionSecondaryCheckBox.Create("Occlusion - Secondary: "); + occlusionSecondaryCheckBox.SetTooltip("If enabled, occlusion map's RED channel will be used as occlusion map"); + occlusionSecondaryCheckBox.SetPos(XMFLOAT2(670, y += step)); + occlusionSecondaryCheckBox.SetSize(XMFLOAT2(hei, hei)); + occlusionSecondaryCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetOcclusionEnabled_Secondary(args.bValue); }); - materialWindow->AddWidget(occlusionSecondaryCheckBox); + AddWidget(&occlusionSecondaryCheckBox); - windCheckBox = new wiCheckBox("Wind: "); - windCheckBox->SetTooltip("If enabled, vertex wind weights will affect how much wind offset affects the subset."); - windCheckBox->SetPos(XMFLOAT2(670, y += step)); - windCheckBox->SetSize(XMFLOAT2(hei, hei)); - windCheckBox->OnClick([&](wiEventArgs args) { + windCheckBox.Create("Wind: "); + windCheckBox.SetTooltip("If enabled, vertex wind weights will affect how much wind offset affects the subset."); + windCheckBox.SetPos(XMFLOAT2(670, y += step)); + windCheckBox.SetSize(XMFLOAT2(hei, hei)); + windCheckBox.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetUseWind(args.bValue); }); - materialWindow->AddWidget(windCheckBox); + AddWidget(&windCheckBox); + + + + x = 520; + float wid = 170; + + + shaderTypeComboBox.Create("Shader: "); + shaderTypeComboBox.SetTooltip("Select a shader for this material. \nCustom shaders (*) will also show up here (see wiRenderer:RegisterCustomShader() for more info.)\nNote that custom shaders (*) can't select between blend modes, as they are created with an explicit blend mode."); + shaderTypeComboBox.SetPos(XMFLOAT2(x, y += step)); + shaderTypeComboBox.SetSize(XMFLOAT2(wid, hei)); + shaderTypeComboBox.OnSelect([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + if (args.iValue >= MaterialComponent::SHADERTYPE_COUNT) + { + material->SetCustomShaderID(args.iValue - MaterialComponent::SHADERTYPE_COUNT); + blendModeComboBox.SetEnabled(false); + } + else + { + material->shaderType = (MaterialComponent::SHADERTYPE)args.iValue; + material->SetCustomShaderID(-1); + blendModeComboBox.SetEnabled(true); + } + } + }); + shaderTypeComboBox.AddItem("PBR"); + shaderTypeComboBox.AddItem("PBR + Planar reflections"); + shaderTypeComboBox.AddItem("PBR + Par. occl. mapping"); + shaderTypeComboBox.AddItem("PBR + Anisotropic"); + shaderTypeComboBox.AddItem("Water"); + shaderTypeComboBox.AddItem("Cartoon"); + shaderTypeComboBox.AddItem("Unlit"); + for (auto& x : wiRenderer::GetCustomShaders()) + { + shaderTypeComboBox.AddItem("*" + x.name); + } + shaderTypeComboBox.SetEnabled(false); + shaderTypeComboBox.SetMaxVisibleItemCount(5); + AddWidget(&shaderTypeComboBox); + + blendModeComboBox.Create("Blend mode: "); + blendModeComboBox.SetPos(XMFLOAT2(x, y += step)); + blendModeComboBox.SetSize(XMFLOAT2(wid, hei)); + blendModeComboBox.OnSelect([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr && args.iValue >= 0) + { + material->userBlendMode = (BLENDMODE)args.iValue; + } + }); + blendModeComboBox.AddItem("Opaque"); + blendModeComboBox.AddItem("Alpha"); + blendModeComboBox.AddItem("Premultiplied"); + blendModeComboBox.AddItem("Additive"); + blendModeComboBox.SetEnabled(false); + blendModeComboBox.SetTooltip("Set the blend mode of the material."); + AddWidget(&blendModeComboBox); + + sssComboBox.Create("Subsurface profile: "); + sssComboBox.SetPos(XMFLOAT2(x, y += step)); + sssComboBox.SetSize(XMFLOAT2(wid, hei)); + sssComboBox.OnSelect([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr && args.iValue >= 0) + { + material->subsurfaceProfile = (MaterialComponent::SUBSURFACE_PROFILE)args.iValue; + } + }); + sssComboBox.AddItem("Solid"); + sssComboBox.AddItem("Skin"); + sssComboBox.AddItem("Snow"); + sssComboBox.SetEnabled(false); + sssComboBox.SetTooltip("Set the subsurface profile of the material. Needs the SSS prost process enabled."); + AddWidget(&sssComboBox); + + shadingRateComboBox.Create("Shading Rate: "); + shadingRateComboBox.SetTooltip("Select shading rate for this material. \nSelecting larger shading rate will decrease rendering quality of this material, \nbut increases performance.\nDX12 only and requires Tier1 hardware support for variable shading rate"); + shadingRateComboBox.SetPos(XMFLOAT2(x, y += step)); + shadingRateComboBox.SetSize(XMFLOAT2(wid, hei)); + shadingRateComboBox.OnSelect([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->shadingRate = (SHADING_RATE)args.iValue; + } + }); + shadingRateComboBox.AddItem("1X1"); + shadingRateComboBox.AddItem("1X2"); + shadingRateComboBox.AddItem("2X1"); + shadingRateComboBox.AddItem("2X2"); + shadingRateComboBox.AddItem("2X4"); + shadingRateComboBox.AddItem("4X2"); + shadingRateComboBox.AddItem("4X4"); + shadingRateComboBox.SetEnabled(false); + shadingRateComboBox.SetMaxVisibleItemCount(4); + AddWidget(&shadingRateComboBox); + + + // Sliders: - x = 550; + wid = 150; - normalMapSlider = new wiSlider(0, 4, 1, 4000, "Normalmap: "); - normalMapSlider->SetTooltip("How much the normal map should distort the face normals (bumpiness)."); - normalMapSlider->SetSize(XMFLOAT2(100, hei)); - normalMapSlider->SetPos(XMFLOAT2(x, y += step)); - normalMapSlider->OnSlide([&](wiEventArgs args) { + normalMapSlider.Create(0, 4, 1, 4000, "Normalmap: "); + normalMapSlider.SetTooltip("How much the normal map should distort the face normals (bumpiness)."); + normalMapSlider.SetSize(XMFLOAT2(wid, hei)); + normalMapSlider.SetPos(XMFLOAT2(x, y += step)); + normalMapSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetNormalMapStrength(args.fValue); }); - materialWindow->AddWidget(normalMapSlider); + AddWidget(&normalMapSlider); - roughnessSlider = new wiSlider(0, 1, 0.5f, 1000, "Roughness: "); - roughnessSlider->SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); - roughnessSlider->SetSize(XMFLOAT2(100, hei)); - roughnessSlider->SetPos(XMFLOAT2(x, y += step)); - roughnessSlider->OnSlide([&](wiEventArgs args) { + roughnessSlider.Create(0, 1, 0.5f, 1000, "Roughness: "); + roughnessSlider.SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); + roughnessSlider.SetSize(XMFLOAT2(wid, hei)); + roughnessSlider.SetPos(XMFLOAT2(x, y += step)); + roughnessSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetRoughness(args.fValue); }); - materialWindow->AddWidget(roughnessSlider); + AddWidget(&roughnessSlider); - reflectanceSlider = new wiSlider(0, 1, 0.5f, 1000, "Reflectance: "); - reflectanceSlider->SetTooltip("Adjust the overall surface reflectivity."); - reflectanceSlider->SetSize(XMFLOAT2(100, hei)); - reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); - reflectanceSlider->OnSlide([&](wiEventArgs args) { + reflectanceSlider.Create(0, 1, 0.5f, 1000, "Reflectance: "); + reflectanceSlider.SetTooltip("Adjust the overall surface reflectivity."); + reflectanceSlider.SetSize(XMFLOAT2(wid, hei)); + reflectanceSlider.SetPos(XMFLOAT2(x, y += step)); + reflectanceSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetReflectance(args.fValue); }); - materialWindow->AddWidget(reflectanceSlider); + AddWidget(&reflectanceSlider); - metalnessSlider = new wiSlider(0, 1, 0.0f, 1000, "Metalness: "); - metalnessSlider->SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); - metalnessSlider->SetSize(XMFLOAT2(100, hei)); - metalnessSlider->SetPos(XMFLOAT2(x, y += step)); - metalnessSlider->OnSlide([&](wiEventArgs args) { + metalnessSlider.Create(0, 1, 0.0f, 1000, "Metalness: "); + metalnessSlider.SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); + metalnessSlider.SetSize(XMFLOAT2(wid, hei)); + metalnessSlider.SetPos(XMFLOAT2(x, y += step)); + metalnessSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetMetalness(args.fValue); }); - materialWindow->AddWidget(metalnessSlider); + AddWidget(&metalnessSlider); - alphaRefSlider = new wiSlider(0, 1, 1.0f, 1000, "AlphaRef: "); - alphaRefSlider->SetTooltip("Adjust the alpha cutoff threshold. Some performance optimizations will be disabled."); - alphaRefSlider->SetSize(XMFLOAT2(100, hei)); - alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); - alphaRefSlider->OnSlide([&](wiEventArgs args) { + alphaRefSlider.Create(0, 1, 1.0f, 1000, "AlphaRef: "); + alphaRefSlider.SetTooltip("Adjust the alpha cutoff threshold. Some performance optimizations will be disabled."); + alphaRefSlider.SetSize(XMFLOAT2(wid, hei)); + alphaRefSlider.SetPos(XMFLOAT2(x, y += step)); + alphaRefSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetAlphaRef(args.fValue); }); - materialWindow->AddWidget(alphaRefSlider); + AddWidget(&alphaRefSlider); - refractionIndexSlider = new wiSlider(0, 1.0f, 0.02f, 1000, "Refraction Index: "); - refractionIndexSlider->SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object. No effect when BlendMode is set to OPAQUE."); - refractionIndexSlider->SetSize(XMFLOAT2(100, hei)); - refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); - refractionIndexSlider->OnSlide([&](wiEventArgs args) { + refractionIndexSlider.Create(0, 1.0f, 0.02f, 1000, "Refraction Index: "); + refractionIndexSlider.SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object. No effect when BlendMode is set to OPAQUE."); + refractionIndexSlider.SetSize(XMFLOAT2(wid, hei)); + refractionIndexSlider.SetPos(XMFLOAT2(x, y += step)); + refractionIndexSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetRefractionIndex(args.fValue); }); - materialWindow->AddWidget(refractionIndexSlider); + AddWidget(&refractionIndexSlider); - emissiveSlider = new wiSlider(0, 1, 0.0f, 1000, "Emissive: "); - emissiveSlider->SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); - emissiveSlider->SetSize(XMFLOAT2(100, hei)); - emissiveSlider->SetPos(XMFLOAT2(x, y += step)); - emissiveSlider->OnSlide([&](wiEventArgs args) { + emissiveSlider.Create(0, 1, 0.0f, 1000, "Emissive: "); + emissiveSlider.SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); + emissiveSlider.SetSize(XMFLOAT2(wid, hei)); + emissiveSlider.SetPos(XMFLOAT2(x, y += step)); + emissiveSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetEmissiveStrength(args.fValue); }); - materialWindow->AddWidget(emissiveSlider); + AddWidget(&emissiveSlider); - sssSlider = new wiSlider(0, 1, 0.0f, 1000, "Subsurface Scattering: "); - sssSlider->SetTooltip("Adjust how much the light is scattered when entered inside the surface of the object. (SSS postprocess must be enabled)"); - sssSlider->SetSize(XMFLOAT2(100, hei)); - sssSlider->SetPos(XMFLOAT2(x, y += step)); - sssSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - material->SetSubsurfaceScattering(args.fValue); - }); - materialWindow->AddWidget(sssSlider); - - pomSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); - pomSlider->SetTooltip("Adjust how much the bump map should modulate the surface parallax effect."); - pomSlider->SetSize(XMFLOAT2(100, hei)); - pomSlider->SetPos(XMFLOAT2(x, y += step)); - pomSlider->OnSlide([&](wiEventArgs args) { + pomSlider.Create(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); + pomSlider.SetTooltip("Adjust how much the bump map should modulate the surface parallax effect. \nOnly works with PBR + Parallax shader."); + pomSlider.SetSize(XMFLOAT2(wid, hei)); + pomSlider.SetPos(XMFLOAT2(x, y += step)); + pomSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetParallaxOcclusionMapping(args.fValue); }); - materialWindow->AddWidget(pomSlider); + AddWidget(&pomSlider); - displacementMappingSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Displacement Mapping: "); - displacementMappingSlider->SetTooltip("Adjust how much the bump map should modulate the geometry when using tessellation."); - displacementMappingSlider->SetSize(XMFLOAT2(100, hei)); - displacementMappingSlider->SetPos(XMFLOAT2(x, y += step)); - displacementMappingSlider->OnSlide([&](wiEventArgs args) { + displacementMappingSlider.Create(0, 0.1f, 0.0f, 1000, "Displacement Mapping: "); + displacementMappingSlider.SetTooltip("Adjust how much the bump map should modulate the geometry when using tessellation."); + displacementMappingSlider.SetSize(XMFLOAT2(wid, hei)); + displacementMappingSlider.SetPos(XMFLOAT2(x, y += step)); + displacementMappingSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetDisplacementMapping(args.fValue); }); - materialWindow->AddWidget(displacementMappingSlider); + AddWidget(&displacementMappingSlider); - texAnimFrameRateSlider = new wiSlider(0, 60, 0, 60, "Texcoord anim FPS: "); - texAnimFrameRateSlider->SetTooltip("Adjust the texture animation frame rate (frames per second). Any value above 0 will make the material dynamic."); - texAnimFrameRateSlider->SetSize(XMFLOAT2(100, hei)); - texAnimFrameRateSlider->SetPos(XMFLOAT2(x, y += step)); - texAnimFrameRateSlider->OnSlide([&](wiEventArgs args) { + texAnimFrameRateSlider.Create(0, 60, 0, 60, "Texcoord anim FPS: "); + texAnimFrameRateSlider.SetTooltip("Adjust the texture animation frame rate (frames per second). Any value above 0 will make the material dynamic."); + texAnimFrameRateSlider.SetSize(XMFLOAT2(wid, hei)); + texAnimFrameRateSlider.SetPos(XMFLOAT2(x, y += step)); + texAnimFrameRateSlider.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimFrameRate = args.fValue; } }); - materialWindow->AddWidget(texAnimFrameRateSlider); + AddWidget(&texAnimFrameRateSlider); - texAnimDirectionSliderU = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); - texAnimDirectionSliderU->SetTooltip("Adjust the texture animation speed along the U direction in texture space."); - texAnimDirectionSliderU->SetSize(XMFLOAT2(100, hei)); - texAnimDirectionSliderU->SetPos(XMFLOAT2(x, y += step)); - texAnimDirectionSliderU->OnSlide([&](wiEventArgs args) { + texAnimDirectionSliderU.Create(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); + texAnimDirectionSliderU.SetTooltip("Adjust the texture animation speed along the U direction in texture space."); + texAnimDirectionSliderU.SetSize(XMFLOAT2(wid, hei)); + texAnimDirectionSliderU.SetPos(XMFLOAT2(x, y += step)); + texAnimDirectionSliderU.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimDirection.x = args.fValue; } }); - materialWindow->AddWidget(texAnimDirectionSliderU); + AddWidget(&texAnimDirectionSliderU); - texAnimDirectionSliderV = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); - texAnimDirectionSliderV->SetTooltip("Adjust the texture animation speed along the V direction in texture space."); - texAnimDirectionSliderV->SetSize(XMFLOAT2(100, hei)); - texAnimDirectionSliderV->SetPos(XMFLOAT2(x, y += step)); - texAnimDirectionSliderV->OnSlide([&](wiEventArgs args) { + texAnimDirectionSliderV.Create(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); + texAnimDirectionSliderV.SetTooltip("Adjust the texture animation speed along the V direction in texture space."); + texAnimDirectionSliderV.SetSize(XMFLOAT2(wid, hei)); + texAnimDirectionSliderV.SetPos(XMFLOAT2(x, y += step)); + texAnimDirectionSliderV.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimDirection.y = args.fValue; } }); - materialWindow->AddWidget(texAnimDirectionSliderV); + AddWidget(&texAnimDirectionSliderV); - texMulSliderX = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); - texMulSliderX->SetTooltip("Adjust the texture mapping size."); - texMulSliderX->SetSize(XMFLOAT2(100, hei)); - texMulSliderX->SetPos(XMFLOAT2(x, y += step)); - texMulSliderX->OnSlide([&](wiEventArgs args) { + texMulSliderX.Create(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); + texMulSliderX.SetTooltip("Adjust the texture mapping size."); + texMulSliderX.SetSize(XMFLOAT2(wid, hei)); + texMulSliderX.SetPos(XMFLOAT2(x, y += step)); + texMulSliderX.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { @@ -284,13 +339,13 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->texMulAdd.x = args.fValue; } }); - materialWindow->AddWidget(texMulSliderX); + AddWidget(&texMulSliderX); - texMulSliderY = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); - texMulSliderY->SetTooltip("Adjust the texture mapping size."); - texMulSliderY->SetSize(XMFLOAT2(100, hei)); - texMulSliderY->SetPos(XMFLOAT2(x, y += step)); - texMulSliderY->OnSlide([&](wiEventArgs args) { + texMulSliderY.Create(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); + texMulSliderY.SetTooltip("Adjust the texture mapping size."); + texMulSliderY.SetSize(XMFLOAT2(wid, hei)); + texMulSliderY.SetPos(XMFLOAT2(x, y += step)); + texMulSliderY.OnSlide([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { @@ -298,70 +353,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->texMulAdd.y = args.fValue; } }); - materialWindow->AddWidget(texMulSliderY); - - - blendModeComboBox = new wiComboBox("Blend mode: "); - blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); - blendModeComboBox->SetSize(XMFLOAT2(100, hei)); - blendModeComboBox->OnSelect([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr && args.iValue >= 0) - { - material->userBlendMode = static_cast(args.iValue); - } - }); - blendModeComboBox->AddItem("Opaque"); - blendModeComboBox->AddItem("Alpha"); - blendModeComboBox->AddItem("Premultiplied"); - blendModeComboBox->AddItem("Additive"); - blendModeComboBox->SetEnabled(false); - blendModeComboBox->SetTooltip("Set the blend mode of the material."); - materialWindow->AddWidget(blendModeComboBox); - - - shaderTypeComboBox = new wiComboBox("Custom Shader: "); - shaderTypeComboBox->SetTooltip("Select a custom shader for his material. See wiRenderer:RegisterCustomShader() for more info."); - shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); - shaderTypeComboBox->SetSize(XMFLOAT2(100, hei)); - shaderTypeComboBox->OnSelect([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetCustomShaderID(args.iValue - 1); - } - }); - shaderTypeComboBox->AddItem("None"); - for (auto& x : wiRenderer::GetCustomShaders()) - { - shaderTypeComboBox->AddItem(x.name); - } - shaderTypeComboBox->SetEnabled(false); - materialWindow->AddWidget(shaderTypeComboBox); - - - - shadingRateComboBox = new wiComboBox("Shading Rate: "); - shadingRateComboBox->SetTooltip("Select shading rate for this material. \nSelecting larger shading rate will decrease rendering quality of this material, \nbut increases performance.\nDX12 only and requires Tier1 hardware support for variable shading rate"); - shadingRateComboBox->SetPos(XMFLOAT2(x, y += step)); - shadingRateComboBox->SetSize(XMFLOAT2(100, hei)); - shadingRateComboBox->OnSelect([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->shadingRate = (SHADING_RATE)args.iValue; - } - }); - shadingRateComboBox->AddItem("1X1"); - shadingRateComboBox->AddItem("1X2"); - shadingRateComboBox->AddItem("2X1"); - shadingRateComboBox->AddItem("2X2"); - shadingRateComboBox->AddItem("2X4"); - shadingRateComboBox->AddItem("4X2"); - shadingRateComboBox->AddItem("4X4"); - shadingRateComboBox->SetEnabled(false); - shadingRateComboBox->SetMaxVisibleItemCount(4); - materialWindow->AddWidget(shadingRateComboBox); + AddWidget(&texMulSliderY); // Textures: @@ -371,42 +363,43 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) hei = 20; step = hei + 2; - materialNameField = new wiTextInputField("MaterialName"); - materialNameField->SetTooltip("Set a name for the material..."); - materialNameField->SetPos(XMFLOAT2(10, y += step)); - materialNameField->SetSize(XMFLOAT2(300, hei)); - materialNameField->OnInputAccepted([&](wiEventArgs args) { + materialNameField.Create("MaterialName"); + materialNameField.SetTooltip("Set a name for the material..."); + materialNameField.SetPos(XMFLOAT2(10, y += step)); + materialNameField.SetSize(XMFLOAT2(300, hei)); + materialNameField.OnInputAccepted([&](wiEventArgs args) { NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; } }); - materialWindow->AddWidget(materialNameField); + AddWidget(&materialNameField); - newMaterialButton = new wiButton("New Material"); - newMaterialButton->SetPos(XMFLOAT2(10 + 5 + 300, y)); - newMaterialButton->SetSize(XMFLOAT2(100, hei)); - newMaterialButton->OnClick([=](wiEventArgs args) { + newMaterialButton.Create("New Material"); + newMaterialButton.SetPos(XMFLOAT2(10 + 5 + 300, y)); + newMaterialButton.SetSize(XMFLOAT2(100, hei)); + newMaterialButton.OnClick([=](wiEventArgs args) { Scene& scene = wiScene::GetScene(); Entity entity = scene.Entity_CreateMaterial("editorMaterial"); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); - materialWindow->AddWidget(newMaterialButton); + AddWidget(&newMaterialButton); - texture_baseColor_Label = new wiLabel("BaseColorMap: "); - texture_baseColor_Label->SetPos(XMFLOAT2(x, y += step)); - texture_baseColor_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_baseColor_Label); + texture_baseColor_Label.Create("BaseColorMap: "); + texture_baseColor_Label.SetPos(XMFLOAT2(x, y += step)); + texture_baseColor_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_baseColor_Label); - texture_baseColor_Button = new wiButton("BaseColor"); - texture_baseColor_Button->SetText(""); - texture_baseColor_Button->SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); - texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); - texture_baseColor_Button->OnClick([&](wiEventArgs args) { + texture_baseColor_Button.Create("BaseColor"); + texture_baseColor_Button.SetText(""); + texture_baseColor_Button.SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); + texture_baseColor_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_baseColor_Button.SetSize(XMFLOAT2(260, 20)); + texture_baseColor_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -416,7 +409,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->baseColorMap = nullptr; material->baseColorMapName = ""; material->SetDirty(); - texture_baseColor_Button->SetText(""); + texture_baseColor_Button.SetText(""); } else { @@ -432,40 +425,40 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->baseColorMap = wiResourceManager::Load(fileName); material->baseColorMapName = fileName; material->SetDirty(); - texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_baseColor_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_baseColor_Button); + AddWidget(&texture_baseColor_Button); - texture_baseColor_uvset_Field = new wiTextInputField("uvset_baseColor"); - texture_baseColor_uvset_Field->SetText(""); - texture_baseColor_uvset_Field->SetTooltip("uv set number"); - texture_baseColor_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_baseColor_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_baseColor_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_baseColor_uvset_Field.Create("uvset_baseColor"); + texture_baseColor_uvset_Field.SetText(""); + texture_baseColor_uvset_Field.SetTooltip("uv set number"); + texture_baseColor_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_baseColor_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_baseColor_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_BaseColorMap(args.iValue); } }); - materialWindow->AddWidget(texture_baseColor_uvset_Field); + AddWidget(&texture_baseColor_uvset_Field); - texture_normal_Label = new wiLabel("NormalMap: "); - texture_normal_Label->SetPos(XMFLOAT2(x, y += step)); - texture_normal_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_normal_Label); + texture_normal_Label.Create("NormalMap: "); + texture_normal_Label.SetPos(XMFLOAT2(x, y += step)); + texture_normal_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_normal_Label); - texture_normal_Button = new wiButton("NormalMap"); - texture_normal_Button->SetText(""); - texture_normal_Button->SetTooltip("Load the normalmap texture. RGB: Normal"); - texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_normal_Button->SetSize(XMFLOAT2(260, 20)); - texture_normal_Button->OnClick([&](wiEventArgs args) { + texture_normal_Button.Create("NormalMap"); + texture_normal_Button.SetText(""); + texture_normal_Button.SetTooltip("Load the normalmap texture. RGB: Normal"); + texture_normal_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_normal_Button.SetSize(XMFLOAT2(260, 20)); + texture_normal_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -475,7 +468,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->normalMap = nullptr; material->normalMapName = ""; material->SetDirty(); - texture_normal_Button->SetText(""); + texture_normal_Button.SetText(""); } else { @@ -491,40 +484,40 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->normalMap = wiResourceManager::Load(fileName); material->normalMapName = fileName; material->SetDirty(); - texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_normal_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_normal_Button); + AddWidget(&texture_normal_Button); - texture_normal_uvset_Field = new wiTextInputField("uvset_normal"); - texture_normal_uvset_Field->SetText(""); - texture_normal_uvset_Field->SetTooltip("uv set number"); - texture_normal_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_normal_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_normal_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_normal_uvset_Field.Create("uvset_normal"); + texture_normal_uvset_Field.SetText(""); + texture_normal_uvset_Field.SetTooltip("uv set number"); + texture_normal_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_normal_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_normal_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_NormalMap(args.iValue); } }); - materialWindow->AddWidget(texture_normal_uvset_Field); + AddWidget(&texture_normal_uvset_Field); - texture_surface_Label = new wiLabel("SurfaceMap: "); - texture_surface_Label->SetPos(XMFLOAT2(x, y += step)); - texture_surface_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_surface_Label); + texture_surface_Label.Create("SurfaceMap: "); + texture_surface_Label.SetPos(XMFLOAT2(x, y += step)); + texture_surface_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_surface_Label); - texture_surface_Button = new wiButton("SurfaceMap"); - texture_surface_Button->SetText(""); - texture_surface_Button->SetTooltip("Load the surface property texture: R: Occlusion, G: Roughness, B: Metalness, A: Reflectance"); - texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_surface_Button->SetSize(XMFLOAT2(260, 20)); - texture_surface_Button->OnClick([&](wiEventArgs args) { + texture_surface_Button.Create("SurfaceMap"); + texture_surface_Button.SetText(""); + texture_surface_Button.SetTooltip("Load the surface property texture: R: Occlusion, G: Roughness, B: Metalness, A: Reflectance"); + texture_surface_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_surface_Button.SetSize(XMFLOAT2(260, 20)); + texture_surface_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -534,7 +527,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->surfaceMap = nullptr; material->surfaceMapName = ""; material->SetDirty(); - texture_surface_Button->SetText(""); + texture_surface_Button.SetText(""); } else { @@ -550,40 +543,40 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->surfaceMap = wiResourceManager::Load(fileName); material->surfaceMapName = fileName; material->SetDirty(); - texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_surface_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_surface_Button); + AddWidget(&texture_surface_Button); - texture_surface_uvset_Field = new wiTextInputField("uvset_surface"); - texture_surface_uvset_Field->SetText(""); - texture_surface_uvset_Field->SetTooltip("uv set number"); - texture_surface_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_surface_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_surface_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_surface_uvset_Field.Create("uvset_surface"); + texture_surface_uvset_Field.SetText(""); + texture_surface_uvset_Field.SetTooltip("uv set number"); + texture_surface_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_surface_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_surface_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_SurfaceMap(args.iValue); } }); - materialWindow->AddWidget(texture_surface_uvset_Field); + AddWidget(&texture_surface_uvset_Field); - texture_emissive_Label = new wiLabel("EmissiveMap: "); - texture_emissive_Label->SetPos(XMFLOAT2(x, y += step)); - texture_emissive_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_emissive_Label); + texture_emissive_Label.Create("EmissiveMap: "); + texture_emissive_Label.SetPos(XMFLOAT2(x, y += step)); + texture_emissive_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_emissive_Label); - texture_emissive_Button = new wiButton("EmissiveMap"); - texture_emissive_Button->SetText(""); - texture_emissive_Button->SetTooltip("Load the emissive map texture."); - texture_emissive_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_emissive_Button->SetSize(XMFLOAT2(260, 20)); - texture_emissive_Button->OnClick([&](wiEventArgs args) { + texture_emissive_Button.Create("EmissiveMap"); + texture_emissive_Button.SetText(""); + texture_emissive_Button.SetTooltip("Load the emissive map texture."); + texture_emissive_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_emissive_Button.SetSize(XMFLOAT2(260, 20)); + texture_emissive_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -593,7 +586,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->emissiveMap = nullptr; material->emissiveMapName = ""; material->SetDirty(); - texture_emissive_Button->SetText(""); + texture_emissive_Button.SetText(""); } else { @@ -609,40 +602,40 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->emissiveMap = wiResourceManager::Load(fileName); material->emissiveMapName = fileName; material->SetDirty(); - texture_emissive_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_emissive_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_emissive_Button); + AddWidget(&texture_emissive_Button); - texture_emissive_uvset_Field = new wiTextInputField("uvset_emissive"); - texture_emissive_uvset_Field->SetText(""); - texture_emissive_uvset_Field->SetTooltip("uv set number"); - texture_emissive_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_emissive_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_emissive_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_emissive_uvset_Field.Create("uvset_emissive"); + texture_emissive_uvset_Field.SetText(""); + texture_emissive_uvset_Field.SetTooltip("uv set number"); + texture_emissive_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_emissive_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_emissive_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_EmissiveMap(args.iValue); } }); - materialWindow->AddWidget(texture_emissive_uvset_Field); + AddWidget(&texture_emissive_uvset_Field); - texture_displacement_Label = new wiLabel("DisplacementMap: "); - texture_displacement_Label->SetPos(XMFLOAT2(x, y += step)); - texture_displacement_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_displacement_Label); + texture_displacement_Label.Create("DisplacementMap: "); + texture_displacement_Label.SetPos(XMFLOAT2(x, y += step)); + texture_displacement_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_displacement_Label); - texture_displacement_Button = new wiButton("DisplacementMap"); - texture_displacement_Button->SetText(""); - texture_displacement_Button->SetTooltip("Load the displacement map texture."); - texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); - texture_displacement_Button->OnClick([&](wiEventArgs args) { + texture_displacement_Button.Create("DisplacementMap"); + texture_displacement_Button.SetText(""); + texture_displacement_Button.SetTooltip("Load the displacement map texture."); + texture_displacement_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_displacement_Button.SetSize(XMFLOAT2(260, 20)); + texture_displacement_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -652,7 +645,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->displacementMap = nullptr; material->displacementMapName = ""; material->SetDirty(); - texture_displacement_Button->SetText(""); + texture_displacement_Button.SetText(""); } else { @@ -668,41 +661,41 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->displacementMap = wiResourceManager::Load(fileName); material->displacementMapName = fileName; material->SetDirty(); - texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_displacement_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_displacement_Button); + AddWidget(&texture_displacement_Button); - texture_displacement_uvset_Field = new wiTextInputField("uvset_displacement"); - texture_displacement_uvset_Field->SetText(""); - texture_displacement_uvset_Field->SetTooltip("uv set number"); - texture_displacement_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_displacement_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_displacement_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_displacement_uvset_Field.Create("uvset_displacement"); + texture_displacement_uvset_Field.SetText(""); + texture_displacement_uvset_Field.SetTooltip("uv set number"); + texture_displacement_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_displacement_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_displacement_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_DisplacementMap(args.iValue); } }); - materialWindow->AddWidget(texture_displacement_uvset_Field); + AddWidget(&texture_displacement_uvset_Field); - texture_occlusion_Label = new wiLabel("OcclusionMap: "); - texture_occlusion_Label->SetPos(XMFLOAT2(x, y += step)); - texture_occlusion_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_occlusion_Label); + texture_occlusion_Label.Create("OcclusionMap: "); + texture_occlusion_Label.SetPos(XMFLOAT2(x, y += step)); + texture_occlusion_Label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&texture_occlusion_Label); - texture_occlusion_Button = new wiButton("OcclusionMap"); - texture_occlusion_Button->SetText(""); - texture_occlusion_Button->SetTooltip("Load the occlusion map texture. R: occlusion factor"); - texture_occlusion_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_occlusion_Button->SetSize(XMFLOAT2(260, 20)); - texture_occlusion_Button->OnClick([&](wiEventArgs args) { + texture_occlusion_Button.Create("OcclusionMap"); + texture_occlusion_Button.SetText(""); + texture_occlusion_Button.SetTooltip("Load the occlusion map texture. R: occlusion factor"); + texture_occlusion_Button.SetPos(XMFLOAT2(x + 122, y)); + texture_occlusion_Button.SetSize(XMFLOAT2(260, 20)); + texture_occlusion_Button.OnClick([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -712,7 +705,7 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->occlusionMap = nullptr; material->occlusionMapName = ""; material->SetDirty(); - texture_occlusion_Button->SetText(""); + texture_occlusion_Button.SetText(""); } else { @@ -728,49 +721,49 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) material->occlusionMap = wiResourceManager::Load(fileName); material->occlusionMapName = fileName; material->SetDirty(); - texture_occlusion_Button->SetText(wiHelper::GetFileNameFromPath(fileName)); + texture_occlusion_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); }); }); } }); - materialWindow->AddWidget(texture_occlusion_Button); + AddWidget(&texture_occlusion_Button); - texture_occlusion_uvset_Field = new wiTextInputField("uvset_occlusion"); - texture_occlusion_uvset_Field->SetText(""); - texture_occlusion_uvset_Field->SetTooltip("uv set number"); - texture_occlusion_uvset_Field->SetPos(XMFLOAT2(x + 392, y)); - texture_occlusion_uvset_Field->SetSize(XMFLOAT2(20, 20)); - texture_occlusion_uvset_Field->OnInputAccepted([&](wiEventArgs args) { + texture_occlusion_uvset_Field.Create("uvset_occlusion"); + texture_occlusion_uvset_Field.SetText(""); + texture_occlusion_uvset_Field.SetTooltip("uv set number"); + texture_occlusion_uvset_Field.SetPos(XMFLOAT2(x + 392, y)); + texture_occlusion_uvset_Field.SetSize(XMFLOAT2(20, 20)); + texture_occlusion_uvset_Field.OnInputAccepted([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_OcclusionMap(args.iValue); } }); - materialWindow->AddWidget(texture_occlusion_uvset_Field); + AddWidget(&texture_occlusion_uvset_Field); y = 180; - colorComboBox = new wiComboBox("Color picker mode: "); - colorComboBox->SetSize(XMFLOAT2(120, hei)); - colorComboBox->SetPos(XMFLOAT2(x + 150, y += step)); - colorComboBox->AddItem("Base color"); - colorComboBox->AddItem("Emissive color"); - colorComboBox->SetTooltip("Choose the destination data of the color picker."); - materialWindow->AddWidget(colorComboBox); + colorComboBox.Create("Color picker mode: "); + colorComboBox.SetSize(XMFLOAT2(120, hei)); + colorComboBox.SetPos(XMFLOAT2(x + 150, y += step)); + colorComboBox.AddItem("Base color"); + colorComboBox.AddItem("Emissive color"); + colorComboBox.SetTooltip("Choose the destination data of the color picker."); + AddWidget(&colorComboBox); y += 10; - colorPicker = new wiColorPicker(GUI, "Color", false); - colorPicker->SetPos(XMFLOAT2(10, y += step)); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { + colorPicker.Create("Color", false); + colorPicker.SetPos(XMFLOAT2(10, y += step)); + colorPicker.SetVisible(true); + colorPicker.SetEnabled(true); + colorPicker.OnColorChanged([&](wiEventArgs args) { MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); if (material != nullptr) { - switch (colorComboBox->GetSelected()) + switch (colorComboBox.GetSelected()) { default: case 0: @@ -785,22 +778,15 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - materialWindow->AddWidget(colorPicker); + AddWidget(&colorPicker); - materialWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 880, 120, 0)); - materialWindow->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 880, 120, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } -MaterialWindow::~MaterialWindow() -{ - materialWindow->RemoveWidgets(true); - GUI->RemoveWidget(materialWindow); - delete materialWindow; -} - void MaterialWindow::SetEntity(Entity entity) @@ -812,89 +798,112 @@ void MaterialWindow::SetEntity(Entity entity) if (material != nullptr) { + SetEnabled(true); + const NameComponent& name = *scene.names.GetComponent(entity); - materialNameField->SetValue(name.name); - waterCheckBox->SetCheck(material->IsWater()); - planarReflCheckBox->SetCheck(material->HasPlanarReflection()); - shadowCasterCheckBox->SetCheck(material->IsCastingShadow()); - flipNormalMapCheckBox->SetCheck(material->IsFlipNormalMap()); - useVertexColorsCheckBox->SetCheck(material->IsUsingVertexColors()); - specularGlossinessCheckBox->SetCheck(material->IsUsingSpecularGlossinessWorkflow()); - occlusionPrimaryCheckBox->SetCheck(material->IsOcclusionEnabled_Primary()); - occlusionSecondaryCheckBox->SetCheck(material->IsOcclusionEnabled_Secondary()); - windCheckBox->SetCheck(material->IsUsingWind()); - normalMapSlider->SetValue(material->normalMapStrength); - roughnessSlider->SetValue(material->roughness); - reflectanceSlider->SetValue(material->reflectance); - metalnessSlider->SetValue(material->metalness); - refractionIndexSlider->SetValue(material->refractionIndex); - emissiveSlider->SetValue(material->emissiveColor.w); - sssSlider->SetValue(material->subsurfaceScattering); - pomSlider->SetValue(material->parallaxOcclusionMapping); - displacementMappingSlider->SetValue(material->displacementMapping); - texAnimFrameRateSlider->SetValue(material->texAnimFrameRate); - texAnimDirectionSliderU->SetValue(material->texAnimDirection.x); - texAnimDirectionSliderV->SetValue(material->texAnimDirection.y); - texMulSliderX->SetValue(material->texMulAdd.x); - texMulSliderY->SetValue(material->texMulAdd.y); - alphaRefSlider->SetValue(material->alphaRef); - materialWindow->SetEnabled(true); - blendModeComboBox->SetSelected((int)material->userBlendMode); - shaderTypeComboBox->SetSelected(max(0, material->GetCustomShaderID() + 1)); - shadingRateComboBox->SetSelected((int)material->shadingRate); + materialNameField.SetValue(name.name); + shadowCasterCheckBox.SetCheck(material->IsCastingShadow()); + useVertexColorsCheckBox.SetCheck(material->IsUsingVertexColors()); + specularGlossinessCheckBox.SetCheck(material->IsUsingSpecularGlossinessWorkflow()); + occlusionPrimaryCheckBox.SetCheck(material->IsOcclusionEnabled_Primary()); + occlusionSecondaryCheckBox.SetCheck(material->IsOcclusionEnabled_Secondary()); + windCheckBox.SetCheck(material->IsUsingWind()); + normalMapSlider.SetValue(material->normalMapStrength); + roughnessSlider.SetValue(material->roughness); + reflectanceSlider.SetValue(material->reflectance); + metalnessSlider.SetValue(material->metalness); + refractionIndexSlider.SetValue(material->refractionIndex); + emissiveSlider.SetValue(material->emissiveColor.w); + pomSlider.SetValue(material->parallaxOcclusionMapping); + displacementMappingSlider.SetValue(material->displacementMapping); + texAnimFrameRateSlider.SetValue(material->texAnimFrameRate); + texAnimDirectionSliderU.SetValue(material->texAnimDirection.x); + texAnimDirectionSliderV.SetValue(material->texAnimDirection.y); + texMulSliderX.SetValue(material->texMulAdd.x); + texMulSliderY.SetValue(material->texMulAdd.y); + alphaRefSlider.SetValue(material->alphaRef); + blendModeComboBox.SetSelected((int)material->userBlendMode); + sssComboBox.SetSelected((int)material->subsurfaceProfile); + if (material->GetCustomShaderID() >= 0) + { + shaderTypeComboBox.SetSelected(MaterialComponent::SHADERTYPE_COUNT + material->GetCustomShaderID()); + } + else + { + shaderTypeComboBox.SetSelected((int)material->shaderType); + } + shadingRateComboBox.SetSelected((int)material->shadingRate); - texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName)); - texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - texture_emissive_Button->SetText(wiHelper::GetFileNameFromPath(material->emissiveMapName)); - texture_occlusion_Button->SetText(wiHelper::GetFileNameFromPath(material->occlusionMapName)); + texture_baseColor_Button.SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName)); + texture_normal_Button.SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); + texture_surface_Button.SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); + texture_displacement_Button.SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); + texture_emissive_Button.SetText(wiHelper::GetFileNameFromPath(material->emissiveMapName)); + texture_occlusion_Button.SetText(wiHelper::GetFileNameFromPath(material->occlusionMapName)); - texture_baseColor_uvset_Field->SetText(std::to_string(material->uvset_baseColorMap)); - texture_normal_uvset_Field->SetText(std::to_string(material->uvset_normalMap)); - texture_surface_uvset_Field->SetText(std::to_string(material->uvset_surfaceMap)); - texture_displacement_uvset_Field->SetText(std::to_string(material->uvset_displacementMap)); - texture_emissive_uvset_Field->SetText(std::to_string(material->uvset_emissiveMap)); - texture_occlusion_uvset_Field->SetText(std::to_string(material->uvset_occlusionMap)); + texture_baseColor_uvset_Field.SetText(std::to_string(material->uvset_baseColorMap)); + texture_normal_uvset_Field.SetText(std::to_string(material->uvset_normalMap)); + texture_surface_uvset_Field.SetText(std::to_string(material->uvset_surfaceMap)); + texture_displacement_uvset_Field.SetText(std::to_string(material->uvset_displacementMap)); + texture_emissive_uvset_Field.SetText(std::to_string(material->uvset_emissiveMap)); + texture_occlusion_uvset_Field.SetText(std::to_string(material->uvset_occlusionMap)); - colorComboBox->SetEnabled(true); - colorPicker->SetEnabled(true); + colorComboBox.SetEnabled(true); + colorPicker.SetEnabled(true); - switch (colorComboBox->GetSelected()) + switch (colorComboBox.GetSelected()) { default: case 0: - colorPicker->SetPickColor(wiColor::fromFloat4(material->baseColor)); + colorPicker.SetPickColor(wiColor::fromFloat4(material->baseColor)); break; case 1: - colorPicker->SetPickColor(wiColor::fromFloat3(XMFLOAT3(material->emissiveColor.x, material->emissiveColor.y, material->emissiveColor.z))); + colorPicker.SetPickColor(wiColor::fromFloat3(XMFLOAT3(material->emissiveColor.x, material->emissiveColor.y, material->emissiveColor.z))); break; } - + + switch (material->shaderType) + { + case MaterialComponent::SHADERTYPE_PBR_ANISOTROPIC: + pomSlider.SetText("Anisotropy: "); + pomSlider.SetTooltip("Adjust anisotropy specular effect. \nOnly works with PBR + Anisotropic shader."); + pomSlider.SetRange(0, 0.99f); + break; + case MaterialComponent::SHADERTYPE_PBR_PARALLAXOCCLUSIONMAPPING: + pomSlider.SetText("Parallax Occlusion Mapping: "); + pomSlider.SetTooltip("Adjust how much the bump map should modulate the surface parallax effect. \nOnly works with PBR + Parallax shader."); + pomSlider.SetRange(0, 0.1f); + break; + default: + pomSlider.SetEnabled(false); + break; + } + + shadingRateComboBox.SetEnabled(wiRenderer::GetDevice()->CheckCapability(GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING)); } else { - materialNameField->SetValue("No material selected"); - materialWindow->SetEnabled(false); - colorComboBox->SetEnabled(false); - colorPicker->SetEnabled(false); + materialNameField.SetValue("No material selected"); + SetEnabled(false); + colorComboBox.SetEnabled(false); + colorPicker.SetEnabled(false); - texture_baseColor_Button->SetText(""); - texture_normal_Button->SetText(""); - texture_surface_Button->SetText(""); - texture_displacement_Button->SetText(""); - texture_emissive_Button->SetText(""); - texture_occlusion_Button->SetText(""); + texture_baseColor_Button.SetText(""); + texture_normal_Button.SetText(""); + texture_surface_Button.SetText(""); + texture_displacement_Button.SetText(""); + texture_emissive_Button.SetText(""); + texture_occlusion_Button.SetText(""); - texture_baseColor_uvset_Field->SetText(""); - texture_normal_uvset_Field->SetText(""); - texture_surface_uvset_Field->SetText(""); - texture_displacement_uvset_Field->SetText(""); - texture_emissive_uvset_Field->SetText(""); - texture_occlusion_uvset_Field->SetText(""); + texture_baseColor_uvset_Field.SetText(""); + texture_normal_uvset_Field.SetText(""); + texture_surface_uvset_Field.SetText(""); + texture_displacement_uvset_Field.SetText(""); + texture_emissive_uvset_Field.SetText(""); + texture_occlusion_uvset_Field.SetText(""); } - newMaterialButton->SetEnabled(true); + newMaterialButton.SetEnabled(true); } diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index 378445ad9..e080491a6 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -1,81 +1,65 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiColorPicker; -class wiButton; -class wiComboBox; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class MaterialWindow +class MaterialWindow : public wiWindow { public: - MaterialWindow(EditorComponent* editor); - ~MaterialWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; + wiTextInputField materialNameField; + wiButton newMaterialButton; + wiCheckBox shadowCasterCheckBox; + wiCheckBox useVertexColorsCheckBox; + wiCheckBox specularGlossinessCheckBox; + wiCheckBox occlusionPrimaryCheckBox; + wiCheckBox occlusionSecondaryCheckBox; + wiCheckBox windCheckBox; + wiSlider normalMapSlider; + wiSlider roughnessSlider; + wiSlider reflectanceSlider; + wiSlider metalnessSlider; + wiSlider refractionIndexSlider; + wiSlider emissiveSlider; + wiSlider pomSlider; + wiSlider displacementMappingSlider; + wiSlider texAnimFrameRateSlider; + wiSlider texAnimDirectionSliderU; + wiSlider texAnimDirectionSliderV; + wiSlider texMulSliderX; + wiSlider texMulSliderY; + wiSlider alphaRefSlider; + wiComboBox shaderTypeComboBox; + wiComboBox blendModeComboBox; + wiComboBox sssComboBox; + wiComboBox shadingRateComboBox; - wiWindow* materialWindow; - wiTextInputField* materialNameField; - wiButton* newMaterialButton; - wiCheckBox* waterCheckBox; - wiCheckBox* planarReflCheckBox; - wiCheckBox* shadowCasterCheckBox; - wiCheckBox* flipNormalMapCheckBox; - wiCheckBox* useVertexColorsCheckBox; - wiCheckBox* specularGlossinessCheckBox; - wiCheckBox* occlusionPrimaryCheckBox; - wiCheckBox* occlusionSecondaryCheckBox; - wiCheckBox* windCheckBox; - wiSlider* normalMapSlider; - wiSlider* roughnessSlider; - wiSlider* reflectanceSlider; - wiSlider* metalnessSlider; - wiSlider* refractionIndexSlider; - wiSlider* emissiveSlider; - wiSlider* sssSlider; - wiSlider* pomSlider; - wiSlider* displacementMappingSlider; - wiSlider* texAnimFrameRateSlider; - wiSlider* texAnimDirectionSliderU; - wiSlider* texAnimDirectionSliderV; - wiSlider* texMulSliderX; - wiSlider* texMulSliderY; - wiSlider* alphaRefSlider; - wiComboBox* blendModeComboBox; - wiComboBox* shaderTypeComboBox; - wiComboBox* shadingRateComboBox; + wiLabel texture_baseColor_Label; + wiLabel texture_normal_Label; + wiLabel texture_surface_Label; + wiLabel texture_displacement_Label; + wiLabel texture_emissive_Label; + wiLabel texture_occlusion_Label; - wiLabel* texture_baseColor_Label; - wiLabel* texture_normal_Label; - wiLabel* texture_surface_Label; - wiLabel* texture_displacement_Label; - wiLabel* texture_emissive_Label; - wiLabel* texture_occlusion_Label; + wiButton texture_baseColor_Button; + wiButton texture_normal_Button; + wiButton texture_surface_Button; + wiButton texture_displacement_Button; + wiButton texture_emissive_Button; + wiButton texture_occlusion_Button; - wiButton* texture_baseColor_Button; - wiButton* texture_normal_Button; - wiButton* texture_surface_Button; - wiButton* texture_displacement_Button; - wiButton* texture_emissive_Button; - wiButton* texture_occlusion_Button; + wiTextInputField texture_baseColor_uvset_Field; + wiTextInputField texture_normal_uvset_Field; + wiTextInputField texture_surface_uvset_Field; + wiTextInputField texture_displacement_uvset_Field; + wiTextInputField texture_emissive_uvset_Field; + wiTextInputField texture_occlusion_uvset_Field; - wiTextInputField* texture_baseColor_uvset_Field; - wiTextInputField* texture_normal_uvset_Field; - wiTextInputField* texture_surface_uvset_Field; - wiTextInputField* texture_displacement_uvset_Field; - wiTextInputField* texture_emissive_uvset_Field; - wiTextInputField* texture_occlusion_uvset_Field; - - wiComboBox* colorComboBox; - wiColorPicker* colorPicker; + wiComboBox colorComboBox; + wiColorPicker colorPicker; }; diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index efbd5eb6c..faebb13b2 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -10,45 +10,104 @@ using namespace std; using namespace wiECS; using namespace wiScene; -MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +struct TerraGen : public wiWindow { - assert(GUI && "Invalid GUI!"); + wiSlider dimXSlider; + wiSlider dimYSlider; + wiSlider dimZSlider; + wiButton heightmapButton; + + // heightmap texture: + unsigned char* rgb = nullptr; + const int channelCount = 4; + int width = 0, height = 0; + + TerraGen() + { + wiWindow::Create("TerraGen"); + SetSize(XMFLOAT2(260, 130)); + + float xx = 20; + float yy = 0; + float stepstep = 25; + float heihei = 20; + + dimXSlider.Create(16, 1024, 128, 1024 - 16, "X: "); + dimXSlider.SetTooltip("Terrain mesh grid resolution on X axis"); + dimXSlider.SetSize(XMFLOAT2(200, heihei)); + dimXSlider.SetPos(XMFLOAT2(xx, yy += stepstep)); + AddWidget(&dimXSlider); + + dimYSlider.Create(0, 1, 0.5f, 10000, "Y: "); + dimYSlider.SetTooltip("Terrain mesh grid heightmap scale on Y axis"); + dimYSlider.SetSize(XMFLOAT2(200, heihei)); + dimYSlider.SetPos(XMFLOAT2(xx, yy += stepstep)); + AddWidget(&dimYSlider); + + dimZSlider.Create(16, 1024, 128, 1024 - 16, "Z: "); + dimZSlider.SetTooltip("Terrain mesh grid resolution on Z axis"); + dimZSlider.SetSize(XMFLOAT2(200, heihei)); + dimZSlider.SetPos(XMFLOAT2(xx, yy += stepstep)); + AddWidget(&dimZSlider); - meshWindow = new wiWindow(GUI, "Mesh Window"); - meshWindow->SetSize(XMFLOAT2(580, 500)); - GUI->AddWidget(meshWindow); + heightmapButton.Create("Load Heightmap..."); + heightmapButton.SetTooltip("Load a heightmap texture, where the red channel corresponds to terrain height and the resolution to dimensions"); + heightmapButton.SetSize(XMFLOAT2(200, heihei)); + heightmapButton.SetPos(XMFLOAT2(xx, yy += stepstep)); + + AddWidget(&heightmapButton); + } + ~TerraGen() + { + Cleanup(); + } + + void Cleanup() + { + if (rgb != nullptr) + { + stbi_image_free(rgb); + rgb = nullptr; + } + } +} terragen; + +void MeshWindow::Create(EditorComponent* editor) +{ + wiWindow::Create("Mesh Window"); + SetSize(XMFLOAT2(580, 500)); float x = 150; float y = 0; float hei = 18; float step = hei + 2; - meshInfoLabel = new wiLabel("Mesh Info"); - meshInfoLabel->SetPos(XMFLOAT2(x - 50, y += step)); - meshInfoLabel->SetSize(XMFLOAT2(450, 180)); - meshWindow->AddWidget(meshInfoLabel); + meshInfoLabel.Create("Mesh Info"); + meshInfoLabel.SetPos(XMFLOAT2(x - 50, y += step)); + meshInfoLabel.SetSize(XMFLOAT2(450, 180)); + AddWidget(&meshInfoLabel); y += 190; - doubleSidedCheckBox = new wiCheckBox("Double Sided: "); - doubleSidedCheckBox->SetTooltip("If enabled, the inside of the mesh will be visible."); - doubleSidedCheckBox->SetSize(XMFLOAT2(hei, hei)); - doubleSidedCheckBox->SetPos(XMFLOAT2(x, y += step)); - doubleSidedCheckBox->OnClick([&](wiEventArgs args) { + doubleSidedCheckBox.Create("Double Sided: "); + doubleSidedCheckBox.SetTooltip("If enabled, the inside of the mesh will be visible."); + doubleSidedCheckBox.SetSize(XMFLOAT2(hei, hei)); + doubleSidedCheckBox.SetPos(XMFLOAT2(x, y += step)); + doubleSidedCheckBox.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->SetDoubleSided(args.bValue); } }); - meshWindow->AddWidget(doubleSidedCheckBox); + AddWidget(&doubleSidedCheckBox); - softbodyCheckBox = new wiCheckBox("Soft body: "); - softbodyCheckBox->SetTooltip("Enable soft body simulation. Tip: Use the Paint Tool to control vertex pinning."); - softbodyCheckBox->SetSize(XMFLOAT2(hei, hei)); - softbodyCheckBox->SetPos(XMFLOAT2(x, y += step)); - softbodyCheckBox->OnClick([&](wiEventArgs args) { + softbodyCheckBox.Create("Soft body: "); + softbodyCheckBox.SetTooltip("Enable soft body simulation. Tip: Use the Paint Tool to control vertex pinning."); + softbodyCheckBox.SetSize(XMFLOAT2(hei, hei)); + softbodyCheckBox.SetPos(XMFLOAT2(x, y += step)); + softbodyCheckBox.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); SoftBodyPhysicsComponent* physicscomponent = scene.softbodies.GetComponent(entity); @@ -58,8 +117,8 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) if (physicscomponent == nullptr) { SoftBodyPhysicsComponent& softbody = scene.softbodies.Create(entity); - softbody.friction = frictionSlider->GetValue(); - softbody.mass = massSlider->GetValue(); + softbody.friction = frictionSlider.GetValue(); + softbody.mass = massSlider.GetValue(); } } else @@ -71,79 +130,79 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } }); - meshWindow->AddWidget(softbodyCheckBox); + AddWidget(&softbodyCheckBox); - massSlider = new wiSlider(0, 10, 0, 100000, "Mass: "); - massSlider->SetTooltip("Set the mass amount for the physics engine."); - massSlider->SetSize(XMFLOAT2(100, hei)); - massSlider->SetPos(XMFLOAT2(x, y += step)); - massSlider->OnSlide([&](wiEventArgs args) { + massSlider.Create(0, 10, 0, 100000, "Mass: "); + massSlider.SetTooltip("Set the mass amount for the physics engine."); + massSlider.SetSize(XMFLOAT2(100, hei)); + massSlider.SetPos(XMFLOAT2(x, y += step)); + massSlider.OnSlide([&](wiEventArgs args) { SoftBodyPhysicsComponent* physicscomponent = wiScene::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->mass = args.fValue; } }); - meshWindow->AddWidget(massSlider); + AddWidget(&massSlider); - frictionSlider = new wiSlider(0, 2, 0, 100000, "Friction: "); - frictionSlider->SetTooltip("Set the friction amount for the physics engine."); - frictionSlider->SetSize(XMFLOAT2(100, hei)); - frictionSlider->SetPos(XMFLOAT2(x, y += step)); - frictionSlider->OnSlide([&](wiEventArgs args) { + frictionSlider.Create(0, 2, 0, 100000, "Friction: "); + frictionSlider.SetTooltip("Set the friction amount for the physics engine."); + frictionSlider.SetSize(XMFLOAT2(100, hei)); + frictionSlider.SetPos(XMFLOAT2(x, y += step)); + frictionSlider.OnSlide([&](wiEventArgs args) { SoftBodyPhysicsComponent* physicscomponent = wiScene::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->friction = args.fValue; } }); - meshWindow->AddWidget(frictionSlider); + AddWidget(&frictionSlider); - impostorCreateButton = new wiButton("Create Impostor"); - impostorCreateButton->SetTooltip("Create an impostor image of the mesh. The mesh will be replaced by this image when far away, to render faster."); - impostorCreateButton->SetSize(XMFLOAT2(240, hei)); - impostorCreateButton->SetPos(XMFLOAT2(x - 50, y += step)); - impostorCreateButton->OnClick([&](wiEventArgs args) { + impostorCreateButton.Create("Create Impostor"); + impostorCreateButton.SetTooltip("Create an impostor image of the mesh. The mesh will be replaced by this image when far away, to render faster."); + impostorCreateButton.SetSize(XMFLOAT2(240, hei)); + impostorCreateButton.SetPos(XMFLOAT2(x - 50, y += step)); + impostorCreateButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { Scene& scene = wiScene::GetScene(); - scene.impostors.Create(entity).swapInDistance = impostorDistanceSlider->GetValue(); + scene.impostors.Create(entity).swapInDistance = impostorDistanceSlider.GetValue(); } }); - meshWindow->AddWidget(impostorCreateButton); + AddWidget(&impostorCreateButton); - impostorDistanceSlider = new wiSlider(0, 1000, 100, 10000, "Impostor Distance: "); - impostorDistanceSlider->SetTooltip("Assign the distance where the mesh geometry should be switched to the impostor image."); - impostorDistanceSlider->SetSize(XMFLOAT2(100, hei)); - impostorDistanceSlider->SetPos(XMFLOAT2(x, y += step)); - impostorDistanceSlider->OnSlide([&](wiEventArgs args) { + impostorDistanceSlider.Create(0, 1000, 100, 10000, "Impostor Distance: "); + impostorDistanceSlider.SetTooltip("Assign the distance where the mesh geometry should be switched to the impostor image."); + impostorDistanceSlider.SetSize(XMFLOAT2(100, hei)); + impostorDistanceSlider.SetPos(XMFLOAT2(x, y += step)); + impostorDistanceSlider.OnSlide([&](wiEventArgs args) { ImpostorComponent* impostor = wiScene::GetScene().impostors.GetComponent(entity); if (impostor != nullptr) { impostor->swapInDistance = args.fValue; } }); - meshWindow->AddWidget(impostorDistanceSlider); + AddWidget(&impostorDistanceSlider); - tessellationFactorSlider = new wiSlider(0, 16, 0, 10000, "Tessellation Factor: "); - tessellationFactorSlider->SetTooltip("Set the dynamic tessellation amount. Tessellation should be enabled in the Renderer window and your GPU must support it!"); - tessellationFactorSlider->SetSize(XMFLOAT2(100, hei)); - tessellationFactorSlider->SetPos(XMFLOAT2(x, y += step)); - tessellationFactorSlider->OnSlide([&](wiEventArgs args) { + tessellationFactorSlider.Create(0, 16, 0, 10000, "Tessellation Factor: "); + tessellationFactorSlider.SetTooltip("Set the dynamic tessellation amount. Tessellation should be enabled in the Renderer window and your GPU must support it!"); + tessellationFactorSlider.SetSize(XMFLOAT2(100, hei)); + tessellationFactorSlider.SetPos(XMFLOAT2(x, y += step)); + tessellationFactorSlider.OnSlide([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->tessellationFactor = args.fValue; } }); - meshWindow->AddWidget(tessellationFactorSlider); + AddWidget(&tessellationFactorSlider); - flipCullingButton = new wiButton("Flip Culling"); - flipCullingButton->SetTooltip("Flip faces to reverse triangle culling order."); - flipCullingButton->SetSize(XMFLOAT2(240, hei)); - flipCullingButton->SetPos(XMFLOAT2(x - 50, y += step)); - flipCullingButton->OnClick([&](wiEventArgs args) { + flipCullingButton.Create("Flip Culling"); + flipCullingButton.SetTooltip("Flip faces to reverse triangle culling order."); + flipCullingButton.SetSize(XMFLOAT2(240, hei)); + flipCullingButton.SetPos(XMFLOAT2(x - 50, y += step)); + flipCullingButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -151,13 +210,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(flipCullingButton); + AddWidget(&flipCullingButton); - flipNormalsButton = new wiButton("Flip Normals"); - flipNormalsButton->SetTooltip("Flip surface normals."); - flipNormalsButton->SetSize(XMFLOAT2(240, hei)); - flipNormalsButton->SetPos(XMFLOAT2(x - 50, y += step)); - flipNormalsButton->OnClick([&](wiEventArgs args) { + flipNormalsButton.Create("Flip Normals"); + flipNormalsButton.SetTooltip("Flip surface normals."); + flipNormalsButton.SetSize(XMFLOAT2(240, hei)); + flipNormalsButton.SetPos(XMFLOAT2(x - 50, y += step)); + flipNormalsButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -165,13 +224,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(flipNormalsButton); + AddWidget(&flipNormalsButton); - computeNormalsSmoothButton = new wiButton("Compute Normals [SMOOTH]"); - computeNormalsSmoothButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per vertex. This can reduce vertex count, but is slow."); - computeNormalsSmoothButton->SetSize(XMFLOAT2(240, hei)); - computeNormalsSmoothButton->SetPos(XMFLOAT2(x - 50, y += step)); - computeNormalsSmoothButton->OnClick([&](wiEventArgs args) { + computeNormalsSmoothButton.Create("Compute Normals [SMOOTH]"); + computeNormalsSmoothButton.SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per vertex. This can reduce vertex count, but is slow."); + computeNormalsSmoothButton.SetSize(XMFLOAT2(240, hei)); + computeNormalsSmoothButton.SetPos(XMFLOAT2(x - 50, y += step)); + computeNormalsSmoothButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -179,13 +238,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(computeNormalsSmoothButton); + AddWidget(&computeNormalsSmoothButton); - computeNormalsHardButton = new wiButton("Compute Normals [HARD]"); - computeNormalsHardButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per face. This can increase vertex count."); - computeNormalsHardButton->SetSize(XMFLOAT2(240, hei)); - computeNormalsHardButton->SetPos(XMFLOAT2(x - 50, y += step)); - computeNormalsHardButton->OnClick([&](wiEventArgs args) { + computeNormalsHardButton.Create("Compute Normals [HARD]"); + computeNormalsHardButton.SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per face. This can increase vertex count."); + computeNormalsHardButton.SetSize(XMFLOAT2(240, hei)); + computeNormalsHardButton.SetPos(XMFLOAT2(x - 50, y += step)); + computeNormalsHardButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -193,13 +252,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(computeNormalsHardButton); + AddWidget(&computeNormalsHardButton); - recenterButton = new wiButton("Recenter"); - recenterButton->SetTooltip("Recenter mesh to AABB center."); - recenterButton->SetSize(XMFLOAT2(240, hei)); - recenterButton->SetPos(XMFLOAT2(x - 50, y += step)); - recenterButton->OnClick([&](wiEventArgs args) { + recenterButton.Create("Recenter"); + recenterButton.SetTooltip("Recenter mesh to AABB center."); + recenterButton.SetSize(XMFLOAT2(240, hei)); + recenterButton.SetPos(XMFLOAT2(x - 50, y += step)); + recenterButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -207,13 +266,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(recenterButton); + AddWidget(&recenterButton); - recenterToBottomButton = new wiButton("RecenterToBottom"); - recenterToBottomButton->SetTooltip("Recenter mesh to AABB bottom."); - recenterToBottomButton->SetSize(XMFLOAT2(240, hei)); - recenterToBottomButton->SetPos(XMFLOAT2(x - 50, y += step)); - recenterToBottomButton->OnClick([&](wiEventArgs args) { + recenterToBottomButton.Create("RecenterToBottom"); + recenterToBottomButton.SetTooltip("Recenter mesh to AABB bottom."); + recenterToBottomButton.SetSize(XMFLOAT2(240, hei)); + recenterToBottomButton.SetPos(XMFLOAT2(x - 50, y += step)); + recenterToBottomButton.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -221,16 +280,16 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); } }); - meshWindow->AddWidget(recenterToBottomButton); + AddWidget(&recenterToBottomButton); x = 150; y = 190; - terrainCheckBox = new wiCheckBox("Terrain: "); - terrainCheckBox->SetTooltip("If enabled, the mesh will use multiple materials and blend between them based on vertex colors."); - terrainCheckBox->SetSize(XMFLOAT2(hei, hei)); - terrainCheckBox->SetPos(XMFLOAT2(x, y += step)); - terrainCheckBox->OnClick([&](wiEventArgs args) { + terrainCheckBox.Create("Terrain: "); + terrainCheckBox.SetTooltip("If enabled, the mesh will use multiple materials and blend between them based on vertex colors."); + terrainCheckBox.SetSize(XMFLOAT2(hei, hei)); + terrainCheckBox.SetPos(XMFLOAT2(x, y += step)); + terrainCheckBox.OnClick([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -253,13 +312,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(entity); // refresh information label } }); - meshWindow->AddWidget(terrainCheckBox); + AddWidget(&terrainCheckBox); - terrainMat1Combo = new wiComboBox("Terrain Material 1: "); - terrainMat1Combo->SetSize(XMFLOAT2(200, hei)); - terrainMat1Combo->SetPos(XMFLOAT2(x + 180, y)); - terrainMat1Combo->SetEnabled(false); - terrainMat1Combo->OnSelect([&](wiEventArgs args) { + terrainMat1Combo.Create("Terrain Material 1: "); + terrainMat1Combo.SetSize(XMFLOAT2(200, hei)); + terrainMat1Combo.SetPos(XMFLOAT2(x + 180, y)); + terrainMat1Combo.SetEnabled(false); + terrainMat1Combo.OnSelect([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -274,14 +333,14 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - terrainMat1Combo->SetTooltip("Choose a sub terrain blend material. (GREEN vertex color mask)"); - meshWindow->AddWidget(terrainMat1Combo); + terrainMat1Combo.SetTooltip("Choose a sub terrain blend material. (GREEN vertex color mask)"); + AddWidget(&terrainMat1Combo); - terrainMat2Combo = new wiComboBox("Terrain Material 2: "); - terrainMat2Combo->SetSize(XMFLOAT2(200, hei)); - terrainMat2Combo->SetPos(XMFLOAT2(x + 180, y += step)); - terrainMat2Combo->SetEnabled(false); - terrainMat2Combo->OnSelect([&](wiEventArgs args) { + terrainMat2Combo.Create("Terrain Material 2: "); + terrainMat2Combo.SetSize(XMFLOAT2(200, hei)); + terrainMat2Combo.SetPos(XMFLOAT2(x + 180, y += step)); + terrainMat2Combo.SetEnabled(false); + terrainMat2Combo.OnSelect([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -296,14 +355,14 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - terrainMat2Combo->SetTooltip("Choose a sub terrain blend material. (BLUE vertex color mask)"); - meshWindow->AddWidget(terrainMat2Combo); + terrainMat2Combo.SetTooltip("Choose a sub terrain blend material. (BLUE vertex color mask)"); + AddWidget(&terrainMat2Combo); - terrainMat3Combo = new wiComboBox("Terrain Material 3: "); - terrainMat3Combo->SetSize(XMFLOAT2(200, hei)); - terrainMat3Combo->SetPos(XMFLOAT2(x + 180, y += step)); - terrainMat3Combo->SetEnabled(false); - terrainMat3Combo->OnSelect([&](wiEventArgs args) { + terrainMat3Combo.Create("Terrain Material 3: "); + terrainMat3Combo.SetSize(XMFLOAT2(200, hei)); + terrainMat3Combo.SetPos(XMFLOAT2(x + 180, y += step)); + terrainMat3Combo.SetEnabled(false); + terrainMat3Combo.OnSelect([&](wiEventArgs args) { MeshComponent* mesh = wiScene::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { @@ -318,38 +377,25 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - terrainMat3Combo->SetTooltip("Choose a sub terrain blend material. (ALPHA vertex color mask)"); - meshWindow->AddWidget(terrainMat3Combo); + terrainMat3Combo.SetTooltip("Choose a sub terrain blend material. (ALPHA vertex color mask)"); + AddWidget(&terrainMat3Combo); - terrainGenButton = new wiButton("Generate Terrain..."); - terrainGenButton->SetTooltip("Generate terrain meshes."); - terrainGenButton->SetSize(XMFLOAT2(200, hei)); - terrainGenButton->SetPos(XMFLOAT2(x + 180, y += step)); - terrainGenButton->OnClick([=](wiEventArgs args) { + terrainGenButton.Create("Generate Terrain..."); + terrainGenButton.SetTooltip("Generate terrain meshes."); + terrainGenButton.SetSize(XMFLOAT2(200, hei)); + terrainGenButton.SetPos(XMFLOAT2(x + 180, y += step)); + terrainGenButton.OnClick([=](wiEventArgs args) { - if (terrainGenWindow != nullptr) - { - GUI->RemoveWidget(terrainGenWindow); - delete terrainGenWindow; - terrainGenWindow = nullptr; - } - if (this->rgb != nullptr) - { - stbi_image_free(this->rgb); - this->rgb = nullptr; - } - - terrainGenWindow = new wiWindow(GUI, "Terrain Gen"); - terrainGenWindow->SetSize(XMFLOAT2(260, 130)); - GUI->AddWidget(terrainGenWindow); - - - float xx = 20; - float yy = 0; - float stepstep = 25; - float heihei = 20; + terragen.Cleanup(); + terragen.SetVisible(true); + editor->GetGUI().RemoveWidget(&terragen); + editor->GetGUI().AddWidget(&terragen); + terragen.SetPos(XMFLOAT2( + terrainGenButton.translation.x + terrainGenButton.scale.x + 10, + terrainGenButton.translation.y) + ); Scene& scene = wiScene::GetScene(); Entity entity = scene.Entity_CreateObject("editorTerrain"); @@ -421,47 +467,24 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) SetEntity(object.meshID); - wiSlider* dimXSlider; - wiSlider* dimYSlider; - wiSlider* dimZSlider; - dimXSlider = new wiSlider(16, 1024, 128, 1024 - 16, "X: "); - dimXSlider->SetTooltip("Terrain mesh grid resolution on X axis"); - dimXSlider->SetSize(XMFLOAT2(200, heihei)); - dimXSlider->SetPos(XMFLOAT2(xx, yy += stepstep)); - terrainGenWindow->AddWidget(dimXSlider); - dimYSlider = new wiSlider(0, 1, 0.5f, 10000, "Y: "); - dimYSlider->SetTooltip("Terrain mesh grid heightmap scale on Y axis"); - dimYSlider->SetSize(XMFLOAT2(200, heihei)); - dimYSlider->SetPos(XMFLOAT2(xx, yy += stepstep)); - terrainGenWindow->AddWidget(dimYSlider); - dimZSlider = new wiSlider(16, 1024, 128, 1024 - 16, "Z: "); - dimZSlider->SetTooltip("Terrain mesh grid resolution on Z axis"); - dimZSlider->SetSize(XMFLOAT2(200, heihei)); - dimZSlider->SetPos(XMFLOAT2(xx, yy += stepstep)); - terrainGenWindow->AddWidget(dimZSlider); - - dimXSlider->OnSlide([=](wiEventArgs args) { - this->width = (int)dimXSlider->GetValue(); - this->height = (int)dimZSlider->GetValue(); - generate_mesh(this->width, this->height); + terragen.dimXSlider.OnSlide([=](wiEventArgs args) { + terragen.width = (int)terragen.dimXSlider.GetValue(); + terragen.height = (int)terragen.dimZSlider.GetValue(); + generate_mesh(terragen.width, terragen.height); }); - dimZSlider->OnSlide([=](wiEventArgs args) { - this->width = (int)dimXSlider->GetValue(); - this->height = (int)dimZSlider->GetValue(); - generate_mesh(this->width, this->height); + terragen.dimZSlider.OnSlide([=](wiEventArgs args) { + terragen.width = (int)terragen.dimXSlider.GetValue(); + terragen.height = (int)terragen.dimZSlider.GetValue(); + generate_mesh(terragen.width, terragen.height); }); - dimYSlider->OnSlide([=](wiEventArgs args) { - generate_mesh(this->width, this->height, this->rgb, this->channelCount, args.fValue); + terragen.dimYSlider.OnSlide([=](wiEventArgs args) { + generate_mesh(terragen.width, terragen.height, terragen.rgb, terragen.channelCount, args.fValue); }); - wiButton* heightmapButton = new wiButton("Load Heightmap..."); - heightmapButton->SetTooltip("Load a heightmap texture, where the red channel corresponds to terrain height and the resolution to dimensions"); - heightmapButton->SetSize(XMFLOAT2(200, heihei)); - heightmapButton->SetPos(XMFLOAT2(xx, yy += stepstep)); - heightmapButton->OnClick([=](wiEventArgs args) { + terragen.heightmapButton.OnClick([=](wiEventArgs args) { wiHelper::FileDialogParams params; params.type = wiHelper::FileDialogParams::OPEN; @@ -472,56 +495,31 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) params.extensions.push_back("tga"); wiHelper::FileDialog(params, [=](std::string fileName) { wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - if (this->rgb != nullptr) + if (terragen.rgb != nullptr) { - stbi_image_free(this->rgb); - this->rgb = nullptr; + stbi_image_free(terragen.rgb); + terragen.rgb = nullptr; } int bpp; - this->rgb = stbi_load(fileName.c_str(), &this->width, &this->height, &bpp, channelCount); + terragen.rgb = stbi_load(fileName.c_str(), &terragen.width, &terragen.height, &bpp, terragen.channelCount); - generate_mesh(width, height, rgb, channelCount, dimYSlider->GetValue()); + generate_mesh(terragen.width, terragen.height, terragen.rgb, terragen.channelCount, terragen.dimYSlider.GetValue()); }); }); }); - terrainGenWindow->AddWidget(heightmapButton); - terrainGenWindow->Translate(XMFLOAT3( - terrainGenButton->translation.x + terrainGenButton->scale.x + 10, - terrainGenButton->translation.y, - 0) - ); }); - meshWindow->AddWidget(terrainGenButton); + AddWidget(&terrainGenButton); - meshWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 1000, 80, 0)); - meshWindow->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 1000, 80, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } -MeshWindow::~MeshWindow() -{ - meshWindow->RemoveWidgets(true); - GUI->RemoveWidget(meshWindow); - delete meshWindow; - - if (terrainGenWindow != nullptr) - { - GUI->RemoveWidget(terrainGenWindow); - delete terrainGenWindow; - terrainGenWindow = nullptr; - } - if (this->rgb != nullptr) - { - stbi_image_free(this->rgb); - this->rgb = nullptr; - } -} - void MeshWindow::SetEntity(Entity entity) { this->entity = entity; @@ -532,17 +530,8 @@ void MeshWindow::SetEntity(Entity entity) if (mesh == nullptr || !mesh->IsTerrain()) { - if (terrainGenWindow != nullptr) - { - GUI->RemoveWidget(terrainGenWindow); - delete terrainGenWindow; - terrainGenWindow = nullptr; - } - if (this->rgb != nullptr) - { - stbi_image_free(this->rgb); - this->rgb = nullptr; - } + terragen.Cleanup(); + terragen.SetVisible(false); } if (mesh != nullptr) @@ -564,63 +553,63 @@ void MeshWindow::SetEntity(Entity entity) if (mesh->vertexBuffer_BON.IsValid()) ss << "bone; "; if (mesh->streamoutBuffer_POS.IsValid()) ss << "streamout; "; if (mesh->IsTerrain()) ss << endl << endl << "Terrain will use 4 blend materials and blend by vertex colors, the default one is always the subset material and uses RED vertex color channel mask, the other 3 are selectable below."; - meshInfoLabel->SetText(ss.str()); + meshInfoLabel.SetText(ss.str()); - terrainCheckBox->SetCheck(mesh->IsTerrain()); + terrainCheckBox.SetCheck(mesh->IsTerrain()); - terrainMat1Combo->ClearItems(); - terrainMat1Combo->AddItem("OFF (Use subset)"); - terrainMat2Combo->ClearItems(); - terrainMat2Combo->AddItem("OFF (Use subset)"); - terrainMat3Combo->ClearItems(); - terrainMat3Combo->AddItem("OFF (Use subset)"); + terrainMat1Combo.ClearItems(); + terrainMat1Combo.AddItem("OFF (Use subset)"); + terrainMat2Combo.ClearItems(); + terrainMat2Combo.AddItem("OFF (Use subset)"); + terrainMat3Combo.ClearItems(); + terrainMat3Combo.AddItem("OFF (Use subset)"); for (size_t i = 0; i < scene.materials.GetCount(); ++i) { Entity entity = scene.materials.GetEntity(i); const NameComponent& name = *scene.names.GetComponent(entity); - terrainMat1Combo->AddItem(name.name); - terrainMat2Combo->AddItem(name.name); - terrainMat3Combo->AddItem(name.name); + terrainMat1Combo.AddItem(name.name); + terrainMat2Combo.AddItem(name.name); + terrainMat3Combo.AddItem(name.name); if (mesh->terrain_material1 == entity) { - terrainMat1Combo->SetSelected((int)i + 1); + terrainMat1Combo.SetSelected((int)i + 1); } if (mesh->terrain_material2 == entity) { - terrainMat2Combo->SetSelected((int)i + 1); + terrainMat2Combo.SetSelected((int)i + 1); } if (mesh->terrain_material3 == entity) { - terrainMat3Combo->SetSelected((int)i + 1); + terrainMat3Combo.SetSelected((int)i + 1); } } - doubleSidedCheckBox->SetCheck(mesh->IsDoubleSided()); + doubleSidedCheckBox.SetCheck(mesh->IsDoubleSided()); const ImpostorComponent* impostor = scene.impostors.GetComponent(entity); if (impostor != nullptr) { - impostorDistanceSlider->SetValue(impostor->swapInDistance); + impostorDistanceSlider.SetValue(impostor->swapInDistance); } - tessellationFactorSlider->SetValue(mesh->GetTessellationFactor()); + tessellationFactorSlider.SetValue(mesh->GetTessellationFactor()); - softbodyCheckBox->SetCheck(false); + softbodyCheckBox.SetCheck(false); SoftBodyPhysicsComponent* physicscomponent = wiScene::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { - softbodyCheckBox->SetCheck(true); - massSlider->SetValue(physicscomponent->mass); - frictionSlider->SetValue(physicscomponent->friction); + softbodyCheckBox.SetCheck(true); + massSlider.SetValue(physicscomponent->mass); + frictionSlider.SetValue(physicscomponent->friction); } - meshWindow->SetEnabled(true); + SetEnabled(true); } else { - meshInfoLabel->SetText("Select a mesh..."); - meshWindow->SetEnabled(false); + meshInfoLabel.SetText("Select a mesh..."); + SetEnabled(false); } - terrainGenButton->SetEnabled(true); + terrainGenButton.SetEnabled(true); } diff --git a/Editor/MeshWindow.h b/Editor/MeshWindow.h index 3566df1c4..3ddc2af12 100644 --- a/Editor/MeshWindow.h +++ b/Editor/MeshWindow.h @@ -1,53 +1,35 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiButton; -class wiComboBox; +#include "WickedEngine.h" class EditorComponent; -class MeshWindow +class MeshWindow : public wiWindow { public: - MeshWindow(EditorComponent* editor); - ~MeshWindow(); - - wiGUI* GUI; + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiWindow* meshWindow; - wiLabel* meshInfoLabel; - wiCheckBox* doubleSidedCheckBox; - wiCheckBox* softbodyCheckBox; - wiSlider* massSlider; - wiSlider* frictionSlider; - wiButton* impostorCreateButton; - wiSlider* impostorDistanceSlider; - wiSlider* tessellationFactorSlider; - wiButton* flipCullingButton; - wiButton* flipNormalsButton; - wiButton* computeNormalsSmoothButton; - wiButton* computeNormalsHardButton; - wiButton* recenterButton; - wiButton* recenterToBottomButton; + wiLabel meshInfoLabel; + wiCheckBox doubleSidedCheckBox; + wiCheckBox softbodyCheckBox; + wiSlider massSlider; + wiSlider frictionSlider; + wiButton impostorCreateButton; + wiSlider impostorDistanceSlider; + wiSlider tessellationFactorSlider; + wiButton flipCullingButton; + wiButton flipNormalsButton; + wiButton computeNormalsSmoothButton; + wiButton computeNormalsHardButton; + wiButton recenterButton; + wiButton recenterToBottomButton; - wiCheckBox* terrainCheckBox; - wiComboBox* terrainMat1Combo; - wiComboBox* terrainMat2Combo; - wiComboBox* terrainMat3Combo; - wiButton* terrainGenButton; - - wiWindow* terrainGenWindow = nullptr; - - // heightmap texture: - unsigned char* rgb = nullptr; - const int channelCount = 4; - int width = 0, height = 0; + wiCheckBox terrainCheckBox; + wiComboBox terrainMat1Combo; + wiComboBox terrainMat2Combo; + wiComboBox terrainMat3Combo; + wiButton terrainGenButton; }; diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 0e7232423..5c161e172 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -355,7 +355,6 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) string directory, name; wiHelper::SplitPath(fileName, directory, name); string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(name)); - wiHelper::RemoveExtensionFromFileName(name); tinygltf::TinyGLTF loader; @@ -407,6 +406,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) Entity rootEntity = CreateEntity(); scene.transforms.Create(rootEntity); + scene.names.Create(rootEntity) = name; // Create materials: for (auto& x : state.gltfModel.materials) @@ -450,7 +450,6 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) auto& img = state.gltfModel.images[tex.source]; material.normalMap = RegisterTexture(&img, "normal"); material.normalMapName = img.uri; - material.SetFlipNormalMap(true); // gltf import will always flip normal map by default material.uvset_normalMap = normalTexture->second.TextureTexCoord(); } if (metallicRoughnessTexture != x.values.end()) @@ -513,6 +512,12 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) } } + auto unlit = x.extensions.find("KHR_materials_unlit"); + if (unlit != x.extensions.end()) + { + material.shaderType = MaterialComponent::SHADERTYPE_UNLIT; + } + // specular-glossiness workflow (todo): auto specularGlossinessWorkflow = x.extensions.find("KHR_materials_pbrSpecularGlossiness"); if (specularGlossinessWorkflow != x.extensions.end()) @@ -679,6 +684,15 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) mesh.vertex_normals[vertexOffset + i] = ((XMFLOAT3*)data)[i]; } } + else if (!attr_name.compare("TANGENT")) + { + mesh.vertex_tangents.resize(vertexOffset + vertexCount); + assert(stride == 16); + for (size_t i = 0; i < vertexCount; ++i) + { + mesh.vertex_tangents[vertexOffset + i] = ((XMFLOAT4*)data)[i]; + } + } else if (!attr_name.compare("TEXCOORD_0")) { mesh.vertex_uvset_0.resize(vertexOffset + vertexCount); diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 742d29327..b0667a64a 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -76,7 +76,6 @@ void ImportModel_OBJ(const std::string& fileName, Scene& scene) { string directory, name; wiHelper::SplitPath(fileName, directory, name); - wiHelper::RemoveExtensionFromFileName(name); tinyobj::attrib_t obj_attrib; vector obj_shapes; diff --git a/Editor/NameWindow.cpp b/Editor/NameWindow.cpp index 64beb3214..cacee8f5b 100644 --- a/Editor/NameWindow.cpp +++ b/Editor/NameWindow.cpp @@ -6,13 +6,10 @@ using namespace wiECS; using namespace wiScene; -NameWindow::NameWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void NameWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - window = new wiWindow(GUI, "Name Window"); - window->SetSize(XMFLOAT2(360, 80)); - GUI->AddWidget(window); + wiWindow::Create("Name Window"); + SetSize(XMFLOAT2(360, 80)); float x = 60; float y = 0; @@ -20,11 +17,11 @@ NameWindow::NameWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) float siz = 280; float hei = 20; - nameInput = new wiTextInputField(""); - nameInput->SetDescription("Name: "); - nameInput->SetPos(XMFLOAT2(x, y += step)); - nameInput->SetSize(XMFLOAT2(siz, hei)); - nameInput->OnInputAccepted([&](wiEventArgs args) { + nameInput.Create(""); + nameInput.SetDescription("Name: "); + nameInput.SetPos(XMFLOAT2(x, y += step)); + nameInput.SetSize(XMFLOAT2(siz, hei)); + nameInput.OnInputAccepted([&](wiEventArgs args) { NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name == nullptr) { @@ -32,39 +29,31 @@ NameWindow::NameWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } name->name = args.sValue; }); - window->AddWidget(nameInput); + AddWidget(&nameInput); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 450, 200, 0)); - window->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 450, 200, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -NameWindow::~NameWindow() -{ - window->RemoveWidgets(true); - GUI->RemoveWidget(window); - delete window; -} - void NameWindow::SetEntity(Entity entity) { this->entity = entity; if (entity != INVALID_ENTITY) { - window->SetEnabled(true); + SetEnabled(true); NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name != nullptr) { - nameInput->SetValue(name->name); + nameInput.SetValue(name->name); } } else { - window->SetEnabled(false); - nameInput->SetValue("Select entity to modify name..."); + SetEnabled(false); + nameInput.SetValue("Select entity to modify name..."); } } diff --git a/Editor/NameWindow.h b/Editor/NameWindow.h index 96551b69f..14e3ba035 100644 --- a/Editor/NameWindow.h +++ b/Editor/NameWindow.h @@ -1,29 +1,16 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class NameWindow +class NameWindow : public wiWindow { public: - NameWindow(EditorComponent* editor); - ~NameWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* window; - - wiTextInputField* nameInput; + wiTextInputField nameInput; }; diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 54c0894e5..4d2436347 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -245,82 +245,80 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu } -ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) +void ObjectWindow::Create(EditorComponent* editor) { - GUI = &editor->GetGUI(); - assert(GUI && "Invalid GUI!"); + this->editor = editor; - objectWindow = new wiWindow(GUI, "Object Window"); - objectWindow->SetSize(XMFLOAT2(350, 610)); - GUI->AddWidget(objectWindow); + wiWindow::Create("Object Window"); + SetSize(XMFLOAT2(350, 610)); float x = 200; float y = 0; float hei = 18; float step = hei + 2; - nameLabel = new wiLabel("NAMELABEL"); - nameLabel->SetText(""); - nameLabel->SetPos(XMFLOAT2(x - 30, y += step)); - nameLabel->SetSize(XMFLOAT2(150, hei)); - objectWindow->AddWidget(nameLabel); + nameLabel.Create("NAMELABEL"); + nameLabel.SetText(""); + nameLabel.SetPos(XMFLOAT2(x - 30, y += step)); + nameLabel.SetSize(XMFLOAT2(150, hei)); + AddWidget(&nameLabel); - renderableCheckBox = new wiCheckBox("Renderable: "); - renderableCheckBox->SetTooltip("Set object to be participating in rendering."); - renderableCheckBox->SetSize(XMFLOAT2(hei, hei)); - renderableCheckBox->SetPos(XMFLOAT2(x, y += step)); - renderableCheckBox->SetCheck(true); - renderableCheckBox->OnClick([&](wiEventArgs args) { + renderableCheckBox.Create("Renderable: "); + renderableCheckBox.SetTooltip("Set object to be participating in rendering."); + renderableCheckBox.SetSize(XMFLOAT2(hei, hei)); + renderableCheckBox.SetPos(XMFLOAT2(x, y += step)); + renderableCheckBox.SetCheck(true); + renderableCheckBox.OnClick([&](wiEventArgs args) { ObjectComponent* object = wiScene::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->SetRenderable(args.bValue); } }); - objectWindow->AddWidget(renderableCheckBox); + AddWidget(&renderableCheckBox); - ditherSlider = new wiSlider(0, 1, 0, 1000, "Dither: "); - ditherSlider->SetTooltip("Adjust dithered transparency of the object. This disables some optimizations so performance can be affected."); - ditherSlider->SetSize(XMFLOAT2(100, hei)); - ditherSlider->SetPos(XMFLOAT2(x, y += step)); - ditherSlider->OnSlide([&](wiEventArgs args) { + ditherSlider.Create(0, 1, 0, 1000, "Dither: "); + ditherSlider.SetTooltip("Adjust dithered transparency of the object. This disables some optimizations so performance can be affected."); + ditherSlider.SetSize(XMFLOAT2(100, hei)); + ditherSlider.SetPos(XMFLOAT2(x, y += step)); + ditherSlider.OnSlide([&](wiEventArgs args) { ObjectComponent* object = wiScene::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->color.w = 1 - args.fValue; } }); - objectWindow->AddWidget(ditherSlider); + AddWidget(&ditherSlider); - cascadeMaskSlider = new wiSlider(0, 3, 0, 3, "Cascade Mask: "); - cascadeMaskSlider->SetTooltip("How many shadow cascades to skip when rendering this object into shadow maps? (0: skip none, it will be in all cascades, 1: skip first (biggest cascade), ...etc..."); - cascadeMaskSlider->SetSize(XMFLOAT2(100, hei)); - cascadeMaskSlider->SetPos(XMFLOAT2(x, y += step)); - cascadeMaskSlider->OnSlide([&](wiEventArgs args) { + cascadeMaskSlider.Create(0, 3, 0, 3, "Cascade Mask: "); + cascadeMaskSlider.SetTooltip("How many shadow cascades to skip when rendering this object into shadow maps? (0: skip none, it will be in all cascades, 1: skip first (biggest cascade), ...etc..."); + cascadeMaskSlider.SetSize(XMFLOAT2(100, hei)); + cascadeMaskSlider.SetPos(XMFLOAT2(x, y += step)); + cascadeMaskSlider.OnSlide([&](wiEventArgs args) { ObjectComponent* object = wiScene::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->cascadeMask = (uint32_t)args.iValue; } }); - objectWindow->AddWidget(cascadeMaskSlider); + AddWidget(&cascadeMaskSlider); y += step; - physicsLabel = new wiLabel("PHYSICSLABEL"); - physicsLabel->SetText("PHYSICS SETTINGS"); - physicsLabel->SetPos(XMFLOAT2(x - 30, y += step)); - physicsLabel->SetSize(XMFLOAT2(150, hei)); - objectWindow->AddWidget(physicsLabel); + physicsLabel.Create("PHYSICSLABEL"); + physicsLabel.SetText("PHYSICS SETTINGS"); + physicsLabel.SetPos(XMFLOAT2(x - 30, y += step)); + physicsLabel.SetSize(XMFLOAT2(150, hei)); + AddWidget(&physicsLabel); - rigidBodyCheckBox = new wiCheckBox("Rigid Body Physics: "); - rigidBodyCheckBox->SetTooltip("Enable rigid body physics simulation."); - rigidBodyCheckBox->SetSize(XMFLOAT2(hei, hei)); - rigidBodyCheckBox->SetPos(XMFLOAT2(x, y += step)); - rigidBodyCheckBox->SetCheck(false); - rigidBodyCheckBox->OnClick([&](wiEventArgs args) + rigidBodyCheckBox.Create("Rigid Body Physics: "); + rigidBodyCheckBox.SetTooltip("Enable rigid body physics simulation."); + rigidBodyCheckBox.SetSize(XMFLOAT2(hei, hei)); + rigidBodyCheckBox.SetPos(XMFLOAT2(x, y += step)); + rigidBodyCheckBox.SetCheck(false); + rigidBodyCheckBox.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); RigidBodyPhysicsComponent* physicscomponent = scene.rigidbodies.GetComponent(entity); @@ -330,9 +328,9 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) if (physicscomponent == nullptr) { RigidBodyPhysicsComponent& rigidbody = scene.rigidbodies.Create(entity); - rigidbody.SetKinematic(kinematicCheckBox->GetCheck()); - rigidbody.SetDisableDeactivation(disabledeactivationCheckBox->GetCheck()); - rigidbody.shape = (RigidBodyPhysicsComponent::CollisionShape)collisionShapeComboBox->GetSelected(); + rigidbody.SetKinematic(kinematicCheckBox.GetCheck()); + rigidbody.SetDisableDeactivation(disabledeactivationCheckBox.GetCheck()); + rigidbody.shape = (RigidBodyPhysicsComponent::CollisionShape)collisionShapeComboBox.GetSelected(); } } else @@ -344,45 +342,45 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) } }); - objectWindow->AddWidget(rigidBodyCheckBox); + AddWidget(&rigidBodyCheckBox); - kinematicCheckBox = new wiCheckBox("Kinematic: "); - kinematicCheckBox->SetTooltip("Toggle kinematic behaviour."); - kinematicCheckBox->SetSize(XMFLOAT2(hei, hei)); - kinematicCheckBox->SetPos(XMFLOAT2(x, y += step)); - kinematicCheckBox->SetCheck(false); - kinematicCheckBox->OnClick([&](wiEventArgs args) { + kinematicCheckBox.Create("Kinematic: "); + kinematicCheckBox.SetTooltip("Toggle kinematic behaviour."); + kinematicCheckBox.SetSize(XMFLOAT2(hei, hei)); + kinematicCheckBox.SetPos(XMFLOAT2(x, y += step)); + kinematicCheckBox.SetCheck(false); + kinematicCheckBox.OnClick([&](wiEventArgs args) { RigidBodyPhysicsComponent* physicscomponent = wiScene::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->SetKinematic(args.bValue); } }); - objectWindow->AddWidget(kinematicCheckBox); + AddWidget(&kinematicCheckBox); - disabledeactivationCheckBox = new wiCheckBox("Disable Deactivation: "); - disabledeactivationCheckBox->SetTooltip("Toggle kinematic behaviour."); - disabledeactivationCheckBox->SetSize(XMFLOAT2(hei, hei)); - disabledeactivationCheckBox->SetPos(XMFLOAT2(x, y += step)); - disabledeactivationCheckBox->SetCheck(false); - disabledeactivationCheckBox->OnClick([&](wiEventArgs args) { + disabledeactivationCheckBox.Create("Disable Deactivation: "); + disabledeactivationCheckBox.SetTooltip("Toggle kinematic behaviour."); + disabledeactivationCheckBox.SetSize(XMFLOAT2(hei, hei)); + disabledeactivationCheckBox.SetPos(XMFLOAT2(x, y += step)); + disabledeactivationCheckBox.SetCheck(false); + disabledeactivationCheckBox.OnClick([&](wiEventArgs args) { RigidBodyPhysicsComponent* physicscomponent = wiScene::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->SetDisableDeactivation(args.bValue); } }); - objectWindow->AddWidget(disabledeactivationCheckBox); + AddWidget(&disabledeactivationCheckBox); - collisionShapeComboBox = new wiComboBox("Collision Shape:"); - collisionShapeComboBox->SetSize(XMFLOAT2(100, hei)); - collisionShapeComboBox->SetPos(XMFLOAT2(x, y += step)); - collisionShapeComboBox->AddItem("Box"); - collisionShapeComboBox->AddItem("Sphere"); - collisionShapeComboBox->AddItem("Capsule"); - collisionShapeComboBox->AddItem("Convex Hull"); - collisionShapeComboBox->AddItem("Triangle Mesh"); - collisionShapeComboBox->OnSelect([&](wiEventArgs args) + collisionShapeComboBox.Create("Collision Shape:"); + collisionShapeComboBox.SetSize(XMFLOAT2(100, hei)); + collisionShapeComboBox.SetPos(XMFLOAT2(x, y += step)); + collisionShapeComboBox.AddItem("Box"); + collisionShapeComboBox.AddItem("Sphere"); + collisionShapeComboBox.AddItem("Capsule"); + collisionShapeComboBox.AddItem("Convex Hull"); + collisionShapeComboBox.AddItem("Triangle Mesh"); + collisionShapeComboBox.OnSelect([&](wiEventArgs args) { RigidBodyPhysicsComponent* physicscomponent = wiScene::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) @@ -409,41 +407,41 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) } } }); - collisionShapeComboBox->SetSelected(0); - collisionShapeComboBox->SetEnabled(true); - collisionShapeComboBox->SetTooltip("Set rigid body collision shape."); - objectWindow->AddWidget(collisionShapeComboBox); + collisionShapeComboBox.SetSelected(0); + collisionShapeComboBox.SetEnabled(true); + collisionShapeComboBox.SetTooltip("Set rigid body collision shape."); + AddWidget(&collisionShapeComboBox); y += step; - lightmapResolutionSlider = new wiSlider(32, 1024, 128, 1024 - 32, "Lightmap resolution: "); - lightmapResolutionSlider->SetTooltip("Set the approximate resolution for this object's lightmap. This will be packed into the larger global lightmap later."); - lightmapResolutionSlider->SetSize(XMFLOAT2(100, hei)); - lightmapResolutionSlider->SetPos(XMFLOAT2(x, y += step)); - lightmapResolutionSlider->OnSlide([&](wiEventArgs args) { + lightmapResolutionSlider.Create(32, 1024, 128, 1024 - 32, "Lightmap resolution: "); + lightmapResolutionSlider.SetTooltip("Set the approximate resolution for this object's lightmap. This will be packed into the larger global lightmap later."); + lightmapResolutionSlider.SetSize(XMFLOAT2(100, hei)); + lightmapResolutionSlider.SetPos(XMFLOAT2(x, y += step)); + lightmapResolutionSlider.OnSlide([&](wiEventArgs args) { // unfortunately, we must be pow2 with full float lightmap format, otherwise it could be unlimited (but accumulation blending would suffer then) // or at least for me, downloading the lightmap was glitching out when non-pow 2 and RGBA32_FLOAT format - lightmapResolutionSlider->SetValue(float(wiMath::GetNextPowerOfTwo(uint32_t(args.fValue)))); + lightmapResolutionSlider.SetValue(float(wiMath::GetNextPowerOfTwo(uint32_t(args.fValue)))); }); - objectWindow->AddWidget(lightmapResolutionSlider); + AddWidget(&lightmapResolutionSlider); - lightmapSourceUVSetComboBox = new wiComboBox("UV Set: "); - lightmapSourceUVSetComboBox->SetPos(XMFLOAT2(x - 130, y += step)); - lightmapSourceUVSetComboBox->AddItem("Copy UV 0"); - lightmapSourceUVSetComboBox->AddItem("Copy UV 1"); - lightmapSourceUVSetComboBox->AddItem("Keep Atlas"); - lightmapSourceUVSetComboBox->AddItem("Generate Atlas"); - lightmapSourceUVSetComboBox->SetSelected(3); - lightmapSourceUVSetComboBox->SetTooltip("Set which UV set to use when generating the lightmap Atlas"); - objectWindow->AddWidget(lightmapSourceUVSetComboBox); + lightmapSourceUVSetComboBox.Create("UV Set: "); + lightmapSourceUVSetComboBox.SetPos(XMFLOAT2(x - 130, y += step)); + lightmapSourceUVSetComboBox.AddItem("Copy UV 0"); + lightmapSourceUVSetComboBox.AddItem("Copy UV 1"); + lightmapSourceUVSetComboBox.AddItem("Keep Atlas"); + lightmapSourceUVSetComboBox.AddItem("Generate Atlas"); + lightmapSourceUVSetComboBox.SetSelected(3); + lightmapSourceUVSetComboBox.SetTooltip("Set which UV set to use when generating the lightmap Atlas"); + AddWidget(&lightmapSourceUVSetComboBox); - generateLightmapButton = new wiButton("Generate Lightmap"); - generateLightmapButton->SetTooltip("Render the lightmap for only this object. It will automatically combined with the global lightmap."); - generateLightmapButton->SetPos(XMFLOAT2(x, y)); - generateLightmapButton->SetSize(XMFLOAT2(140, hei)); - generateLightmapButton->OnClick([&](wiEventArgs args) { + generateLightmapButton.Create("Generate Lightmap"); + generateLightmapButton.SetTooltip("Render the lightmap for only this object. It will automatically combined with the global lightmap."); + generateLightmapButton.SetPos(XMFLOAT2(x, y)); + generateLightmapButton.SetSize(XMFLOAT2(140, hei)); + generateLightmapButton.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); @@ -454,7 +452,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) UV_GEN_KEEP_ATLAS, UV_GEN_GENERATE_ATLAS, }; - UV_GEN_TYPE gen_type = (UV_GEN_TYPE)lightmapSourceUVSetComboBox->GetSelected(); + UV_GEN_TYPE gen_type = (UV_GEN_TYPE)lightmapSourceUVSetComboBox.GetSelected(); std::unordered_set gen_objects; std::unordered_map gen_meshes; @@ -493,7 +491,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) else if (gen_type == UV_GEN_GENERATE_ATLAS) { wiJobSystem::Execute(ctx, [&](wiJobArgs args) { - it.second = GenerateMeshAtlas(mesh, (uint32_t)lightmapResolutionSlider->GetValue()); + it.second = GenerateMeshAtlas(mesh, (uint32_t)lightmapResolutionSlider.GetValue()); }); } } @@ -510,7 +508,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) } else { - x->lightmapWidth = x->lightmapHeight = (uint32_t)lightmapResolutionSlider->GetValue(); + x->lightmapWidth = x->lightmapHeight = (uint32_t)lightmapResolutionSlider.GetValue(); } x->SetLightmapRenderRequest(true); } @@ -518,13 +516,13 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) wiRenderer::InvalidateBVH(); }); - objectWindow->AddWidget(generateLightmapButton); + AddWidget(&generateLightmapButton); - stopLightmapGenButton = new wiButton("Stop Lightmap Gen"); - stopLightmapGenButton->SetTooltip("Stop the lightmap rendering and save the lightmap."); - stopLightmapGenButton->SetPos(XMFLOAT2(x, y += step)); - stopLightmapGenButton->SetSize(XMFLOAT2(140, hei)); - stopLightmapGenButton->OnClick([&](wiEventArgs args) { + stopLightmapGenButton.Create("Stop Lightmap Gen"); + stopLightmapGenButton.SetTooltip("Stop the lightmap rendering and save the lightmap."); + stopLightmapGenButton.SetPos(XMFLOAT2(x, y += step)); + stopLightmapGenButton.SetSize(XMFLOAT2(140, hei)); + stopLightmapGenButton.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); @@ -539,13 +537,13 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) } }); - objectWindow->AddWidget(stopLightmapGenButton); + AddWidget(&stopLightmapGenButton); - clearLightmapButton = new wiButton("Clear Lightmap"); - clearLightmapButton->SetTooltip("Clear the lightmap from this object."); - clearLightmapButton->SetPos(XMFLOAT2(x, y += step)); - clearLightmapButton->SetSize(XMFLOAT2(140, hei)); - clearLightmapButton->OnClick([&](wiEventArgs args) { + clearLightmapButton.Create("Clear Lightmap"); + clearLightmapButton.SetTooltip("Clear the lightmap from this object."); + clearLightmapButton.SetPos(XMFLOAT2(x, y += step)); + clearLightmapButton.SetSize(XMFLOAT2(140, hei)); + clearLightmapButton.OnClick([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); @@ -559,15 +557,15 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) } }); - objectWindow->AddWidget(clearLightmapButton); + AddWidget(&clearLightmapButton); y += step; - colorPicker = new wiColorPicker(GUI, "Object Color", false); - colorPicker->SetPos(XMFLOAT2(20, y += step)); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { + colorPicker.Create("Object Color", false); + colorPicker.SetPos(XMFLOAT2(20, y += step)); + colorPicker.SetVisible(true); + colorPicker.SetEnabled(true); + colorPicker.OnColorChanged([&](wiEventArgs args) { ObjectComponent* object = wiScene::GetScene().objects.GetComponent(entity); if (object != nullptr) { @@ -575,24 +573,16 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) object->color = XMFLOAT4(col.x, col.y, col.z, object->color.w); } }); - objectWindow->AddWidget(colorPicker); + AddWidget(&colorPicker); - objectWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 120, 0)); - objectWindow->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 720, 120, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } -ObjectWindow::~ObjectWindow() -{ - objectWindow->RemoveWidgets(true); - GUI->RemoveWidget(objectWindow); - delete objectWindow; -} - - void ObjectWindow::SetEntity(Entity entity) { this->entity = entity; @@ -603,51 +593,51 @@ void ObjectWindow::SetEntity(Entity entity) if (object != nullptr) { - objectWindow->SetEnabled(true); + SetEnabled(true); const NameComponent* name = scene.names.GetComponent(entity); - nameLabel->SetText(name == nullptr ? std::to_string(entity) : name->name); + nameLabel.SetText(name == nullptr ? std::to_string(entity) : name->name); - renderableCheckBox->SetCheck(object->IsRenderable()); - cascadeMaskSlider->SetValue((float)object->cascadeMask); - ditherSlider->SetValue(object->GetTransparency()); - colorPicker->SetPickColor(wiColor::fromFloat4(object->color)); + renderableCheckBox.SetCheck(object->IsRenderable()); + cascadeMaskSlider.SetValue((float)object->cascadeMask); + ditherSlider.SetValue(object->GetTransparency()); + colorPicker.SetPickColor(wiColor::fromFloat4(object->color)); const RigidBodyPhysicsComponent* physicsComponent = scene.rigidbodies.GetComponent(entity); - rigidBodyCheckBox->SetCheck(physicsComponent != nullptr); + rigidBodyCheckBox.SetCheck(physicsComponent != nullptr); if (physicsComponent != nullptr) { - kinematicCheckBox->SetCheck(physicsComponent->IsKinematic()); - disabledeactivationCheckBox->SetCheck(physicsComponent->IsDisableDeactivation()); + kinematicCheckBox.SetCheck(physicsComponent->IsKinematic()); + disabledeactivationCheckBox.SetCheck(physicsComponent->IsDisableDeactivation()); if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::BOX) { - collisionShapeComboBox->SetSelected(0); + collisionShapeComboBox.SetSelected(0); } else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::SPHERE) { - collisionShapeComboBox->SetSelected(1); + collisionShapeComboBox.SetSelected(1); } else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::CAPSULE) { - collisionShapeComboBox->SetSelected(2); + collisionShapeComboBox.SetSelected(2); } else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL) { - collisionShapeComboBox->SetSelected(3); + collisionShapeComboBox.SetSelected(3); } else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH) { - collisionShapeComboBox->SetSelected(4); + collisionShapeComboBox.SetSelected(4); } } } else { - objectWindow->SetEnabled(false); + SetEnabled(false); } } diff --git a/Editor/ObjectWindow.h b/Editor/ObjectWindow.h index fc11421c6..bcc830be9 100644 --- a/Editor/ObjectWindow.h +++ b/Editor/ObjectWindow.h @@ -1,44 +1,33 @@ #pragma once +#include "WickedEngine.h" + class EditorComponent; -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; - -class ObjectWindow +class ObjectWindow : public wiWindow { public: - ObjectWindow(EditorComponent* editor); - ~ObjectWindow(); + void Create(EditorComponent* editor); EditorComponent* editor; wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; + wiLabel nameLabel; + wiCheckBox renderableCheckBox; + wiSlider ditherSlider; + wiSlider cascadeMaskSlider; + wiColorPicker colorPicker; - wiWindow* objectWindow; + wiLabel physicsLabel; + wiCheckBox rigidBodyCheckBox; + wiCheckBox disabledeactivationCheckBox; + wiCheckBox kinematicCheckBox; + wiComboBox collisionShapeComboBox; - wiLabel* nameLabel; - wiCheckBox* renderableCheckBox; - wiSlider* ditherSlider; - wiSlider* cascadeMaskSlider; - wiColorPicker* colorPicker; - - wiLabel* physicsLabel; - wiCheckBox* rigidBodyCheckBox; - wiCheckBox* disabledeactivationCheckBox; - wiCheckBox* kinematicCheckBox; - wiComboBox* collisionShapeComboBox; - - wiSlider* lightmapResolutionSlider; - wiComboBox* lightmapSourceUVSetComboBox; - wiButton* generateLightmapButton; - wiButton* stopLightmapGenButton; - wiButton* clearLightmapButton; + wiSlider lightmapResolutionSlider; + wiComboBox lightmapSourceUVSetComboBox; + wiButton generateLightmapButton; + wiButton stopLightmapGenButton; + wiButton clearLightmapButton; }; diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index 61d63c261..92936ff7c 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -10,143 +10,144 @@ using namespace wiECS; using namespace wiScene; using namespace wiGraphics; -PaintToolWindow::PaintToolWindow(EditorComponent* editor) : editor(editor) +void PaintToolWindow::Create(EditorComponent* editor) { - window = new wiWindow(&editor->GetGUI(), "Paint Tool Window"); - window->SetSize(XMFLOAT2(400, 600)); - editor->GetGUI().AddWidget(window); + this->editor = editor; + + wiWindow::Create("Paint Tool Window"); + SetSize(XMFLOAT2(400, 600)); float x = 100; float y = 5; float hei = 20; float step = hei + 4; - modeComboBox = new wiComboBox("Mode: "); - modeComboBox->SetTooltip("Choose paint tool mode"); - modeComboBox->SetPos(XMFLOAT2(x, y += step)); - modeComboBox->SetSize(XMFLOAT2(200, hei)); - modeComboBox->AddItem("Disabled"); - modeComboBox->AddItem("Texture"); - modeComboBox->AddItem("Vertexcolor"); - modeComboBox->AddItem("Sculpting - Add"); - modeComboBox->AddItem("Sculpting - Subtract"); - modeComboBox->AddItem("Softbody - Pinning"); - modeComboBox->AddItem("Softbody - Physics"); - modeComboBox->AddItem("Hairparticle - Add Triangle"); - modeComboBox->AddItem("Hairparticle - Remove Triangle"); - modeComboBox->AddItem("Hairparticle - Length (Alpha)"); - modeComboBox->AddItem("Wind weight (Alpha)"); - modeComboBox->SetSelected(0); - modeComboBox->OnSelect([&](wiEventArgs args) { - textureSlotComboBox->SetEnabled(false); - saveTextureButton->SetEnabled(false); + modeComboBox.Create("Mode: "); + modeComboBox.SetTooltip("Choose paint tool mode"); + modeComboBox.SetPos(XMFLOAT2(x, y += step)); + modeComboBox.SetSize(XMFLOAT2(200, hei)); + modeComboBox.AddItem("Disabled"); + modeComboBox.AddItem("Texture"); + modeComboBox.AddItem("Vertexcolor"); + modeComboBox.AddItem("Sculpting - Add"); + modeComboBox.AddItem("Sculpting - Subtract"); + modeComboBox.AddItem("Softbody - Pinning"); + modeComboBox.AddItem("Softbody - Physics"); + modeComboBox.AddItem("Hairparticle - Add Triangle"); + modeComboBox.AddItem("Hairparticle - Remove Triangle"); + modeComboBox.AddItem("Hairparticle - Length (Alpha)"); + modeComboBox.AddItem("Wind weight (Alpha)"); + modeComboBox.SetSelected(0); + modeComboBox.OnSelect([&](wiEventArgs args) { + textureSlotComboBox.SetEnabled(false); + saveTextureButton.SetEnabled(false); switch (args.iValue) { case MODE_DISABLED: - infoLabel->SetText("Paint Tool is disabled."); + infoLabel.SetText("Paint Tool is disabled."); break; case MODE_TEXTURE: - infoLabel->SetText("In texture paint mode, you can paint on textures. Brush will be applied in texture space.\nREMEMBER to save texture when finished to save texture file!\nREMEMBER to save scene to retain new texture bindings on materials!"); - textureSlotComboBox->SetEnabled(true); - saveTextureButton->SetEnabled(true); + infoLabel.SetText("In texture paint mode, you can paint on textures. Brush will be applied in texture space.\nREMEMBER to save texture when finished to save texture file!\nREMEMBER to save scene to retain new texture bindings on materials!"); + textureSlotComboBox.SetEnabled(true); + saveTextureButton.SetEnabled(true); break; case MODE_VERTEXCOLOR: - infoLabel->SetText("In vertex color mode, you can paint colors on selected geometry (per vertex). \"Use vertex colors\" will be automatically enabled for the selected material, or all materials if the whole object is selected. If there is no vertexcolors vertex buffer, one will be created with white as default for every vertex."); + infoLabel.SetText("In vertex color mode, you can paint colors on selected geometry (per vertex). \"Use vertex colors\" will be automatically enabled for the selected material, or all materials if the whole object is selected. If there is no vertexcolors vertex buffer, one will be created with white as default for every vertex."); break; case MODE_SCULPTING_ADD: - infoLabel->SetText("In sculpt - ADD mode, you can modify vertex positions by ADD operation along normal vector (average normal of vertices touched by brush)."); + infoLabel.SetText("In sculpt - ADD mode, you can modify vertex positions by ADD operation along normal vector (average normal of vertices touched by brush)."); break; case MODE_SCULPTING_SUBTRACT: - infoLabel->SetText("In sculpt - SUBTRACT mode, you can modify vertex positions by SUBTRACT operation along normal vector (average normal of vertices touched by brush)."); + infoLabel.SetText("In sculpt - SUBTRACT mode, you can modify vertex positions by SUBTRACT operation along normal vector (average normal of vertices touched by brush)."); break; case MODE_SOFTBODY_PINNING: - infoLabel->SetText("In soft body pinning mode, the selected object's soft body vertices can be pinned down (so they will be fixed and drive physics)"); + infoLabel.SetText("In soft body pinning mode, the selected object's soft body vertices can be pinned down (so they will be fixed and drive physics)"); break; case MODE_SOFTBODY_PHYSICS: - infoLabel->SetText("In soft body physics mode, the selected object's soft body vertices can be unpinned (so they will be simulated by physics)"); + infoLabel.SetText("In soft body physics mode, the selected object's soft body vertices can be unpinned (so they will be simulated by physics)"); break; case MODE_HAIRPARTICLE_ADD_TRIANGLE: - infoLabel->SetText("In hair particle add triangle mode, you can add triangles to the hair base mesh.\nThis will modify random distribution of hair!"); + infoLabel.SetText("In hair particle add triangle mode, you can add triangles to the hair base mesh.\nThis will modify random distribution of hair!"); break; case MODE_HAIRPARTICLE_REMOVE_TRIANGLE: - infoLabel->SetText("In hair particle remove triangle mode, you can remove triangles from the hair base mesh.\nThis will modify random distribution of hair!"); + infoLabel.SetText("In hair particle remove triangle mode, you can remove triangles from the hair base mesh.\nThis will modify random distribution of hair!"); break; case MODE_HAIRPARTICLE_LENGTH: - infoLabel->SetText("In hair particle length mode, you can adjust length of hair particles with the colorpicker Alpha channel (A). The Alpha channel is 0-255, but the length will be normalized to 0-1 range.\nThis will NOT modify random distribution of hair!"); + infoLabel.SetText("In hair particle length mode, you can adjust length of hair particles with the colorpicker Alpha channel (A). The Alpha channel is 0-255, but the length will be normalized to 0-1 range.\nThis will NOT modify random distribution of hair!"); break; case MODE_WIND: - infoLabel->SetText("Paint the wind affection amount onto the vertices. Use the Alpha channel to control the amount."); + infoLabel.SetText("Paint the wind affection amount onto the vertices. Use the Alpha channel to control the amount."); break; } }); - window->AddWidget(modeComboBox); + AddWidget(&modeComboBox); y += step + 5; - infoLabel = new wiLabel("Paint Tool is disabled."); - infoLabel->SetSize(XMFLOAT2(400 - 20, 100)); - infoLabel->SetPos(XMFLOAT2(10, y)); - infoLabel->SetColor(wiColor::Transparent()); - window->AddWidget(infoLabel); - y += infoLabel->GetScale().y - step + 5; + infoLabel.Create("Paint Tool is disabled."); + infoLabel.SetSize(XMFLOAT2(400 - 20, 100)); + infoLabel.SetPos(XMFLOAT2(10, y)); + infoLabel.SetColor(wiColor::Transparent()); + AddWidget(&infoLabel); + y += infoLabel.GetScale().y - step + 5; - radiusSlider = new wiSlider(1.0f, 500.0f, 50, 10000, "Brush Radius: "); - radiusSlider->SetTooltip("Set the brush radius in pixel units"); - radiusSlider->SetSize(XMFLOAT2(200, hei)); - radiusSlider->SetPos(XMFLOAT2(x, y += step)); - window->AddWidget(radiusSlider); + radiusSlider.Create(1.0f, 500.0f, 50, 10000, "Brush Radius: "); + radiusSlider.SetTooltip("Set the brush radius in pixel units"); + radiusSlider.SetSize(XMFLOAT2(200, hei)); + radiusSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&radiusSlider); - amountSlider = new wiSlider(0, 1, 1, 10000, "Brush Amount: "); - amountSlider->SetTooltip("Set the brush amount. 0 = minimum affection, 1 = maximum affection"); - amountSlider->SetSize(XMFLOAT2(200, hei)); - amountSlider->SetPos(XMFLOAT2(x, y += step)); - window->AddWidget(amountSlider); + amountSlider.Create(0, 1, 1, 10000, "Brush Amount: "); + amountSlider.SetTooltip("Set the brush amount. 0 = minimum affection, 1 = maximum affection"); + amountSlider.SetSize(XMFLOAT2(200, hei)); + amountSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&amountSlider); - falloffSlider = new wiSlider(0, 16, 0, 10000, "Brush Falloff: "); - falloffSlider->SetTooltip("Set the brush power. 0 = no falloff, 1 = linear falloff, more = falloff power"); - falloffSlider->SetSize(XMFLOAT2(200, hei)); - falloffSlider->SetPos(XMFLOAT2(x, y += step)); - window->AddWidget(falloffSlider); + falloffSlider.Create(0, 16, 0, 10000, "Brush Falloff: "); + falloffSlider.SetTooltip("Set the brush power. 0 = no falloff, 1 = linear falloff, more = falloff power"); + falloffSlider.SetSize(XMFLOAT2(200, hei)); + falloffSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&falloffSlider); - spacingSlider = new wiSlider(0, 500, 1, 500, "Brush Spacing: "); - spacingSlider->SetTooltip("Brush spacing means how much brush movement (in pixels) starts a new stroke. 0 = new stroke every frame, 100 = every 100 pixel movement since last stroke will start a new stroke."); - spacingSlider->SetSize(XMFLOAT2(200, hei)); - spacingSlider->SetPos(XMFLOAT2(x, y += step)); - window->AddWidget(spacingSlider); + spacingSlider.Create(0, 500, 1, 500, "Brush Spacing: "); + spacingSlider.SetTooltip("Brush spacing means how much brush movement (in pixels) starts a new stroke. 0 = new stroke every frame, 100 = every 100 pixel movement since last stroke will start a new stroke."); + spacingSlider.SetSize(XMFLOAT2(200, hei)); + spacingSlider.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&spacingSlider); - backfaceCheckBox = new wiCheckBox("Backfaces: "); - backfaceCheckBox->SetTooltip("Set whether to paint on backfaces of geometry or not"); - backfaceCheckBox->SetSize(XMFLOAT2(hei, hei)); - backfaceCheckBox->SetPos(XMFLOAT2(x, y += step)); - window->AddWidget(backfaceCheckBox); + backfaceCheckBox.Create("Backfaces: "); + backfaceCheckBox.SetTooltip("Set whether to paint on backfaces of geometry or not"); + backfaceCheckBox.SetSize(XMFLOAT2(hei, hei)); + backfaceCheckBox.SetPos(XMFLOAT2(x, y += step)); + AddWidget(&backfaceCheckBox); - wireCheckBox = new wiCheckBox("Wireframe: "); - wireCheckBox->SetTooltip("Set whether to draw wireframe on top of geometry or not"); - wireCheckBox->SetSize(XMFLOAT2(hei, hei)); - wireCheckBox->SetPos(XMFLOAT2(x + 100, y)); - wireCheckBox->SetCheck(true); - window->AddWidget(wireCheckBox); + wireCheckBox.Create("Wireframe: "); + wireCheckBox.SetTooltip("Set whether to draw wireframe on top of geometry or not"); + wireCheckBox.SetSize(XMFLOAT2(hei, hei)); + wireCheckBox.SetPos(XMFLOAT2(x + 100, y)); + wireCheckBox.SetCheck(true); + AddWidget(&wireCheckBox); - textureSlotComboBox = new wiComboBox("Texture Slot: "); - textureSlotComboBox->SetTooltip("Choose texture slot of the selected material to paint (texture paint mode only)"); - textureSlotComboBox->SetPos(XMFLOAT2(x, y += step)); - textureSlotComboBox->SetSize(XMFLOAT2(200, hei)); - textureSlotComboBox->AddItem("BaseColor (RGBA)"); - textureSlotComboBox->AddItem("Normal (RGB)"); - textureSlotComboBox->AddItem("SurfaceMap (RGBA)"); - textureSlotComboBox->AddItem("DisplacementMap (R)"); - textureSlotComboBox->AddItem("EmissiveMap (RGBA)"); - textureSlotComboBox->AddItem("OcclusionMap (R)"); - textureSlotComboBox->SetSelected(0); - textureSlotComboBox->SetEnabled(false); - window->AddWidget(textureSlotComboBox); + textureSlotComboBox.Create("Texture Slot: "); + textureSlotComboBox.SetTooltip("Choose texture slot of the selected material to paint (texture paint mode only)"); + textureSlotComboBox.SetPos(XMFLOAT2(x, y += step)); + textureSlotComboBox.SetSize(XMFLOAT2(200, hei)); + textureSlotComboBox.AddItem("BaseColor (RGBA)"); + textureSlotComboBox.AddItem("Normal (RGB)"); + textureSlotComboBox.AddItem("SurfaceMap (RGBA)"); + textureSlotComboBox.AddItem("DisplacementMap (R)"); + textureSlotComboBox.AddItem("EmissiveMap (RGBA)"); + textureSlotComboBox.AddItem("OcclusionMap (R)"); + textureSlotComboBox.SetSelected(0); + textureSlotComboBox.SetEnabled(false); + AddWidget(&textureSlotComboBox); - saveTextureButton = new wiButton("Save Texture"); - saveTextureButton->SetTooltip("Save edited texture. This will append _0 postfix to texture name and save as new PNG texture."); - saveTextureButton->SetSize(XMFLOAT2(200, hei)); - saveTextureButton->SetPos(XMFLOAT2(x, y += step)); - saveTextureButton->SetEnabled(false); - saveTextureButton->OnClick([this] (wiEventArgs args) { + saveTextureButton.Create("Save Texture"); + saveTextureButton.SetTooltip("Save edited texture. This will append _0 postfix to texture name and save as new PNG texture."); + saveTextureButton.SetSize(XMFLOAT2(200, hei)); + saveTextureButton.SetPos(XMFLOAT2(x, y += step)); + saveTextureButton.SetEnabled(false); + saveTextureButton.OnClick([this] (wiEventArgs args) { Scene& scene = wiScene::GetScene(); ObjectComponent* object = scene.objects.GetComponent(entity); @@ -165,7 +166,7 @@ PaintToolWindow::PaintToolWindow(EditorComponent* editor) : editor(editor) std::string* slotname = nullptr; - int sel = textureSlotComboBox->GetSelected(); + int sel = textureSlotComboBox.GetSelected(); switch (sel) { default: @@ -198,20 +199,14 @@ PaintToolWindow::PaintToolWindow(EditorComponent* editor) : editor(editor) wiHelper::messageBox("Saving texture failed! Check filename of texture slot in the material!"); } }); - window->AddWidget(saveTextureButton); + AddWidget(&saveTextureButton); - colorPicker = new wiColorPicker(&editor->GetGUI(), "Color", false); - colorPicker->SetPos(XMFLOAT2(10, y += step)); - window->AddWidget(colorPicker); + colorPicker.Create("Color", false); + colorPicker.SetPos(XMFLOAT2(10, y += step)); + AddWidget(&colorPicker); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 550, 50, 0)); - window->SetVisible(false); -} -PaintToolWindow::~PaintToolWindow() -{ - window->RemoveWidgets(true); - editor->GetGUI().RemoveWidget(window); - delete window; + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 550, 50, 0)); + SetVisible(false); } void PaintToolWindow::Update(float dt) @@ -239,7 +234,7 @@ void PaintToolWindow::Update(float dt) posNew = XMFLOAT2(pointer.x, pointer.y); stroke_dist += wiMath::Distance(pos, posNew); - const float spacing = spacingSlider->GetValue(); + const float spacing = spacingSlider.GetValue(); const bool pointer_moved = stroke_dist >= spacing; const bool painting = pointer_moved && pointer_down; @@ -251,13 +246,13 @@ void PaintToolWindow::Update(float dt) pos = posNew; const MODE mode = GetMode(); - const float radius = radiusSlider->GetValue(); - const float amount = amountSlider->GetValue(); - const float falloff = falloffSlider->GetValue(); - const wiColor color = colorPicker->GetPickColor(); + const float radius = radiusSlider.GetValue(); + const float amount = amountSlider.GetValue(); + const float falloff = falloffSlider.GetValue(); + const wiColor color = colorPicker.GetPickColor(); const XMFLOAT4 color_float = color.toFloat4(); - const bool backfaces = backfaceCheckBox->GetCheck(); - const bool wireframe = wireCheckBox->GetCheck(); + const bool backfaces = backfaceCheckBox.GetCheck(); + const bool wireframe = wireCheckBox.GetCheck(); Scene& scene = wiScene::GetScene(); const CameraComponent& camera = wiRenderer::GetCamera(); @@ -880,7 +875,7 @@ void PaintToolWindow::DrawBrush() const return; const int segmentcount = 36; - const float radius = radiusSlider->GetValue(); + const float radius = radiusSlider.GetValue(); for (int i = 0; i < segmentcount; i += 1) { @@ -899,7 +894,7 @@ void PaintToolWindow::DrawBrush() const PaintToolWindow::MODE PaintToolWindow::GetMode() const { - return (MODE)modeComboBox->GetSelected(); + return (MODE)modeComboBox.GetSelected(); } void PaintToolWindow::SetEntity(wiECS::Entity value, int subsetindex) { @@ -908,11 +903,11 @@ void PaintToolWindow::SetEntity(wiECS::Entity value, int subsetindex) if (entity == INVALID_ENTITY) { - saveTextureButton->SetEnabled(false); + saveTextureButton.SetEnabled(false); } else if (GetMode() == MODE_TEXTURE) { - saveTextureButton->SetEnabled(true); + saveTextureButton.SetEnabled(true); } } @@ -963,7 +958,7 @@ void PaintToolWindow::RecordHistory(bool start, CommandList cmd) auto resource = GetEditTextureSlot(*material); - archive << textureSlotComboBox->GetSelected(); + archive << textureSlotComboBox.GetSelected(); if (history_textureIndex >= history_textures.size()) { @@ -1075,7 +1070,7 @@ void PaintToolWindow::ConsumeHistoryOperation(wiArchive& archive, bool undo) archive >> (uint32_t&)historymode; archive >> entity; - modeComboBox->SetSelected(historymode); + modeComboBox.SetSelected(historymode); Scene& scene = wiScene::GetScene(); @@ -1106,12 +1101,12 @@ void PaintToolWindow::ConsumeHistoryOperation(wiArchive& archive, bool undo) if (undo) { - textureSlotComboBox->SetSelected(undo_slot); + textureSlotComboBox.SetSelected(undo_slot); history_textureIndex = undo_textureindex; } else { - textureSlotComboBox->SetSelected(redo_slot); + textureSlotComboBox.SetSelected(redo_slot); history_textureIndex = redo_textureindex; } ReplaceEditTextureSlot(*material, history_textures[history_textureIndex]); @@ -1264,7 +1259,7 @@ void PaintToolWindow::ConsumeHistoryOperation(wiArchive& archive, bool undo) } std::shared_ptr PaintToolWindow::GetEditTextureSlot(const MaterialComponent& material, int* uvset) { - int sel = textureSlotComboBox->GetSelected(); + int sel = textureSlotComboBox.GetSelected(); switch (sel) { default: @@ -1290,7 +1285,7 @@ std::shared_ptr PaintToolWindow::GetEditTextureSlot(const MaterialCo } void PaintToolWindow::ReplaceEditTextureSlot(wiScene::MaterialComponent& material, std::shared_ptr resource) { - int sel = textureSlotComboBox->GetSelected(); + int sel = textureSlotComboBox.GetSelected(); switch (sel) { default: diff --git a/Editor/PaintToolWindow.h b/Editor/PaintToolWindow.h index 386f88269..1367e082f 100644 --- a/Editor/PaintToolWindow.h +++ b/Editor/PaintToolWindow.h @@ -1,18 +1,9 @@ #pragma once -#include "CommonInclude.h" - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiButton; +#include "WickedEngine.h" class EditorComponent; -class PaintToolWindow +class PaintToolWindow : public wiWindow { float rot = 0; float stroke_dist = 0; @@ -23,25 +14,23 @@ class PaintToolWindow std::shared_ptr GetEditTextureSlot(const wiScene::MaterialComponent& material, int* uvset = nullptr); void ReplaceEditTextureSlot(wiScene::MaterialComponent& material, std::shared_ptr resource); public: - PaintToolWindow(EditorComponent* editor); - ~PaintToolWindow(); + void Create(EditorComponent* editor); EditorComponent* editor = nullptr; wiECS::Entity entity = wiECS::INVALID_ENTITY; int subset = -1; - wiWindow* window; - wiComboBox* modeComboBox; - wiLabel* infoLabel; - wiSlider* radiusSlider; - wiSlider* amountSlider; - wiSlider* falloffSlider; - wiSlider* spacingSlider; - wiCheckBox* backfaceCheckBox; - wiCheckBox* wireCheckBox; - wiColorPicker* colorPicker; - wiComboBox* textureSlotComboBox; - wiButton* saveTextureButton; + wiComboBox modeComboBox; + wiLabel infoLabel; + wiSlider radiusSlider; + wiSlider amountSlider; + wiSlider falloffSlider; + wiSlider spacingSlider; + wiCheckBox backfaceCheckBox; + wiCheckBox wireCheckBox; + wiColorPicker colorPicker; + wiComboBox textureSlotComboBox; + wiButton saveTextureButton; void Update(float dt); void DrawBrush() const; diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp index 45d8316f4..a2bbd7272 100644 --- a/Editor/PostprocessWindow.cpp +++ b/Editor/PostprocessWindow.cpp @@ -8,292 +8,299 @@ using namespace std; using namespace wiGraphics; -PostprocessWindow::PostprocessWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void PostprocessWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - ppWindow = new wiWindow(GUI, "PostProcess Window"); - ppWindow->SetSize(XMFLOAT2(420, 500)); - GUI->AddWidget(ppWindow); + wiWindow::Create("PostProcess Window"); + SetSize(XMFLOAT2(420, 520)); float x = 150; float y = 10; float hei = 18; float step = hei + 2; - exposureSlider = new wiSlider(0.0f, 3.0f, 1, 10000, "Exposure: "); - exposureSlider->SetTooltip("Set the tonemap exposure value"); - exposureSlider->SetScriptTip("RenderPath3D::SetExposure(float value)"); - exposureSlider->SetSize(XMFLOAT2(100, hei)); - exposureSlider->SetPos(XMFLOAT2(x, y += step)); - exposureSlider->SetValue(editor->renderPath->getExposure()); - exposureSlider->OnSlide([=](wiEventArgs args) { + exposureSlider.Create(0.0f, 3.0f, 1, 10000, "Exposure: "); + exposureSlider.SetTooltip("Set the tonemap exposure value"); + exposureSlider.SetScriptTip("RenderPath3D::SetExposure(float value)"); + exposureSlider.SetSize(XMFLOAT2(100, hei)); + exposureSlider.SetPos(XMFLOAT2(x, y += step)); + exposureSlider.SetValue(editor->renderPath->getExposure()); + exposureSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setExposure(args.fValue); }); - ppWindow->AddWidget(exposureSlider); + AddWidget(&exposureSlider); - lensFlareCheckBox = new wiCheckBox("LensFlare: "); - lensFlareCheckBox->SetTooltip("Toggle visibility of light source flares. Additional setup needed per light for a lensflare to be visible."); - lensFlareCheckBox->SetScriptTip("RenderPath3D::SetLensFlareEnabled(bool value)"); - lensFlareCheckBox->SetSize(XMFLOAT2(hei, hei)); - lensFlareCheckBox->SetPos(XMFLOAT2(x, y += step)); - lensFlareCheckBox->SetCheck(editor->renderPath->getLensFlareEnabled()); - lensFlareCheckBox->OnClick([=](wiEventArgs args) { + lensFlareCheckBox.Create("LensFlare: "); + lensFlareCheckBox.SetTooltip("Toggle visibility of light source flares. Additional setup needed per light for a lensflare to be visible."); + lensFlareCheckBox.SetScriptTip("RenderPath3D::SetLensFlareEnabled(bool value)"); + lensFlareCheckBox.SetSize(XMFLOAT2(hei, hei)); + lensFlareCheckBox.SetPos(XMFLOAT2(x, y += step)); + lensFlareCheckBox.SetCheck(editor->renderPath->getLensFlareEnabled()); + lensFlareCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setLensFlareEnabled(args.bValue); }); - ppWindow->AddWidget(lensFlareCheckBox); + AddWidget(&lensFlareCheckBox); - lightShaftsCheckBox = new wiCheckBox("LightShafts: "); - lightShaftsCheckBox->SetTooltip("Enable light shaft for directional light sources."); - lightShaftsCheckBox->SetScriptTip("RenderPath3D::SetLightShaftsEnabled(bool value)"); - lightShaftsCheckBox->SetSize(XMFLOAT2(hei, hei)); - lightShaftsCheckBox->SetPos(XMFLOAT2(x, y += step)); - lightShaftsCheckBox->SetCheck(editor->renderPath->getLightShaftsEnabled()); - lightShaftsCheckBox->OnClick([=](wiEventArgs args) { + lightShaftsCheckBox.Create("LightShafts: "); + lightShaftsCheckBox.SetTooltip("Enable light shaft for directional light sources."); + lightShaftsCheckBox.SetScriptTip("RenderPath3D::SetLightShaftsEnabled(bool value)"); + lightShaftsCheckBox.SetSize(XMFLOAT2(hei, hei)); + lightShaftsCheckBox.SetPos(XMFLOAT2(x, y += step)); + lightShaftsCheckBox.SetCheck(editor->renderPath->getLightShaftsEnabled()); + lightShaftsCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setLightShaftsEnabled(args.bValue); }); - ppWindow->AddWidget(lightShaftsCheckBox); + AddWidget(&lightShaftsCheckBox); - volumetricCloudsCheckBox = new wiCheckBox("Volumetric clouds: "); - volumetricCloudsCheckBox->SetTooltip("Enable volumetric cloud rendering."); - volumetricCloudsCheckBox->SetSize(XMFLOAT2(hei, hei)); - volumetricCloudsCheckBox->SetPos(XMFLOAT2(x, y += step)); - volumetricCloudsCheckBox->SetCheck(editor->renderPath->getVolumetricCloudsEnabled()); - volumetricCloudsCheckBox->OnClick([=](wiEventArgs args) { + volumetricCloudsCheckBox.Create("Volumetric clouds: "); + volumetricCloudsCheckBox.SetTooltip("Enable volumetric cloud rendering."); + volumetricCloudsCheckBox.SetSize(XMFLOAT2(hei, hei)); + volumetricCloudsCheckBox.SetPos(XMFLOAT2(x, y += step)); + volumetricCloudsCheckBox.SetCheck(editor->renderPath->getVolumetricCloudsEnabled()); + volumetricCloudsCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setVolumetricCloudsEnabled(args.bValue); }); - ppWindow->AddWidget(volumetricCloudsCheckBox); + AddWidget(&volumetricCloudsCheckBox); - aoComboBox = new wiComboBox("AO: "); - aoComboBox->SetTooltip("Choose Ambient Occlusion type. RTAO is only available if hardware supports ray tracing"); - aoComboBox->SetScriptTip("RenderPath3D::SetAO(int value)"); - aoComboBox->SetSize(XMFLOAT2(150, hei)); - aoComboBox->SetPos(XMFLOAT2(x, y += step)); - aoComboBox->AddItem("Disabled"); - aoComboBox->AddItem("SSAO"); - aoComboBox->AddItem("HBAO"); - aoComboBox->AddItem("MSAO"); + aoComboBox.Create("AO: "); + aoComboBox.SetTooltip("Choose Ambient Occlusion type. RTAO is only available if hardware supports ray tracing"); + aoComboBox.SetScriptTip("RenderPath3D::SetAO(int value)"); + aoComboBox.SetSize(XMFLOAT2(150, hei)); + aoComboBox.SetPos(XMFLOAT2(x, y += step)); + aoComboBox.AddItem("Disabled"); + aoComboBox.AddItem("SSAO"); + aoComboBox.AddItem("HBAO"); + aoComboBox.AddItem("MSAO"); if (wiRenderer::GetDevice()->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING)) { - aoComboBox->AddItem("RTAO"); + aoComboBox.AddItem("RTAO"); } - aoComboBox->SetSelected(editor->renderPath->getAO()); - aoComboBox->OnSelect([=](wiEventArgs args) { + aoComboBox.SetSelected(editor->renderPath->getAO()); + aoComboBox.OnSelect([=](wiEventArgs args) { editor->renderPath->setAO((RenderPath3D::AO)args.iValue); switch (editor->renderPath->getAO()) { case RenderPath3D::AO_SSAO: - aoRangeSlider->SetEnabled(true); - aoRangeSlider->SetValue(2.0f); - aoSampleCountSlider->SetEnabled(true); - aoSampleCountSlider->SetValue(9.0f); + aoRangeSlider.SetEnabled(true); + aoRangeSlider.SetValue(2.0f); + aoSampleCountSlider.SetEnabled(true); + aoSampleCountSlider.SetValue(9.0f); break; case RenderPath3D::AO_RTAO: - aoRangeSlider->SetEnabled(true); - aoRangeSlider->SetValue(10.0f); - aoSampleCountSlider->SetEnabled(true); - aoSampleCountSlider->SetValue(2.0f); + aoRangeSlider.SetEnabled(true); + aoRangeSlider.SetValue(10.0f); + aoSampleCountSlider.SetEnabled(true); + aoSampleCountSlider.SetValue(2.0f); break; default: - aoRangeSlider->SetEnabled(false); - aoSampleCountSlider->SetEnabled(false); + aoRangeSlider.SetEnabled(false); + aoSampleCountSlider.SetEnabled(false); break; } - editor->renderPath->setAORange(aoRangeSlider->GetValue()); - editor->renderPath->setAOSampleCount((uint32_t)aoSampleCountSlider->GetValue()); + editor->renderPath->setAORange(aoRangeSlider.GetValue()); + editor->renderPath->setAOSampleCount((uint32_t)aoSampleCountSlider.GetValue()); }); - ppWindow->AddWidget(aoComboBox); + AddWidget(&aoComboBox); - aoPowerSlider = new wiSlider(0.25f, 8.0f, 2, 1000, "Power: "); - aoPowerSlider->SetTooltip("Set SSAO Power. Higher values produce darker, more pronounced effect"); - aoPowerSlider->SetSize(XMFLOAT2(100, hei)); - aoPowerSlider->SetPos(XMFLOAT2(x + 100, y += step)); - aoPowerSlider->SetValue((float)editor->renderPath->getAOPower()); - aoPowerSlider->OnSlide([=](wiEventArgs args) { + aoPowerSlider.Create(0.25f, 8.0f, 2, 1000, "Power: "); + aoPowerSlider.SetTooltip("Set SSAO Power. Higher values produce darker, more pronounced effect"); + aoPowerSlider.SetSize(XMFLOAT2(100, hei)); + aoPowerSlider.SetPos(XMFLOAT2(x + 100, y += step)); + aoPowerSlider.SetValue((float)editor->renderPath->getAOPower()); + aoPowerSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setAOPower(args.fValue); }); - ppWindow->AddWidget(aoPowerSlider); + AddWidget(&aoPowerSlider); - aoRangeSlider = new wiSlider(1.0f, 100.0f, 1, 1000, "Range: "); - aoRangeSlider->SetTooltip("Set AO ray length. Only for SSAO and RTAO"); - aoRangeSlider->SetSize(XMFLOAT2(100, hei)); - aoRangeSlider->SetPos(XMFLOAT2(x + 100, y += step)); - aoRangeSlider->SetValue((float)editor->renderPath->getAOPower()); - aoRangeSlider->OnSlide([=](wiEventArgs args) { + aoRangeSlider.Create(1.0f, 100.0f, 1, 1000, "Range: "); + aoRangeSlider.SetTooltip("Set AO ray length. Only for SSAO and RTAO"); + aoRangeSlider.SetSize(XMFLOAT2(100, hei)); + aoRangeSlider.SetPos(XMFLOAT2(x + 100, y += step)); + aoRangeSlider.SetValue((float)editor->renderPath->getAOPower()); + aoRangeSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setAORange(args.fValue); }); - ppWindow->AddWidget(aoRangeSlider); + AddWidget(&aoRangeSlider); - aoSampleCountSlider = new wiSlider(1, 16, 9, 15, "Sample Count: "); - aoSampleCountSlider->SetTooltip("Set AO ray count. Only for SSAO and RTAO"); - aoSampleCountSlider->SetSize(XMFLOAT2(100, hei)); - aoSampleCountSlider->SetPos(XMFLOAT2(x + 100, y += step)); - aoSampleCountSlider->SetValue((float)editor->renderPath->getAOPower()); - aoSampleCountSlider->OnSlide([=](wiEventArgs args) { + aoSampleCountSlider.Create(1, 16, 9, 15, "Sample Count: "); + aoSampleCountSlider.SetTooltip("Set AO ray count. Only for SSAO and RTAO"); + aoSampleCountSlider.SetSize(XMFLOAT2(100, hei)); + aoSampleCountSlider.SetPos(XMFLOAT2(x + 100, y += step)); + aoSampleCountSlider.SetValue((float)editor->renderPath->getAOPower()); + aoSampleCountSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setAOSampleCount(args.iValue); }); - ppWindow->AddWidget(aoSampleCountSlider); + AddWidget(&aoSampleCountSlider); - ssrCheckBox = new wiCheckBox("SSR: "); - ssrCheckBox->SetTooltip("Enable Screen Space Reflections."); - ssrCheckBox->SetScriptTip("RenderPath3D::SetSSREnabled(bool value)"); - ssrCheckBox->SetSize(XMFLOAT2(hei, hei)); - ssrCheckBox->SetPos(XMFLOAT2(x, y += step)); - ssrCheckBox->SetCheck(editor->renderPath->getSSREnabled()); - ssrCheckBox->OnClick([=](wiEventArgs args) { + ssrCheckBox.Create("SSR: "); + ssrCheckBox.SetTooltip("Enable Screen Space Reflections."); + ssrCheckBox.SetScriptTip("RenderPath3D::SetSSREnabled(bool value)"); + ssrCheckBox.SetSize(XMFLOAT2(hei, hei)); + ssrCheckBox.SetPos(XMFLOAT2(x, y += step)); + ssrCheckBox.SetCheck(editor->renderPath->getSSREnabled()); + ssrCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setSSREnabled(args.bValue); }); - ppWindow->AddWidget(ssrCheckBox); + AddWidget(&ssrCheckBox); - ssrCheckBox = new wiCheckBox("Ray Traced Reflections: "); - ssrCheckBox->SetTooltip("Enable Ray Traced Reflections. Only if GPU supports raytracing."); - ssrCheckBox->SetScriptTip("RenderPath3D::SetRaytracedReflectionsEnabled(bool value)"); - ssrCheckBox->SetSize(XMFLOAT2(hei, hei)); - ssrCheckBox->SetPos(XMFLOAT2(x + 200, y)); - ssrCheckBox->SetCheck(editor->renderPath->getRaytracedReflectionEnabled()); - ssrCheckBox->OnClick([=](wiEventArgs args) { + raytracedReflectionsCheckBox.Create("Ray Traced Reflections: "); + raytracedReflectionsCheckBox.SetTooltip("Enable Ray Traced Reflections. Only if GPU supports raytracing."); + raytracedReflectionsCheckBox.SetScriptTip("RenderPath3D::SetRaytracedReflectionsEnabled(bool value)"); + raytracedReflectionsCheckBox.SetSize(XMFLOAT2(hei, hei)); + raytracedReflectionsCheckBox.SetPos(XMFLOAT2(x + 200, y)); + raytracedReflectionsCheckBox.SetCheck(editor->renderPath->getRaytracedReflectionEnabled()); + raytracedReflectionsCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setRaytracedReflectionsEnabled(args.bValue); }); - ppWindow->AddWidget(ssrCheckBox); - ssrCheckBox->SetEnabled(wiRenderer::GetDevice()->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING)); + AddWidget(&raytracedReflectionsCheckBox); + raytracedReflectionsCheckBox.SetEnabled(wiRenderer::GetDevice()->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING)); - sssCheckBox = new wiCheckBox("SSS: "); - sssCheckBox->SetTooltip("Enable Subsurface Scattering. (Deferred only for now)"); - sssCheckBox->SetScriptTip("RenderPath3D::SetSSSEnabled(bool value)"); - sssCheckBox->SetSize(XMFLOAT2(hei, hei)); - sssCheckBox->SetPos(XMFLOAT2(x, y += step)); - sssCheckBox->SetCheck(editor->renderPath->getSSSEnabled()); - sssCheckBox->OnClick([=](wiEventArgs args) { + sssCheckBox.Create("SSS: "); + sssCheckBox.SetTooltip("Enable Subsurface Scattering. Only for PBR shaders."); + sssCheckBox.SetScriptTip("RenderPath3D::SetSSSEnabled(bool value)"); + sssCheckBox.SetSize(XMFLOAT2(hei, hei)); + sssCheckBox.SetPos(XMFLOAT2(x, y += step)); + sssCheckBox.SetCheck(editor->renderPath->getSSSEnabled()); + sssCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setSSSEnabled(args.bValue); }); - ppWindow->AddWidget(sssCheckBox); + AddWidget(&sssCheckBox); - eyeAdaptionCheckBox = new wiCheckBox("EyeAdaption: "); - eyeAdaptionCheckBox->SetTooltip("Enable eye adaption for the overall screen luminance"); - eyeAdaptionCheckBox->SetSize(XMFLOAT2(hei, hei)); - eyeAdaptionCheckBox->SetPos(XMFLOAT2(x, y += step)); - eyeAdaptionCheckBox->SetCheck(editor->renderPath->getEyeAdaptionEnabled()); - eyeAdaptionCheckBox->OnClick([=](wiEventArgs args) { + sssSlider.Create(0.0f, 2.0f, 1, 1000, "Amount: "); + sssSlider.SetTooltip("Set SSS amount for subsurface materials."); + sssSlider.SetSize(XMFLOAT2(100, hei)); + sssSlider.SetPos(XMFLOAT2(x + 100, y)); + sssSlider.SetValue((float)editor->renderPath->getSSSBlurAmount()); + sssSlider.OnSlide([=](wiEventArgs args) { + editor->renderPath->setSSSBlurAmount(args.fValue); + }); + AddWidget(&sssSlider); + + eyeAdaptionCheckBox.Create("EyeAdaption: "); + eyeAdaptionCheckBox.SetTooltip("Enable eye adaption for the overall screen luminance"); + eyeAdaptionCheckBox.SetSize(XMFLOAT2(hei, hei)); + eyeAdaptionCheckBox.SetPos(XMFLOAT2(x, y += step)); + eyeAdaptionCheckBox.SetCheck(editor->renderPath->getEyeAdaptionEnabled()); + eyeAdaptionCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setEyeAdaptionEnabled(args.bValue); }); - ppWindow->AddWidget(eyeAdaptionCheckBox); + AddWidget(&eyeAdaptionCheckBox); - motionBlurCheckBox = new wiCheckBox("MotionBlur: "); - motionBlurCheckBox->SetTooltip("Enable motion blur for camera movement and animated meshes."); - motionBlurCheckBox->SetScriptTip("RenderPath3D::SetMotionBlurEnabled(bool value)"); - motionBlurCheckBox->SetSize(XMFLOAT2(hei, hei)); - motionBlurCheckBox->SetPos(XMFLOAT2(x, y += step)); - motionBlurCheckBox->SetCheck(editor->renderPath->getMotionBlurEnabled()); - motionBlurCheckBox->OnClick([=](wiEventArgs args) { + motionBlurCheckBox.Create("MotionBlur: "); + motionBlurCheckBox.SetTooltip("Enable motion blur for camera movement and animated meshes."); + motionBlurCheckBox.SetScriptTip("RenderPath3D::SetMotionBlurEnabled(bool value)"); + motionBlurCheckBox.SetSize(XMFLOAT2(hei, hei)); + motionBlurCheckBox.SetPos(XMFLOAT2(x, y += step)); + motionBlurCheckBox.SetCheck(editor->renderPath->getMotionBlurEnabled()); + motionBlurCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setMotionBlurEnabled(args.bValue); }); - ppWindow->AddWidget(motionBlurCheckBox); + AddWidget(&motionBlurCheckBox); - motionBlurStrengthSlider = new wiSlider(0.1f, 400, 100, 10000, "Strength: "); - motionBlurStrengthSlider->SetTooltip("Set the camera shutter speed for motion blur (higher value means stronger blur)."); - motionBlurStrengthSlider->SetScriptTip("RenderPath3D::SetMotionBlurStrength(float value)"); - motionBlurStrengthSlider->SetSize(XMFLOAT2(100, hei)); - motionBlurStrengthSlider->SetPos(XMFLOAT2(x + 100, y)); - motionBlurStrengthSlider->SetValue(editor->renderPath->getMotionBlurStrength()); - motionBlurStrengthSlider->OnSlide([=](wiEventArgs args) { + motionBlurStrengthSlider.Create(0.1f, 400, 100, 10000, "Strength: "); + motionBlurStrengthSlider.SetTooltip("Set the camera shutter speed for motion blur (higher value means stronger blur)."); + motionBlurStrengthSlider.SetScriptTip("RenderPath3D::SetMotionBlurStrength(float value)"); + motionBlurStrengthSlider.SetSize(XMFLOAT2(100, hei)); + motionBlurStrengthSlider.SetPos(XMFLOAT2(x + 100, y)); + motionBlurStrengthSlider.SetValue(editor->renderPath->getMotionBlurStrength()); + motionBlurStrengthSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setMotionBlurStrength(args.fValue); }); - ppWindow->AddWidget(motionBlurStrengthSlider); + AddWidget(&motionBlurStrengthSlider); - depthOfFieldCheckBox = new wiCheckBox("DepthOfField: "); - depthOfFieldCheckBox->SetTooltip("Enable Depth of field effect. Additional focus and strength setup required."); - depthOfFieldCheckBox->SetScriptTip("RenderPath3D::SetDepthOfFieldEnabled(bool value)"); - depthOfFieldCheckBox->SetSize(XMFLOAT2(hei, hei)); - depthOfFieldCheckBox->SetPos(XMFLOAT2(x, y += step)); - depthOfFieldCheckBox->SetCheck(editor->renderPath->getDepthOfFieldEnabled()); - depthOfFieldCheckBox->OnClick([=](wiEventArgs args) { + depthOfFieldCheckBox.Create("DepthOfField: "); + depthOfFieldCheckBox.SetTooltip("Enable Depth of field effect. Additional focus and strength setup required."); + depthOfFieldCheckBox.SetScriptTip("RenderPath3D::SetDepthOfFieldEnabled(bool value)"); + depthOfFieldCheckBox.SetSize(XMFLOAT2(hei, hei)); + depthOfFieldCheckBox.SetPos(XMFLOAT2(x, y += step)); + depthOfFieldCheckBox.SetCheck(editor->renderPath->getDepthOfFieldEnabled()); + depthOfFieldCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setDepthOfFieldEnabled(args.bValue); }); - ppWindow->AddWidget(depthOfFieldCheckBox); + AddWidget(&depthOfFieldCheckBox); - depthOfFieldFocusSlider = new wiSlider(1.0f, 100, 10, 10000, "Focus: "); - depthOfFieldFocusSlider->SetTooltip("Set the focus distance from the camera. The picture will be sharper near the focus, and blurrier further from it."); - depthOfFieldFocusSlider->SetScriptTip("RenderPath3D::SetDepthOfFieldFocus(float value)"); - depthOfFieldFocusSlider->SetSize(XMFLOAT2(100, hei)); - depthOfFieldFocusSlider->SetPos(XMFLOAT2(x + 100, y)); - depthOfFieldFocusSlider->SetValue(editor->renderPath->getDepthOfFieldFocus()); - depthOfFieldFocusSlider->OnSlide([=](wiEventArgs args) { + depthOfFieldFocusSlider.Create(1.0f, 100, 10, 10000, "Focus: "); + depthOfFieldFocusSlider.SetTooltip("Set the focus distance from the camera. The picture will be sharper near the focus, and blurrier further from it."); + depthOfFieldFocusSlider.SetScriptTip("RenderPath3D::SetDepthOfFieldFocus(float value)"); + depthOfFieldFocusSlider.SetSize(XMFLOAT2(100, hei)); + depthOfFieldFocusSlider.SetPos(XMFLOAT2(x + 100, y)); + depthOfFieldFocusSlider.SetValue(editor->renderPath->getDepthOfFieldFocus()); + depthOfFieldFocusSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setDepthOfFieldFocus(args.fValue); }); - ppWindow->AddWidget(depthOfFieldFocusSlider); + AddWidget(&depthOfFieldFocusSlider); - depthOfFieldScaleSlider = new wiSlider(1.0f, 20, 100, 1000, "Scale: "); - depthOfFieldScaleSlider->SetTooltip("Set depth of field scale/falloff."); - depthOfFieldScaleSlider->SetScriptTip("RenderPath3D::SetDepthOfFieldStrength(float value)"); - depthOfFieldScaleSlider->SetSize(XMFLOAT2(100, hei)); - depthOfFieldScaleSlider->SetPos(XMFLOAT2(x + 100, y += step)); - depthOfFieldScaleSlider->SetValue(editor->renderPath->getDepthOfFieldStrength()); - depthOfFieldScaleSlider->OnSlide([=](wiEventArgs args) { + depthOfFieldScaleSlider.Create(1.0f, 20, 100, 1000, "Scale: "); + depthOfFieldScaleSlider.SetTooltip("Set depth of field scale/falloff."); + depthOfFieldScaleSlider.SetScriptTip("RenderPath3D::SetDepthOfFieldStrength(float value)"); + depthOfFieldScaleSlider.SetSize(XMFLOAT2(100, hei)); + depthOfFieldScaleSlider.SetPos(XMFLOAT2(x + 100, y += step)); + depthOfFieldScaleSlider.SetValue(editor->renderPath->getDepthOfFieldStrength()); + depthOfFieldScaleSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setDepthOfFieldStrength(args.fValue); }); - ppWindow->AddWidget(depthOfFieldScaleSlider); + AddWidget(&depthOfFieldScaleSlider); - depthOfFieldAspectSlider = new wiSlider(0.01f, 2, 1, 1000, "Aspect: "); - depthOfFieldAspectSlider->SetTooltip("Set depth of field bokeh aspect ratio (width/height)."); - depthOfFieldAspectSlider->SetScriptTip("RenderPath3D::SetDepthOfFieldAspect(float value)"); - depthOfFieldAspectSlider->SetSize(XMFLOAT2(100, hei)); - depthOfFieldAspectSlider->SetPos(XMFLOAT2(x + 100, y += step)); - depthOfFieldAspectSlider->SetValue(editor->renderPath->getDepthOfFieldAspect()); - depthOfFieldAspectSlider->OnSlide([=](wiEventArgs args) { + depthOfFieldAspectSlider.Create(0.01f, 2, 1, 1000, "Aspect: "); + depthOfFieldAspectSlider.SetTooltip("Set depth of field bokeh aspect ratio (width/height)."); + depthOfFieldAspectSlider.SetScriptTip("RenderPath3D::SetDepthOfFieldAspect(float value)"); + depthOfFieldAspectSlider.SetSize(XMFLOAT2(100, hei)); + depthOfFieldAspectSlider.SetPos(XMFLOAT2(x + 100, y += step)); + depthOfFieldAspectSlider.SetValue(editor->renderPath->getDepthOfFieldAspect()); + depthOfFieldAspectSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setDepthOfFieldAspect(args.fValue); }); - ppWindow->AddWidget(depthOfFieldAspectSlider); + AddWidget(&depthOfFieldAspectSlider); - bloomCheckBox = new wiCheckBox("Bloom: "); - bloomCheckBox->SetTooltip("Enable bloom. The effect adds color bleeding to the brightest parts of the scene."); - bloomCheckBox->SetScriptTip("RenderPath3D::SetBloomEnabled(bool value)"); - bloomCheckBox->SetSize(XMFLOAT2(hei, hei)); - bloomCheckBox->SetPos(XMFLOAT2(x, y += step)); - bloomCheckBox->SetCheck(editor->renderPath->getBloomEnabled()); - bloomCheckBox->OnClick([=](wiEventArgs args) { + bloomCheckBox.Create("Bloom: "); + bloomCheckBox.SetTooltip("Enable bloom. The effect adds color bleeding to the brightest parts of the scene."); + bloomCheckBox.SetScriptTip("RenderPath3D::SetBloomEnabled(bool value)"); + bloomCheckBox.SetSize(XMFLOAT2(hei, hei)); + bloomCheckBox.SetPos(XMFLOAT2(x, y += step)); + bloomCheckBox.SetCheck(editor->renderPath->getBloomEnabled()); + bloomCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setBloomEnabled(args.bValue); }); - ppWindow->AddWidget(bloomCheckBox); + AddWidget(&bloomCheckBox); - bloomStrengthSlider = new wiSlider(0.0f, 10, 1, 1000, "Threshold: "); - bloomStrengthSlider->SetTooltip("Set bloom threshold. The values below this will not glow on the screen."); - bloomStrengthSlider->SetSize(XMFLOAT2(100, hei)); - bloomStrengthSlider->SetPos(XMFLOAT2(x + 100, y)); - bloomStrengthSlider->SetValue(editor->renderPath->getBloomThreshold()); - bloomStrengthSlider->OnSlide([=](wiEventArgs args) { + bloomStrengthSlider.Create(0.0f, 10, 1, 1000, "Threshold: "); + bloomStrengthSlider.SetTooltip("Set bloom threshold. The values below this will not glow on the screen."); + bloomStrengthSlider.SetSize(XMFLOAT2(100, hei)); + bloomStrengthSlider.SetPos(XMFLOAT2(x + 100, y)); + bloomStrengthSlider.SetValue(editor->renderPath->getBloomThreshold()); + bloomStrengthSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setBloomThreshold(args.fValue); }); - ppWindow->AddWidget(bloomStrengthSlider); + AddWidget(&bloomStrengthSlider); - fxaaCheckBox = new wiCheckBox("FXAA: "); - fxaaCheckBox->SetTooltip("Fast Approximate Anti Aliasing. A fast antialiasing method, but can be a bit too blurry."); - fxaaCheckBox->SetScriptTip("RenderPath3D::SetFXAAEnabled(bool value)"); - fxaaCheckBox->SetSize(XMFLOAT2(hei, hei)); - fxaaCheckBox->SetPos(XMFLOAT2(x, y += step)); - fxaaCheckBox->SetCheck(editor->renderPath->getFXAAEnabled()); - fxaaCheckBox->OnClick([=](wiEventArgs args) { + fxaaCheckBox.Create("FXAA: "); + fxaaCheckBox.SetTooltip("Fast Approximate Anti Aliasing. A fast antialiasing method, but can be a bit too blurry."); + fxaaCheckBox.SetScriptTip("RenderPath3D::SetFXAAEnabled(bool value)"); + fxaaCheckBox.SetSize(XMFLOAT2(hei, hei)); + fxaaCheckBox.SetPos(XMFLOAT2(x, y += step)); + fxaaCheckBox.SetCheck(editor->renderPath->getFXAAEnabled()); + fxaaCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setFXAAEnabled(args.bValue); }); - ppWindow->AddWidget(fxaaCheckBox); + AddWidget(&fxaaCheckBox); - colorGradingCheckBox = new wiCheckBox("Color Grading: "); - colorGradingCheckBox->SetTooltip("Enable color grading of the final render. An additional lookup texture must be set for it to take effect."); - colorGradingCheckBox->SetScriptTip("RenderPath3D::SetColorGradingEnabled(bool value)"); - colorGradingCheckBox->SetSize(XMFLOAT2(hei, hei)); - colorGradingCheckBox->SetPos(XMFLOAT2(x, y += step)); - colorGradingCheckBox->SetCheck(editor->renderPath->getColorGradingEnabled()); - colorGradingCheckBox->OnClick([=](wiEventArgs args) { + colorGradingCheckBox.Create("Color Grading: "); + colorGradingCheckBox.SetTooltip("Enable color grading of the final render. An additional lookup texture must be set for it to take effect."); + colorGradingCheckBox.SetScriptTip("RenderPath3D::SetColorGradingEnabled(bool value)"); + colorGradingCheckBox.SetSize(XMFLOAT2(hei, hei)); + colorGradingCheckBox.SetPos(XMFLOAT2(x, y += step)); + colorGradingCheckBox.SetCheck(editor->renderPath->getColorGradingEnabled()); + colorGradingCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setColorGradingEnabled(args.bValue); }); - ppWindow->AddWidget(colorGradingCheckBox); + AddWidget(&colorGradingCheckBox); - colorGradingButton = new wiButton("Load Color Grading LUT..."); - colorGradingButton->SetTooltip("Load a color grading lookup texture..."); - colorGradingButton->SetPos(XMFLOAT2(x + 35, y)); - colorGradingButton->SetSize(XMFLOAT2(200, hei)); - colorGradingButton->OnClick([=](wiEventArgs args) { + colorGradingButton.Create("Load Color Grading LUT..."); + colorGradingButton.SetTooltip("Load a color grading lookup texture..."); + colorGradingButton.SetPos(XMFLOAT2(x + 35, y)); + colorGradingButton.SetSize(XMFLOAT2(200, hei)); + colorGradingButton.OnClick([=](wiEventArgs args) { auto x = editor->renderPath->getColorGradingTexture(); if (x == nullptr) @@ -310,7 +317,7 @@ PostprocessWindow::PostprocessWindow(EditorComponent* editor) : GUI(&editor->Get editor->renderPath->setColorGradingTexture(wiResourceManager::Load(fileName)); if (editor->renderPath->getColorGradingTexture() != nullptr) { - colorGradingButton->SetText(fileName); + colorGradingButton.SetText(fileName); } }); }); @@ -318,104 +325,96 @@ PostprocessWindow::PostprocessWindow(EditorComponent* editor) : GUI(&editor->Get else { editor->renderPath->setColorGradingTexture(nullptr); - colorGradingButton->SetText("Load Color Grading LUT..."); + colorGradingButton.SetText("Load Color Grading LUT..."); } }); - ppWindow->AddWidget(colorGradingButton); + AddWidget(&colorGradingButton); - outlineCheckBox = new wiCheckBox("Dithering: "); - outlineCheckBox->SetTooltip("Toggle the full screen dithering effect. This helps to reduce color banding."); - outlineCheckBox->SetSize(XMFLOAT2(hei, hei)); - outlineCheckBox->SetPos(XMFLOAT2(x, y += step)); - outlineCheckBox->SetCheck(editor->renderPath->getDitherEnabled()); - outlineCheckBox->OnClick([=](wiEventArgs args) { + ditherCheckBox.Create("Dithering: "); + ditherCheckBox.SetTooltip("Toggle the full screen dithering effect. This helps to reduce color banding."); + ditherCheckBox.SetSize(XMFLOAT2(hei, hei)); + ditherCheckBox.SetPos(XMFLOAT2(x, y += step)); + ditherCheckBox.SetCheck(editor->renderPath->getDitherEnabled()); + ditherCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setDitherEnabled(args.bValue); }); - ppWindow->AddWidget(outlineCheckBox); + AddWidget(&ditherCheckBox); - sharpenFilterCheckBox = new wiCheckBox("Sharpen Filter: "); - sharpenFilterCheckBox->SetTooltip("Toggle sharpening post process of the final image."); - sharpenFilterCheckBox->SetScriptTip("RenderPath3D::SetSharpenFilterEnabled(bool value)"); - sharpenFilterCheckBox->SetSize(XMFLOAT2(hei, hei)); - sharpenFilterCheckBox->SetPos(XMFLOAT2(x, y += step)); - sharpenFilterCheckBox->SetCheck(editor->renderPath->getSharpenFilterEnabled()); - sharpenFilterCheckBox->OnClick([=](wiEventArgs args) { + sharpenFilterCheckBox.Create("Sharpen Filter: "); + sharpenFilterCheckBox.SetTooltip("Toggle sharpening post process of the final image."); + sharpenFilterCheckBox.SetScriptTip("RenderPath3D::SetSharpenFilterEnabled(bool value)"); + sharpenFilterCheckBox.SetSize(XMFLOAT2(hei, hei)); + sharpenFilterCheckBox.SetPos(XMFLOAT2(x, y += step)); + sharpenFilterCheckBox.SetCheck(editor->renderPath->getSharpenFilterEnabled()); + sharpenFilterCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setSharpenFilterEnabled(args.bValue); }); - ppWindow->AddWidget(sharpenFilterCheckBox); + AddWidget(&sharpenFilterCheckBox); - sharpenFilterAmountSlider = new wiSlider(0, 4, 1, 1000, "Amount: "); - sharpenFilterAmountSlider->SetTooltip("Set sharpness filter strength."); - sharpenFilterAmountSlider->SetScriptTip("RenderPath3D::SetSharpenFilterAmount(float value)"); - sharpenFilterAmountSlider->SetSize(XMFLOAT2(100, hei)); - sharpenFilterAmountSlider->SetPos(XMFLOAT2(x + 100, y)); - sharpenFilterAmountSlider->SetValue(editor->renderPath->getSharpenFilterAmount()); - sharpenFilterAmountSlider->OnSlide([=](wiEventArgs args) { + sharpenFilterAmountSlider.Create(0, 4, 1, 1000, "Amount: "); + sharpenFilterAmountSlider.SetTooltip("Set sharpness filter strength."); + sharpenFilterAmountSlider.SetScriptTip("RenderPath3D::SetSharpenFilterAmount(float value)"); + sharpenFilterAmountSlider.SetSize(XMFLOAT2(100, hei)); + sharpenFilterAmountSlider.SetPos(XMFLOAT2(x + 100, y)); + sharpenFilterAmountSlider.SetValue(editor->renderPath->getSharpenFilterAmount()); + sharpenFilterAmountSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setSharpenFilterAmount(args.fValue); }); - ppWindow->AddWidget(sharpenFilterAmountSlider); + AddWidget(&sharpenFilterAmountSlider); - outlineCheckBox = new wiCheckBox("Cartoon Outline: "); - outlineCheckBox->SetTooltip("Toggle the full screen cartoon outline effect."); - outlineCheckBox->SetSize(XMFLOAT2(hei, hei)); - outlineCheckBox->SetPos(XMFLOAT2(x, y += step)); - outlineCheckBox->SetCheck(editor->renderPath->getOutlineEnabled()); - outlineCheckBox->OnClick([=](wiEventArgs args) { + outlineCheckBox.Create("Cartoon Outline: "); + outlineCheckBox.SetTooltip("Toggle the full screen cartoon outline effect."); + outlineCheckBox.SetSize(XMFLOAT2(hei, hei)); + outlineCheckBox.SetPos(XMFLOAT2(x, y += step)); + outlineCheckBox.SetCheck(editor->renderPath->getOutlineEnabled()); + outlineCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setOutlineEnabled(args.bValue); }); - ppWindow->AddWidget(outlineCheckBox); + AddWidget(&outlineCheckBox); - outlineThresholdSlider = new wiSlider(0, 1, 0.1f, 1000, "Threshold: "); - outlineThresholdSlider->SetTooltip("Outline edge detection threshold. Increase if not enough otlines are detected, decrease if too many outlines are detected."); - outlineThresholdSlider->SetSize(XMFLOAT2(100, hei)); - outlineThresholdSlider->SetPos(XMFLOAT2(x + 100, y)); - outlineThresholdSlider->SetValue(editor->renderPath->getOutlineThreshold()); - outlineThresholdSlider->OnSlide([=](wiEventArgs args) { + outlineThresholdSlider.Create(0, 1, 0.1f, 1000, "Threshold: "); + outlineThresholdSlider.SetTooltip("Outline edge detection threshold. Increase if not enough otlines are detected, decrease if too many outlines are detected."); + outlineThresholdSlider.SetSize(XMFLOAT2(100, hei)); + outlineThresholdSlider.SetPos(XMFLOAT2(x + 100, y)); + outlineThresholdSlider.SetValue(editor->renderPath->getOutlineThreshold()); + outlineThresholdSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setOutlineThreshold(args.fValue); }); - ppWindow->AddWidget(outlineThresholdSlider); + AddWidget(&outlineThresholdSlider); - outlineThicknessSlider = new wiSlider(0, 4, 1, 1000, "Thickness: "); - outlineThicknessSlider->SetTooltip("Set outline thickness."); - outlineThicknessSlider->SetSize(XMFLOAT2(100, hei)); - outlineThicknessSlider->SetPos(XMFLOAT2(x + 100, y += step)); - outlineThicknessSlider->SetValue(editor->renderPath->getOutlineThickness()); - outlineThicknessSlider->OnSlide([=](wiEventArgs args) { + outlineThicknessSlider.Create(0, 4, 1, 1000, "Thickness: "); + outlineThicknessSlider.SetTooltip("Set outline thickness."); + outlineThicknessSlider.SetSize(XMFLOAT2(100, hei)); + outlineThicknessSlider.SetPos(XMFLOAT2(x + 100, y += step)); + outlineThicknessSlider.SetValue(editor->renderPath->getOutlineThickness()); + outlineThicknessSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setOutlineThickness(args.fValue); }); - ppWindow->AddWidget(outlineThicknessSlider); + AddWidget(&outlineThicknessSlider); - chromaticaberrationCheckBox = new wiCheckBox("Chromatic Aberration: "); - chromaticaberrationCheckBox->SetTooltip("Toggle the full screen chromatic aberration effect. This simulates lens distortion at screen edges."); - chromaticaberrationCheckBox->SetSize(XMFLOAT2(hei, hei)); - chromaticaberrationCheckBox->SetPos(XMFLOAT2(x, y += step)); - chromaticaberrationCheckBox->SetCheck(editor->renderPath->getOutlineEnabled()); - chromaticaberrationCheckBox->OnClick([=](wiEventArgs args) { + chromaticaberrationCheckBox.Create("Chromatic Aberration: "); + chromaticaberrationCheckBox.SetTooltip("Toggle the full screen chromatic aberration effect. This simulates lens distortion at screen edges."); + chromaticaberrationCheckBox.SetSize(XMFLOAT2(hei, hei)); + chromaticaberrationCheckBox.SetPos(XMFLOAT2(x, y += step)); + chromaticaberrationCheckBox.SetCheck(editor->renderPath->getOutlineEnabled()); + chromaticaberrationCheckBox.OnClick([=](wiEventArgs args) { editor->renderPath->setChromaticAberrationEnabled(args.bValue); }); - ppWindow->AddWidget(chromaticaberrationCheckBox); + AddWidget(&chromaticaberrationCheckBox); - chromaticaberrationSlider = new wiSlider(0, 4, 1.0f, 1000, "Amount: "); - chromaticaberrationSlider->SetTooltip("The lens distortion amount."); - chromaticaberrationSlider->SetSize(XMFLOAT2(100, hei)); - chromaticaberrationSlider->SetPos(XMFLOAT2(x + 100, y)); - chromaticaberrationSlider->SetValue(editor->renderPath->getChromaticAberrationAmount()); - chromaticaberrationSlider->OnSlide([=](wiEventArgs args) { + chromaticaberrationSlider.Create(0, 4, 1.0f, 1000, "Amount: "); + chromaticaberrationSlider.SetTooltip("The lens distortion amount."); + chromaticaberrationSlider.SetSize(XMFLOAT2(100, hei)); + chromaticaberrationSlider.SetPos(XMFLOAT2(x + 100, y)); + chromaticaberrationSlider.SetValue(editor->renderPath->getChromaticAberrationAmount()); + chromaticaberrationSlider.OnSlide([=](wiEventArgs args) { editor->renderPath->setChromaticAberrationAmount(args.fValue); }); - ppWindow->AddWidget(chromaticaberrationSlider); + AddWidget(&chromaticaberrationSlider); - ppWindow->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 500, 80, 0)); - ppWindow->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 500, 80, 0)); + SetVisible(false); } - - -PostprocessWindow::~PostprocessWindow() -{ - ppWindow->RemoveWidgets(true); - GUI->RemoveWidget(ppWindow); - delete ppWindow; -} diff --git a/Editor/PostprocessWindow.h b/Editor/PostprocessWindow.h index df5260f60..b10f039ca 100644 --- a/Editor/PostprocessWindow.h +++ b/Editor/PostprocessWindow.h @@ -1,55 +1,45 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiButton; -class wiComboBox; +#include "WickedEngine.h" class EditorComponent; -class PostprocessWindow +class PostprocessWindow : public wiWindow { public: - PostprocessWindow(EditorComponent* editor); - ~PostprocessWindow(); + void Create(EditorComponent* editor); - wiGUI* GUI; - - wiWindow* ppWindow; - wiSlider* exposureSlider; - wiCheckBox* lensFlareCheckBox; - wiCheckBox* lightShaftsCheckBox; - wiCheckBox* volumetricCloudsCheckBox; - wiComboBox* aoComboBox; - wiSlider* aoPowerSlider; - wiSlider* aoRangeSlider; - wiSlider* aoSampleCountSlider; - wiCheckBox* ssrCheckBox; - wiCheckBox* raytracedReflectionsCheckBox; - wiCheckBox* sssCheckBox; - wiCheckBox* eyeAdaptionCheckBox; - wiCheckBox* motionBlurCheckBox; - wiSlider* motionBlurStrengthSlider; - wiCheckBox* depthOfFieldCheckBox; - wiSlider* depthOfFieldFocusSlider; - wiSlider* depthOfFieldScaleSlider; - wiSlider* depthOfFieldAspectSlider; - wiCheckBox* bloomCheckBox; - wiSlider* bloomStrengthSlider; - wiCheckBox* fxaaCheckBox; - wiCheckBox* colorGradingCheckBox; - wiButton* colorGradingButton; - wiCheckBox* ditherCheckBox; - wiCheckBox* sharpenFilterCheckBox; - wiSlider* sharpenFilterAmountSlider; - wiCheckBox* outlineCheckBox; - wiSlider* outlineThresholdSlider; - wiSlider* outlineThicknessSlider; - wiCheckBox* chromaticaberrationCheckBox; - wiSlider* chromaticaberrationSlider; + wiSlider exposureSlider; + wiCheckBox lensFlareCheckBox; + wiCheckBox lightShaftsCheckBox; + wiCheckBox volumetricCloudsCheckBox; + wiComboBox aoComboBox; + wiSlider aoPowerSlider; + wiSlider aoRangeSlider; + wiSlider aoSampleCountSlider; + wiCheckBox ssrCheckBox; + wiCheckBox raytracedReflectionsCheckBox; + wiCheckBox sssCheckBox; + wiSlider sssSlider; + wiCheckBox eyeAdaptionCheckBox; + wiCheckBox motionBlurCheckBox; + wiSlider motionBlurStrengthSlider; + wiCheckBox depthOfFieldCheckBox; + wiSlider depthOfFieldFocusSlider; + wiSlider depthOfFieldScaleSlider; + wiSlider depthOfFieldAspectSlider; + wiCheckBox bloomCheckBox; + wiSlider bloomStrengthSlider; + wiCheckBox fxaaCheckBox; + wiCheckBox colorGradingCheckBox; + wiButton colorGradingButton; + wiCheckBox ditherCheckBox; + wiCheckBox sharpenFilterCheckBox; + wiSlider sharpenFilterAmountSlider; + wiCheckBox outlineCheckBox; + wiSlider outlineThresholdSlider; + wiSlider outlineThicknessSlider; + wiCheckBox chromaticaberrationCheckBox; + wiSlider chromaticaberrationSlider; }; diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index 2e561589b..440fb1573 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -4,244 +4,232 @@ #include "Editor.h" -RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void RendererWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); + wiWindow::Create("Renderer Window"); wiRenderer::SetToDrawDebugEnvProbes(true); wiRenderer::SetToDrawGridHelper(true); wiRenderer::SetToDrawDebugCameras(true); - rendererWindow = new wiWindow(GUI, "Renderer Window"); - rendererWindow->SetSize(XMFLOAT2(580, 540)); - GUI->AddWidget(rendererWindow); + SetSize(XMFLOAT2(580, 520)); float x = 220, y = 5, step = 20, itemheight = 18; - vsyncCheckBox = new wiCheckBox("VSync: "); - vsyncCheckBox->SetTooltip("Toggle vertical sync"); - vsyncCheckBox->SetScriptTip("SetVSyncEnabled(opt bool enabled)"); - vsyncCheckBox->SetPos(XMFLOAT2(x, y += step)); - vsyncCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - vsyncCheckBox->OnClick([](wiEventArgs args) { + vsyncCheckBox.Create("VSync: "); + vsyncCheckBox.SetTooltip("Toggle vertical sync"); + vsyncCheckBox.SetScriptTip("SetVSyncEnabled(opt bool enabled)"); + vsyncCheckBox.SetPos(XMFLOAT2(x, y += step)); + vsyncCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + vsyncCheckBox.OnClick([](wiEventArgs args) { wiRenderer::GetDevice()->SetVSyncEnabled(args.bValue); }); - vsyncCheckBox->SetCheck(wiRenderer::GetDevice()->GetVSyncEnabled()); - rendererWindow->AddWidget(vsyncCheckBox); + vsyncCheckBox.SetCheck(wiRenderer::GetDevice()->GetVSyncEnabled()); + AddWidget(&vsyncCheckBox); - occlusionCullingCheckBox = new wiCheckBox("Occlusion Culling: "); - occlusionCullingCheckBox->SetTooltip("Toggle occlusion culling. This can boost framerate if many objects are occluded in the scene."); - occlusionCullingCheckBox->SetScriptTip("SetOcclusionCullingEnabled(bool enabled)"); - occlusionCullingCheckBox->SetPos(XMFLOAT2(x, y += step)); - occlusionCullingCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - occlusionCullingCheckBox->OnClick([](wiEventArgs args) { + occlusionCullingCheckBox.Create("Occlusion Culling: "); + occlusionCullingCheckBox.SetTooltip("Toggle occlusion culling. This can boost framerate if many objects are occluded in the scene."); + occlusionCullingCheckBox.SetScriptTip("SetOcclusionCullingEnabled(bool enabled)"); + occlusionCullingCheckBox.SetPos(XMFLOAT2(x, y += step)); + occlusionCullingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + occlusionCullingCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetOcclusionCullingEnabled(args.bValue); }); - occlusionCullingCheckBox->SetCheck(wiRenderer::GetOcclusionCullingEnabled()); - rendererWindow->AddWidget(occlusionCullingCheckBox); + occlusionCullingCheckBox.SetCheck(wiRenderer::GetOcclusionCullingEnabled()); + AddWidget(&occlusionCullingCheckBox); - resolutionScaleSlider = new wiSlider(0.25f, 2.0f, 1.0f, 7.0f, "Resolution Scale: "); - resolutionScaleSlider->SetTooltip("Adjust the internal rendering resolution."); - resolutionScaleSlider->SetSize(XMFLOAT2(100, itemheight)); - resolutionScaleSlider->SetPos(XMFLOAT2(x, y += step)); - resolutionScaleSlider->SetValue(wiRenderer::GetResolutionScale()); - resolutionScaleSlider->OnSlide([&](wiEventArgs args) { + resolutionScaleSlider.Create(0.25f, 2.0f, 1.0f, 7.0f, "Resolution Scale: "); + resolutionScaleSlider.SetTooltip("Adjust the internal rendering resolution."); + resolutionScaleSlider.SetSize(XMFLOAT2(100, itemheight)); + resolutionScaleSlider.SetPos(XMFLOAT2(x, y += step)); + resolutionScaleSlider.SetValue(wiRenderer::GetResolutionScale()); + resolutionScaleSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetResolutionScale(args.fValue); }); - rendererWindow->AddWidget(resolutionScaleSlider); + AddWidget(&resolutionScaleSlider); - gammaSlider = new wiSlider(1.0f, 3.0f, 2.2f, 1000.0f, "Gamma: "); - gammaSlider->SetTooltip("Adjust the gamma correction for the display device."); - gammaSlider->SetSize(XMFLOAT2(100, itemheight)); - gammaSlider->SetPos(XMFLOAT2(x, y += step)); - gammaSlider->SetValue(wiRenderer::GetGamma()); - gammaSlider->OnSlide([&](wiEventArgs args) { + gammaSlider.Create(1.0f, 3.0f, 2.2f, 1000.0f, "Gamma: "); + gammaSlider.SetTooltip("Adjust the gamma correction for the display device."); + gammaSlider.SetSize(XMFLOAT2(100, itemheight)); + gammaSlider.SetPos(XMFLOAT2(x, y += step)); + gammaSlider.SetValue(wiRenderer::GetGamma()); + gammaSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetGamma(args.fValue); }); - rendererWindow->AddWidget(gammaSlider); + AddWidget(&gammaSlider); - voxelRadianceCheckBox = new wiCheckBox("Voxel GI: "); - voxelRadianceCheckBox->SetTooltip("Toggle voxel Global Illumination computation."); - voxelRadianceCheckBox->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - voxelRadianceCheckBox->OnClick([](wiEventArgs args) { + voxelRadianceCheckBox.Create("Voxel GI: "); + voxelRadianceCheckBox.SetTooltip("Toggle voxel Global Illumination computation."); + voxelRadianceCheckBox.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + voxelRadianceCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetVoxelRadianceEnabled(args.bValue); }); - voxelRadianceCheckBox->SetCheck(wiRenderer::GetVoxelRadianceEnabled()); - rendererWindow->AddWidget(voxelRadianceCheckBox); + voxelRadianceCheckBox.SetCheck(wiRenderer::GetVoxelRadianceEnabled()); + AddWidget(&voxelRadianceCheckBox); - voxelRadianceDebugCheckBox = new wiCheckBox("DEBUG: "); - voxelRadianceDebugCheckBox->SetTooltip("Toggle Voxel GI visualization."); - voxelRadianceDebugCheckBox->SetPos(XMFLOAT2(x + 122, y)); - voxelRadianceDebugCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - voxelRadianceDebugCheckBox->OnClick([](wiEventArgs args) { + voxelRadianceDebugCheckBox.Create("DEBUG: "); + voxelRadianceDebugCheckBox.SetTooltip("Toggle Voxel GI visualization."); + voxelRadianceDebugCheckBox.SetPos(XMFLOAT2(x + 122, y)); + voxelRadianceDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + voxelRadianceDebugCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawVoxelHelper(args.bValue); }); - voxelRadianceDebugCheckBox->SetCheck(wiRenderer::GetToDrawVoxelHelper()); - rendererWindow->AddWidget(voxelRadianceDebugCheckBox); + voxelRadianceDebugCheckBox.SetCheck(wiRenderer::GetToDrawVoxelHelper()); + AddWidget(&voxelRadianceDebugCheckBox); - voxelRadianceSecondaryBounceCheckBox = new wiCheckBox("Secondary Light Bounce: "); - voxelRadianceSecondaryBounceCheckBox->SetTooltip("Toggle secondary light bounce computation for Voxel GI."); - voxelRadianceSecondaryBounceCheckBox->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceSecondaryBounceCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - voxelRadianceSecondaryBounceCheckBox->OnClick([](wiEventArgs args) { + voxelRadianceSecondaryBounceCheckBox.Create("Secondary Light Bounce: "); + voxelRadianceSecondaryBounceCheckBox.SetTooltip("Toggle secondary light bounce computation for Voxel GI."); + voxelRadianceSecondaryBounceCheckBox.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceSecondaryBounceCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + voxelRadianceSecondaryBounceCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetVoxelRadianceSecondaryBounceEnabled(args.bValue); }); - voxelRadianceSecondaryBounceCheckBox->SetCheck(wiRenderer::GetVoxelRadianceSecondaryBounceEnabled()); - rendererWindow->AddWidget(voxelRadianceSecondaryBounceCheckBox); + voxelRadianceSecondaryBounceCheckBox.SetCheck(wiRenderer::GetVoxelRadianceSecondaryBounceEnabled()); + AddWidget(&voxelRadianceSecondaryBounceCheckBox); - voxelRadianceReflectionsCheckBox = new wiCheckBox("Reflections: "); - voxelRadianceReflectionsCheckBox->SetTooltip("Toggle specular reflections computation for Voxel GI."); - voxelRadianceReflectionsCheckBox->SetPos(XMFLOAT2(x + 122, y)); - voxelRadianceReflectionsCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - voxelRadianceReflectionsCheckBox->OnClick([](wiEventArgs args) { + voxelRadianceReflectionsCheckBox.Create("Reflections: "); + voxelRadianceReflectionsCheckBox.SetTooltip("Toggle specular reflections computation for Voxel GI."); + voxelRadianceReflectionsCheckBox.SetPos(XMFLOAT2(x + 122, y)); + voxelRadianceReflectionsCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + voxelRadianceReflectionsCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetVoxelRadianceReflectionsEnabled(args.bValue); }); - voxelRadianceReflectionsCheckBox->SetCheck(wiRenderer::GetVoxelRadianceReflectionsEnabled()); - rendererWindow->AddWidget(voxelRadianceReflectionsCheckBox); + voxelRadianceReflectionsCheckBox.SetCheck(wiRenderer::GetVoxelRadianceReflectionsEnabled()); + AddWidget(&voxelRadianceReflectionsCheckBox); - voxelRadianceVoxelSizeSlider = new wiSlider(0.25, 2, 1, 7, "Voxel GI Voxel Size: "); - voxelRadianceVoxelSizeSlider->SetTooltip("Adjust the voxel size for Voxel GI calculations."); - voxelRadianceVoxelSizeSlider->SetSize(XMFLOAT2(100, itemheight)); - voxelRadianceVoxelSizeSlider->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceVoxelSizeSlider->SetValue(wiRenderer::GetVoxelRadianceVoxelSize()); - voxelRadianceVoxelSizeSlider->OnSlide([&](wiEventArgs args) { + voxelRadianceVoxelSizeSlider.Create(0.25, 2, 1, 7, "Voxel GI Voxel Size: "); + voxelRadianceVoxelSizeSlider.SetTooltip("Adjust the voxel size for Voxel GI calculations."); + voxelRadianceVoxelSizeSlider.SetSize(XMFLOAT2(100, itemheight)); + voxelRadianceVoxelSizeSlider.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceVoxelSizeSlider.SetValue(wiRenderer::GetVoxelRadianceVoxelSize()); + voxelRadianceVoxelSizeSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetVoxelRadianceVoxelSize(args.fValue); }); - rendererWindow->AddWidget(voxelRadianceVoxelSizeSlider); + AddWidget(&voxelRadianceVoxelSizeSlider); - voxelRadianceConeTracingSlider = new wiSlider(1, 16, 8, 15, "Voxel GI NumCones: "); - voxelRadianceConeTracingSlider->SetTooltip("Adjust the number of cones sampled in the radiance gathering phase."); - voxelRadianceConeTracingSlider->SetSize(XMFLOAT2(100, itemheight)); - voxelRadianceConeTracingSlider->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceConeTracingSlider->SetValue((float)wiRenderer::GetVoxelRadianceNumCones()); - voxelRadianceConeTracingSlider->OnSlide([&](wiEventArgs args) { + voxelRadianceConeTracingSlider.Create(1, 16, 8, 15, "Voxel GI NumCones: "); + voxelRadianceConeTracingSlider.SetTooltip("Adjust the number of cones sampled in the radiance gathering phase."); + voxelRadianceConeTracingSlider.SetSize(XMFLOAT2(100, itemheight)); + voxelRadianceConeTracingSlider.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceConeTracingSlider.SetValue((float)wiRenderer::GetVoxelRadianceNumCones()); + voxelRadianceConeTracingSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetVoxelRadianceNumCones(args.iValue); }); - rendererWindow->AddWidget(voxelRadianceConeTracingSlider); + AddWidget(&voxelRadianceConeTracingSlider); - voxelRadianceRayStepSizeSlider = new wiSlider(0.5f, 2.0f, 0.5f, 10000, "Voxel GI Ray Step Size: "); - voxelRadianceRayStepSizeSlider->SetTooltip("Adjust the precision of ray marching for cone tracing step. Lower values = more precision but slower performance."); - voxelRadianceRayStepSizeSlider->SetSize(XMFLOAT2(100, itemheight)); - voxelRadianceRayStepSizeSlider->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceRayStepSizeSlider->SetValue(wiRenderer::GetVoxelRadianceRayStepSize()); - voxelRadianceRayStepSizeSlider->OnSlide([&](wiEventArgs args) { + voxelRadianceRayStepSizeSlider.Create(0.5f, 2.0f, 0.5f, 10000, "Voxel GI Ray Step Size: "); + voxelRadianceRayStepSizeSlider.SetTooltip("Adjust the precision of ray marching for cone tracing step. Lower values = more precision but slower performance."); + voxelRadianceRayStepSizeSlider.SetSize(XMFLOAT2(100, itemheight)); + voxelRadianceRayStepSizeSlider.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceRayStepSizeSlider.SetValue(wiRenderer::GetVoxelRadianceRayStepSize()); + voxelRadianceRayStepSizeSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetVoxelRadianceRayStepSize(args.fValue); }); - rendererWindow->AddWidget(voxelRadianceRayStepSizeSlider); + AddWidget(&voxelRadianceRayStepSizeSlider); - voxelRadianceMaxDistanceSlider = new wiSlider(0, 100, 10, 10000, "Voxel GI Max Distance: "); - voxelRadianceMaxDistanceSlider->SetTooltip("Adjust max raymarching distance for voxel GI."); - voxelRadianceMaxDistanceSlider->SetSize(XMFLOAT2(100, itemheight)); - voxelRadianceMaxDistanceSlider->SetPos(XMFLOAT2(x, y += step)); - voxelRadianceMaxDistanceSlider->SetValue(wiRenderer::GetVoxelRadianceMaxDistance()); - voxelRadianceMaxDistanceSlider->OnSlide([&](wiEventArgs args) { + voxelRadianceMaxDistanceSlider.Create(0, 100, 10, 10000, "Voxel GI Max Distance: "); + voxelRadianceMaxDistanceSlider.SetTooltip("Adjust max raymarching distance for voxel GI."); + voxelRadianceMaxDistanceSlider.SetSize(XMFLOAT2(100, itemheight)); + voxelRadianceMaxDistanceSlider.SetPos(XMFLOAT2(x, y += step)); + voxelRadianceMaxDistanceSlider.SetValue(wiRenderer::GetVoxelRadianceMaxDistance()); + voxelRadianceMaxDistanceSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetVoxelRadianceMaxDistance(args.fValue); }); - rendererWindow->AddWidget(voxelRadianceMaxDistanceSlider); + AddWidget(&voxelRadianceMaxDistanceSlider); - wireFrameCheckBox = new wiCheckBox("Render Wireframe: "); - wireFrameCheckBox->SetTooltip("Visualize the scene as a wireframe"); - wireFrameCheckBox->SetPos(XMFLOAT2(x, y += step)); - wireFrameCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - wireFrameCheckBox->OnClick([](wiEventArgs args) { + wireFrameCheckBox.Create("Render Wireframe: "); + wireFrameCheckBox.SetTooltip("Visualize the scene as a wireframe"); + wireFrameCheckBox.SetPos(XMFLOAT2(x, y += step)); + wireFrameCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + wireFrameCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetWireRender(args.bValue); }); - wireFrameCheckBox->SetCheck(wiRenderer::IsWireRender()); - rendererWindow->AddWidget(wireFrameCheckBox); + wireFrameCheckBox.SetCheck(wiRenderer::IsWireRender()); + AddWidget(&wireFrameCheckBox); - variableRateShadingClassificationCheckBox = new wiCheckBox("VRS Classification: "); - variableRateShadingClassificationCheckBox->SetTooltip("Enable classification of variable rate shading on the screen. Less important parts will be shaded with lesser resolution.\nDX12 only and requires Tier1 hardware support for variable shading rate"); - variableRateShadingClassificationCheckBox->SetPos(XMFLOAT2(x, y += step)); - variableRateShadingClassificationCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - variableRateShadingClassificationCheckBox->OnClick([](wiEventArgs args) { + variableRateShadingClassificationCheckBox.Create("VRS Classification: "); + variableRateShadingClassificationCheckBox.SetTooltip("Enable classification of variable rate shading on the screen. Less important parts will be shaded with lesser resolution.\nDX12 only and requires Tier1 hardware support for variable shading rate"); + variableRateShadingClassificationCheckBox.SetPos(XMFLOAT2(x, y += step)); + variableRateShadingClassificationCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + variableRateShadingClassificationCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetVariableRateShadingClassification(args.bValue); }); - variableRateShadingClassificationCheckBox->SetCheck(wiRenderer::GetVariableRateShadingClassification()); - rendererWindow->AddWidget(variableRateShadingClassificationCheckBox); - variableRateShadingClassificationCheckBox->SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)); + variableRateShadingClassificationCheckBox.SetCheck(wiRenderer::GetVariableRateShadingClassification()); + AddWidget(&variableRateShadingClassificationCheckBox); + variableRateShadingClassificationCheckBox.SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)); - variableRateShadingClassificationDebugCheckBox = new wiCheckBox("DEBUG: "); - variableRateShadingClassificationDebugCheckBox->SetTooltip("Toggle visualization of variable rate shading classification feature"); - variableRateShadingClassificationDebugCheckBox->SetPos(XMFLOAT2(x + 122, y)); - variableRateShadingClassificationDebugCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - variableRateShadingClassificationDebugCheckBox->OnClick([](wiEventArgs args) { + variableRateShadingClassificationDebugCheckBox.Create("DEBUG: "); + variableRateShadingClassificationDebugCheckBox.SetTooltip("Toggle visualization of variable rate shading classification feature"); + variableRateShadingClassificationDebugCheckBox.SetPos(XMFLOAT2(x + 122, y)); + variableRateShadingClassificationDebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + variableRateShadingClassificationDebugCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetVariableRateShadingClassificationDebug(args.bValue); }); - variableRateShadingClassificationDebugCheckBox->SetCheck(wiRenderer::GetVariableRateShadingClassificationDebug()); - rendererWindow->AddWidget(variableRateShadingClassificationDebugCheckBox); - variableRateShadingClassificationDebugCheckBox->SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)); + variableRateShadingClassificationDebugCheckBox.SetCheck(wiRenderer::GetVariableRateShadingClassificationDebug()); + AddWidget(&variableRateShadingClassificationDebugCheckBox); + variableRateShadingClassificationDebugCheckBox.SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)); - advancedLightCullingCheckBox = new wiCheckBox("2.5D Light Culling: "); - advancedLightCullingCheckBox->SetTooltip("Enable a more aggressive light culling approach which can result in slower culling but faster rendering (Tiled renderer only)"); - advancedLightCullingCheckBox->SetPos(XMFLOAT2(x, y += step)); - advancedLightCullingCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - advancedLightCullingCheckBox->OnClick([](wiEventArgs args) { + advancedLightCullingCheckBox.Create("2.5D Light Culling: "); + advancedLightCullingCheckBox.SetTooltip("Enable a more aggressive light culling approach which can result in slower culling but faster rendering (Tiled renderer only)"); + advancedLightCullingCheckBox.SetPos(XMFLOAT2(x, y += step)); + advancedLightCullingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + advancedLightCullingCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetAdvancedLightCulling(args.bValue); }); - advancedLightCullingCheckBox->SetCheck(wiRenderer::GetAdvancedLightCulling()); - rendererWindow->AddWidget(advancedLightCullingCheckBox); + advancedLightCullingCheckBox.SetCheck(wiRenderer::GetAdvancedLightCulling()); + AddWidget(&advancedLightCullingCheckBox); - debugLightCullingCheckBox = new wiCheckBox("DEBUG: "); - debugLightCullingCheckBox->SetTooltip("Toggle visualization of the screen space light culling heatmap grid (Tiled renderer only)"); - debugLightCullingCheckBox->SetPos(XMFLOAT2(x + 122, y)); - debugLightCullingCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - debugLightCullingCheckBox->OnClick([](wiEventArgs args) { + debugLightCullingCheckBox.Create("DEBUG: "); + debugLightCullingCheckBox.SetTooltip("Toggle visualization of the screen space light culling heatmap grid (Tiled renderer only)"); + debugLightCullingCheckBox.SetPos(XMFLOAT2(x + 122, y)); + debugLightCullingCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + debugLightCullingCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetDebugLightCulling(args.bValue); }); - debugLightCullingCheckBox->SetCheck(wiRenderer::GetDebugLightCulling()); - rendererWindow->AddWidget(debugLightCullingCheckBox); + debugLightCullingCheckBox.SetCheck(wiRenderer::GetDebugLightCulling()); + AddWidget(&debugLightCullingCheckBox); - tessellationCheckBox = new wiCheckBox("Tessellation Enabled: "); - tessellationCheckBox->SetTooltip("Enable tessellation feature. You also need to specify a tessellation factor for individual objects."); - tessellationCheckBox->SetPos(XMFLOAT2(x, y += step)); - tessellationCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - tessellationCheckBox->OnClick([=](wiEventArgs args) { + tessellationCheckBox.Create("Tessellation Enabled: "); + tessellationCheckBox.SetTooltip("Enable tessellation feature. You also need to specify a tessellation factor for individual objects."); + tessellationCheckBox.SetPos(XMFLOAT2(x, y += step)); + tessellationCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + tessellationCheckBox.OnClick([=](wiEventArgs args) { wiRenderer::SetTessellationEnabled(args.bValue); }); - tessellationCheckBox->SetCheck(wiRenderer::GetTessellationEnabled()); - rendererWindow->AddWidget(tessellationCheckBox); - tessellationCheckBox->SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_TESSELLATION)); + tessellationCheckBox.SetCheck(wiRenderer::GetTessellationEnabled()); + AddWidget(&tessellationCheckBox); + tessellationCheckBox.SetEnabled(wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_TESSELLATION)); - alphaCompositionCheckBox = new wiCheckBox("Alpha Composition: "); - alphaCompositionCheckBox->SetTooltip("Enable Alpha Composition. Enables softer alpha blending on partly solid geometry (eg. vegetation) but rendering performance will be slower."); - alphaCompositionCheckBox->SetPos(XMFLOAT2(x, y += step)); - alphaCompositionCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - alphaCompositionCheckBox->OnClick([=](wiEventArgs args) { - wiRenderer::SetAlphaCompositionEnabled(args.bValue); - }); - alphaCompositionCheckBox->SetCheck(wiRenderer::GetAlphaCompositionEnabled()); - rendererWindow->AddWidget(alphaCompositionCheckBox); - - speedMultiplierSlider = new wiSlider(0, 4, 1, 100000, "Speed: "); - speedMultiplierSlider->SetTooltip("Adjust the global speed (time multiplier)"); - speedMultiplierSlider->SetSize(XMFLOAT2(100, itemheight)); - speedMultiplierSlider->SetPos(XMFLOAT2(x, y += step)); - speedMultiplierSlider->SetValue(wiRenderer::GetGameSpeed()); - speedMultiplierSlider->OnSlide([&](wiEventArgs args) { + speedMultiplierSlider.Create(0, 4, 1, 100000, "Speed: "); + speedMultiplierSlider.SetTooltip("Adjust the global speed (time multiplier)"); + speedMultiplierSlider.SetSize(XMFLOAT2(100, itemheight)); + speedMultiplierSlider.SetPos(XMFLOAT2(x, y += step)); + speedMultiplierSlider.SetValue(wiRenderer::GetGameSpeed()); + speedMultiplierSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetGameSpeed(args.fValue); }); - rendererWindow->AddWidget(speedMultiplierSlider); + AddWidget(&speedMultiplierSlider); - transparentShadowsCheckBox = new wiCheckBox("Transparent Shadows: "); - transparentShadowsCheckBox->SetTooltip("Enables color tinted shadows and refraction caustics effects for transparent objects and water."); - transparentShadowsCheckBox->SetPos(XMFLOAT2(x, y += step)); - transparentShadowsCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - transparentShadowsCheckBox->SetCheck(wiRenderer::GetTransparentShadowsEnabled()); - transparentShadowsCheckBox->OnClick([=](wiEventArgs args) { + transparentShadowsCheckBox.Create("Transparent Shadows: "); + transparentShadowsCheckBox.SetTooltip("Enables color tinted shadows and refraction caustics effects for transparent objects and water."); + transparentShadowsCheckBox.SetPos(XMFLOAT2(x, y += step)); + transparentShadowsCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + transparentShadowsCheckBox.SetCheck(wiRenderer::GetTransparentShadowsEnabled()); + transparentShadowsCheckBox.OnClick([=](wiEventArgs args) { wiRenderer::SetTransparentShadowsEnabled(args.bValue); }); - rendererWindow->AddWidget(transparentShadowsCheckBox); + AddWidget(&transparentShadowsCheckBox); - shadowTypeComboBox = new wiComboBox("Shadow type: "); - shadowTypeComboBox->SetSize(XMFLOAT2(100, itemheight)); - shadowTypeComboBox->SetPos(XMFLOAT2(x, y += step)); - shadowTypeComboBox->AddItem("Shadowmaps"); + shadowTypeComboBox.Create("Shadow type: "); + shadowTypeComboBox.SetSize(XMFLOAT2(100, itemheight)); + shadowTypeComboBox.SetPos(XMFLOAT2(x, y += step)); + shadowTypeComboBox.AddItem("Shadowmaps"); if (wiRenderer::GetDevice()->CheckCapability(wiGraphics::GRAPHICSDEVICE_CAPABILITY_RAYTRACING_INLINE)) { - shadowTypeComboBox->AddItem("Ray traced"); + shadowTypeComboBox.AddItem("Ray traced"); } - shadowTypeComboBox->OnSelect([&](wiEventArgs args) { + shadowTypeComboBox.OnSelect([&](wiEventArgs args) { switch (args.iValue) { @@ -254,22 +242,22 @@ RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) break; } }); - shadowTypeComboBox->SetSelected(0); - shadowTypeComboBox->SetEnabled(true); - shadowTypeComboBox->SetTooltip("Choose between shadowmaps and ray traced shadows (if available).\n(ray traced shadows experimental, needs hardware support and shaders compiled with HLSL6.5)"); - rendererWindow->AddWidget(shadowTypeComboBox); + shadowTypeComboBox.SetSelected(0); + shadowTypeComboBox.SetEnabled(true); + shadowTypeComboBox.SetTooltip("Choose between shadowmaps and ray traced shadows (if available).\n(ray traced shadows experimental, needs hardware support and shaders compiled with HLSL6.5)"); + AddWidget(&shadowTypeComboBox); - shadowProps2DComboBox = new wiComboBox("2D Shadowmap resolution: "); - shadowProps2DComboBox->SetSize(XMFLOAT2(100, itemheight)); - shadowProps2DComboBox->SetPos(XMFLOAT2(x, y += step)); - shadowProps2DComboBox->AddItem("Off"); - shadowProps2DComboBox->AddItem("128"); - shadowProps2DComboBox->AddItem("256"); - shadowProps2DComboBox->AddItem("512"); - shadowProps2DComboBox->AddItem("1024"); - shadowProps2DComboBox->AddItem("2048"); - shadowProps2DComboBox->AddItem("4096"); - shadowProps2DComboBox->OnSelect([&](wiEventArgs args) { + shadowProps2DComboBox.Create("2D Shadowmap resolution: "); + shadowProps2DComboBox.SetSize(XMFLOAT2(100, itemheight)); + shadowProps2DComboBox.SetPos(XMFLOAT2(x, y += step)); + shadowProps2DComboBox.AddItem("Off"); + shadowProps2DComboBox.AddItem("128"); + shadowProps2DComboBox.AddItem("256"); + shadowProps2DComboBox.AddItem("512"); + shadowProps2DComboBox.AddItem("1024"); + shadowProps2DComboBox.AddItem("2048"); + shadowProps2DComboBox.AddItem("4096"); + shadowProps2DComboBox.OnSelect([&](wiEventArgs args) { switch (args.iValue) { @@ -298,23 +286,23 @@ RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) break; } }); - shadowProps2DComboBox->SetSelected(4); - shadowProps2DComboBox->SetEnabled(true); - shadowProps2DComboBox->SetTooltip("Choose a shadow quality preset for 2D shadow maps (spotlights, directional lights)..."); - shadowProps2DComboBox->SetScriptTip("SetShadowProps2D(int resolution, int count, int softShadowQuality)"); - rendererWindow->AddWidget(shadowProps2DComboBox); + shadowProps2DComboBox.SetSelected(4); + shadowProps2DComboBox.SetEnabled(true); + shadowProps2DComboBox.SetTooltip("Choose a shadow quality preset for 2D shadow maps (spotlights, directional lights)..."); + shadowProps2DComboBox.SetScriptTip("SetShadowProps2D(int resolution, int count, int softShadowQuality)"); + AddWidget(&shadowProps2DComboBox); - shadowPropsCubeComboBox = new wiComboBox("Cube Shadowmap resolution: "); - shadowPropsCubeComboBox->SetSize(XMFLOAT2(100, itemheight)); - shadowPropsCubeComboBox->SetPos(XMFLOAT2(x, y += step)); - shadowPropsCubeComboBox->AddItem("Off"); - shadowPropsCubeComboBox->AddItem("128"); - shadowPropsCubeComboBox->AddItem("256"); - shadowPropsCubeComboBox->AddItem("512"); - shadowPropsCubeComboBox->AddItem("1024"); - shadowPropsCubeComboBox->AddItem("2048"); - shadowPropsCubeComboBox->AddItem("4096"); - shadowPropsCubeComboBox->OnSelect([&](wiEventArgs args) { + shadowPropsCubeComboBox.Create("Cube Shadowmap resolution: "); + shadowPropsCubeComboBox.SetSize(XMFLOAT2(100, itemheight)); + shadowPropsCubeComboBox.SetPos(XMFLOAT2(x, y += step)); + shadowPropsCubeComboBox.AddItem("Off"); + shadowPropsCubeComboBox.AddItem("128"); + shadowPropsCubeComboBox.AddItem("256"); + shadowPropsCubeComboBox.AddItem("512"); + shadowPropsCubeComboBox.AddItem("1024"); + shadowPropsCubeComboBox.AddItem("2048"); + shadowPropsCubeComboBox.AddItem("4096"); + shadowPropsCubeComboBox.OnSelect([&](wiEventArgs args) { switch (args.iValue) { case 0: @@ -342,20 +330,20 @@ RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) break; } }); - shadowPropsCubeComboBox->SetSelected(2); - shadowPropsCubeComboBox->SetEnabled(true); - shadowPropsCubeComboBox->SetTooltip("Choose a shadow quality preset for cube shadow maps (pointlights, area lights)..."); - shadowPropsCubeComboBox->SetScriptTip("SetShadowPropsCube(int resolution, int count)"); - rendererWindow->AddWidget(shadowPropsCubeComboBox); + shadowPropsCubeComboBox.SetSelected(2); + shadowPropsCubeComboBox.SetEnabled(true); + shadowPropsCubeComboBox.SetTooltip("Choose a shadow quality preset for cube shadow maps (pointlights, area lights)..."); + shadowPropsCubeComboBox.SetScriptTip("SetShadowPropsCube(int resolution, int count)"); + AddWidget(&shadowPropsCubeComboBox); - MSAAComboBox = new wiComboBox("MSAA: "); - MSAAComboBox->SetSize(XMFLOAT2(100, itemheight)); - MSAAComboBox->SetPos(XMFLOAT2(x, y += step)); - MSAAComboBox->AddItem("Off"); - MSAAComboBox->AddItem("2"); - MSAAComboBox->AddItem("4"); - MSAAComboBox->AddItem("8"); - MSAAComboBox->OnSelect([=](wiEventArgs args) { + MSAAComboBox.Create("MSAA: "); + MSAAComboBox.SetSize(XMFLOAT2(100, itemheight)); + MSAAComboBox.SetPos(XMFLOAT2(x, y += step)); + MSAAComboBox.AddItem("Off"); + MSAAComboBox.AddItem("2"); + MSAAComboBox.AddItem("4"); + MSAAComboBox.AddItem("8"); + MSAAComboBox.OnSelect([=](wiEventArgs args) { switch (args.iValue) { case 0: @@ -375,40 +363,40 @@ RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } editor->ResizeBuffers(); }); - MSAAComboBox->SetSelected(0); - MSAAComboBox->SetEnabled(true); - MSAAComboBox->SetTooltip("Multisampling Anti Aliasing quality. It is only available for Forward render paths."); - rendererWindow->AddWidget(MSAAComboBox); + MSAAComboBox.SetSelected(0); + MSAAComboBox.SetEnabled(true); + MSAAComboBox.SetTooltip("Multisampling Anti Aliasing quality. "); + AddWidget(&MSAAComboBox); - temporalAACheckBox = new wiCheckBox("Temporal AA: "); - temporalAACheckBox->SetTooltip("Toggle Temporal Anti Aliasing. It is a supersampling techique which is performed across multiple frames."); - temporalAACheckBox->SetPos(XMFLOAT2(x, y += step)); - temporalAACheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - temporalAACheckBox->OnClick([](wiEventArgs args) { + temporalAACheckBox.Create("Temporal AA: "); + temporalAACheckBox.SetTooltip("Toggle Temporal Anti Aliasing. It is a supersampling techique which is performed across multiple frames."); + temporalAACheckBox.SetPos(XMFLOAT2(x, y += step)); + temporalAACheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + temporalAACheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetTemporalAAEnabled(args.bValue); }); - temporalAACheckBox->SetCheck(wiRenderer::GetTemporalAAEnabled()); - rendererWindow->AddWidget(temporalAACheckBox); + temporalAACheckBox.SetCheck(wiRenderer::GetTemporalAAEnabled()); + AddWidget(&temporalAACheckBox); - temporalAADebugCheckBox = new wiCheckBox("DEBUGJitter: "); - temporalAADebugCheckBox->SetText("DEBUG: "); - temporalAADebugCheckBox->SetTooltip("Disable blending of frame history. Camera Subpixel jitter will be visible."); - temporalAADebugCheckBox->SetPos(XMFLOAT2(x + 122, y)); - temporalAADebugCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - temporalAADebugCheckBox->OnClick([](wiEventArgs args) { + temporalAADebugCheckBox.Create("DEBUGJitter: "); + temporalAADebugCheckBox.SetText("DEBUG: "); + temporalAADebugCheckBox.SetTooltip("Disable blending of frame history. Camera Subpixel jitter will be visible."); + temporalAADebugCheckBox.SetPos(XMFLOAT2(x + 122, y)); + temporalAADebugCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + temporalAADebugCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetTemporalAADebugEnabled(args.bValue); }); - temporalAADebugCheckBox->SetCheck(wiRenderer::GetTemporalAADebugEnabled()); - rendererWindow->AddWidget(temporalAADebugCheckBox); + temporalAADebugCheckBox.SetCheck(wiRenderer::GetTemporalAADebugEnabled()); + AddWidget(&temporalAADebugCheckBox); - textureQualityComboBox = new wiComboBox("Texture Quality: "); - textureQualityComboBox->SetSize(XMFLOAT2(100, itemheight)); - textureQualityComboBox->SetPos(XMFLOAT2(x, y += step)); - textureQualityComboBox->AddItem("Nearest"); - textureQualityComboBox->AddItem("Bilinear"); - textureQualityComboBox->AddItem("Trilinear"); - textureQualityComboBox->AddItem("Anisotropic"); - textureQualityComboBox->OnSelect([&](wiEventArgs args) { + textureQualityComboBox.Create("Texture Quality: "); + textureQualityComboBox.SetSize(XMFLOAT2(100, itemheight)); + textureQualityComboBox.SetPos(XMFLOAT2(x, y += step)); + textureQualityComboBox.AddItem("Nearest"); + textureQualityComboBox.AddItem("Bilinear"); + textureQualityComboBox.AddItem("Trilinear"); + textureQualityComboBox.AddItem("Anisotropic"); + textureQualityComboBox.OnSelect([&](wiEventArgs args) { wiGraphics::SamplerDesc desc = wiRenderer::GetSampler(SSLOT_OBJECTSHADER)->GetDesc(); switch (args.iValue) @@ -432,259 +420,251 @@ RendererWindow::RendererWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER); }); - textureQualityComboBox->SetSelected(3); - textureQualityComboBox->SetEnabled(true); - textureQualityComboBox->SetTooltip("Choose a texture sampling method for material textures."); - rendererWindow->AddWidget(textureQualityComboBox); + textureQualityComboBox.SetSelected(3); + textureQualityComboBox.SetEnabled(true); + textureQualityComboBox.SetTooltip("Choose a texture sampling method for material textures."); + AddWidget(&textureQualityComboBox); - mipLodBiasSlider = new wiSlider(-2, 2, 0, 100000, "MipLOD Bias: "); - mipLodBiasSlider->SetTooltip("Bias the rendered mip map level of the material textures."); - mipLodBiasSlider->SetSize(XMFLOAT2(100, itemheight)); - mipLodBiasSlider->SetPos(XMFLOAT2(x, y += step)); - mipLodBiasSlider->OnSlide([&](wiEventArgs args) { + mipLodBiasSlider.Create(-2, 2, 0, 100000, "MipLOD Bias: "); + mipLodBiasSlider.SetTooltip("Bias the rendered mip map level of the material textures."); + mipLodBiasSlider.SetSize(XMFLOAT2(100, itemheight)); + mipLodBiasSlider.SetPos(XMFLOAT2(x, y += step)); + mipLodBiasSlider.OnSlide([&](wiEventArgs args) { wiGraphics::SamplerDesc desc = wiRenderer::GetSampler(SSLOT_OBJECTSHADER)->GetDesc(); desc.MipLODBias = wiMath::Clamp(args.fValue, -15.9f, 15.9f); wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER); }); - rendererWindow->AddWidget(mipLodBiasSlider); + AddWidget(&mipLodBiasSlider); - raytraceBounceCountSlider = new wiSlider(1, 10, 1, 9, "Raytrace Bounces: "); - raytraceBounceCountSlider->SetTooltip("How many light bounces to compute when doing ray tracing."); - raytraceBounceCountSlider->SetSize(XMFLOAT2(100, itemheight)); - raytraceBounceCountSlider->SetPos(XMFLOAT2(x, y += step)); - raytraceBounceCountSlider->SetValue((float)wiRenderer::GetRaytraceBounceCount()); - raytraceBounceCountSlider->OnSlide([&](wiEventArgs args) { + raytraceBounceCountSlider.Create(1, 10, 1, 9, "Raytrace Bounces: "); + raytraceBounceCountSlider.SetTooltip("How many light bounces to compute when doing ray tracing."); + raytraceBounceCountSlider.SetSize(XMFLOAT2(100, itemheight)); + raytraceBounceCountSlider.SetPos(XMFLOAT2(x, y += step)); + raytraceBounceCountSlider.SetValue((float)wiRenderer::GetRaytraceBounceCount()); + raytraceBounceCountSlider.OnSlide([&](wiEventArgs args) { wiRenderer::SetRaytraceBounceCount((uint32_t)args.iValue); }); - rendererWindow->AddWidget(raytraceBounceCountSlider); + AddWidget(&raytraceBounceCountSlider); // Visualizer toggles: x = 540, y = 5; - partitionBoxesCheckBox = new wiCheckBox("SPTree visualizer: "); - partitionBoxesCheckBox->SetTooltip("Visualize the world space partitioning tree as boxes"); - partitionBoxesCheckBox->SetScriptTip("SetDebugPartitionTreeEnabled(bool enabled)"); - partitionBoxesCheckBox->SetPos(XMFLOAT2(x, y += step)); - partitionBoxesCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - partitionBoxesCheckBox->OnClick([](wiEventArgs args) { + partitionBoxesCheckBox.Create("SPTree visualizer: "); + partitionBoxesCheckBox.SetTooltip("Visualize the world space partitioning tree as boxes"); + partitionBoxesCheckBox.SetScriptTip("SetDebugPartitionTreeEnabled(bool enabled)"); + partitionBoxesCheckBox.SetPos(XMFLOAT2(x, y += step)); + partitionBoxesCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + partitionBoxesCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugPartitionTree(args.bValue); }); - partitionBoxesCheckBox->SetCheck(wiRenderer::GetToDrawDebugPartitionTree()); - partitionBoxesCheckBox->SetEnabled(false); // SP tree is not implemented at the moment anymore - rendererWindow->AddWidget(partitionBoxesCheckBox); + partitionBoxesCheckBox.SetCheck(wiRenderer::GetToDrawDebugPartitionTree()); + partitionBoxesCheckBox.SetEnabled(false); // SP tree is not implemented at the moment anymore + AddWidget(&partitionBoxesCheckBox); - boneLinesCheckBox = new wiCheckBox("Bone line visualizer: "); - boneLinesCheckBox->SetTooltip("Visualize bones of armatures"); - boneLinesCheckBox->SetScriptTip("SetDebugBonesEnabled(bool enabled)"); - boneLinesCheckBox->SetPos(XMFLOAT2(x, y += step)); - boneLinesCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - boneLinesCheckBox->OnClick([](wiEventArgs args) { + boneLinesCheckBox.Create("Bone line visualizer: "); + boneLinesCheckBox.SetTooltip("Visualize bones of armatures"); + boneLinesCheckBox.SetScriptTip("SetDebugBonesEnabled(bool enabled)"); + boneLinesCheckBox.SetPos(XMFLOAT2(x, y += step)); + boneLinesCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + boneLinesCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugBoneLines(args.bValue); }); - boneLinesCheckBox->SetCheck(wiRenderer::GetToDrawDebugBoneLines()); - rendererWindow->AddWidget(boneLinesCheckBox); + boneLinesCheckBox.SetCheck(wiRenderer::GetToDrawDebugBoneLines()); + AddWidget(&boneLinesCheckBox); - debugEmittersCheckBox = new wiCheckBox("Emitter visualizer: "); - debugEmittersCheckBox->SetTooltip("Visualize emitters"); - debugEmittersCheckBox->SetScriptTip("SetDebugEmittersEnabled(bool enabled)"); - debugEmittersCheckBox->SetPos(XMFLOAT2(x, y += step)); - debugEmittersCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - debugEmittersCheckBox->OnClick([](wiEventArgs args) { + debugEmittersCheckBox.Create("Emitter visualizer: "); + debugEmittersCheckBox.SetTooltip("Visualize emitters"); + debugEmittersCheckBox.SetScriptTip("SetDebugEmittersEnabled(bool enabled)"); + debugEmittersCheckBox.SetPos(XMFLOAT2(x, y += step)); + debugEmittersCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + debugEmittersCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugEmitters(args.bValue); }); - debugEmittersCheckBox->SetCheck(wiRenderer::GetToDrawDebugEmitters()); - rendererWindow->AddWidget(debugEmittersCheckBox); + debugEmittersCheckBox.SetCheck(wiRenderer::GetToDrawDebugEmitters()); + AddWidget(&debugEmittersCheckBox); - debugForceFieldsCheckBox = new wiCheckBox("Force Field visualizer: "); - debugForceFieldsCheckBox->SetTooltip("Visualize force fields"); - debugForceFieldsCheckBox->SetScriptTip("SetDebugForceFieldsEnabled(bool enabled)"); - debugForceFieldsCheckBox->SetPos(XMFLOAT2(x, y += step)); - debugForceFieldsCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - debugForceFieldsCheckBox->OnClick([](wiEventArgs args) { + debugForceFieldsCheckBox.Create("Force Field visualizer: "); + debugForceFieldsCheckBox.SetTooltip("Visualize force fields"); + debugForceFieldsCheckBox.SetScriptTip("SetDebugForceFieldsEnabled(bool enabled)"); + debugForceFieldsCheckBox.SetPos(XMFLOAT2(x, y += step)); + debugForceFieldsCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + debugForceFieldsCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugForceFields(args.bValue); }); - debugForceFieldsCheckBox->SetCheck(wiRenderer::GetToDrawDebugForceFields()); - rendererWindow->AddWidget(debugForceFieldsCheckBox); + debugForceFieldsCheckBox.SetCheck(wiRenderer::GetToDrawDebugForceFields()); + AddWidget(&debugForceFieldsCheckBox); - debugRaytraceBVHCheckBox = new wiCheckBox("Raytrace BVH visualizer: "); - debugRaytraceBVHCheckBox->SetTooltip("Visualize scene BVH if raytracing is enabled"); - debugRaytraceBVHCheckBox->SetPos(XMFLOAT2(x, y += step)); - debugRaytraceBVHCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - debugRaytraceBVHCheckBox->OnClick([](wiEventArgs args) { + debugRaytraceBVHCheckBox.Create("Raytrace BVH visualizer: "); + debugRaytraceBVHCheckBox.SetTooltip("Visualize scene BVH if raytracing is enabled"); + debugRaytraceBVHCheckBox.SetPos(XMFLOAT2(x, y += step)); + debugRaytraceBVHCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + debugRaytraceBVHCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetRaytraceDebugBVHVisualizerEnabled(args.bValue); }); - debugRaytraceBVHCheckBox->SetCheck(wiRenderer::GetRaytraceDebugBVHVisualizerEnabled()); - rendererWindow->AddWidget(debugRaytraceBVHCheckBox); + debugRaytraceBVHCheckBox.SetCheck(wiRenderer::GetRaytraceDebugBVHVisualizerEnabled()); + AddWidget(&debugRaytraceBVHCheckBox); - envProbesCheckBox = new wiCheckBox("Env probe visualizer: "); - envProbesCheckBox->SetTooltip("Toggle visualization of environment probes as reflective spheres"); - envProbesCheckBox->SetPos(XMFLOAT2(x, y += step)); - envProbesCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - envProbesCheckBox->OnClick([](wiEventArgs args) { + envProbesCheckBox.Create("Env probe visualizer: "); + envProbesCheckBox.SetTooltip("Toggle visualization of environment probes as reflective spheres"); + envProbesCheckBox.SetPos(XMFLOAT2(x, y += step)); + envProbesCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + envProbesCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugEnvProbes(args.bValue); }); - envProbesCheckBox->SetCheck(wiRenderer::GetToDrawDebugEnvProbes()); - rendererWindow->AddWidget(envProbesCheckBox); + envProbesCheckBox.SetCheck(wiRenderer::GetToDrawDebugEnvProbes()); + AddWidget(&envProbesCheckBox); - cameraVisCheckBox = new wiCheckBox("Camera Proxy visualizer: "); - cameraVisCheckBox->SetTooltip("Toggle visualization of camera proxies in the scene"); - cameraVisCheckBox->SetPos(XMFLOAT2(x, y += step)); - cameraVisCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - cameraVisCheckBox->OnClick([](wiEventArgs args) { + cameraVisCheckBox.Create("Camera Proxy visualizer: "); + cameraVisCheckBox.SetTooltip("Toggle visualization of camera proxies in the scene"); + cameraVisCheckBox.SetPos(XMFLOAT2(x, y += step)); + cameraVisCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + cameraVisCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawDebugCameras(args.bValue); }); - cameraVisCheckBox->SetCheck(wiRenderer::GetToDrawDebugCameras()); - rendererWindow->AddWidget(cameraVisCheckBox); + cameraVisCheckBox.SetCheck(wiRenderer::GetToDrawDebugCameras()); + AddWidget(&cameraVisCheckBox); - gridHelperCheckBox = new wiCheckBox("Grid helper: "); - gridHelperCheckBox->SetTooltip("Toggle showing of unit visualizer grid in the world origin"); - gridHelperCheckBox->SetPos(XMFLOAT2(x, y += step)); - gridHelperCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - gridHelperCheckBox->OnClick([](wiEventArgs args) { + gridHelperCheckBox.Create("Grid helper: "); + gridHelperCheckBox.SetTooltip("Toggle showing of unit visualizer grid in the world origin"); + gridHelperCheckBox.SetPos(XMFLOAT2(x, y += step)); + gridHelperCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + gridHelperCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetToDrawGridHelper(args.bValue); }); - gridHelperCheckBox->SetCheck(wiRenderer::GetToDrawGridHelper()); - rendererWindow->AddWidget(gridHelperCheckBox); + gridHelperCheckBox.SetCheck(wiRenderer::GetToDrawGridHelper()); + AddWidget(&gridHelperCheckBox); - pickTypeObjectCheckBox = new wiCheckBox("Pick Objects: "); - pickTypeObjectCheckBox->SetTooltip("Enable if you want to pick objects with the pointer"); - pickTypeObjectCheckBox->SetPos(XMFLOAT2(x, y += step * 2)); - pickTypeObjectCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeObjectCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeObjectCheckBox); + pickTypeObjectCheckBox.Create("Pick Objects: "); + pickTypeObjectCheckBox.SetTooltip("Enable if you want to pick objects with the pointer"); + pickTypeObjectCheckBox.SetPos(XMFLOAT2(x, y += step * 2)); + pickTypeObjectCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeObjectCheckBox.SetCheck(true); + AddWidget(&pickTypeObjectCheckBox); - pickTypeEnvProbeCheckBox = new wiCheckBox("Pick EnvProbes: "); - pickTypeEnvProbeCheckBox->SetTooltip("Enable if you want to pick environment probes with the pointer"); - pickTypeEnvProbeCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeEnvProbeCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeEnvProbeCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeEnvProbeCheckBox); + pickTypeEnvProbeCheckBox.Create("Pick EnvProbes: "); + pickTypeEnvProbeCheckBox.SetTooltip("Enable if you want to pick environment probes with the pointer"); + pickTypeEnvProbeCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeEnvProbeCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeEnvProbeCheckBox.SetCheck(true); + AddWidget(&pickTypeEnvProbeCheckBox); - pickTypeLightCheckBox = new wiCheckBox("Pick Lights: "); - pickTypeLightCheckBox->SetTooltip("Enable if you want to pick lights with the pointer"); - pickTypeLightCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeLightCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeLightCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeLightCheckBox); + pickTypeLightCheckBox.Create("Pick Lights: "); + pickTypeLightCheckBox.SetTooltip("Enable if you want to pick lights with the pointer"); + pickTypeLightCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeLightCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeLightCheckBox.SetCheck(true); + AddWidget(&pickTypeLightCheckBox); - pickTypeDecalCheckBox = new wiCheckBox("Pick Decals: "); - pickTypeDecalCheckBox->SetTooltip("Enable if you want to pick decals with the pointer"); - pickTypeDecalCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeDecalCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeDecalCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeDecalCheckBox); + pickTypeDecalCheckBox.Create("Pick Decals: "); + pickTypeDecalCheckBox.SetTooltip("Enable if you want to pick decals with the pointer"); + pickTypeDecalCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeDecalCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeDecalCheckBox.SetCheck(true); + AddWidget(&pickTypeDecalCheckBox); - pickTypeForceFieldCheckBox = new wiCheckBox("Pick Force Fields: "); - pickTypeForceFieldCheckBox->SetTooltip("Enable if you want to pick force fields with the pointer"); - pickTypeForceFieldCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeForceFieldCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeForceFieldCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeForceFieldCheckBox); + pickTypeForceFieldCheckBox.Create("Pick Force Fields: "); + pickTypeForceFieldCheckBox.SetTooltip("Enable if you want to pick force fields with the pointer"); + pickTypeForceFieldCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeForceFieldCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeForceFieldCheckBox.SetCheck(true); + AddWidget(&pickTypeForceFieldCheckBox); - pickTypeEmitterCheckBox = new wiCheckBox("Pick Emitters: "); - pickTypeEmitterCheckBox->SetTooltip("Enable if you want to pick emitters with the pointer"); - pickTypeEmitterCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeEmitterCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeEmitterCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeEmitterCheckBox); + pickTypeEmitterCheckBox.Create("Pick Emitters: "); + pickTypeEmitterCheckBox.SetTooltip("Enable if you want to pick emitters with the pointer"); + pickTypeEmitterCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeEmitterCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeEmitterCheckBox.SetCheck(true); + AddWidget(&pickTypeEmitterCheckBox); - pickTypeHairCheckBox = new wiCheckBox("Pick Hairs: "); - pickTypeHairCheckBox->SetTooltip("Enable if you want to pick hairs with the pointer"); - pickTypeHairCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeHairCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeHairCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeHairCheckBox); + pickTypeHairCheckBox.Create("Pick Hairs: "); + pickTypeHairCheckBox.SetTooltip("Enable if you want to pick hairs with the pointer"); + pickTypeHairCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeHairCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeHairCheckBox.SetCheck(true); + AddWidget(&pickTypeHairCheckBox); - pickTypeCameraCheckBox = new wiCheckBox("Pick Cameras: "); - pickTypeCameraCheckBox->SetTooltip("Enable if you want to pick cameras with the pointer"); - pickTypeCameraCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeCameraCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeCameraCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeCameraCheckBox); + pickTypeCameraCheckBox.Create("Pick Cameras: "); + pickTypeCameraCheckBox.SetTooltip("Enable if you want to pick cameras with the pointer"); + pickTypeCameraCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeCameraCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeCameraCheckBox.SetCheck(true); + AddWidget(&pickTypeCameraCheckBox); - pickTypeArmatureCheckBox = new wiCheckBox("Pick Armatures: "); - pickTypeArmatureCheckBox->SetTooltip("Enable if you want to pick armatures with the pointer"); - pickTypeArmatureCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeArmatureCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeArmatureCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeArmatureCheckBox); + pickTypeArmatureCheckBox.Create("Pick Armatures: "); + pickTypeArmatureCheckBox.SetTooltip("Enable if you want to pick armatures with the pointer"); + pickTypeArmatureCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeArmatureCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeArmatureCheckBox.SetCheck(true); + AddWidget(&pickTypeArmatureCheckBox); - pickTypeSoundCheckBox = new wiCheckBox("Pick Sounds: "); - pickTypeSoundCheckBox->SetTooltip("Enable if you want to pick sounds with the pointer"); - pickTypeSoundCheckBox->SetPos(XMFLOAT2(x, y += step)); - pickTypeSoundCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - pickTypeSoundCheckBox->SetCheck(true); - rendererWindow->AddWidget(pickTypeSoundCheckBox); + pickTypeSoundCheckBox.Create("Pick Sounds: "); + pickTypeSoundCheckBox.SetTooltip("Enable if you want to pick sounds with the pointer"); + pickTypeSoundCheckBox.SetPos(XMFLOAT2(x, y += step)); + pickTypeSoundCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + pickTypeSoundCheckBox.SetCheck(true); + AddWidget(&pickTypeSoundCheckBox); - freezeCullingCameraCheckBox = new wiCheckBox("Freeze culling camera: "); - freezeCullingCameraCheckBox->SetTooltip("Freeze culling camera update. Scene culling will not be updated with the view"); - freezeCullingCameraCheckBox->SetPos(XMFLOAT2(x, y += step * 2)); - freezeCullingCameraCheckBox->SetSize(XMFLOAT2(itemheight, itemheight)); - freezeCullingCameraCheckBox->OnClick([](wiEventArgs args) { + freezeCullingCameraCheckBox.Create("Freeze culling camera: "); + freezeCullingCameraCheckBox.SetTooltip("Freeze culling camera update. Scene culling will not be updated with the view"); + freezeCullingCameraCheckBox.SetPos(XMFLOAT2(x, y += step * 2)); + freezeCullingCameraCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + freezeCullingCameraCheckBox.OnClick([](wiEventArgs args) { wiRenderer::SetFreezeCullingCameraEnabled(args.bValue); }); - freezeCullingCameraCheckBox->SetCheck(wiRenderer::GetToDrawDebugForceFields()); - rendererWindow->AddWidget(freezeCullingCameraCheckBox); + freezeCullingCameraCheckBox.SetCheck(wiRenderer::GetToDrawDebugForceFields()); + AddWidget(&freezeCullingCameraCheckBox); - rendererWindow->Translate(XMFLOAT3(100, 50, 0)); - rendererWindow->SetVisible(false); + Translate(XMFLOAT3(100, 50, 0)); + SetVisible(false); } - -RendererWindow::~RendererWindow() -{ - rendererWindow->RemoveWidgets(true); - GUI->RemoveWidget(rendererWindow); - delete rendererWindow; -} - -uint32_t RendererWindow::GetPickType() +uint32_t RendererWindow::GetPickType() const { uint32_t pickType = PICK_VOID; - if (pickTypeObjectCheckBox->GetCheck()) + if (pickTypeObjectCheckBox.GetCheck()) { pickType |= PICK_OBJECT; } - if (pickTypeEnvProbeCheckBox->GetCheck()) + if (pickTypeEnvProbeCheckBox.GetCheck()) { pickType |= PICK_ENVPROBE; } - if (pickTypeLightCheckBox->GetCheck()) + if (pickTypeLightCheckBox.GetCheck()) { pickType |= PICK_LIGHT; } - if (pickTypeDecalCheckBox->GetCheck()) + if (pickTypeDecalCheckBox.GetCheck()) { pickType |= PICK_DECAL; } - if (pickTypeForceFieldCheckBox->GetCheck()) + if (pickTypeForceFieldCheckBox.GetCheck()) { pickType |= PICK_FORCEFIELD; } - if (pickTypeEmitterCheckBox->GetCheck()) + if (pickTypeEmitterCheckBox.GetCheck()) { pickType |= PICK_EMITTER; } - if (pickTypeHairCheckBox->GetCheck()) + if (pickTypeHairCheckBox.GetCheck()) { pickType |= PICK_HAIR; } - if (pickTypeCameraCheckBox->GetCheck()) + if (pickTypeCameraCheckBox.GetCheck()) { pickType |= PICK_CAMERA; } - if (pickTypeArmatureCheckBox->GetCheck()) + if (pickTypeArmatureCheckBox.GetCheck()) { pickType |= PICK_ARMATURE; } - if (pickTypeSoundCheckBox->GetCheck()) + if (pickTypeSoundCheckBox.GetCheck()) { pickType |= PICK_SOUND; } diff --git a/Editor/RendererWindow.h b/Editor/RendererWindow.h index b445ef9da..7a1b81b90 100644 --- a/Editor/RendererWindow.h +++ b/Editor/RendererWindow.h @@ -1,11 +1,5 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; +#include "WickedEngine.h" class EditorComponent; @@ -24,66 +18,61 @@ enum PICKTYPE PICK_SOUND = 2048, }; -class RendererWindow +class RendererWindow : public wiWindow { public: - RendererWindow(EditorComponent* editorcomponent); - ~RendererWindow(); + void Create(EditorComponent* editorcomponent); - wiGUI* GUI; + wiCheckBox vsyncCheckBox; + wiCheckBox occlusionCullingCheckBox; + wiSlider resolutionScaleSlider; + wiSlider gammaSlider; + wiCheckBox voxelRadianceCheckBox; + wiCheckBox voxelRadianceDebugCheckBox; + wiCheckBox voxelRadianceSecondaryBounceCheckBox; + wiCheckBox voxelRadianceReflectionsCheckBox; + wiSlider voxelRadianceVoxelSizeSlider; + wiSlider voxelRadianceConeTracingSlider; + wiSlider voxelRadianceRayStepSizeSlider; + wiSlider voxelRadianceMaxDistanceSlider; + wiCheckBox partitionBoxesCheckBox; + wiCheckBox boneLinesCheckBox; + wiCheckBox debugEmittersCheckBox; + wiCheckBox debugForceFieldsCheckBox; + wiCheckBox debugRaytraceBVHCheckBox; + wiCheckBox wireFrameCheckBox; + wiCheckBox variableRateShadingClassificationCheckBox; + wiCheckBox variableRateShadingClassificationDebugCheckBox; + wiCheckBox advancedLightCullingCheckBox; + wiCheckBox debugLightCullingCheckBox; + wiCheckBox tessellationCheckBox; + wiCheckBox envProbesCheckBox; + wiCheckBox gridHelperCheckBox; + wiCheckBox cameraVisCheckBox; + wiCheckBox pickTypeObjectCheckBox; + wiCheckBox pickTypeEnvProbeCheckBox; + wiCheckBox pickTypeLightCheckBox; + wiCheckBox pickTypeDecalCheckBox; + wiCheckBox pickTypeForceFieldCheckBox; + wiCheckBox pickTypeEmitterCheckBox; + wiCheckBox pickTypeHairCheckBox; + wiCheckBox pickTypeCameraCheckBox; + wiCheckBox pickTypeArmatureCheckBox; + wiCheckBox pickTypeSoundCheckBox; + wiSlider speedMultiplierSlider; + wiCheckBox transparentShadowsCheckBox; + wiComboBox shadowTypeComboBox; + wiComboBox shadowProps2DComboBox; + wiComboBox shadowPropsCubeComboBox; + wiComboBox MSAAComboBox; + wiCheckBox temporalAACheckBox; + wiCheckBox temporalAADebugCheckBox; + wiComboBox textureQualityComboBox; + wiSlider mipLodBiasSlider; + wiSlider raytraceBounceCountSlider; - wiWindow* rendererWindow; - wiCheckBox* vsyncCheckBox; - wiCheckBox* occlusionCullingCheckBox; - wiSlider* resolutionScaleSlider; - wiSlider* gammaSlider; - wiCheckBox* voxelRadianceCheckBox; - wiCheckBox* voxelRadianceDebugCheckBox; - wiCheckBox* voxelRadianceSecondaryBounceCheckBox; - wiCheckBox* voxelRadianceReflectionsCheckBox; - wiSlider* voxelRadianceVoxelSizeSlider; - wiSlider* voxelRadianceConeTracingSlider; - wiSlider* voxelRadianceRayStepSizeSlider; - wiSlider* voxelRadianceMaxDistanceSlider; - wiCheckBox* partitionBoxesCheckBox; - wiCheckBox* boneLinesCheckBox; - wiCheckBox* debugEmittersCheckBox; - wiCheckBox* debugForceFieldsCheckBox; - wiCheckBox* debugRaytraceBVHCheckBox; - wiCheckBox* wireFrameCheckBox; - wiCheckBox* variableRateShadingClassificationCheckBox; - wiCheckBox* variableRateShadingClassificationDebugCheckBox; - wiCheckBox* advancedLightCullingCheckBox; - wiCheckBox* debugLightCullingCheckBox; - wiCheckBox* tessellationCheckBox; - wiCheckBox* alphaCompositionCheckBox; - wiCheckBox* envProbesCheckBox; - wiCheckBox* gridHelperCheckBox; - wiCheckBox* cameraVisCheckBox; - wiCheckBox* pickTypeObjectCheckBox; - wiCheckBox* pickTypeEnvProbeCheckBox; - wiCheckBox* pickTypeLightCheckBox; - wiCheckBox* pickTypeDecalCheckBox; - wiCheckBox* pickTypeForceFieldCheckBox; - wiCheckBox* pickTypeEmitterCheckBox; - wiCheckBox* pickTypeHairCheckBox; - wiCheckBox* pickTypeCameraCheckBox; - wiCheckBox* pickTypeArmatureCheckBox; - wiCheckBox* pickTypeSoundCheckBox; - wiSlider* speedMultiplierSlider; - wiCheckBox* transparentShadowsCheckBox; - wiComboBox* shadowTypeComboBox; - wiComboBox* shadowProps2DComboBox; - wiComboBox* shadowPropsCubeComboBox; - wiComboBox* MSAAComboBox; - wiCheckBox* temporalAACheckBox; - wiCheckBox* temporalAADebugCheckBox; - wiComboBox* textureQualityComboBox; - wiSlider* mipLodBiasSlider; - wiSlider* raytraceBounceCountSlider; + wiCheckBox freezeCullingCameraCheckBox; - wiCheckBox* freezeCullingCameraCheckBox; - - uint32_t GetPickType(); + uint32_t GetPickType() const; }; diff --git a/Editor/SoundWindow.cpp b/Editor/SoundWindow.cpp index 721083121..0b41fbe21 100644 --- a/Editor/SoundWindow.cpp +++ b/Editor/SoundWindow.cpp @@ -10,65 +10,62 @@ using namespace wiGraphics; using namespace wiECS; using namespace wiScene; -SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void SoundWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - soundWindow = new wiWindow(GUI, "Sound Window"); - soundWindow->SetSize(XMFLOAT2(440, 220)); - GUI->AddWidget(soundWindow); + wiWindow::Create("Sound Window"); + SetSize(XMFLOAT2(440, 220)); float x = 20; float y = 10; float hei = 18; float step = hei + 2; - reverbComboBox = new wiComboBox("Reverb: "); - reverbComboBox->SetPos(XMFLOAT2(x + 80, y += step)); - reverbComboBox->SetSize(XMFLOAT2(180, hei)); - reverbComboBox->OnSelect([&](wiEventArgs args) { + reverbComboBox.Create("Reverb: "); + reverbComboBox.SetPos(XMFLOAT2(x + 80, y += step)); + reverbComboBox.SetSize(XMFLOAT2(180, hei)); + reverbComboBox.OnSelect([&](wiEventArgs args) { wiAudio::SetReverb((wiAudio::REVERB_PRESET)args.iValue); }); - reverbComboBox->AddItem("DEFAULT"); - reverbComboBox->AddItem("GENERIC"); - reverbComboBox->AddItem("FOREST"); - reverbComboBox->AddItem("PADDEDCELL"); - reverbComboBox->AddItem("ROOM"); - reverbComboBox->AddItem("BATHROOM"); - reverbComboBox->AddItem("LIVINGROOM"); - reverbComboBox->AddItem("STONEROOM"); - reverbComboBox->AddItem("AUDITORIUM"); - reverbComboBox->AddItem("CONCERTHALL"); - reverbComboBox->AddItem("CAVE"); - reverbComboBox->AddItem("ARENA"); - reverbComboBox->AddItem("HANGAR"); - reverbComboBox->AddItem("CARPETEDHALLWAY"); - reverbComboBox->AddItem("HALLWAY"); - reverbComboBox->AddItem("STONECORRIDOR"); - reverbComboBox->AddItem("ALLEY"); - reverbComboBox->AddItem("CITY"); - reverbComboBox->AddItem("MOUNTAINS"); - reverbComboBox->AddItem("QUARRY"); - reverbComboBox->AddItem("PLAIN"); - reverbComboBox->AddItem("PARKINGLOT"); - reverbComboBox->AddItem("SEWERPIPE"); - reverbComboBox->AddItem("UNDERWATER"); - reverbComboBox->AddItem("SMALLROOM"); - reverbComboBox->AddItem("MEDIUMROOM"); - reverbComboBox->AddItem("LARGEROOM"); - reverbComboBox->AddItem("MEDIUMHALL"); - reverbComboBox->AddItem("LARGEHALL"); - reverbComboBox->AddItem("PLATE"); - reverbComboBox->SetTooltip("Set the global reverb setting. Sound instances need to enable reverb to take effect!"); - soundWindow->AddWidget(reverbComboBox); + reverbComboBox.AddItem("DEFAULT"); + reverbComboBox.AddItem("GENERIC"); + reverbComboBox.AddItem("FOREST"); + reverbComboBox.AddItem("PADDEDCELL"); + reverbComboBox.AddItem("ROOM"); + reverbComboBox.AddItem("BATHROOM"); + reverbComboBox.AddItem("LIVINGROOM"); + reverbComboBox.AddItem("STONEROOM"); + reverbComboBox.AddItem("AUDITORIUM"); + reverbComboBox.AddItem("CONCERTHALL"); + reverbComboBox.AddItem("CAVE"); + reverbComboBox.AddItem("ARENA"); + reverbComboBox.AddItem("HANGAR"); + reverbComboBox.AddItem("CARPETEDHALLWAY"); + reverbComboBox.AddItem("HALLWAY"); + reverbComboBox.AddItem("STONECORRIDOR"); + reverbComboBox.AddItem("ALLEY"); + reverbComboBox.AddItem("CITY"); + reverbComboBox.AddItem("MOUNTAINS"); + reverbComboBox.AddItem("QUARRY"); + reverbComboBox.AddItem("PLAIN"); + reverbComboBox.AddItem("PARKINGLOT"); + reverbComboBox.AddItem("SEWERPIPE"); + reverbComboBox.AddItem("UNDERWATER"); + reverbComboBox.AddItem("SMALLROOM"); + reverbComboBox.AddItem("MEDIUMROOM"); + reverbComboBox.AddItem("LARGEROOM"); + reverbComboBox.AddItem("MEDIUMHALL"); + reverbComboBox.AddItem("LARGEHALL"); + reverbComboBox.AddItem("PLATE"); + reverbComboBox.SetTooltip("Set the global reverb setting. Sound instances need to enable reverb to take effect!"); + AddWidget(&reverbComboBox); y += step; - addButton = new wiButton("Add Sound"); - addButton->SetTooltip("Add a sound file to the scene."); - addButton->SetPos(XMFLOAT2(x, y += step)); - addButton->SetSize(XMFLOAT2(80, hei)); - addButton->OnClick([=](wiEventArgs args) { + addButton.Create("Add Sound"); + addButton.SetTooltip("Add a sound file to the scene."); + addButton.SetPos(XMFLOAT2(x, y += step)); + addButton.SetSize(XMFLOAT2(80, hei)); + addButton.OnClick([=](wiEventArgs args) { wiHelper::FileDialogParams params; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Sound"; @@ -79,22 +76,23 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) Entity entity = GetScene().Entity_CreateSound("editorSound", fileName); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); }); }); - soundWindow->AddWidget(addButton); + AddWidget(&addButton); - filenameLabel = new wiLabel("Filename"); - filenameLabel->SetPos(XMFLOAT2(x, y += step)); - filenameLabel->SetSize(XMFLOAT2(400, hei)); - soundWindow->AddWidget(filenameLabel); + filenameLabel.Create("Filename"); + filenameLabel.SetPos(XMFLOAT2(x, y += step)); + filenameLabel.SetSize(XMFLOAT2(400, hei)); + AddWidget(&filenameLabel); - nameField = new wiTextInputField("SoundName"); - nameField->SetTooltip("Enter a sound name to identify this entity..."); - nameField->SetPos(XMFLOAT2(x, y += step)); - nameField->SetSize(XMFLOAT2(300, hei)); - nameField->OnInputAccepted([&](wiEventArgs args) { + nameField.Create("SoundName"); + nameField.SetTooltip("Enter a sound name to identify this entity..."); + nameField.SetPos(XMFLOAT2(x, y += step)); + nameField.SetSize(XMFLOAT2(300, hei)); + nameField.OnInputAccepted([&](wiEventArgs args) { NameComponent* name = wiScene::GetScene().names.GetComponent(entity); if (name == nullptr) { @@ -102,51 +100,51 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } *name = args.sValue; }); - soundWindow->AddWidget(nameField); - nameField->SetEnabled(false); + AddWidget(&nameField); + nameField.SetEnabled(false); - playstopButton = new wiButton("Play"); - playstopButton->SetTooltip("Play/Stop selected sound instance."); - playstopButton->SetPos(XMFLOAT2(x, y += step)); - playstopButton->SetSize(XMFLOAT2(80, hei)); - playstopButton->OnClick([&](wiEventArgs args) { + playstopButton.Create("Play"); + playstopButton.SetTooltip("Play/Stop selected sound instance."); + playstopButton.SetPos(XMFLOAT2(x, y += step)); + playstopButton.SetSize(XMFLOAT2(80, hei)); + playstopButton.OnClick([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { if (sound->IsPlaying()) { sound->Stop(); - playstopButton->SetText("Play"); + playstopButton.SetText("Play"); } else { sound->Play(); - playstopButton->SetText("Stop"); + playstopButton.SetText("Stop"); } } }); - soundWindow->AddWidget(playstopButton); - playstopButton->SetEnabled(false); + AddWidget(&playstopButton); + playstopButton.SetEnabled(false); - loopedCheckbox = new wiCheckBox("Looped: "); - loopedCheckbox->SetTooltip("Enable looping for the selected sound instance."); - loopedCheckbox->SetPos(XMFLOAT2(x + 150, y)); - loopedCheckbox->SetSize(XMFLOAT2(hei, hei)); - loopedCheckbox->OnClick([&](wiEventArgs args) { + loopedCheckbox.Create("Looped: "); + loopedCheckbox.SetTooltip("Enable looping for the selected sound instance."); + loopedCheckbox.SetPos(XMFLOAT2(x + 150, y)); + loopedCheckbox.SetSize(XMFLOAT2(hei, hei)); + loopedCheckbox.OnClick([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { sound->SetLooped(args.bValue); } }); - soundWindow->AddWidget(loopedCheckbox); - loopedCheckbox->SetEnabled(false); + AddWidget(&loopedCheckbox); + loopedCheckbox.SetEnabled(false); - reverbCheckbox = new wiCheckBox("Reverb: "); - reverbCheckbox->SetTooltip("Enable/disable reverb."); - reverbCheckbox->SetPos(XMFLOAT2(x + 240, y)); - reverbCheckbox->SetSize(XMFLOAT2(hei, hei)); - reverbCheckbox->OnClick([&](wiEventArgs args) { + reverbCheckbox.Create("Reverb: "); + reverbCheckbox.SetTooltip("Enable/disable reverb."); + reverbCheckbox.SetPos(XMFLOAT2(x + 240, y)); + reverbCheckbox.SetSize(XMFLOAT2(hei, hei)); + reverbCheckbox.OnClick([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { @@ -154,14 +152,14 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiAudio::CreateSoundInstance(sound->soundResource->sound, &sound->soundinstance); } }); - soundWindow->AddWidget(reverbCheckbox); - reverbCheckbox->SetEnabled(false); + AddWidget(&reverbCheckbox); + reverbCheckbox.SetEnabled(false); - disable3dCheckbox = new wiCheckBox("2D: "); - disable3dCheckbox->SetTooltip("Sounds in the scene are 3D spatial by default. Select this to disable 3D effect."); - disable3dCheckbox->SetPos(XMFLOAT2(x + 300, y)); - disable3dCheckbox->SetSize(XMFLOAT2(hei, hei)); - disable3dCheckbox->OnClick([&](wiEventArgs args) { + disable3dCheckbox.Create("2D: "); + disable3dCheckbox.SetTooltip("Sounds in the scene are 3D spatial by default. Select this to disable 3D effect."); + disable3dCheckbox.SetPos(XMFLOAT2(x + 300, y)); + disable3dCheckbox.SetSize(XMFLOAT2(hei, hei)); + disable3dCheckbox.OnClick([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { @@ -169,27 +167,27 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiAudio::CreateSoundInstance(sound->soundResource->sound, &sound->soundinstance); } }); - soundWindow->AddWidget(disable3dCheckbox); - loopedCheckbox->SetEnabled(false); + AddWidget(&disable3dCheckbox); + loopedCheckbox.SetEnabled(false); - volumeSlider = new wiSlider(0, 1, 1, 1000, "Volume: "); - volumeSlider->SetTooltip("Set volume level for the selected sound instance."); - volumeSlider->SetPos(XMFLOAT2(x + 60, y += step)); - volumeSlider->SetSize(XMFLOAT2(240, hei)); - volumeSlider->OnSlide([&](wiEventArgs args) { + volumeSlider.Create(0, 1, 1, 1000, "Volume: "); + volumeSlider.SetTooltip("Set volume level for the selected sound instance."); + volumeSlider.SetPos(XMFLOAT2(x + 60, y += step)); + volumeSlider.SetSize(XMFLOAT2(240, hei)); + volumeSlider.OnSlide([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { sound->volume = args.fValue; } }); - soundWindow->AddWidget(volumeSlider); - volumeSlider->SetEnabled(false); + AddWidget(&volumeSlider); + volumeSlider.SetEnabled(false); - submixComboBox = new wiComboBox("Submix: "); - submixComboBox->SetPos(XMFLOAT2(x + 80, y += step)); - submixComboBox->SetSize(XMFLOAT2(180, hei)); - submixComboBox->OnSelect([&](wiEventArgs args) { + submixComboBox.Create("Submix: "); + submixComboBox.SetPos(XMFLOAT2(x + 80, y += step)); + submixComboBox.SetSize(XMFLOAT2(180, hei)); + submixComboBox.OnSelect([&](wiEventArgs args) { SoundComponent* sound = GetScene().sounds.GetComponent(entity); if (sound != nullptr) { @@ -197,27 +195,20 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiAudio::CreateSoundInstance(sound->soundResource->sound, &sound->soundinstance); } }); - submixComboBox->AddItem("SOUNDEFFECT"); - submixComboBox->AddItem("MUSIC"); - submixComboBox->AddItem("USER0"); - submixComboBox->AddItem("USER1"); - submixComboBox->SetTooltip("Set the submix channel of the sound. \nSound properties like volume can be set per sound, or per submix channel."); - submixComboBox->SetScriptTip("SoundInstance::SetSubmixType(int submixType)"); - soundWindow->AddWidget(submixComboBox); + submixComboBox.AddItem("SOUNDEFFECT"); + submixComboBox.AddItem("MUSIC"); + submixComboBox.AddItem("USER0"); + submixComboBox.AddItem("USER1"); + submixComboBox.SetTooltip("Set the submix channel of the sound. \nSound properties like volume can be set per sound, or per submix channel."); + submixComboBox.SetScriptTip("SoundInstance::SetSubmixType(int submixType)"); + AddWidget(&submixComboBox); - soundWindow->Translate(XMFLOAT3(400, 120, 0)); - soundWindow->SetVisible(false); + Translate(XMFLOAT3(400, 120, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } -SoundWindow::~SoundWindow() -{ - soundWindow->RemoveWidgets(true); - GUI->RemoveWidget(soundWindow); - delete soundWindow; -} - void SoundWindow::SetEntity(Entity entity) @@ -230,50 +221,50 @@ void SoundWindow::SetEntity(Entity entity) if (sound != nullptr) { - filenameLabel->SetText(sound->filename); + filenameLabel.SetText(sound->filename); if (name == nullptr) { - nameField->SetText("Enter a sound name..."); + nameField.SetText("Enter a sound name..."); } else { - nameField->SetText(name->name); + nameField.SetText(name->name); } - nameField->SetEnabled(true); - playstopButton->SetEnabled(true); - loopedCheckbox->SetEnabled(true); - loopedCheckbox->SetCheck(sound->IsLooped()); - reverbCheckbox->SetEnabled(true); - reverbCheckbox->SetCheck(sound->soundinstance.IsEnableReverb()); - disable3dCheckbox->SetEnabled(true); - disable3dCheckbox->SetCheck(sound->IsDisable3D()); - volumeSlider->SetEnabled(true); - volumeSlider->SetValue(sound->volume); + nameField.SetEnabled(true); + playstopButton.SetEnabled(true); + loopedCheckbox.SetEnabled(true); + loopedCheckbox.SetCheck(sound->IsLooped()); + reverbCheckbox.SetEnabled(true); + reverbCheckbox.SetCheck(sound->soundinstance.IsEnableReverb()); + disable3dCheckbox.SetEnabled(true); + disable3dCheckbox.SetCheck(sound->IsDisable3D()); + volumeSlider.SetEnabled(true); + volumeSlider.SetValue(sound->volume); if (sound->IsPlaying()) { - playstopButton->SetText("Stop"); + playstopButton.SetText("Stop"); } else { - playstopButton->SetText("Play"); + playstopButton.SetText("Play"); } - submixComboBox->SetEnabled(true); - if (submixComboBox->GetSelected() != (int)sound->soundinstance.type) + submixComboBox.SetEnabled(true); + if (submixComboBox.GetSelected() != (int)sound->soundinstance.type) { - submixComboBox->SetSelected((int)sound->soundinstance.type); + submixComboBox.SetSelected((int)sound->soundinstance.type); } } else { - filenameLabel->SetText(""); - nameField->SetText(""); - nameField->SetEnabled(false); - playstopButton->SetEnabled(false); - loopedCheckbox->SetEnabled(false); - reverbCheckbox->SetEnabled(false); - disable3dCheckbox->SetEnabled(false); - volumeSlider->SetEnabled(false); - submixComboBox->SetEnabled(false); + filenameLabel.SetText(""); + nameField.SetText(""); + nameField.SetEnabled(false); + playstopButton.SetEnabled(false); + loopedCheckbox.SetEnabled(false); + reverbCheckbox.SetEnabled(false); + disable3dCheckbox.SetEnabled(false); + volumeSlider.SetEnabled(false); + submixComboBox.SetEnabled(false); } } diff --git a/Editor/SoundWindow.h b/Editor/SoundWindow.h index 676c2bfd7..c0f89bc3e 100644 --- a/Editor/SoundWindow.h +++ b/Editor/SoundWindow.h @@ -1,37 +1,24 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiColorPicker; -class wiButton; -class wiComboBox; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class SoundWindow +class SoundWindow : public wiWindow { public: - SoundWindow(EditorComponent* editor); - ~SoundWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity = wiECS::INVALID_ENTITY; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* soundWindow; - wiComboBox* reverbComboBox; - wiButton* addButton; - wiLabel* filenameLabel; - wiTextInputField* nameField; - wiButton* playstopButton; - wiCheckBox* loopedCheckbox; - wiCheckBox* reverbCheckbox; - wiCheckBox* disable3dCheckbox; - wiSlider* volumeSlider; - wiComboBox* submixComboBox; + wiComboBox reverbComboBox; + wiButton addButton; + wiLabel filenameLabel; + wiTextInputField nameField; + wiButton playstopButton; + wiCheckBox loopedCheckbox; + wiCheckBox reverbCheckbox; + wiCheckBox disable3dCheckbox; + wiSlider volumeSlider; + wiComboBox submixComboBox; }; diff --git a/Editor/SpringWindow.cpp b/Editor/SpringWindow.cpp index c2c1de788..70da124d8 100644 --- a/Editor/SpringWindow.cpp +++ b/Editor/SpringWindow.cpp @@ -6,13 +6,10 @@ using namespace wiECS; using namespace wiScene; -SpringWindow::SpringWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void SpringWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - window = new wiWindow(GUI, "Spring Window"); - window->SetSize(XMFLOAT2(460, 200)); - GUI->AddWidget(window); + wiWindow::Create("Spring Window"); + SetSize(XMFLOAT2(460, 200)); float x = 150; float y = 10; @@ -20,86 +17,78 @@ SpringWindow::SpringWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) float hei = 18; float step = hei + 2; - createButton = new wiButton("Create"); - createButton->SetTooltip("Create/Remove Spring Component to selected entity"); - createButton->SetPos(XMFLOAT2(x, y += step)); - createButton->SetSize(XMFLOAT2(siz, hei)); - window->AddWidget(createButton); + createButton.Create("Create"); + createButton.SetTooltip("Create/Remove Spring Component to selected entity"); + createButton.SetPos(XMFLOAT2(x, y += step)); + createButton.SetSize(XMFLOAT2(siz, hei)); + AddWidget(&createButton); - debugCheckBox = new wiCheckBox("DEBUG: "); - debugCheckBox->SetTooltip("Enabling this will visualize springs as small yellow X-es in the scene"); - debugCheckBox->SetPos(XMFLOAT2(x, y += step)); - debugCheckBox->SetSize(XMFLOAT2(hei, hei)); - window->AddWidget(debugCheckBox); + debugCheckBox.Create("DEBUG: "); + debugCheckBox.SetTooltip("Enabling this will visualize springs as small yellow X-es in the scene"); + debugCheckBox.SetPos(XMFLOAT2(x, y += step)); + debugCheckBox.SetSize(XMFLOAT2(hei, hei)); + AddWidget(&debugCheckBox); - disabledCheckBox = new wiCheckBox("Disabled: "); - disabledCheckBox->SetTooltip("Disable simulation."); - disabledCheckBox->SetPos(XMFLOAT2(x, y += step)); - disabledCheckBox->SetSize(XMFLOAT2(hei, hei)); - disabledCheckBox->OnClick([=](wiEventArgs args) { + disabledCheckBox.Create("Disabled: "); + disabledCheckBox.SetTooltip("Disable simulation."); + disabledCheckBox.SetPos(XMFLOAT2(x, y += step)); + disabledCheckBox.SetSize(XMFLOAT2(hei, hei)); + disabledCheckBox.OnClick([=](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->SetDisabled(args.bValue); }); - window->AddWidget(disabledCheckBox); + AddWidget(&disabledCheckBox); - stretchCheckBox = new wiCheckBox("Stretch enabled: "); - stretchCheckBox->SetTooltip("Stretch means that length from parent transform won't be preserved."); - stretchCheckBox->SetPos(XMFLOAT2(x, y += step)); - stretchCheckBox->SetSize(XMFLOAT2(hei, hei)); - stretchCheckBox->OnClick([=](wiEventArgs args) { + stretchCheckBox.Create("Stretch enabled: "); + stretchCheckBox.SetTooltip("Stretch means that length from parent transform won't be preserved."); + stretchCheckBox.SetPos(XMFLOAT2(x, y += step)); + stretchCheckBox.SetSize(XMFLOAT2(hei, hei)); + stretchCheckBox.OnClick([=](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->SetStretchEnabled(args.bValue); }); - window->AddWidget(stretchCheckBox); + AddWidget(&stretchCheckBox); - gravityCheckBox = new wiCheckBox("Gravity enabled: "); - gravityCheckBox->SetTooltip("Whether global gravity should affect the spring"); - gravityCheckBox->SetPos(XMFLOAT2(x, y += step)); - gravityCheckBox->SetSize(XMFLOAT2(hei, hei)); - gravityCheckBox->OnClick([=](wiEventArgs args) { + gravityCheckBox.Create("Gravity enabled: "); + gravityCheckBox.SetTooltip("Whether global gravity should affect the spring"); + gravityCheckBox.SetPos(XMFLOAT2(x, y += step)); + gravityCheckBox.SetSize(XMFLOAT2(hei, hei)); + gravityCheckBox.OnClick([=](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->SetGravityEnabled(args.bValue); }); - window->AddWidget(gravityCheckBox); + AddWidget(&gravityCheckBox); - stiffnessSlider = new wiSlider(0, 1000, 100, 100000, "Stiffness: "); - stiffnessSlider->SetTooltip("The stiffness affects how strongly the spring tries to orient itself to rest pose (higher values increase the jiggliness)"); - stiffnessSlider->SetPos(XMFLOAT2(x, y += step)); - stiffnessSlider->SetSize(XMFLOAT2(siz, hei)); - stiffnessSlider->OnSlide([&](wiEventArgs args) { + stiffnessSlider.Create(0, 1000, 100, 100000, "Stiffness: "); + stiffnessSlider.SetTooltip("The stiffness affects how strongly the spring tries to orient itself to rest pose (higher values increase the jiggliness)"); + stiffnessSlider.SetPos(XMFLOAT2(x, y += step)); + stiffnessSlider.SetSize(XMFLOAT2(siz, hei)); + stiffnessSlider.OnSlide([&](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->stiffness = args.fValue; }); - window->AddWidget(stiffnessSlider); + AddWidget(&stiffnessSlider); - dampingSlider = new wiSlider(0, 1, 0.8f, 100000, "Damping: "); - dampingSlider->SetTooltip("The damping affects how fast energy is lost (higher values make the spring come to rest faster)"); - dampingSlider->SetPos(XMFLOAT2(x, y += step)); - dampingSlider->SetSize(XMFLOAT2(siz, hei)); - dampingSlider->OnSlide([&](wiEventArgs args) { + dampingSlider.Create(0, 1, 0.8f, 100000, "Damping: "); + dampingSlider.SetTooltip("The damping affects how fast energy is lost (higher values make the spring come to rest faster)"); + dampingSlider.SetPos(XMFLOAT2(x, y += step)); + dampingSlider.SetSize(XMFLOAT2(siz, hei)); + dampingSlider.OnSlide([&](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->damping = args.fValue; }); - window->AddWidget(dampingSlider); + AddWidget(&dampingSlider); - windSlider = new wiSlider(0, 1, 0, 100000, "Wind affection: "); - windSlider->SetTooltip("How much the global wind effect affects the spring"); - windSlider->SetPos(XMFLOAT2(x, y += step)); - windSlider->SetSize(XMFLOAT2(siz, hei)); - windSlider->OnSlide([&](wiEventArgs args) { + windSlider.Create(0, 1, 0, 100000, "Wind affection: "); + windSlider.SetTooltip("How much the global wind effect affects the spring"); + windSlider.SetPos(XMFLOAT2(x, y += step)); + windSlider.SetSize(XMFLOAT2(siz, hei)); + windSlider.OnSlide([&](wiEventArgs args) { wiScene::GetScene().springs.GetComponent(entity)->wind_affection = args.fValue; }); - window->AddWidget(windSlider); + AddWidget(&windSlider); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 700, 80, 0)); - window->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 700, 80, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -SpringWindow::~SpringWindow() -{ - window->RemoveWidgets(true); - GUI->RemoveWidget(window); - delete window; -} - void SpringWindow::SetEntity(Entity entity) { this->entity = entity; @@ -108,42 +97,42 @@ void SpringWindow::SetEntity(Entity entity) if (spring != nullptr) { - window->SetEnabled(true); + SetEnabled(true); - disabledCheckBox->SetCheck(spring->IsDisabled()); - stretchCheckBox->SetCheck(spring->IsStretchEnabled()); - gravityCheckBox->SetCheck(spring->IsGravityEnabled()); - stiffnessSlider->SetValue(spring->stiffness); - dampingSlider->SetValue(spring->damping); - windSlider->SetValue(spring->wind_affection); + disabledCheckBox.SetCheck(spring->IsDisabled()); + stretchCheckBox.SetCheck(spring->IsStretchEnabled()); + gravityCheckBox.SetCheck(spring->IsGravityEnabled()); + stiffnessSlider.SetValue(spring->stiffness); + dampingSlider.SetValue(spring->damping); + windSlider.SetValue(spring->wind_affection); } else { - window->SetEnabled(false); + SetEnabled(false); } const TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { - createButton->SetEnabled(true); + createButton.SetEnabled(true); if (spring == nullptr) { - createButton->SetText("Create"); - createButton->OnClick([=](wiEventArgs args) { + createButton.SetText("Create"); + createButton.OnClick([=](wiEventArgs args) { wiScene::GetScene().springs.Create(entity); SetEntity(entity); }); } else { - createButton->SetText("Remove"); - createButton->OnClick([=](wiEventArgs args) { + createButton.SetText("Remove"); + createButton.OnClick([=](wiEventArgs args) { wiScene::GetScene().springs.Remove_KeepSorted(entity); SetEntity(entity); }); } } - debugCheckBox->SetEnabled(true); + debugCheckBox.SetEnabled(true); } diff --git a/Editor/SpringWindow.h b/Editor/SpringWindow.h index f456c260d..53ffa5dab 100644 --- a/Editor/SpringWindow.h +++ b/Editor/SpringWindow.h @@ -1,35 +1,23 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; +#include "WickedEngine.h" class EditorComponent; -class SpringWindow +class SpringWindow : public wiWindow { public: - SpringWindow(EditorComponent* editor); - ~SpringWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; - - wiWindow* window; - - wiButton* createButton; - wiCheckBox* debugCheckBox; - wiCheckBox* disabledCheckBox; - wiCheckBox* stretchCheckBox; - wiCheckBox* gravityCheckBox; - wiSlider* stiffnessSlider; - wiSlider* dampingSlider; - wiSlider* windSlider; + wiButton createButton; + wiCheckBox debugCheckBox; + wiCheckBox disabledCheckBox; + wiCheckBox stretchCheckBox; + wiCheckBox gravityCheckBox; + wiSlider stiffnessSlider; + wiSlider dampingSlider; + wiSlider windSlider; }; diff --git a/Editor/TransformWindow.cpp b/Editor/TransformWindow.cpp index 697503e16..0b4b26dfa 100644 --- a/Editor/TransformWindow.cpp +++ b/Editor/TransformWindow.cpp @@ -6,13 +6,10 @@ using namespace wiECS; using namespace wiScene; -TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void TransformWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - window = new wiWindow(GUI, "Transform Window"); - window->SetSize(XMFLOAT2(460, 180)); - GUI->AddWidget(window); + wiWindow::Create("Transform Window"); + SetSize(XMFLOAT2(460, 180)); float x = 100; float y = 0; @@ -20,24 +17,25 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( float siz = 50; float hei = 20; - createButton = new wiButton("Create New Transform"); - createButton->SetTooltip("Create a new entity with only a trasform component"); - createButton->SetPos(XMFLOAT2(x, y += step)); - createButton->SetSize(XMFLOAT2(350, hei)); - createButton->OnClick([=](wiEventArgs args) { + createButton.Create("Create New Transform"); + createButton.SetTooltip("Create a new entity with only a trasform component"); + createButton.SetPos(XMFLOAT2(x, y += step)); + createButton.SetSize(XMFLOAT2(350, hei)); + createButton.OnClick([=](wiEventArgs args) { Entity entity = CreateEntity(); wiScene::GetScene().transforms.Create(entity); editor->ClearSelected(); editor->AddSelected(entity); + editor->RefreshSceneGraphView(); SetEntity(entity); }); - window->AddWidget(createButton); + AddWidget(&createButton); - parentCombo = new wiComboBox("Parent: "); - parentCombo->SetSize(XMFLOAT2(330, hei)); - parentCombo->SetPos(XMFLOAT2(x, y += step)); - parentCombo->SetEnabled(false); - parentCombo->OnSelect([&](wiEventArgs args) { + parentCombo.Create("Parent: "); + parentCombo.SetSize(XMFLOAT2(330, hei)); + parentCombo.SetPos(XMFLOAT2(x, y += step)); + parentCombo.SetEnabled(false); + parentCombo.OnSelect([&](wiEventArgs args) { Scene& scene = wiScene::GetScene(); HierarchyComponent* hier = scene.hierarchy.GetComponent(entity); @@ -59,15 +57,15 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( } }); - parentCombo->SetTooltip("Choose a parent entity for the transform"); - window->AddWidget(parentCombo); + parentCombo.SetTooltip("Choose a parent entity for the transform"); + AddWidget(&parentCombo); - txInput = new wiTextInputField(""); - txInput->SetValue(0); - txInput->SetDescription("Translation X: "); - txInput->SetPos(XMFLOAT2(x, y += step)); - txInput->SetSize(XMFLOAT2(siz, hei)); - txInput->OnInputAccepted([&](wiEventArgs args) { + txInput.Create(""); + txInput.SetValue(0); + txInput.SetDescription("Translation X: "); + txInput.SetPos(XMFLOAT2(x, y += step)); + txInput.SetSize(XMFLOAT2(siz, hei)); + txInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -75,14 +73,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(txInput); + AddWidget(&txInput); - tyInput = new wiTextInputField(""); - tyInput->SetValue(0); - tyInput->SetDescription("Translation Y: "); - tyInput->SetPos(XMFLOAT2(x, y += step)); - tyInput->SetSize(XMFLOAT2(siz, hei)); - tyInput->OnInputAccepted([&](wiEventArgs args) { + tyInput.Create(""); + tyInput.SetValue(0); + tyInput.SetDescription("Translation Y: "); + tyInput.SetPos(XMFLOAT2(x, y += step)); + tyInput.SetSize(XMFLOAT2(siz, hei)); + tyInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -90,14 +88,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(tyInput); + AddWidget(&tyInput); - tzInput = new wiTextInputField(""); - tzInput->SetValue(0); - tzInput->SetDescription("Translation Z: "); - tzInput->SetPos(XMFLOAT2(x, y += step)); - tzInput->SetSize(XMFLOAT2(siz, hei)); - tzInput->OnInputAccepted([&](wiEventArgs args) { + tzInput.Create(""); + tzInput.SetValue(0); + tzInput.SetDescription("Translation Z: "); + tzInput.SetPos(XMFLOAT2(x, y += step)); + tzInput.SetSize(XMFLOAT2(siz, hei)); + tzInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -105,7 +103,7 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(tzInput); + AddWidget(&tzInput); @@ -113,12 +111,12 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( y = step * 2; - rxInput = new wiTextInputField(""); - rxInput->SetValue(0); - rxInput->SetDescription("Rotation X: "); - rxInput->SetPos(XMFLOAT2(x, y += step)); - rxInput->SetSize(XMFLOAT2(siz, hei)); - rxInput->OnInputAccepted([&](wiEventArgs args) { + rxInput.Create(""); + rxInput.SetValue(0); + rxInput.SetDescription("Rotation X: "); + rxInput.SetPos(XMFLOAT2(x, y += step)); + rxInput.SetSize(XMFLOAT2(siz, hei)); + rxInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -126,14 +124,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(rxInput); + AddWidget(&rxInput); - ryInput = new wiTextInputField(""); - ryInput->SetValue(0); - ryInput->SetDescription("Rotation Y: "); - ryInput->SetPos(XMFLOAT2(x, y += step)); - ryInput->SetSize(XMFLOAT2(siz, hei)); - ryInput->OnInputAccepted([&](wiEventArgs args) { + ryInput.Create(""); + ryInput.SetValue(0); + ryInput.SetDescription("Rotation Y: "); + ryInput.SetPos(XMFLOAT2(x, y += step)); + ryInput.SetSize(XMFLOAT2(siz, hei)); + ryInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -141,14 +139,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(ryInput); + AddWidget(&ryInput); - rzInput = new wiTextInputField(""); - rzInput->SetValue(0); - rzInput->SetDescription("Rotation Z: "); - rzInput->SetPos(XMFLOAT2(x, y += step)); - rzInput->SetSize(XMFLOAT2(siz, hei)); - rzInput->OnInputAccepted([&](wiEventArgs args) { + rzInput.Create(""); + rzInput.SetValue(0); + rzInput.SetDescription("Rotation Z: "); + rzInput.SetPos(XMFLOAT2(x, y += step)); + rzInput.SetSize(XMFLOAT2(siz, hei)); + rzInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -156,14 +154,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(rzInput); + AddWidget(&rzInput); - rwInput = new wiTextInputField(""); - rwInput->SetValue(1); - rwInput->SetDescription("Rotation W: "); - rwInput->SetPos(XMFLOAT2(x, y += step)); - rwInput->SetSize(XMFLOAT2(siz, hei)); - rwInput->OnInputAccepted([&](wiEventArgs args) { + rwInput.Create(""); + rwInput.SetValue(1); + rwInput.SetDescription("Rotation W: "); + rwInput.SetPos(XMFLOAT2(x, y += step)); + rwInput.SetSize(XMFLOAT2(siz, hei)); + rwInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -171,7 +169,7 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(rwInput); + AddWidget(&rwInput); @@ -180,12 +178,12 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( y = step * 2; - sxInput = new wiTextInputField(""); - sxInput->SetValue(1); - sxInput->SetDescription("Scale X: "); - sxInput->SetPos(XMFLOAT2(x, y += step)); - sxInput->SetSize(XMFLOAT2(siz, hei)); - sxInput->OnInputAccepted([&](wiEventArgs args) { + sxInput.Create(""); + sxInput.SetValue(1); + sxInput.SetDescription("Scale X: "); + sxInput.SetPos(XMFLOAT2(x, y += step)); + sxInput.SetSize(XMFLOAT2(siz, hei)); + sxInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -193,14 +191,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(sxInput); + AddWidget(&sxInput); - syInput = new wiTextInputField(""); - syInput->SetValue(1); - syInput->SetDescription("Scale Y: "); - syInput->SetPos(XMFLOAT2(x, y += step)); - syInput->SetSize(XMFLOAT2(siz, hei)); - syInput->OnInputAccepted([&](wiEventArgs args) { + syInput.Create(""); + syInput.SetValue(1); + syInput.SetDescription("Scale Y: "); + syInput.SetPos(XMFLOAT2(x, y += step)); + syInput.SetSize(XMFLOAT2(siz, hei)); + syInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -208,14 +206,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(syInput); + AddWidget(&syInput); - szInput = new wiTextInputField(""); - szInput->SetValue(1); - szInput->SetDescription("Scale Z: "); - szInput->SetPos(XMFLOAT2(x, y += step)); - szInput->SetSize(XMFLOAT2(siz, hei)); - szInput->OnInputAccepted([&](wiEventArgs args) { + szInput.Create(""); + szInput.SetValue(1); + szInput.SetDescription("Scale Z: "); + szInput.SetPos(XMFLOAT2(x, y += step)); + szInput.SetSize(XMFLOAT2(siz, hei)); + szInput.OnInputAccepted([&](wiEventArgs args) { TransformComponent* transform = wiScene::GetScene().transforms.GetComponent(entity); if (transform != nullptr) { @@ -223,22 +221,14 @@ TransformWindow::TransformWindow(EditorComponent* editor) : GUI(&editor->GetGUI( transform->SetDirty(); } }); - window->AddWidget(szInput); + AddWidget(&szInput); - window->Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 750, 100, 0)); - window->SetVisible(false); + Translate(XMFLOAT3((float)wiRenderer::GetDevice()->GetScreenWidth() - 750, 100, 0)); + SetVisible(false); SetEntity(INVALID_ENTITY); } - -TransformWindow::~TransformWindow() -{ - window->RemoveWidgets(true); - GUI->RemoveWidget(window); - delete window; -} - void TransformWindow::SetEntity(Entity entity) { this->entity = entity; @@ -248,41 +238,41 @@ void TransformWindow::SetEntity(Entity entity) if (transform != nullptr) { - parentCombo->ClearItems(); - parentCombo->AddItem("NO PARENT"); + parentCombo.ClearItems(); + parentCombo.AddItem("NO PARENT"); HierarchyComponent* hier = scene.hierarchy.GetComponent(entity); for (size_t i = 0; i < scene.transforms.GetCount(); ++i) { Entity entity = scene.transforms.GetEntity(i); const NameComponent* name = scene.names.GetComponent(entity); - parentCombo->AddItem(name == nullptr ? std::to_string(entity) : name->name); + parentCombo.AddItem(name == nullptr ? std::to_string(entity) : name->name); if (hier != nullptr && hier->parentID == entity) { - parentCombo->SetSelected((int)i + 1); + parentCombo.SetSelected((int)i + 1); } } - txInput->SetValue(transform->translation_local.x); - tyInput->SetValue(transform->translation_local.y); - tzInput->SetValue(transform->translation_local.z); + txInput.SetValue(transform->translation_local.x); + tyInput.SetValue(transform->translation_local.y); + tzInput.SetValue(transform->translation_local.z); - rxInput->SetValue(transform->rotation_local.x); - ryInput->SetValue(transform->rotation_local.y); - rzInput->SetValue(transform->rotation_local.z); - rwInput->SetValue(transform->rotation_local.w); + rxInput.SetValue(transform->rotation_local.x); + ryInput.SetValue(transform->rotation_local.y); + rzInput.SetValue(transform->rotation_local.z); + rwInput.SetValue(transform->rotation_local.w); - sxInput->SetValue(transform->scale_local.x); - syInput->SetValue(transform->scale_local.y); - szInput->SetValue(transform->scale_local.z); + sxInput.SetValue(transform->scale_local.x); + syInput.SetValue(transform->scale_local.y); + szInput.SetValue(transform->scale_local.z); - window->SetEnabled(true); + SetEnabled(true); } else { - window->SetEnabled(false); + SetEnabled(false); } - createButton->SetEnabled(true); + createButton.SetEnabled(true); } diff --git a/Editor/TransformWindow.h b/Editor/TransformWindow.h index c5f994f30..489e4a788 100644 --- a/Editor/TransformWindow.h +++ b/Editor/TransformWindow.h @@ -1,44 +1,31 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiComboBox; -class wiColorPicker; -class wiTextInputField; +#include "WickedEngine.h" class EditorComponent; -class TransformWindow +class TransformWindow : public wiWindow { public: - TransformWindow(EditorComponent* editor); - ~TransformWindow(); + void Create(EditorComponent* editor); wiECS::Entity entity; void SetEntity(wiECS::Entity entity); - wiGUI* GUI; + wiButton createButton; - wiWindow* window; + wiComboBox parentCombo; - wiButton* createButton; - - wiComboBox* parentCombo; - - wiTextInputField* txInput; - wiTextInputField* tyInput; - wiTextInputField* tzInput; - - wiTextInputField* rxInput; - wiTextInputField* ryInput; - wiTextInputField* rzInput; - wiTextInputField* rwInput; - - wiTextInputField* sxInput; - wiTextInputField* syInput; - wiTextInputField* szInput; + wiTextInputField txInput; + wiTextInputField tyInput; + wiTextInputField tzInput; + + wiTextInputField rxInput; + wiTextInputField ryInput; + wiTextInputField rzInput; + wiTextInputField rwInput; + + wiTextInputField sxInput; + wiTextInputField syInput; + wiTextInputField szInput; }; diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 62fa45654..fe4c2236e 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -56,7 +56,7 @@ namespace Translator_Internal } } -Translator::Translator() +void Translator::Create() { GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/Editor/Translator.h b/Editor/Translator.h index 06885869e..e222ed10e 100644 --- a/Editor/Translator.h +++ b/Editor/Translator.h @@ -12,7 +12,7 @@ private: bool dragStarted = false; bool dragEnded = false; public: - Translator(); + void Create(); void Update(); void Draw(const wiScene::CameraComponent& camera, wiGraphics::CommandList cmd) const; diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 59f88b97d..ba1c70a10 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -9,13 +9,10 @@ using namespace wiECS; using namespace wiScene; using namespace wiGraphics; -WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) +void WeatherWindow::Create(EditorComponent* editor) { - assert(GUI && "Invalid GUI!"); - - weatherWindow = new wiWindow(GUI, "Weather Window"); - weatherWindow->SetSize(XMFLOAT2(660, 520)); - GUI->AddWidget(weatherWindow); + wiWindow::Create("Weather Window"); + SetSize(XMFLOAT2(660, 520)); float x = 180; float y = 20; @@ -23,109 +20,109 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) float step = hei + 2; - fogStartSlider = new wiSlider(0, 5000, 0, 100000, "Fog Start: "); - fogStartSlider->SetSize(XMFLOAT2(100, hei)); - fogStartSlider->SetPos(XMFLOAT2(x, y += step)); - fogStartSlider->OnSlide([&](wiEventArgs args) { + fogStartSlider.Create(0, 5000, 0, 100000, "Fog Start: "); + fogStartSlider.SetSize(XMFLOAT2(100, hei)); + fogStartSlider.SetPos(XMFLOAT2(x, y += step)); + fogStartSlider.OnSlide([&](wiEventArgs args) { GetWeather().fogStart = args.fValue; }); - weatherWindow->AddWidget(fogStartSlider); + AddWidget(&fogStartSlider); - fogEndSlider = new wiSlider(1, 5000, 1000, 10000, "Fog End: "); - fogEndSlider->SetSize(XMFLOAT2(100, hei)); - fogEndSlider->SetPos(XMFLOAT2(x, y += step)); - fogEndSlider->OnSlide([&](wiEventArgs args) { + fogEndSlider.Create(1, 5000, 1000, 10000, "Fog End: "); + fogEndSlider.SetSize(XMFLOAT2(100, hei)); + fogEndSlider.SetPos(XMFLOAT2(x, y += step)); + fogEndSlider.OnSlide([&](wiEventArgs args) { GetWeather().fogEnd = args.fValue; }); - weatherWindow->AddWidget(fogEndSlider); + AddWidget(&fogEndSlider); - fogHeightSlider = new wiSlider(0, 1, 0, 10000, "Fog Height: "); - fogHeightSlider->SetSize(XMFLOAT2(100, hei)); - fogHeightSlider->SetPos(XMFLOAT2(x, y += step)); - fogHeightSlider->OnSlide([&](wiEventArgs args) { + fogHeightSlider.Create(0, 1, 0, 10000, "Fog Height: "); + fogHeightSlider.SetSize(XMFLOAT2(100, hei)); + fogHeightSlider.SetPos(XMFLOAT2(x, y += step)); + fogHeightSlider.OnSlide([&](wiEventArgs args) { GetWeather().fogHeight = args.fValue; }); - weatherWindow->AddWidget(fogHeightSlider); + AddWidget(&fogHeightSlider); - cloudinessSlider = new wiSlider(0, 1, 0.0f, 10000, "Cloudiness: "); - cloudinessSlider->SetSize(XMFLOAT2(100, hei)); - cloudinessSlider->SetPos(XMFLOAT2(x, y += step)); - cloudinessSlider->OnSlide([&](wiEventArgs args) { + cloudinessSlider.Create(0, 1, 0.0f, 10000, "Cloudiness: "); + cloudinessSlider.SetSize(XMFLOAT2(100, hei)); + cloudinessSlider.SetPos(XMFLOAT2(x, y += step)); + cloudinessSlider.OnSlide([&](wiEventArgs args) { GetWeather().cloudiness = args.fValue; }); - weatherWindow->AddWidget(cloudinessSlider); + AddWidget(&cloudinessSlider); - cloudScaleSlider = new wiSlider(0.00005f, 0.001f, 0.0005f, 10000, "Cloud Scale: "); - cloudScaleSlider->SetSize(XMFLOAT2(100, hei)); - cloudScaleSlider->SetPos(XMFLOAT2(x, y += step)); - cloudScaleSlider->OnSlide([&](wiEventArgs args) { + cloudScaleSlider.Create(0.00005f, 0.001f, 0.0005f, 10000, "Cloud Scale: "); + cloudScaleSlider.SetSize(XMFLOAT2(100, hei)); + cloudScaleSlider.SetPos(XMFLOAT2(x, y += step)); + cloudScaleSlider.OnSlide([&](wiEventArgs args) { GetWeather().cloudScale = args.fValue; }); - weatherWindow->AddWidget(cloudScaleSlider); + AddWidget(&cloudScaleSlider); - cloudSpeedSlider = new wiSlider(0.001f, 0.2f, 0.1f, 10000, "Cloud Speed: "); - cloudSpeedSlider->SetSize(XMFLOAT2(100, hei)); - cloudSpeedSlider->SetPos(XMFLOAT2(x, y += step)); - cloudSpeedSlider->OnSlide([&](wiEventArgs args) { + cloudSpeedSlider.Create(0.001f, 0.2f, 0.1f, 10000, "Cloud Speed: "); + cloudSpeedSlider.SetSize(XMFLOAT2(100, hei)); + cloudSpeedSlider.SetPos(XMFLOAT2(x, y += step)); + cloudSpeedSlider.OnSlide([&](wiEventArgs args) { GetWeather().cloudSpeed = args.fValue; }); - weatherWindow->AddWidget(cloudSpeedSlider); + AddWidget(&cloudSpeedSlider); - windSpeedSlider = new wiSlider(0.0f, 4.0f, 1.0f, 10000, "Wind Speed: "); - windSpeedSlider->SetSize(XMFLOAT2(100, hei)); - windSpeedSlider->SetPos(XMFLOAT2(x, y += step)); - windSpeedSlider->OnSlide([&](wiEventArgs args) { + windSpeedSlider.Create(0.0f, 4.0f, 1.0f, 10000, "Wind Speed: "); + windSpeedSlider.SetSize(XMFLOAT2(100, hei)); + windSpeedSlider.SetPos(XMFLOAT2(x, y += step)); + windSpeedSlider.OnSlide([&](wiEventArgs args) { GetWeather().windSpeed = args.fValue; }); - weatherWindow->AddWidget(windSpeedSlider); + AddWidget(&windSpeedSlider); - windMagnitudeSlider = new wiSlider(0.0f, 0.2f, 0.0f, 10000, "Wind Magnitude: "); - windMagnitudeSlider->SetSize(XMFLOAT2(100, hei)); - windMagnitudeSlider->SetPos(XMFLOAT2(x, y += step)); - windMagnitudeSlider->OnSlide([&](wiEventArgs args) { + windMagnitudeSlider.Create(0.0f, 0.2f, 0.0f, 10000, "Wind Magnitude: "); + windMagnitudeSlider.SetSize(XMFLOAT2(100, hei)); + windMagnitudeSlider.SetPos(XMFLOAT2(x, y += step)); + windMagnitudeSlider.OnSlide([&](wiEventArgs args) { UpdateWind(); }); - weatherWindow->AddWidget(windMagnitudeSlider); + AddWidget(&windMagnitudeSlider); - windDirectionSlider = new wiSlider(0, 1, 0, 10000, "Wind Direction: "); - windDirectionSlider->SetSize(XMFLOAT2(100, hei)); - windDirectionSlider->SetPos(XMFLOAT2(x, y += step)); - windDirectionSlider->OnSlide([&](wiEventArgs args) { + windDirectionSlider.Create(0, 1, 0, 10000, "Wind Direction: "); + windDirectionSlider.SetSize(XMFLOAT2(100, hei)); + windDirectionSlider.SetPos(XMFLOAT2(x, y += step)); + windDirectionSlider.OnSlide([&](wiEventArgs args) { UpdateWind(); }); - weatherWindow->AddWidget(windDirectionSlider); + AddWidget(&windDirectionSlider); - windWaveSizeSlider = new wiSlider(0, 1, 0, 10000, "Wind Wave Size: "); - windWaveSizeSlider->SetSize(XMFLOAT2(100, hei)); - windWaveSizeSlider->SetPos(XMFLOAT2(x, y += step)); - windWaveSizeSlider->OnSlide([&](wiEventArgs args) { + windWaveSizeSlider.Create(0, 1, 0, 10000, "Wind Wave Size: "); + windWaveSizeSlider.SetSize(XMFLOAT2(100, hei)); + windWaveSizeSlider.SetPos(XMFLOAT2(x, y += step)); + windWaveSizeSlider.OnSlide([&](wiEventArgs args) { GetWeather().windWaveSize = args.fValue; }); - weatherWindow->AddWidget(windWaveSizeSlider); + AddWidget(&windWaveSizeSlider); - windRandomnessSlider = new wiSlider(0, 10, 5, 10000, "Wind Randomness: "); - windRandomnessSlider->SetSize(XMFLOAT2(100, hei)); - windRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); - windRandomnessSlider->OnSlide([&](wiEventArgs args) { + windRandomnessSlider.Create(0, 10, 5, 10000, "Wind Randomness: "); + windRandomnessSlider.SetSize(XMFLOAT2(100, hei)); + windRandomnessSlider.SetPos(XMFLOAT2(x, y += step)); + windRandomnessSlider.OnSlide([&](wiEventArgs args) { GetWeather().windRandomness = args.fValue; }); - weatherWindow->AddWidget(windRandomnessSlider); + AddWidget(&windRandomnessSlider); - simpleskyCheckBox = new wiCheckBox("Simple sky: "); - simpleskyCheckBox->SetTooltip("Simple sky will simply blend horizon and zenith color from bottom to top."); - simpleskyCheckBox->SetSize(XMFLOAT2(hei, hei)); - simpleskyCheckBox->SetPos(XMFLOAT2(x, y += step)); - simpleskyCheckBox->OnClick([&](wiEventArgs args) { + simpleskyCheckBox.Create("Simple sky: "); + simpleskyCheckBox.SetTooltip("Simple sky will simply blend horizon and zenith color from bottom to top."); + simpleskyCheckBox.SetSize(XMFLOAT2(hei, hei)); + simpleskyCheckBox.SetPos(XMFLOAT2(x, y += step)); + simpleskyCheckBox.OnClick([&](wiEventArgs args) { auto& weather = GetWeather(); weather.SetSimpleSky(args.bValue); }); - weatherWindow->AddWidget(simpleskyCheckBox); + AddWidget(&simpleskyCheckBox); - skyButton = new wiButton("Load Sky"); - skyButton->SetTooltip("Load a skybox cubemap texture..."); - skyButton->SetSize(XMFLOAT2(240, hei)); - skyButton->SetPos(XMFLOAT2(x-100, y += step)); - skyButton->OnClick([=](wiEventArgs args) { + skyButton.Create("Load Sky"); + skyButton.SetTooltip("Load a skybox cubemap texture..."); + skyButton.SetSize(XMFLOAT2(240, hei)); + skyButton.SetPos(XMFLOAT2(x-100, y += step)); + skyButton.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); if (weather.skyMap == nullptr) @@ -139,7 +136,7 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) auto& weather = GetWeather(); weather.skyMapName = fileName; weather.skyMap = wiResourceManager::Load(fileName); - skyButton->SetText(fileName); + skyButton.SetText(fileName); }); }); } @@ -147,22 +144,22 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) { weather.skyMap.reset(); weather.skyMapName.clear(); - skyButton->SetText("Load Sky"); + skyButton.SetText("Load Sky"); } // Also, we invalidate all environment probes to reflect the sky changes. InvalidateProbes(); }); - weatherWindow->AddWidget(skyButton); + AddWidget(&skyButton); // Ocean params: - ocean_enabledCheckBox = new wiCheckBox("Ocean simulation enabled: "); - ocean_enabledCheckBox->SetSize(XMFLOAT2(hei, hei)); - ocean_enabledCheckBox->SetPos(XMFLOAT2(x + 100, y += step)); - ocean_enabledCheckBox->OnClick([&](wiEventArgs args) { + ocean_enabledCheckBox.Create("Ocean simulation enabled: "); + ocean_enabledCheckBox.SetSize(XMFLOAT2(hei, hei)); + ocean_enabledCheckBox.SetPos(XMFLOAT2(x + 100, y += step)); + ocean_enabledCheckBox.OnClick([&](wiEventArgs args) { auto& weather = GetWeather(); weather.SetOceanEnabled(args.bValue); if (!weather.IsOceanEnabled()) @@ -170,15 +167,15 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) wiRenderer::OceanRegenerate(); } }); - weatherWindow->AddWidget(ocean_enabledCheckBox); + AddWidget(&ocean_enabledCheckBox); - ocean_patchSizeSlider = new wiSlider(1, 1000, 1000, 100000, "Patch size: "); - ocean_patchSizeSlider->SetSize(XMFLOAT2(100, hei)); - ocean_patchSizeSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_patchSizeSlider->SetValue(wiScene::GetScene().weather.oceanParameters.patch_length); - ocean_patchSizeSlider->SetTooltip("Adjust water tiling patch size"); - ocean_patchSizeSlider->OnSlide([&](wiEventArgs args) { + ocean_patchSizeSlider.Create(1, 1000, 1000, 100000, "Patch size: "); + ocean_patchSizeSlider.SetSize(XMFLOAT2(100, hei)); + ocean_patchSizeSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_patchSizeSlider.SetValue(wiScene::GetScene().weather.oceanParameters.patch_length); + ocean_patchSizeSlider.SetTooltip("Adjust water tiling patch size"); + ocean_patchSizeSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; @@ -189,14 +186,14 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - weatherWindow->AddWidget(ocean_patchSizeSlider); + AddWidget(&ocean_patchSizeSlider); - ocean_waveAmplitudeSlider = new wiSlider(0, 1000, 1000, 100000, "Wave amplitude: "); - ocean_waveAmplitudeSlider->SetSize(XMFLOAT2(100, hei)); - ocean_waveAmplitudeSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_waveAmplitudeSlider->SetValue(wiScene::GetScene().weather.oceanParameters.wave_amplitude); - ocean_waveAmplitudeSlider->SetTooltip("Adjust wave size"); - ocean_waveAmplitudeSlider->OnSlide([&](wiEventArgs args) { + ocean_waveAmplitudeSlider.Create(0, 1000, 1000, 100000, "Wave amplitude: "); + ocean_waveAmplitudeSlider.SetSize(XMFLOAT2(100, hei)); + ocean_waveAmplitudeSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_waveAmplitudeSlider.SetValue(wiScene::GetScene().weather.oceanParameters.wave_amplitude); + ocean_waveAmplitudeSlider.SetTooltip("Adjust wave size"); + ocean_waveAmplitudeSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; @@ -207,28 +204,28 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - weatherWindow->AddWidget(ocean_waveAmplitudeSlider); + AddWidget(&ocean_waveAmplitudeSlider); - ocean_choppyScaleSlider = new wiSlider(0, 10, 1000, 100000, "Choppiness: "); - ocean_choppyScaleSlider->SetSize(XMFLOAT2(100, hei)); - ocean_choppyScaleSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_choppyScaleSlider->SetValue(wiScene::GetScene().weather.oceanParameters.choppy_scale); - ocean_choppyScaleSlider->SetTooltip("Adjust wave choppiness"); - ocean_choppyScaleSlider->OnSlide([&](wiEventArgs args) { + ocean_choppyScaleSlider.Create(0, 10, 1000, 100000, "Choppiness: "); + ocean_choppyScaleSlider.SetSize(XMFLOAT2(100, hei)); + ocean_choppyScaleSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_choppyScaleSlider.SetValue(wiScene::GetScene().weather.oceanParameters.choppy_scale); + ocean_choppyScaleSlider.SetTooltip("Adjust wave choppiness"); + ocean_choppyScaleSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; weather.oceanParameters.choppy_scale = args.fValue; } }); - weatherWindow->AddWidget(ocean_choppyScaleSlider); + AddWidget(&ocean_choppyScaleSlider); - ocean_windDependencySlider = new wiSlider(0, 1, 1000, 100000, "Wind dependency: "); - ocean_windDependencySlider->SetSize(XMFLOAT2(100, hei)); - ocean_windDependencySlider->SetPos(XMFLOAT2(x, y += step)); - ocean_windDependencySlider->SetValue(wiScene::GetScene().weather.oceanParameters.wind_dependency); - ocean_windDependencySlider->SetTooltip("Adjust wind contribution"); - ocean_windDependencySlider->OnSlide([&](wiEventArgs args) { + ocean_windDependencySlider.Create(0, 1, 1000, 100000, "Wind dependency: "); + ocean_windDependencySlider.SetSize(XMFLOAT2(100, hei)); + ocean_windDependencySlider.SetPos(XMFLOAT2(x, y += step)); + ocean_windDependencySlider.SetValue(wiScene::GetScene().weather.oceanParameters.wind_dependency); + ocean_windDependencySlider.SetTooltip("Adjust wind contribution"); + ocean_windDependencySlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; @@ -239,74 +236,74 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } } }); - weatherWindow->AddWidget(ocean_windDependencySlider); + AddWidget(&ocean_windDependencySlider); - ocean_timeScaleSlider = new wiSlider(0, 4, 1000, 100000, "Time scale: "); - ocean_timeScaleSlider->SetSize(XMFLOAT2(100, hei)); - ocean_timeScaleSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_timeScaleSlider->SetValue(wiScene::GetScene().weather.oceanParameters.time_scale); - ocean_timeScaleSlider->SetTooltip("Adjust simulation speed"); - ocean_timeScaleSlider->OnSlide([&](wiEventArgs args) { + ocean_timeScaleSlider.Create(0, 4, 1000, 100000, "Time scale: "); + ocean_timeScaleSlider.SetSize(XMFLOAT2(100, hei)); + ocean_timeScaleSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_timeScaleSlider.SetValue(wiScene::GetScene().weather.oceanParameters.time_scale); + ocean_timeScaleSlider.SetTooltip("Adjust simulation speed"); + ocean_timeScaleSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; weather.oceanParameters.time_scale = args.fValue; } }); - weatherWindow->AddWidget(ocean_timeScaleSlider); + AddWidget(&ocean_timeScaleSlider); - ocean_heightSlider = new wiSlider(-100, 100, 0, 100000, "Water level: "); - ocean_heightSlider->SetSize(XMFLOAT2(100, hei)); - ocean_heightSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_heightSlider->SetValue(0); - ocean_heightSlider->SetTooltip("Adjust water level"); - ocean_heightSlider->OnSlide([&](wiEventArgs args) { + ocean_heightSlider.Create(-100, 100, 0, 100000, "Water level: "); + ocean_heightSlider.SetSize(XMFLOAT2(100, hei)); + ocean_heightSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_heightSlider.SetValue(0); + ocean_heightSlider.SetTooltip("Adjust water level"); + ocean_heightSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; weather.oceanParameters.waterHeight = args.fValue; } }); - weatherWindow->AddWidget(ocean_heightSlider); + AddWidget(&ocean_heightSlider); - ocean_detailSlider = new wiSlider(1, 10, 0, 9, "Surface Detail: "); - ocean_detailSlider->SetSize(XMFLOAT2(100, hei)); - ocean_detailSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_detailSlider->SetValue(4); - ocean_detailSlider->SetTooltip("Adjust surface tessellation resolution. High values can decrease performance."); - ocean_detailSlider->OnSlide([&](wiEventArgs args) { + ocean_detailSlider.Create(1, 10, 0, 9, "Surface Detail: "); + ocean_detailSlider.SetSize(XMFLOAT2(100, hei)); + ocean_detailSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_detailSlider.SetValue(4); + ocean_detailSlider.SetTooltip("Adjust surface tessellation resolution. High values can decrease performance."); + ocean_detailSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; weather.oceanParameters.surfaceDetail = (uint32_t)args.iValue; } }); - weatherWindow->AddWidget(ocean_detailSlider); + AddWidget(&ocean_detailSlider); - ocean_toleranceSlider = new wiSlider(1, 10, 0, 1000, "Displacement Tolerance: "); - ocean_toleranceSlider->SetSize(XMFLOAT2(100, hei)); - ocean_toleranceSlider->SetPos(XMFLOAT2(x, y += step)); - ocean_toleranceSlider->SetValue(2); - ocean_toleranceSlider->SetTooltip("Big waves can introduce glitches on screen borders, this can fix that but surface detail will decrease."); - ocean_toleranceSlider->OnSlide([&](wiEventArgs args) { + ocean_toleranceSlider.Create(1, 10, 0, 1000, "Displacement Tolerance: "); + ocean_toleranceSlider.SetSize(XMFLOAT2(100, hei)); + ocean_toleranceSlider.SetPos(XMFLOAT2(x, y += step)); + ocean_toleranceSlider.SetValue(2); + ocean_toleranceSlider.SetTooltip("Big waves can introduce glitches on screen borders, this can fix that but surface detail will decrease."); + ocean_toleranceSlider.OnSlide([&](wiEventArgs args) { if (wiScene::GetScene().weathers.GetCount() > 0) { WeatherComponent& weather = wiScene::GetScene().weathers[0]; weather.oceanParameters.surfaceDisplacementTolerance = args.fValue; } }); - weatherWindow->AddWidget(ocean_toleranceSlider); + AddWidget(&ocean_toleranceSlider); - ocean_resetButton = new wiButton("Reset Ocean to default"); - ocean_resetButton->SetTooltip("Reset ocean to default values."); - ocean_resetButton->SetSize(XMFLOAT2(240, hei)); - ocean_resetButton->SetPos(XMFLOAT2(x - 100, y += step)); - ocean_resetButton->OnClick([=](wiEventArgs args) { + ocean_resetButton.Create("Reset Ocean to default"); + ocean_resetButton.SetTooltip("Reset ocean to default values."); + ocean_resetButton.SetSize(XMFLOAT2(240, hei)); + ocean_resetButton.SetPos(XMFLOAT2(x - 100, y += step)); + ocean_resetButton.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); weather.oceanParameters = WeatherComponent::OceanParameters(); }); - weatherWindow->AddWidget(ocean_resetButton); + AddWidget(&ocean_resetButton); @@ -320,25 +317,25 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) x = 340; y = 20; - colorComboBox = new wiComboBox("Color picker mode: "); - colorComboBox->SetSize(XMFLOAT2(120, hei)); - colorComboBox->SetPos(XMFLOAT2(x + 150, y += step)); - colorComboBox->AddItem("Ambient color"); - colorComboBox->AddItem("Horizon color"); - colorComboBox->AddItem("Zenith color"); - colorComboBox->AddItem("Ocean color"); - colorComboBox->SetTooltip("Choose the destination data of the color picker."); - weatherWindow->AddWidget(colorComboBox); + colorComboBox.Create("Color picker mode: "); + colorComboBox.SetSize(XMFLOAT2(120, hei)); + colorComboBox.SetPos(XMFLOAT2(x + 150, y += step)); + colorComboBox.AddItem("Ambient color"); + colorComboBox.AddItem("Horizon color"); + colorComboBox.AddItem("Zenith color"); + colorComboBox.AddItem("Ocean color"); + colorComboBox.SetTooltip("Choose the destination data of the color picker."); + AddWidget(&colorComboBox); y += 10; - colorPicker = new wiColorPicker(GUI, "Color", false); - colorPicker->SetPos(XMFLOAT2(x, y += step)); - colorPicker->SetVisible(false); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { + colorPicker.Create("Color", false); + colorPicker.SetPos(XMFLOAT2(x, y += step)); + colorPicker.SetVisible(false); + colorPicker.SetEnabled(true); + colorPicker.OnColorChanged([&](wiEventArgs args) { auto& weather = GetWeather(); - switch (colorComboBox->GetSelected()) + switch (colorComboBox.GetSelected()) { default: case 0: @@ -355,15 +352,15 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) break; } }); - weatherWindow->AddWidget(colorPicker); + AddWidget(&colorPicker); - y += colorPicker->GetScale().y; + y += colorPicker.GetScale().y; - wiButton* preset0Button = new wiButton("WeatherPreset - Default"); - preset0Button->SetTooltip("Apply this weather preset to the world."); - preset0Button->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - preset0Button->SetPos(XMFLOAT2(x, y += step)); - preset0Button->OnClick([=](wiEventArgs args) { + preset0Button.Create("WeatherPreset - Default"); + preset0Button.SetTooltip("Apply this weather preset to the world."); + preset0Button.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + preset0Button.SetPos(XMFLOAT2(x, y += step)); + preset0Button.OnClick([=](wiEventArgs args) { Scene& scene = wiScene::GetScene(); scene.weathers.Clear(); @@ -372,13 +369,13 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) InvalidateProbes(); }); - weatherWindow->AddWidget(preset0Button); + AddWidget(&preset0Button); - wiButton* preset1Button = new wiButton("WeatherPreset - Daytime"); - preset1Button->SetTooltip("Apply this weather preset to the world."); - preset1Button->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - preset1Button->SetPos(XMFLOAT2(x, y += step)); - preset1Button->OnClick([=](wiEventArgs args) { + preset1Button.Create("WeatherPreset - Daytime"); + preset1Button.SetTooltip("Apply this weather preset to the world."); + preset1Button.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + preset1Button.SetPos(XMFLOAT2(x, y += step)); + preset1Button.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); weather.ambient = XMFLOAT3(33.0f / 255.0f, 47.0f / 255.0f, 127.0f / 255.0f); @@ -392,13 +389,13 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) InvalidateProbes(); }); - weatherWindow->AddWidget(preset1Button); + AddWidget(&preset1Button); - wiButton* preset2Button = new wiButton("WeatherPreset - Sunset"); - preset2Button->SetTooltip("Apply this weather preset to the world."); - preset2Button->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - preset2Button->SetPos(XMFLOAT2(x, y += step)); - preset2Button->OnClick([=](wiEventArgs args) { + preset2Button.Create("WeatherPreset - Sunset"); + preset2Button.SetTooltip("Apply this weather preset to the world."); + preset2Button.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + preset2Button.SetPos(XMFLOAT2(x, y += step)); + preset2Button.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); weather.ambient = XMFLOAT3(86.0f / 255.0f, 29.0f / 255.0f, 29.0f / 255.0f); @@ -412,13 +409,13 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) InvalidateProbes(); }); - weatherWindow->AddWidget(preset2Button); + AddWidget(&preset2Button); - wiButton* preset3Button = new wiButton("WeatherPreset - Cloudy"); - preset3Button->SetTooltip("Apply this weather preset to the world."); - preset3Button->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - preset3Button->SetPos(XMFLOAT2(x, y += step)); - preset3Button->OnClick([=](wiEventArgs args) { + preset3Button.Create("WeatherPreset - Cloudy"); + preset3Button.SetTooltip("Apply this weather preset to the world."); + preset3Button.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + preset3Button.SetPos(XMFLOAT2(x, y += step)); + preset3Button.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); weather.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); @@ -432,13 +429,13 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) InvalidateProbes(); }); - weatherWindow->AddWidget(preset3Button); + AddWidget(&preset3Button); - wiButton* preset4Button = new wiButton("WeatherPreset - Night"); - preset4Button->SetTooltip("Apply this weather preset to the world."); - preset4Button->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - preset4Button->SetPos(XMFLOAT2(x, y += step)); - preset4Button->OnClick([=](wiEventArgs args) { + preset4Button.Create("WeatherPreset - Night"); + preset4Button.SetTooltip("Apply this weather preset to the world."); + preset4Button.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + preset4Button.SetPos(XMFLOAT2(x, y += step)); + preset4Button.OnClick([=](wiEventArgs args) { auto& weather = GetWeather(); weather.ambient = XMFLOAT3(12.0f / 255.0f, 21.0f / 255.0f, 77.0f / 255.0f); @@ -452,14 +449,14 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) InvalidateProbes(); }); - weatherWindow->AddWidget(preset4Button); + AddWidget(&preset4Button); - wiButton* eliminateCoarseCascadesButton = new wiButton("EliminateCoarseCascades"); - eliminateCoarseCascadesButton->SetTooltip("Eliminate the coarse cascade mask for every object in the scene."); - eliminateCoarseCascadesButton->SetSize(XMFLOAT2(colorPicker->GetScale().x, hei)); - eliminateCoarseCascadesButton->SetPos(XMFLOAT2(x, y += step * 2)); - eliminateCoarseCascadesButton->OnClick([=](wiEventArgs args) { + eliminateCoarseCascadesButton.Create("EliminateCoarseCascades"); + eliminateCoarseCascadesButton.SetTooltip("Eliminate the coarse cascade mask for every object in the scene."); + eliminateCoarseCascadesButton.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei)); + eliminateCoarseCascadesButton.SetPos(XMFLOAT2(x, y += step * 2)); + eliminateCoarseCascadesButton.OnClick([=](wiEventArgs args) { Scene& scene = wiScene::GetScene(); for (size_t i = 0; i < scene.objects.GetCount(); ++i) @@ -468,21 +465,13 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) } }); - weatherWindow->AddWidget(eliminateCoarseCascadesButton); + AddWidget(&eliminateCoarseCascadesButton); - weatherWindow->Translate(XMFLOAT3(130, 30, 0)); - weatherWindow->SetVisible(false); -} - - -WeatherWindow::~WeatherWindow() -{ - weatherWindow->RemoveWidgets(true); - GUI->RemoveWidget(weatherWindow); - delete weatherWindow; + Translate(XMFLOAT3(130, 30, 0)); + SetVisible(false); } void WeatherWindow::Update() @@ -492,45 +481,45 @@ void WeatherWindow::Update() { auto& weather = scene.weathers[0]; - fogStartSlider->SetValue(weather.fogStart); - fogEndSlider->SetValue(weather.fogEnd); - fogHeightSlider->SetValue(weather.fogHeight); - cloudinessSlider->SetValue(weather.cloudiness); - cloudScaleSlider->SetValue(weather.cloudScale); - cloudSpeedSlider->SetValue(weather.cloudSpeed); - windSpeedSlider->SetValue(weather.windSpeed); - windWaveSizeSlider->SetValue(weather.windWaveSize); - windRandomnessSlider->SetValue(weather.windRandomness); - windMagnitudeSlider->SetValue(XMVectorGetX(XMVector3Length(XMLoadFloat3(&weather.windDirection)))); + fogStartSlider.SetValue(weather.fogStart); + fogEndSlider.SetValue(weather.fogEnd); + fogHeightSlider.SetValue(weather.fogHeight); + cloudinessSlider.SetValue(weather.cloudiness); + cloudScaleSlider.SetValue(weather.cloudScale); + cloudSpeedSlider.SetValue(weather.cloudSpeed); + windSpeedSlider.SetValue(weather.windSpeed); + windWaveSizeSlider.SetValue(weather.windWaveSize); + windRandomnessSlider.SetValue(weather.windRandomness); + windMagnitudeSlider.SetValue(XMVectorGetX(XMVector3Length(XMLoadFloat3(&weather.windDirection)))); - switch (colorComboBox->GetSelected()) + switch (colorComboBox.GetSelected()) { default: case 0: - colorPicker->SetPickColor(wiColor::fromFloat3(weather.ambient)); + colorPicker.SetPickColor(wiColor::fromFloat3(weather.ambient)); break; case 1: - colorPicker->SetPickColor(wiColor::fromFloat3(weather.horizon)); + colorPicker.SetPickColor(wiColor::fromFloat3(weather.horizon)); break; case 2: - colorPicker->SetPickColor(wiColor::fromFloat3(weather.zenith)); + colorPicker.SetPickColor(wiColor::fromFloat3(weather.zenith)); break; case 3: - colorPicker->SetPickColor(wiColor::fromFloat3(weather.oceanParameters.waterColor)); + colorPicker.SetPickColor(wiColor::fromFloat3(weather.oceanParameters.waterColor)); break; } - simpleskyCheckBox->SetCheck(weather.IsSimpleSky()); + simpleskyCheckBox.SetCheck(weather.IsSimpleSky()); - ocean_enabledCheckBox->SetCheck(weather.IsOceanEnabled()); - ocean_patchSizeSlider->SetValue(weather.oceanParameters.patch_length); - ocean_waveAmplitudeSlider->SetValue(weather.oceanParameters.wave_amplitude); - ocean_choppyScaleSlider->SetValue(weather.oceanParameters.choppy_scale); - ocean_windDependencySlider->SetValue(weather.oceanParameters.wind_dependency); - ocean_timeScaleSlider->SetValue(weather.oceanParameters.time_scale); - ocean_heightSlider->SetValue(weather.oceanParameters.waterHeight); - ocean_detailSlider->SetValue((float)weather.oceanParameters.surfaceDetail); - ocean_toleranceSlider->SetValue(weather.oceanParameters.surfaceDisplacementTolerance); + ocean_enabledCheckBox.SetCheck(weather.IsOceanEnabled()); + ocean_patchSizeSlider.SetValue(weather.oceanParameters.patch_length); + ocean_waveAmplitudeSlider.SetValue(weather.oceanParameters.wave_amplitude); + ocean_choppyScaleSlider.SetValue(weather.oceanParameters.choppy_scale); + ocean_windDependencySlider.SetValue(weather.oceanParameters.wind_dependency); + ocean_timeScaleSlider.SetValue(weather.oceanParameters.time_scale); + ocean_heightSlider.SetValue(weather.oceanParameters.waterHeight); + ocean_detailSlider.SetValue((float)weather.oceanParameters.surfaceDetail); + ocean_toleranceSlider.SetValue(weather.oceanParameters.surfaceDisplacementTolerance); } } @@ -557,9 +546,9 @@ void WeatherWindow::InvalidateProbes() const void WeatherWindow::UpdateWind() { - XMMATRIX rot = XMMatrixRotationY(windDirectionSlider->GetValue() * XM_PI * 2); + XMMATRIX rot = XMMatrixRotationY(windDirectionSlider.GetValue() * XM_PI * 2); XMVECTOR dir = XMVectorSet(1, 0, 0, 0); dir = XMVector3TransformNormal(dir, rot); - dir *= windMagnitudeSlider->GetValue(); + dir *= windMagnitudeSlider.GetValue(); XMStoreFloat3(&GetWeather().windDirection, dir); } diff --git a/Editor/WeatherWindow.h b/Editor/WeatherWindow.h index 766067337..5f0c1cc4a 100644 --- a/Editor/WeatherWindow.h +++ b/Editor/WeatherWindow.h @@ -1,59 +1,54 @@ #pragma once - -class wiGUI; -class wiWindow; -class wiLabel; -class wiCheckBox; -class wiSlider; -class wiColorPicker; -class wiButton; -class wiComboBox; +#include "WickedEngine.h" class EditorComponent; -class WeatherWindow +class WeatherWindow : public wiWindow { void UpdateWind(); public: - WeatherWindow(EditorComponent* editor); - ~WeatherWindow(); + void Create(EditorComponent* editor); void Update(); wiScene::WeatherComponent& GetWeather() const; void InvalidateProbes() const; - wiGUI* GUI; - - wiWindow* weatherWindow; - wiSlider* fogStartSlider; - wiSlider* fogEndSlider; - wiSlider* fogHeightSlider; - wiSlider* cloudinessSlider; - wiSlider* cloudScaleSlider; - wiSlider* cloudSpeedSlider; - wiSlider* windSpeedSlider; - wiSlider* windMagnitudeSlider; - wiSlider* windDirectionSlider; - wiSlider* windWaveSizeSlider; - wiSlider* windRandomnessSlider; - wiCheckBox* simpleskyCheckBox; - wiCheckBox* realisticskyCheckBox; - wiButton* skyButton; + wiSlider fogStartSlider; + wiSlider fogEndSlider; + wiSlider fogHeightSlider; + wiSlider cloudinessSlider; + wiSlider cloudScaleSlider; + wiSlider cloudSpeedSlider; + wiSlider windSpeedSlider; + wiSlider windMagnitudeSlider; + wiSlider windDirectionSlider; + wiSlider windWaveSizeSlider; + wiSlider windRandomnessSlider; + wiCheckBox simpleskyCheckBox; + wiCheckBox realisticskyCheckBox; + wiButton skyButton; // ocean params: - wiCheckBox* ocean_enabledCheckBox; - wiSlider* ocean_patchSizeSlider; - wiSlider* ocean_waveAmplitudeSlider; - wiSlider* ocean_choppyScaleSlider; - wiSlider* ocean_windDependencySlider; - wiSlider* ocean_timeScaleSlider; - wiSlider* ocean_heightSlider; - wiSlider* ocean_detailSlider; - wiSlider* ocean_toleranceSlider; - wiButton* ocean_resetButton; + wiCheckBox ocean_enabledCheckBox; + wiSlider ocean_patchSizeSlider; + wiSlider ocean_waveAmplitudeSlider; + wiSlider ocean_choppyScaleSlider; + wiSlider ocean_windDependencySlider; + wiSlider ocean_timeScaleSlider; + wiSlider ocean_heightSlider; + wiSlider ocean_detailSlider; + wiSlider ocean_toleranceSlider; + wiButton ocean_resetButton; - wiComboBox* colorComboBox; - wiColorPicker* colorPicker; + wiComboBox colorComboBox; + wiColorPicker colorPicker; + + wiButton preset0Button; + wiButton preset1Button; + wiButton preset2Button; + wiButton preset3Button; + wiButton preset4Button; + wiButton eliminateCoarseCascadesButton; }; diff --git a/README.md b/README.md index e9a32bb8c..969cd9adf 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ while(true) { #### Basics (C++): ```cpp -RenderPath3D_Deferred myGame; // Declare a game screen component, aka "RenderPath" (you could also override its Update(), Render() etc. functions). This is a 3D, Deferred path for example, but there are others +RenderPath3D myGame; // Declare a game screen component, aka "RenderPath" (you could also override its Update(), Render() etc. functions). main.ActivatePath(&myGame); // Register your game to the application. It will call Start(), Update(), Render(), etc. from now on... wiScene::LoadModel("myModel.wiscene"); // Simply load a model into the current global scene @@ -129,7 +129,7 @@ if (wiInput::Down(wiInput::KEYBOARD_BUTTON_SPACE)) { wiAudio::Play(&mySoundInsta #### Scripting (LUA): ```lua -- Set a rendering path for the application main component -path = RenderPath3D_Deferred; +path = RenderPath3D; main.SetActivePath(path); -- "main" is created automatically -- Load a model entity into the global scene: diff --git a/Template_UWP/Template_UWP.vcxproj b/Template_UWP/Template_UWP.vcxproj index 8d5e785fc..8101bee57 100644 --- a/Template_UWP/Template_UWP.vcxproj +++ b/Template_UWP/Template_UWP.vcxproj @@ -475,6 +475,39 @@ + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + + + Document + Document diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 183da4238..5617076ce 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -26,11 +26,11 @@ void Tests::Initialize() void TestsRenderer::ResizeLayout() { - RenderPath3D_TiledForward::ResizeLayout(); + RenderPath3D::ResizeLayout(); float screenW = wiRenderer::GetDevice()->GetScreenWidth(); float screenH = wiRenderer::GetDevice()->GetScreenHeight(); - label->SetPos(XMFLOAT2(screenW / 2.f - label->scale.x / 2.f, screenH * 0.95f)); + label.SetPos(XMFLOAT2(screenW / 2.f - label.scale.x / 2.f, screenH * 0.95f)); } void TestsRenderer::Load() { @@ -38,22 +38,23 @@ void TestsRenderer::Load() setReflectionsEnabled(true); setFXAAEnabled(false); - label = new wiLabel("Label1"); - label->SetText("Wicked Engine Test Framework"); - label->font.params.h_align = WIFALIGN_CENTER; - label->SetSize(XMFLOAT2(240,20)); - GetGUI().AddWidget(label); + label.Create("Label1"); + label.SetText("Wicked Engine Test Framework"); + label.font.params.h_align = WIFALIGN_CENTER; + label.SetSize(XMFLOAT2(240,20)); + GetGUI().AddWidget(&label); static wiAudio::Sound sound; static wiAudio::SoundInstance soundinstance; - wiButton* audioTest = new wiButton("AudioTest"); - audioTest->SetText("Play Test Audio"); - audioTest->SetSize(XMFLOAT2(200, 20)); - audioTest->SetPos(XMFLOAT2(10, 140)); - audioTest->SetColor(wiColor(255, 205, 43, 200), wiWidget::WIDGETSTATE::IDLE); - audioTest->SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); - audioTest->OnClick([=](wiEventArgs args) { + static wiButton audioTest; + audioTest.Create("AudioTest"); + audioTest.SetText("Play Test Audio"); + audioTest.SetSize(XMFLOAT2(200, 20)); + audioTest.SetPos(XMFLOAT2(10, 140)); + audioTest.SetColor(wiColor(255, 205, 43, 200), wiWidget::WIDGETSTATE::IDLE); + audioTest.SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); + audioTest.OnClick([&](wiEventArgs args) { static bool playing = false; if (!sound.IsValid()) @@ -65,60 +66,61 @@ void TestsRenderer::Load() if (playing) { wiAudio::Stop(&soundinstance); - audioTest->SetText("Play Test Audio"); + audioTest.SetText("Play Test Audio"); } else { wiAudio::Play(&soundinstance); - audioTest->SetText("Stop Test Audio"); + audioTest.SetText("Stop Test Audio"); } playing = !playing; }); - GetGUI().AddWidget(audioTest); + GetGUI().AddWidget(&audioTest); - wiSlider* volume = new wiSlider(0, 100, 50, 100, "Volume"); - volume->SetText("Volume: "); - volume->SetSize(XMFLOAT2(100, 20)); - volume->SetPos(XMFLOAT2(65, 170)); - volume->sprites_knob[wiWidget::WIDGETSTATE::IDLE].params.color = wiColor(255, 205, 43, 200); - volume->sprites_knob[wiWidget::WIDGETSTATE::FOCUS].params.color = wiColor(255, 235, 173, 255); - volume->sprites[wiWidget::WIDGETSTATE::IDLE].params.color = wiMath::Lerp(wiColor::Transparent(), volume->sprites_knob[wiWidget::WIDGETSTATE::IDLE].params.color, 0.5f); - volume->sprites[wiWidget::WIDGETSTATE::FOCUS].params.color = wiMath::Lerp(wiColor::Transparent(), volume->sprites_knob[wiWidget::WIDGETSTATE::FOCUS].params.color, 0.5f); - volume->OnSlide([](wiEventArgs args) { + static wiSlider volume; + volume.Create(0, 100, 50, 100, "Volume"); + volume.SetText("Volume: "); + volume.SetSize(XMFLOAT2(100, 20)); + volume.SetPos(XMFLOAT2(65, 170)); + volume.sprites_knob[wiWidget::WIDGETSTATE::IDLE].params.color = wiColor(255, 205, 43, 200); + volume.sprites_knob[wiWidget::WIDGETSTATE::FOCUS].params.color = wiColor(255, 235, 173, 255); + volume.sprites[wiWidget::WIDGETSTATE::IDLE].params.color = wiMath::Lerp(wiColor::Transparent(), volume.sprites_knob[wiWidget::WIDGETSTATE::IDLE].params.color, 0.5f); + volume.sprites[wiWidget::WIDGETSTATE::FOCUS].params.color = wiMath::Lerp(wiColor::Transparent(), volume.sprites_knob[wiWidget::WIDGETSTATE::FOCUS].params.color, 0.5f); + volume.OnSlide([](wiEventArgs args) { wiAudio::SetVolume(args.fValue / 100.0f, &soundinstance); }); - GetGUI().AddWidget(volume); + GetGUI().AddWidget(&volume); - testSelector = new wiComboBox("TestSelector"); - testSelector->SetText("Demo: "); - testSelector->SetSize(XMFLOAT2(140, 20)); - testSelector->SetPos(XMFLOAT2(50, 200)); - testSelector->SetColor(wiColor(255, 205, 43, 200), wiWidget::WIDGETSTATE::IDLE); - testSelector->SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); - testSelector->AddItem("HelloWorld"); - testSelector->AddItem("Model"); - testSelector->AddItem("EmittedParticle 1"); - testSelector->AddItem("EmittedParticle 2"); - testSelector->AddItem("HairParticle"); - testSelector->AddItem("Lua Script"); - testSelector->AddItem("Water Test"); - testSelector->AddItem("Shadows Test"); - testSelector->AddItem("Physics Test"); - testSelector->AddItem("Cloth Physics Test"); - testSelector->AddItem("Job System Test"); - testSelector->AddItem("Font Test"); - testSelector->AddItem("Volumetric Test"); - testSelector->AddItem("Sprite Test"); - testSelector->AddItem("Lightmap Bake Test"); - testSelector->AddItem("Network Test"); - testSelector->AddItem("Controller Test"); - testSelector->AddItem("Inverse Kinematics"); - testSelector->AddItem("65k Instances"); - testSelector->SetMaxVisibleItemCount(10); - testSelector->OnSelect([=](wiEventArgs args) { + testSelector.Create("TestSelector"); + testSelector.SetText("Demo: "); + testSelector.SetSize(XMFLOAT2(140, 20)); + testSelector.SetPos(XMFLOAT2(50, 200)); + testSelector.SetColor(wiColor(255, 205, 43, 200), wiWidget::WIDGETSTATE::IDLE); + testSelector.SetColor(wiColor(255, 235, 173, 255), wiWidget::WIDGETSTATE::FOCUS); + testSelector.AddItem("HelloWorld"); + testSelector.AddItem("Model"); + testSelector.AddItem("EmittedParticle 1"); + testSelector.AddItem("EmittedParticle 2"); + testSelector.AddItem("HairParticle"); + testSelector.AddItem("Lua Script"); + testSelector.AddItem("Water Test"); + testSelector.AddItem("Shadows Test"); + testSelector.AddItem("Physics Test"); + testSelector.AddItem("Cloth Physics Test"); + testSelector.AddItem("Job System Test"); + testSelector.AddItem("Font Test"); + testSelector.AddItem("Volumetric Test"); + testSelector.AddItem("Sprite Test"); + testSelector.AddItem("Lightmap Bake Test"); + testSelector.AddItem("Network Test"); + testSelector.AddItem("Controller Test"); + testSelector.AddItem("Inverse Kinematics"); + testSelector.AddItem("65k Instances"); + testSelector.SetMaxVisibleItemCount(10); + testSelector.OnSelect([=](wiEventArgs args) { // Reset all state that tests might have modified: wiRenderer::GetDevice()->SetVSyncEnabled(true); @@ -294,14 +296,14 @@ void TestsRenderer::Load() } }); - testSelector->SetSelected(0); - GetGUI().AddWidget(testSelector); + testSelector.SetSelected(0); + GetGUI().AddWidget(&testSelector); - RenderPath3D_TiledForward::Load(); + RenderPath3D::Load(); } void TestsRenderer::Update(float dt) { - switch (testSelector->GetSelected()) + switch (testSelector.GetSelected()) { case 1: { @@ -363,7 +365,7 @@ void TestsRenderer::Update(float dt) break; } - RenderPath3D_TiledForward::Update(dt); + RenderPath3D::Update(dt); } void TestsRenderer::RunJobSystemTest() diff --git a/Tests/Tests.h b/Tests/Tests.h index e5bb5ed32..654fc1a6d 100644 --- a/Tests/Tests.h +++ b/Tests/Tests.h @@ -2,10 +2,10 @@ #include "WickedEngine.h" -class TestsRenderer : public RenderPath3D_TiledForward +class TestsRenderer : public RenderPath3D { - wiLabel* label = nullptr; - wiComboBox* testSelector = nullptr; + wiLabel label; + wiComboBox testSelector; wiECS::Entity ik_entity = wiECS::INVALID_ENTITY; public: void Load() override; diff --git a/WickedEngine/ArchiveVersionHistory.txt b/WickedEngine/ArchiveVersionHistory.txt index c62dce27b..8b6478527 100644 --- a/WickedEngine/ArchiveVersionHistory.txt +++ b/WickedEngine/ArchiveVersionHistory.txt @@ -1,5 +1,8 @@ This file contains changelog of wiArchive versions +52: Serialized MaterialComponent::subsurfaceProfile +51: Serialized MeshComponent::vertex_tangents +50: Serialized MaterialComponent::SHADERTYPE 49: Particles are just using material's shading rate, so removed shading rate from particles 48: Serialized shading rate for material and particles 47: Serialized animation speed diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index f4a25edd1..8cec924e4 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -17,15 +17,7 @@ add_library(WickedEngine STATIC RenderPath2D_BindLua.cpp RenderPath3D.cpp RenderPath3D_BindLua.cpp - RenderPath3D_Deferred.cpp - RenderPath3D_Deferred_BindLua.cpp - RenderPath3D_Forward.cpp - RenderPath3D_Forward_BindLua.cpp RenderPath3D_PathTracing.cpp - RenderPath3D_TiledDeferred.cpp - RenderPath3D_TiledDeferred_BindLua.cpp - RenderPath3D_TiledForward.cpp - RenderPath3D_TiledForward_BindLua.cpp SpriteAnim_BindLua.cpp Texture_BindLua.cpp Vector_BindLua.cpp diff --git a/WickedEngine/ConstantBufferMapping.h b/WickedEngine/ConstantBufferMapping.h index 750510524..53c8d6b5f 100644 --- a/WickedEngine/ConstantBufferMapping.h +++ b/WickedEngine/ConstantBufferMapping.h @@ -20,7 +20,6 @@ #define CBSLOT_RENDERER_MISC 5 #define CBSLOT_RENDERER_MATERIAL 6 #define CBSLOT_RENDERER_FORWARD_LIGHTMASK 7 -#define CBSLOT_RENDERER_CUBEMAPRENDER 7 #define CBSLOT_RENDERER_VOLUMELIGHT 7 #define CBSLOT_RENDERER_LENSFLARE 7 #define CBSLOT_RENDERER_DECAL 7 @@ -31,6 +30,7 @@ #define CBSLOT_RENDERER_BVH 7 #define CBSLOT_RENDERER_UTILITY 7 #define CBSLOT_RENDERER_POSTPROCESS 7 +#define CBSLOT_RENDERER_CUBEMAPRENDER 8 #define CBSLOT_OTHER_EMITTEDPARTICLE 7 #define CBSLOT_OTHER_HAIRPARTICLE 7 diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index 9642592fd..531614a84 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -2,10 +2,6 @@ #include "RenderPath_BindLua.h" #include "RenderPath3D_BindLua.h" #include "RenderPath2D_BindLua.h" -#include "RenderPath3D_Deferred_BindLua.h" -#include "RenderPath3D_Forward_BindLua.h" -#include "RenderPath3D_TiledForward_BindLua.h" -#include "RenderPath3D_TiledDeferred_BindLua.h" #include "LoadingScreen_BindLua.h" #include "wiProfiler.h" @@ -44,38 +40,6 @@ int MainComponent_BindLua::GetActivePath(lua_State *L) return 0; } - //return deferred 3d component if the active one is of that type - RenderPath3D_Deferred* compDef3D = dynamic_cast(component->GetActivePath()); - if (compDef3D != nullptr) - { - Luna::push(L, new RenderPath3D_Deferred_BindLua(compDef3D)); - return 1; - } - - //return tiled deferred 3d component if the active one is of that type - RenderPath3D_TiledDeferred* compTDef3D = dynamic_cast(component->GetActivePath()); - if (compTDef3D != nullptr) - { - Luna::push(L, new RenderPath3D_TiledDeferred_BindLua(compTDef3D)); - return 1; - } - - //return tiled forward 3d component if the active one is of that type - RenderPath3D_TiledForward* compTFwd3D = dynamic_cast(component->GetActivePath()); - if (compTFwd3D != nullptr) - { - Luna::push(L, new RenderPath3D_TiledForward_BindLua(compTFwd3D)); - return 1; - } - - //return forward 3d component if the active one is of that type - RenderPath3D_Forward* compFwd3D = dynamic_cast(component->GetActivePath()); - if (compFwd3D != nullptr) - { - Luna::push(L, new RenderPath3D_Forward_BindLua(compFwd3D)); - return 1; - } - //return 3d component if the active one is of that type RenderPath3D* comp3D = dynamic_cast(component->GetActivePath()); if (comp3D != nullptr) @@ -141,34 +105,6 @@ int MainComponent_BindLua::SetActivePath(lua_State *L) } } - RenderPath3D_Forward_BindLua* compFwd3D = Luna::lightcheck(L, 1); - if (compFwd3D != nullptr) - { - component->ActivatePath(compFwd3D->component, fadeSeconds, fadeColor); - return 0; - } - - RenderPath3D_Deferred_BindLua* compDef3D = Luna::lightcheck(L, 1); - if (compDef3D != nullptr) - { - component->ActivatePath(compDef3D->component, fadeSeconds, fadeColor); - return 0; - } - - RenderPath3D_TiledDeferred_BindLua* compTDef3D = Luna::lightcheck(L, 1); - if (compTDef3D != nullptr) - { - component->ActivatePath(compTDef3D->component, fadeSeconds, fadeColor); - return 0; - } - - RenderPath3D_TiledForward_BindLua* compTFwd3D = Luna::lightcheck(L, 1); - if (compTFwd3D != nullptr) - { - component->ActivatePath(compTFwd3D->component, fadeSeconds, fadeColor); - return 0; - } - RenderPath3D_BindLua* comp3D = Luna::lightcheck(L, 1); if (comp3D != nullptr) { diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index b6550cd69..1ace4565d 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -17,6 +17,112 @@ void RenderPath3D::ResizeBuffers() // Render targets: + + { + TextureDesc desc; + desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; + if (getMSAASampleCount() == 1) + { + desc.BindFlags |= BIND_UNORDERED_ACCESS; + } + desc.Width = wiRenderer::GetInternalResolution().x; + desc.Height = wiRenderer::GetInternalResolution().y; + desc.SampleCount = getMSAASampleCount(); + + desc.Format = FORMAT_R8G8B8A8_UNORM; + device->CreateTexture(&desc, nullptr, &rtGbuffer[GBUFFER_ALBEDO_ROUGHNESS]); + device->SetName(&rtGbuffer[GBUFFER_ALBEDO_ROUGHNESS], "rtGbuffer[GBUFFER_ALBEDO_ROUGHNESS]"); + + desc.Format = FORMAT_R16G16B16A16_FLOAT; + device->CreateTexture(&desc, nullptr, &rtGbuffer[GBUFFER_NORMAL_VELOCITY]); + device->SetName(&rtGbuffer[GBUFFER_NORMAL_VELOCITY], "rtGbuffer[GBUFFER_NORMAL_VELOCITY]"); + + desc.Format = FORMAT_R11G11B10_FLOAT; + device->CreateTexture(&desc, nullptr, &rtGbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE]); + device->SetName(&rtGbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE], "rtGbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE]"); + device->CreateTexture(&desc, nullptr, &rtGbuffer[GBUFFER_LIGHTBUFFER_SPECULAR]); + device->SetName(&rtGbuffer[GBUFFER_LIGHTBUFFER_SPECULAR], "rtGbuffer[GBUFFER_LIGHTBUFFER_SPECULAR]"); + + if (getMSAASampleCount() > 1) + { + desc.SampleCount = 1; + desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; + + desc.Format = FORMAT_R8G8B8A8_UNORM; + device->CreateTexture(&desc, nullptr, &rtGbuffer_resolved[GBUFFER_ALBEDO_ROUGHNESS]); + device->SetName(&rtGbuffer_resolved[GBUFFER_ALBEDO_ROUGHNESS], "rtGbuffer_resolved[GBUFFER_ALBEDO_ROUGHNESS]"); + + desc.Format = FORMAT_R16G16B16A16_FLOAT; + device->CreateTexture(&desc, nullptr, &rtGbuffer_resolved[GBUFFER_NORMAL_VELOCITY]); + device->SetName(&rtGbuffer_resolved[GBUFFER_NORMAL_VELOCITY], "rtGbuffer_resolved[GBUFFER_NORMAL_VELOCITY]"); + + desc.Format = FORMAT_R11G11B10_FLOAT; + device->CreateTexture(&desc, nullptr, &rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_DIFFUSE]); + device->SetName(&rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_DIFFUSE], "rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_DIFFUSE]"); + device->CreateTexture(&desc, nullptr, &rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_SPECULAR]); + device->SetName(&rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_SPECULAR], "rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_SPECULAR]"); + } + + if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_INLINE)) + { + desc.BindFlags |= BIND_UNORDERED_ACCESS; + desc.Format = FORMAT_R11G11B10_FLOAT; + desc.SampleCount = 1; + + device->CreateTexture(&desc, nullptr, &rtDiffuseTemporal[0]); + device->SetName(&rtDiffuseTemporal[0], "rtDiffuseTemporal[0]"); + device->CreateTexture(&desc, nullptr, &rtDiffuseTemporal[1]); + device->SetName(&rtDiffuseTemporal[1], "rtDiffuseTemporal[1]"); + + device->CreateTexture(&desc, nullptr, &rtSpecularTemporal[0]); + device->SetName(&rtSpecularTemporal[0], "rtSpecularTemporal[0]"); + device->CreateTexture(&desc, nullptr, &rtSpecularTemporal[1]); + device->SetName(&rtSpecularTemporal[1], "rtSpecularTemporal[1]"); + } + } + { + TextureDesc desc; + desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; + if (getMSAASampleCount() == 1) + { + desc.BindFlags |= BIND_UNORDERED_ACCESS; + } + desc.Format = FORMAT_R11G11B10_FLOAT; + desc.Width = wiRenderer::GetInternalResolution().x; + desc.Height = wiRenderer::GetInternalResolution().y; + desc.SampleCount = getMSAASampleCount(); + device->CreateTexture(&desc, nullptr, &rtDeferred); + device->SetName(&rtDeferred, "rtDeferred"); + + if (getMSAASampleCount() > 1) + { + desc.SampleCount = 1; + desc.BindFlags |= BIND_UNORDERED_ACCESS; + + device->CreateTexture(&desc, nullptr, &rtDeferred_resolved); + device->SetName(&rtDeferred_resolved, "rtDeferred_resolved"); + } + } + { + TextureDesc desc; + desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; + desc.Format = FORMAT_R11G11B10_FLOAT; + desc.Width = wiRenderer::GetInternalResolution().x; + desc.Height = wiRenderer::GetInternalResolution().y; + desc.SampleCount = getMSAASampleCount(); + device->CreateTexture(&desc, nullptr, &rtSSS[0]); + device->SetName(&rtSSS[0], "rtSSS[0]"); + device->CreateTexture(&desc, nullptr, &rtSSS[1]); + device->SetName(&rtSSS[1], "rtSSS[1]"); + + if (getMSAASampleCount() > 1) + { + desc.SampleCount = 1; + + device->CreateTexture(&desc, nullptr, &rtSSS_resolved); + device->SetName(&rtSSS_resolved, "rtSSS_resolved"); + } + } { TextureDesc desc; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; @@ -240,6 +346,8 @@ void RenderPath3D::ResizeBuffers() desc.layout = IMAGE_LAYOUT_SHADER_RESOURCE; device->CreateTexture(&desc, nullptr, &depthBuffer_Copy); device->SetName(&depthBuffer_Copy, "depthBuffer_Copy"); + device->CreateTexture(&desc, nullptr, &depthBuffer_Copy1); + device->SetName(&depthBuffer_Copy1, "depthBuffer_Copy1"); } { TextureDesc desc; @@ -282,6 +390,115 @@ void RenderPath3D::ResizeBuffers() } // Render passes: + { + RenderPassDesc desc; + desc.attachments.push_back( + RenderPassAttachment::DepthStencil( + &depthBuffer, + RenderPassAttachment::LOADOP_CLEAR, + RenderPassAttachment::STOREOP_STORE, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY + ) + ); + device->CreateRenderPass(&desc, &renderpass_depthprepass); + + desc.attachments.clear(); + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_ALBEDO_ROUGHNESS], RenderPassAttachment::LOADOP_DONTCARE)); + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_NORMAL_VELOCITY], RenderPassAttachment::LOADOP_CLEAR)); + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE], RenderPassAttachment::LOADOP_CLEAR)); + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_LIGHTBUFFER_SPECULAR], RenderPassAttachment::LOADOP_CLEAR)); + desc.attachments.push_back( + RenderPassAttachment::DepthStencil( + &depthBuffer, + RenderPassAttachment::LOADOP_LOAD, + RenderPassAttachment::STOREOP_STORE, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY + ) + ); + if (getMSAASampleCount() > 1) + { + desc.attachments.push_back(RenderPassAttachment::Resolve(GetGbuffer_Read(GBUFFER_ALBEDO_ROUGHNESS))); + desc.attachments.push_back(RenderPassAttachment::Resolve(GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY))); + desc.attachments.push_back(RenderPassAttachment::Resolve(GetGbuffer_Read(GBUFFER_LIGHTBUFFER_DIFFUSE))); + desc.attachments.push_back(RenderPassAttachment::Resolve(GetGbuffer_Read(GBUFFER_LIGHTBUFFER_SPECULAR))); + } + device->CreateRenderPass(&desc, &renderpass_main); + } + { + RenderPassDesc desc; + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtDeferred, RenderPassAttachment::LOADOP_LOAD)); + desc.attachments.push_back( + RenderPassAttachment::DepthStencil( + &depthBuffer, + RenderPassAttachment::LOADOP_LOAD, + RenderPassAttachment::STOREOP_STORE, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY + ) + ); + if (getMSAASampleCount() > 1) + { + desc.attachments.push_back(RenderPassAttachment::Resolve(GetDeferred_Read())); + } + device->CreateRenderPass(&desc, &renderpass_transparent); + } + { + RenderPassDesc desc; + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtDeferred, RenderPassAttachment::LOADOP_LOAD)); + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_NORMAL_VELOCITY], RenderPassAttachment::LOADOP_LOAD)); + desc.attachments.push_back( + RenderPassAttachment::DepthStencil( + &depthBuffer, + RenderPassAttachment::LOADOP_LOAD, + RenderPassAttachment::STOREOP_STORE, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY + ) + ); + + if (getMSAASampleCount() > 1) + { + desc.attachments.push_back(RenderPassAttachment::Resolve(GetDeferred_Read())); + desc.attachments.push_back(RenderPassAttachment::Resolve(GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY))); + } + device->CreateRenderPass(&desc, &renderpass_deferredcomposition); + } + { + RenderPassDesc desc; + desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE], RenderPassAttachment::LOADOP_LOAD)); + desc.attachments.push_back( + RenderPassAttachment::DepthStencil( + &depthBuffer, + RenderPassAttachment::LOADOP_LOAD, + RenderPassAttachment::STOREOP_STORE, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY + ) + ); + + if (getMSAASampleCount() > 1) + { + desc.attachments.push_back(RenderPassAttachment::Resolve(&rtGbuffer_resolved[GBUFFER_LIGHTBUFFER_DIFFUSE])); + } + device->CreateRenderPass(&desc, &renderpass_SSS[0]); + + if (getMSAASampleCount() > 1) + { + desc.attachments.back() = RenderPassAttachment::Resolve(&rtSSS_resolved); + } + desc.attachments[0].texture = &rtSSS[0]; + device->CreateRenderPass(&desc, &renderpass_SSS[1]); + + desc.attachments[0].texture = &rtSSS[1]; + device->CreateRenderPass(&desc, &renderpass_SSS[2]); + } { RenderPassDesc desc; desc.attachments.push_back( @@ -406,6 +623,173 @@ void RenderPath3D::Update(float dt) RenderPath2D::Update(dt); wiRenderer::UpdatePerFrameData(dt, getLayerMask()); + + std::swap(depthBuffer_Copy, depthBuffer_Copy1); +} + +void RenderPath3D::Render() const +{ + GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context ctx; + CommandList cmd; + + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderFrameSetUp(cmd); }); + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderShadows(cmd); }); + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderReflections(cmd); }); + + + static const uint32_t drawscene_flags = + wiRenderer::DRAWSCENE_OPAQUE | + wiRenderer::DRAWSCENE_HAIRPARTICLE | + wiRenderer::DRAWSCENE_TESSELLATION | + wiRenderer::DRAWSCENE_OCCLUSIONCULLING + ; + + // Main scene: + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { + + GraphicsDevice* device = wiRenderer::GetDevice(); + wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); + + // depth prepass + { + auto range = wiProfiler::BeginRangeGPU("Z-Prepass", cmd); + + device->RenderPassBegin(&renderpass_depthprepass, cmd); + + Viewport vp; + vp.Width = (float)depthBuffer.GetDesc().Width; + vp.Height = (float)depthBuffer.GetDesc().Height; + device->BindViewports(1, &vp, cmd); + + wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_DEPTHONLY, cmd, drawscene_flags); + + device->RenderPassEnd(cmd); + + wiProfiler::EndRange(range); + } + + if (getMSAASampleCount() > 1) + { + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_SHADER_RESOURCE), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_GENERAL) + }; + device->Barrier(barriers, arraysize(barriers), cmd); + } + + wiRenderer::ResolveMSAADepthBuffer(depthBuffer_Copy, depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_GENERAL, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, arraysize(barriers), cmd); + } + } + else + { + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_COPY_SRC), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) + }; + device->Barrier(barriers, arraysize(barriers), cmd); + } + + device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, arraysize(barriers), cmd); + } + } + + RenderLinearDepth(cmd); + + RenderAO(cmd); + }); + + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { + + GraphicsDevice* device = wiRenderer::GetDevice(); + wiRenderer::ComputeTiledLightCulling( + depthBuffer_Copy, + cmd + ); + + if (wiRenderer::GetVariableRateShadingClassification() && device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)) + { + wiRenderer::ComputeShadingRateClassification(GetGbuffer_Read(), rtLinearDepth, rtShadingRate, cmd); + device->BindShadingRate(SHADING_RATE_1X1, cmd); + device->BindShadingRateImage(&rtShadingRate, cmd); + } + + device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd); + + // Opaque scene: + { + auto range = wiProfiler::BeginRangeGPU("Opaque Scene", cmd); + + device->RenderPassBegin(&renderpass_main, cmd); + + Viewport vp; + vp.Width = (float)depthBuffer.GetDesc().Width; + vp.Height = (float)depthBuffer.GetDesc().Height; + device->BindViewports(1, &vp, cmd); + + device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd); + device->BindResource(PS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd); + device->BindResource(PS, getSSREnabled() || getRaytracedReflectionEnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, cmd); + wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_MAIN, cmd, drawscene_flags); + + device->RenderPassEnd(cmd); + + wiProfiler::EndRange(range); // Opaque Scene + } + + device->BindShadingRateImage(nullptr, cmd); + }); + + cmd = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { + + GraphicsDevice* device = wiRenderer::GetDevice(); + wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); + wiRenderer::BindCommonResources(cmd); + + RenderSSS(cmd); + + RenderDeferredComposition(cmd); + + DownsampleDepthBuffer(cmd); + + RenderLightShafts(cmd); + + RenderVolumetrics(cmd); + + RenderSceneMIPChain(cmd); + + RenderSSR(cmd); + + RenderTransparents(cmd); + + RenderPostprocessChain(cmd); + }); + + RenderPath2D::Render(); + + wiJobSystem::Wait(ctx); } void RenderPath3D::Compose(CommandList cmd) const @@ -433,7 +817,7 @@ void RenderPath3D::RenderFrameSetUp(CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); - device->BindResource(CS, &depthBuffer_Copy, TEXSLOT_DEPTH, cmd); + device->BindResource(CS, &depthBuffer_Copy1, TEXSLOT_DEPTH, cmd); wiRenderer::UpdateRenderData(cmd); if (getAO() == AO_RTAO || wiRenderer::GetRaytracedShadowsEnabled() || getRaytracedReflectionEnabled()) @@ -501,6 +885,73 @@ void RenderPath3D::RenderShadows(CommandList cmd) const wiRenderer::VoxelRadiance(cmd); } +void RenderPath3D::RenderSSS(CommandList cmd) const +{ + if (getSSSEnabled() && getSSSBlurAmount() > 0) + { + wiRenderer::Postprocess_SSS( + rtLinearDepth, + GetGbuffer_Read(), + renderpass_SSS[0], + renderpass_SSS[1], + renderpass_SSS[2], + cmd, + getSSSBlurAmount() + ); + } +} +void RenderPath3D::RenderDeferredComposition(CommandList cmd) const +{ + GraphicsDevice* device = wiRenderer::GetDevice(); + + auto range = wiProfiler::BeginRangeGPU("Sky and Composition", cmd); + + if (wiRenderer::GetRaytracedShadowsEnabled() && device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_INLINE)) + { + int output = device->GetFrameCount() % 2; + int history = 1 - output; + + wiRenderer::Postprocess_Denoise( + *GetGbuffer_Read(GBUFFER_LIGHTBUFFER_DIFFUSE), + rtDiffuseTemporal[history], + rtDiffuseTemporal[output], + *GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY), + rtLinearDepth, + depthBuffer_Copy1, + cmd + ); + wiRenderer::Postprocess_Denoise( + *GetGbuffer_Read(GBUFFER_LIGHTBUFFER_SPECULAR), + rtSpecularTemporal[history], + rtSpecularTemporal[output], + *GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY), + rtLinearDepth, + depthBuffer_Copy1, + cmd + ); + } + + device->RenderPassBegin(&renderpass_deferredcomposition, cmd); + + Viewport vp; + vp.Width = (float)depthBuffer.GetDesc().Width; + vp.Height = (float)depthBuffer.GetDesc().Height; + device->BindViewports(1, &vp, cmd); + + wiRenderer::DeferredComposition( + GetGbuffer_Read(), + depthBuffer_Copy, + cmd + ); + + wiRenderer::DrawSky(cmd); + + RenderOutline(cmd); + + device->RenderPassEnd(cmd); + + wiProfiler::EndRange(range); +} void RenderPath3D::RenderLinearDepth(CommandList cmd) const { wiRenderer::Postprocess_Lineardepth(depthBuffer_Copy, rtLinearDepth, cmd); @@ -544,6 +995,7 @@ void RenderPath3D::RenderAO(CommandList cmd) const wiRenderer::Postprocess_RTAO( depthBuffer_Copy, rtLinearDepth, + depthBuffer_Copy1, rtAO, cmd, getAORange(), @@ -554,15 +1006,27 @@ void RenderPath3D::RenderAO(CommandList cmd) const } } } -void RenderPath3D::RenderSSR(const Texture& gbuffer1, const Texture& gbuffer2, CommandList cmd) const +void RenderPath3D::RenderSSR(CommandList cmd) const { if (getRaytracedReflectionEnabled()) { - wiRenderer::Postprocess_RTReflection(depthBuffer_Copy, gbuffer1, gbuffer2, rtSSR, cmd); + wiRenderer::Postprocess_RTReflection( + depthBuffer_Copy, + GetGbuffer_Read(), + rtSSR, + cmd + ); } else if (getSSREnabled()) { - wiRenderer::Postprocess_SSR(rtSceneCopy, depthBuffer_Copy, rtLinearDepth, gbuffer1, gbuffer2, rtSSR, cmd); + wiRenderer::Postprocess_SSR( + rtSceneCopy, + depthBuffer_Copy, + rtLinearDepth, + GetGbuffer_Read(), + rtSSR, + cmd + ); } } void RenderPath3D::DownsampleDepthBuffer(CommandList cmd) const @@ -643,7 +1107,7 @@ void RenderPath3D::RenderVolumetrics(CommandList cmd) const device->RenderPassEnd(cmd); } } -void RenderPath3D::RenderSceneMIPChain(const Texture& srcSceneRT, CommandList cmd) const +void RenderPath3D::RenderSceneMIPChain(CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -661,7 +1125,7 @@ void RenderPath3D::RenderSceneMIPChain(const Texture& srcSceneRT, CommandList cm fx.enableFullScreen(); fx.sampleFlag = SAMPLEMODE_CLAMP; fx.quality = QUALITY_LINEAR; - wiImage::Draw(&srcSceneRT, fx, cmd); + wiImage::Draw(GetDeferred_Read(), fx, cmd); device->RenderPassEnd(cmd); @@ -672,7 +1136,7 @@ void RenderPath3D::RenderSceneMIPChain(const Texture& srcSceneRT, CommandList cm device->EventEnd(cmd); wiProfiler::EndRange(range); } -void RenderPath3D::RenderTransparents(const RenderPass& renderpass_transparent, RENDERPASS renderPass, CommandList cmd) const +void RenderPath3D::RenderTransparents(CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -714,7 +1178,7 @@ void RenderPath3D::RenderTransparents(const RenderPass& renderpass_transparent, drawscene_flags |= wiRenderer::DRAWSCENE_TRANSPARENT; drawscene_flags |= wiRenderer::DRAWSCENE_OCCLUSIONCULLING; drawscene_flags |= wiRenderer::DRAWSCENE_HAIRPARTICLE; - wiRenderer::DrawScene(wiRenderer::GetCamera(), renderPass, cmd, drawscene_flags); + wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_MAIN, cmd, drawscene_flags); wiProfiler::EndRange(range); // Transparent Scene } @@ -770,12 +1234,12 @@ void RenderPath3D::RenderTransparents(const RenderPass& renderpass_transparent, wiProfiler::EndRange(range); } } -void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Texture& srcGbuffer1, CommandList cmd) const +void RenderPath3D::RenderPostprocessChain(CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); const Texture* rt_first = nullptr; // not ping-ponged with read / write - const Texture* rt_read = &srcSceneRT; + const Texture* rt_read = GetDeferred_Read(); const Texture* rt_write = &rtPostprocess_HDR; // 1.) HDR post process chain @@ -784,9 +1248,8 @@ void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Textu { const Texture* lightShaftTemp = nullptr; - wiRenderer::Postprocess_VolumetricClouds(rt_first == nullptr ? *rt_read : *rt_first, *rt_write, *lightShaftTemp, rtLinearDepth, depthBuffer_Copy, cmd); - rt_first = nullptr; - + wiRenderer::Postprocess_VolumetricClouds(*rt_read, *rt_write, *lightShaftTemp, rtLinearDepth, depthBuffer_Copy, cmd); + std::swap(rt_read, rt_write); device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd); } @@ -797,7 +1260,14 @@ void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Textu int output = device->GetFrameCount() % 2; int history = 1 - output; - wiRenderer::Postprocess_TemporalAA(*rt_read, rtTemporalAA[history], srcGbuffer1, rtLinearDepth, rtTemporalAA[output], cmd); + wiRenderer::Postprocess_TemporalAA( + *rt_read, rtTemporalAA[history], + *GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY), + rtLinearDepth, + depthBuffer_Copy1, + rtTemporalAA[output], + cmd + ); rt_first = &rtTemporalAA[output]; } @@ -812,7 +1282,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Textu if (getMotionBlurEnabled()) { - wiRenderer::Postprocess_MotionBlur(rt_first == nullptr ? *rt_read : *rt_first, srcGbuffer1, rtLinearDepth, *rt_write, cmd, getMotionBlurStrength()); + wiRenderer::Postprocess_MotionBlur(rt_first == nullptr ? *rt_read : *rt_first, *GetGbuffer_Read(GBUFFER_NORMAL_VELOCITY), rtLinearDepth, *rt_write, cmd, getMotionBlurStrength()); rt_first = nullptr; std::swap(rt_read, rt_write); @@ -835,7 +1305,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Textu wiRenderer::Postprocess_Tonemap( *rt_read, - getEyeAdaptionEnabled() ? *wiRenderer::ComputeLuminance(srcSceneRT, cmd) : *wiTextureHelper::getColor(wiColor::Gray()), + getEyeAdaptionEnabled() ? *wiRenderer::ComputeLuminance(*GetDeferred_Read(), cmd) : *wiTextureHelper::getColor(wiColor::Gray()), getMSAASampleCount() > 1 ? rtParticleDistortion_Resolved : rtParticleDistortion, *rt_write, cmd, diff --git a/WickedEngine/RenderPath3D.h b/WickedEngine/RenderPath3D.h index 2b4df16da..43f4764e9 100644 --- a/WickedEngine/RenderPath3D.h +++ b/WickedEngine/RenderPath3D.h @@ -34,6 +34,7 @@ private: uint32_t aoSampleCount = 16; float aoPower = 2.0f; float chromaticAberrationAmount = 2.0f; + float sssBlurAmount = 1.0f; AO ao = AO_DISABLED; bool fxaaEnabled = false; @@ -61,6 +62,12 @@ private: uint32_t msaaSampleCount = 1; protected: + wiGraphics::Texture rtGbuffer[GBUFFER_COUNT]; + wiGraphics::Texture rtGbuffer_resolved[GBUFFER_COUNT]; + wiGraphics::Texture rtDeferred; + wiGraphics::Texture rtDeferred_resolved; + wiGraphics::Texture rtSSS[2]; + wiGraphics::Texture rtSSS_resolved; wiGraphics::Texture rtReflection; // contains the scene rendered for planar reflections wiGraphics::Texture rtSSR; // standard screen-space reflection results wiGraphics::Texture rtSceneCopy; // contains the rendered scene that can be fed into transparent pass for distortion effect @@ -77,16 +84,22 @@ protected: wiGraphics::Texture rtSun_resolved; // sun render target, but the resolved version if MSAA is enabled wiGraphics::Texture rtGUIBlurredBackground[3]; // downsampled, gaussian blurred scene for GUI wiGraphics::Texture rtShadingRate; // UINT8 shading rate per tile + wiGraphics::Texture rtDiffuseTemporal[2]; // raytraced shadows denoise + wiGraphics::Texture rtSpecularTemporal[2]; // raytraced shadows denoise wiGraphics::Texture rtPostprocess_HDR; // ping-pong with main scene RT in HDR post-process chain wiGraphics::Texture rtPostprocess_LDR[2]; // ping-pong with itself in LDR post-process chain wiGraphics::Texture depthBuffer; // used for depth-testing, can be MSAA wiGraphics::Texture depthBuffer_Copy; // used for shader resource, single sample + wiGraphics::Texture depthBuffer_Copy1; // used for disocclusion check wiGraphics::Texture depthBuffer_Reflection; // used for reflection, single sample wiGraphics::Texture rtLinearDepth; // linear depth result + mipchain (max filter) wiGraphics::Texture smallDepth; // downsampled depth buffer + wiGraphics::RenderPass renderpass_depthprepass; + wiGraphics::RenderPass renderpass_main; + wiGraphics::RenderPass renderpass_transparent; wiGraphics::RenderPass renderpass_occlusionculling; wiGraphics::RenderPass renderpass_reflection; wiGraphics::RenderPass renderpass_downsampledepthbuffer; @@ -95,6 +108,53 @@ protected: wiGraphics::RenderPass renderpass_volumetriclight; wiGraphics::RenderPass renderpass_particledistortion; wiGraphics::RenderPass renderpass_waterripples; + wiGraphics::RenderPass renderpass_deferredcomposition; + wiGraphics::RenderPass renderpass_SSS[3]; + + const constexpr wiGraphics::Texture* GetGbuffer_Read() const + { + if (getMSAASampleCount() > 1) + { + return rtGbuffer_resolved; + } + else + { + return rtGbuffer; + } + } + const constexpr wiGraphics::Texture* GetGbuffer_Read(GBUFFER i) const + { + if (getMSAASampleCount() > 1) + { + return &rtGbuffer_resolved[i]; + } + else + { + return &rtGbuffer[i]; + } + } + const constexpr wiGraphics::Texture* GetDeferred_Read() const + { + if (getMSAASampleCount() > 1) + { + return &rtDeferred_resolved; + } + else + { + return &rtDeferred; + } + } + const constexpr wiGraphics::Texture* GetSSS_Read(int i) const + { + if (getMSAASampleCount() > 1) + { + return &rtSSS_resolved; + } + else + { + return &rtSSS[i]; + } + } // Post-processes are ping-ponged, this function helps to obtain the last postprocess render target that was written const wiGraphics::Texture* GetLastPostprocessRT() const @@ -113,16 +173,18 @@ protected: virtual void RenderReflections(wiGraphics::CommandList cmd) const; virtual void RenderShadows(wiGraphics::CommandList cmd) const; + virtual void RenderSSS(wiGraphics::CommandList cmd) const; + virtual void RenderDeferredComposition(wiGraphics::CommandList cmd) const; virtual void RenderLinearDepth(wiGraphics::CommandList cmd) const; virtual void RenderAO(wiGraphics::CommandList cmd) const; - virtual void RenderSSR(const wiGraphics::Texture& gbuffer1, const wiGraphics::Texture& gbuffer2, wiGraphics::CommandList cmd) const; + virtual void RenderSSR(wiGraphics::CommandList cmd) const; virtual void DownsampleDepthBuffer(wiGraphics::CommandList cmd) const; virtual void RenderOutline(wiGraphics::CommandList cmd) const; virtual void RenderLightShafts(wiGraphics::CommandList cmd) const; virtual void RenderVolumetrics(wiGraphics::CommandList cmd) const; - virtual void RenderSceneMIPChain(const wiGraphics::Texture& srcSceneRT, wiGraphics::CommandList cmd) const; - virtual void RenderTransparents(const wiGraphics::RenderPass& renderpass_transparent, RENDERPASS renderPass, wiGraphics::CommandList cmd) const; - virtual void RenderPostprocessChain(const wiGraphics::Texture& srcSceneRT, const wiGraphics::Texture& srcGbuffer1, wiGraphics::CommandList cmd) const; + virtual void RenderSceneMIPChain(wiGraphics::CommandList cmd) const; + virtual void RenderTransparents(wiGraphics::CommandList cmd) const; + virtual void RenderPostprocessChain(wiGraphics::CommandList cmd) const; public: const wiGraphics::Texture* GetDepthStencil() const override { return &depthBuffer; } @@ -142,6 +204,7 @@ public: constexpr uint32_t getAOSampleCount() const { return aoSampleCount; } constexpr float getAOPower() const { return aoPower; } constexpr float getChromaticAberrationAmount() const { return chromaticAberrationAmount; } + constexpr float getSSSBlurAmount() const { return sssBlurAmount; } constexpr bool getAOEnabled() const { return ao != AO_DISABLED; } constexpr AO getAO() const { return ao; } @@ -183,6 +246,7 @@ public: constexpr void setAOSampleCount(uint32_t value) { aoSampleCount = value; } constexpr void setAOPower(float value) { aoPower = value; } constexpr void setChromaticAberrationAmount(float value) { chromaticAberrationAmount = value; } + constexpr void setSSSBlurAmount(float value) { sssBlurAmount = value; } constexpr void setAO(AO value) { ao = value; } constexpr void setSSREnabled(bool value){ ssrEnabled = value; } @@ -210,7 +274,7 @@ public: virtual void setMSAASampleCount(uint32_t value) { if (msaaSampleCount != value) { msaaSampleCount = value; ResizeBuffers(); } } void Update(float dt) override; - void Render() const override = 0; + void Render() const override; void Compose(wiGraphics::CommandList cmd) const override; }; diff --git a/WickedEngine/RenderPath3D_BindLua.h b/WickedEngine/RenderPath3D_BindLua.h index 6a654889b..19f2e2ee2 100644 --- a/WickedEngine/RenderPath3D_BindLua.h +++ b/WickedEngine/RenderPath3D_BindLua.h @@ -16,7 +16,11 @@ public: { this->component = component; } - RenderPath3D_BindLua(lua_State* L) {} + RenderPath3D_BindLua(lua_State* L) + { + component = new RenderPath3D; + owning = true; + } int SetAO(lua_State* L); int SetSSREnabled(lua_State* L); diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp deleted file mode 100644 index 3157f5778..000000000 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ /dev/null @@ -1,363 +0,0 @@ -#include "RenderPath3D_Deferred.h" -#include "wiRenderer.h" -#include "wiImage.h" -#include "wiHelper.h" -#include "wiTextureHelper.h" -#include "wiSprite.h" -#include "ResourceMapping.h" -#include "wiProfiler.h" - -using namespace wiGraphics; - - -void RenderPath3D_Deferred::ResizeBuffers() -{ - RenderPath3D::ResizeBuffers(); - - GraphicsDevice* device = wiRenderer::GetDevice(); - - FORMAT defaultTextureFormat = device->GetBackBufferFormat(); - - { - TextureDesc desc; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; - - desc.Format = FORMAT_R8G8B8A8_UNORM; - device->CreateTexture(&desc, nullptr, &rtGBuffer[0]); - device->SetName(&rtGBuffer[0], "rtGBuffer[0]"); - - desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture(&desc, nullptr, &rtGBuffer[1]); - device->SetName(&rtGBuffer[1], "rtGBuffer[1]"); - - desc.Format = FORMAT_R8G8B8A8_UNORM; - device->CreateTexture(&desc, nullptr, &rtGBuffer[2]); - device->SetName(&rtGBuffer[2], "rtGBuffer[2]"); - } - { - TextureDesc desc; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture(&desc, nullptr, &rtDeferred); - device->SetName(&rtDeferred, "rtDeferred"); - } - { - TextureDesc desc; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture(&desc, nullptr, &lightbuffer_diffuse); - device->SetName(&lightbuffer_diffuse, "lightbuffer_diffuse"); - device->CreateTexture(&desc, nullptr, &lightbuffer_specular); - device->SetName(&lightbuffer_specular, "lightbuffer_specular"); - } - { - TextureDesc desc; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; - desc.Format = FORMAT_R11G11B10_FLOAT; - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture(&desc, nullptr, &rtSSS[0]); - device->SetName(&rtSSS[0], "rtSSS[0]"); - device->CreateTexture(&desc, nullptr, &rtSSS[1]); - device->SetName(&rtSSS[1], "rtSSS[1]"); - } - - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGBuffer[0], RenderPassAttachment::LOADOP_DONTCARE)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGBuffer[1], RenderPassAttachment::LOADOP_CLEAR)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGBuffer[2], RenderPassAttachment::LOADOP_DONTCARE)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&lightbuffer_diffuse, RenderPassAttachment::LOADOP_DONTCARE)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&lightbuffer_specular, RenderPassAttachment::LOADOP_DONTCARE)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_CLEAR, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_gbuffer); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&lightbuffer_diffuse, RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&lightbuffer_specular, RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_lights); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtGBuffer[0], RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_decals); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtDeferred, RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_deferredcomposition); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&lightbuffer_diffuse, RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_SSS[0]); - - desc.attachments[0].texture = &rtSSS[0]; - device->CreateRenderPass(&desc, &renderpass_SSS[1]); - - desc.attachments[0].texture = &rtSSS[1]; - device->CreateRenderPass(&desc, &renderpass_SSS[2]); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtDeferred, RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - - device->CreateRenderPass(&desc, &renderpass_transparent); - } -} - -void RenderPath3D_Deferred::Render() const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - wiJobSystem::context ctx; - CommandList cmd; - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderFrameSetUp(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderShadows(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderReflections(cmd); }); - - - static const uint32_t drawscene_flags = - wiRenderer::DRAWSCENE_OPAQUE | - wiRenderer::DRAWSCENE_HAIRPARTICLE | - wiRenderer::DRAWSCENE_TESSELLATION | - wiRenderer::DRAWSCENE_OCCLUSIONCULLING - ; - - // Main scene: - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - - { - auto range = wiProfiler::BeginRangeGPU("Opaque Scene", cmd); - - device->RenderPassBegin(&renderpass_gbuffer, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd); - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_DEFERRED, cmd, drawscene_flags); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); // Opaque Scene - } - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_COPY_SRC), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - RenderLinearDepth(cmd); - - RenderAO(cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - RenderDecals(cmd); - - // Deferred lights: - { - device->RenderPassBegin(&renderpass_lights, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - device->BindResource(PS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd); - device->BindResource(PS, getSSREnabled() || getRaytracedReflectionEnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, cmd); - wiRenderer::DrawDeferredLights(wiRenderer::GetCamera(), depthBuffer_Copy, rtGBuffer[0], rtGBuffer[1], rtGBuffer[2], cmd); - - device->RenderPassEnd(cmd); - } - }); - - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - RenderSSS(cmd); - - RenderDeferredComposition(cmd); - - DownsampleDepthBuffer(cmd); - - RenderLightShafts(cmd); - - RenderVolumetrics(cmd); - - RenderSceneMIPChain(rtDeferred, cmd); - - RenderSSR(rtGBuffer[1], rtGBuffer[2], cmd); - - RenderTransparents(renderpass_transparent, RENDERPASS_FORWARD, cmd); - - RenderPostprocessChain(rtDeferred, rtGBuffer[1], cmd); - - }); - - RenderPath2D::Render(); - - wiJobSystem::Wait(ctx); -} - -void RenderPath3D_Deferred::RenderSSS(CommandList cmd) const -{ - if (getSSSEnabled()) - { - wiRenderer::Postprocess_SSS( - rtLinearDepth, - rtGBuffer[0], - renderpass_SSS[0], - renderpass_SSS[1], - renderpass_SSS[2], - cmd - ); - } -} -void RenderPath3D_Deferred::RenderDecals(CommandList cmd) const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - - device->RenderPassBegin(&renderpass_decals, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - wiRenderer::DrawDeferredDecals(wiRenderer::GetCamera(), depthBuffer_Copy, cmd); - - device->RenderPassEnd(cmd); -} -void RenderPath3D_Deferred::RenderDeferredComposition(CommandList cmd) const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - - device->RenderPassBegin(&renderpass_deferredcomposition, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - wiRenderer::DeferredComposition( - rtGBuffer[0], - rtGBuffer[1], - rtGBuffer[2], - lightbuffer_diffuse, - lightbuffer_specular, - getAOEnabled() ? rtAO : *wiTextureHelper::getWhite(), - depthBuffer_Copy, - cmd - ); - wiRenderer::DrawSky(cmd); - - RenderOutline(cmd); - - device->RenderPassEnd(cmd); -} diff --git a/WickedEngine/RenderPath3D_Deferred.h b/WickedEngine/RenderPath3D_Deferred.h deleted file mode 100644 index 2d7e5d149..000000000 --- a/WickedEngine/RenderPath3D_Deferred.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "RenderPath3D.h" - - -class RenderPath3D_Deferred : - public RenderPath3D -{ -protected: - wiGraphics::Texture rtGBuffer[3]; - wiGraphics::Texture rtDeferred; - wiGraphics::Texture rtSSS[2]; - wiGraphics::Texture lightbuffer_diffuse; - wiGraphics::Texture lightbuffer_specular; - - wiGraphics::RenderPass renderpass_gbuffer; - wiGraphics::RenderPass renderpass_lights; - wiGraphics::RenderPass renderpass_decals; - wiGraphics::RenderPass renderpass_deferredcomposition; - wiGraphics::RenderPass renderpass_SSS[3]; - wiGraphics::RenderPass renderpass_transparent; - - void ResizeBuffers() override; - - virtual void RenderSSS(wiGraphics::CommandList cmd) const; - virtual void RenderDecals(wiGraphics::CommandList cmd) const; - virtual void RenderDeferredComposition(wiGraphics::CommandList cmd) const; - -public: - void setMSAASampleCount(uint32_t value) override { /*disable MSAA for deferred*/ } - - void Render() const override; -}; - diff --git a/WickedEngine/RenderPath3D_Deferred_BindLua.cpp b/WickedEngine/RenderPath3D_Deferred_BindLua.cpp deleted file mode 100644 index 954ed0ecc..000000000 --- a/WickedEngine/RenderPath3D_Deferred_BindLua.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "RenderPath3D_Deferred_BindLua.h" - -const char RenderPath3D_Deferred_BindLua::className[] = "RenderPath3D_Deferred"; - -Luna::FunctionType RenderPath3D_Deferred_BindLua::methods[] = { - lunamethod(RenderPath2D_BindLua, AddSprite), - lunamethod(RenderPath2D_BindLua, AddFont), - lunamethod(RenderPath2D_BindLua, RemoveSprite), - lunamethod(RenderPath2D_BindLua, RemoveFont), - lunamethod(RenderPath2D_BindLua, ClearSprites), - lunamethod(RenderPath2D_BindLua, ClearFonts), - lunamethod(RenderPath2D_BindLua, GetSpriteOrder), - lunamethod(RenderPath2D_BindLua, GetFontOrder), - - lunamethod(RenderPath2D_BindLua, AddLayer), - lunamethod(RenderPath2D_BindLua, GetLayers), - lunamethod(RenderPath2D_BindLua, SetLayerOrder), - lunamethod(RenderPath2D_BindLua, SetSpriteOrder), - lunamethod(RenderPath2D_BindLua, SetFontOrder), - - lunamethod(RenderPath_BindLua, GetLayerMask), - lunamethod(RenderPath_BindLua, SetLayerMask), - - lunamethod(RenderPath3D_BindLua, SetAO), - lunamethod(RenderPath3D_BindLua, SetSSREnabled), - lunamethod(RenderPath3D_BindLua, SetRaytracedReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetShadowsEnabled), - lunamethod(RenderPath3D_BindLua, SetReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetFXAAEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomThreshold), - lunamethod(RenderPath3D_BindLua, SetColorGradingEnabled), - lunamethod(RenderPath3D_BindLua, SetVolumeLightsEnabled), - lunamethod(RenderPath3D_BindLua, SetLightShaftsEnabled), - lunamethod(RenderPath3D_BindLua, SetLensFlareEnabled), - lunamethod(RenderPath3D_BindLua, SetMotionBlurEnabled), - lunamethod(RenderPath3D_BindLua, SetSSSEnabled), - lunamethod(RenderPath3D_BindLua, SetDitherEnabled), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldEnabled), - lunamethod(RenderPath3D_BindLua, SetEyeAdaptionEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterAmount), - lunamethod(RenderPath3D_BindLua, SetMotionBlurStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldFocus), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldAspect), - - { NULL, NULL } -}; -Luna::PropertyType RenderPath3D_Deferred_BindLua::properties[] = { - { NULL, NULL } -}; - -void RenderPath3D_Deferred_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetLuaState()); - } -} diff --git a/WickedEngine/RenderPath3D_Deferred_BindLua.h b/WickedEngine/RenderPath3D_Deferred_BindLua.h deleted file mode 100644 index b6d692915..000000000 --- a/WickedEngine/RenderPath3D_Deferred_BindLua.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "wiLua.h" -#include "wiLuna.h" -#include "RenderPath3D_Deferred.h" -#include "RenderPath3D_BindLua.h" - -class RenderPath3D_Deferred_BindLua : public RenderPath3D_BindLua -{ -public: - static const char className[]; - static Luna::FunctionType methods[]; - static Luna::PropertyType properties[]; - - RenderPath3D_Deferred_BindLua() = default; - RenderPath3D_Deferred_BindLua(RenderPath3D_Deferred* component) - { - this->component = component; - } - RenderPath3D_Deferred_BindLua(lua_State* L) - { - component = new RenderPath3D_Deferred; - owning = true; - } - - static void Bind(); -}; diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp deleted file mode 100644 index 5b6c54637..000000000 --- a/WickedEngine/RenderPath3D_Forward.cpp +++ /dev/null @@ -1,275 +0,0 @@ -#include "RenderPath3D_Forward.h" -#include "wiRenderer.h" -#include "wiImage.h" -#include "wiHelper.h" -#include "wiProfiler.h" -#include "wiTextureHelper.h" - -using namespace wiGraphics; - -void RenderPath3D_Forward::ResizeBuffers() -{ - RenderPath3D::ResizeBuffers(); - - GraphicsDevice* device = wiRenderer::GetDevice(); - - FORMAT defaultTextureFormat = device->GetBackBufferFormat(); - - - { - TextureDesc desc; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; - if (getMSAASampleCount() == 1) - { - desc.BindFlags |= BIND_UNORDERED_ACCESS; - } - desc.Width = wiRenderer::GetInternalResolution().x; - desc.Height = wiRenderer::GetInternalResolution().y; - desc.SampleCount = getMSAASampleCount(); - - desc.Format = FORMAT_R11G11B10_FLOAT; - device->CreateTexture(&desc, nullptr, &rtMain[0]); - device->SetName(&rtMain[0], "rtMain[0]"); - - desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture(&desc, nullptr, &rtMain[1]); - device->SetName(&rtMain[1], "rtMain[1]"); - - desc.Format = FORMAT_R8_UNORM; - device->CreateTexture(&desc, nullptr, &rtMain[2]); - device->SetName(&rtMain[2], "rtMain[2]"); - - if (getMSAASampleCount() > 1) - { - desc.SampleCount = 1; - desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - - desc.Format = FORMAT_R11G11B10_FLOAT; - device->CreateTexture(&desc, nullptr, &rtMain_resolved[0]); - device->SetName(&rtMain_resolved[0], "rtMain_resolved[0]"); - - desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture(&desc, nullptr, &rtMain_resolved[1]); - device->SetName(&rtMain_resolved[1], "rtMain_resolved[1]"); - - desc.Format = FORMAT_R8_UNORM; - device->CreateTexture(&desc, nullptr, &rtMain_resolved[2]); - device->SetName(&rtMain_resolved[2], "rtMain_resolved[2]"); - } - } - - { - RenderPassDesc desc; - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_CLEAR, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - device->CreateRenderPass(&desc, &renderpass_depthprepass); - - desc.attachments.clear(); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtMain[0], RenderPassAttachment::LOADOP_DONTCARE)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtMain[1], RenderPassAttachment::LOADOP_CLEAR)); - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtMain[2], RenderPassAttachment::LOADOP_CLEAR)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - if (getMSAASampleCount() > 1) - { - desc.attachments.push_back(RenderPassAttachment::Resolve(GetSceneRT_Read(0))); - desc.attachments.push_back(RenderPassAttachment::Resolve(GetSceneRT_Read(1))); - desc.attachments.push_back(RenderPassAttachment::Resolve(GetSceneRT_Read(2))); - } - device->CreateRenderPass(&desc, &renderpass_main); - } - { - RenderPassDesc desc; - desc.attachments.push_back(RenderPassAttachment::RenderTarget(&rtMain[0], RenderPassAttachment::LOADOP_LOAD)); - desc.attachments.push_back( - RenderPassAttachment::DepthStencil( - &depthBuffer, - RenderPassAttachment::LOADOP_LOAD, - RenderPassAttachment::STOREOP_STORE, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY - ) - ); - if (getMSAASampleCount() > 1) - { - desc.attachments.push_back(RenderPassAttachment::Resolve(GetSceneRT_Read(0))); - } - device->CreateRenderPass(&desc, &renderpass_transparent); - } -} - -void RenderPath3D_Forward::Render() const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - wiJobSystem::context ctx; - CommandList cmd; - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderFrameSetUp(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderShadows(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderReflections(cmd); }); - - static const uint32_t drawscene_flags = - wiRenderer::DRAWSCENE_OPAQUE | - wiRenderer::DRAWSCENE_HAIRPARTICLE | - wiRenderer::DRAWSCENE_TESSELLATION | - wiRenderer::DRAWSCENE_OCCLUSIONCULLING - ; - - // Main scene: - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - - // depth prepass - { - auto range = wiProfiler::BeginRangeGPU("Z-Prepass", cmd); - - device->RenderPassBegin(&renderpass_depthprepass, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_DEPTHONLY, cmd, drawscene_flags); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); - } - - if (getMSAASampleCount() > 1) - { - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_SHADER_RESOURCE), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_GENERAL) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - wiRenderer::ResolveMSAADepthBuffer(depthBuffer_Copy, depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_GENERAL, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - } - else - { - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_COPY_SRC), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - } - - RenderLinearDepth(cmd); - - RenderAO(cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - - if (wiRenderer::GetVariableRateShadingClassification() && device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)) - { - wiRenderer::ComputeShadingRateClassification(*GetSceneRT_Read(1), rtLinearDepth, rtShadingRate, cmd); - device->BindShadingRate(SHADING_RATE_1X1, cmd); - device->BindShadingRateImage(&rtShadingRate, cmd); - } - - // Opaque Scene: - { - auto range = wiProfiler::BeginRangeGPU("Opaque Scene", cmd); - - device->RenderPassBegin(&renderpass_main, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd); - device->BindResource(PS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd); - device->BindResource(PS, getSSREnabled() || getRaytracedReflectionEnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, cmd); - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_FORWARD, cmd, drawscene_flags); - wiRenderer::DrawSky(cmd); - - RenderOutline(cmd); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); // Opaque Scene - } - - device->BindShadingRateImage(nullptr, cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - DownsampleDepthBuffer(cmd); - - RenderLightShafts(cmd); - - RenderVolumetrics(cmd); - - RenderSceneMIPChain(*GetSceneRT_Read(0), cmd); - - RenderSSR(*GetSceneRT_Read(1), *GetSceneRT_Read(2), cmd); - - RenderTransparents(renderpass_transparent, RENDERPASS_FORWARD, cmd); - - RenderPostprocessChain(*GetSceneRT_Read(0), *GetSceneRT_Read(1), cmd); - - }); - - RenderPath2D::Render(); - - wiJobSystem::Wait(ctx); -} diff --git a/WickedEngine/RenderPath3D_Forward.h b/WickedEngine/RenderPath3D_Forward.h deleted file mode 100644 index 18185038c..000000000 --- a/WickedEngine/RenderPath3D_Forward.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "RenderPath3D.h" - - -class RenderPath3D_Forward : - public RenderPath3D -{ -protected: - - wiGraphics::Texture rtMain[3]; - wiGraphics::Texture rtMain_resolved[3]; - - wiGraphics::RenderPass renderpass_depthprepass; - wiGraphics::RenderPass renderpass_main; - wiGraphics::RenderPass renderpass_transparent; - - const constexpr wiGraphics::Texture* GetSceneRT_Read(int i) const - { - if (getMSAASampleCount() > 1) - { - return &rtMain_resolved[i]; - } - else - { - return &rtMain[i]; - } - } - - void ResizeBuffers() override; - -public: - void Render() const override; -}; - diff --git a/WickedEngine/RenderPath3D_Forward_BindLua.cpp b/WickedEngine/RenderPath3D_Forward_BindLua.cpp deleted file mode 100644 index b7cf7621a..000000000 --- a/WickedEngine/RenderPath3D_Forward_BindLua.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "RenderPath3D_Forward_BindLua.h" - -const char RenderPath3D_Forward_BindLua::className[] = "RenderPath3D_Forward"; - -Luna::FunctionType RenderPath3D_Forward_BindLua::methods[] = { - lunamethod(RenderPath2D_BindLua, AddSprite), - lunamethod(RenderPath2D_BindLua, AddFont), - lunamethod(RenderPath2D_BindLua, RemoveSprite), - lunamethod(RenderPath2D_BindLua, RemoveFont), - lunamethod(RenderPath2D_BindLua, ClearSprites), - lunamethod(RenderPath2D_BindLua, ClearFonts), - lunamethod(RenderPath2D_BindLua, GetSpriteOrder), - lunamethod(RenderPath2D_BindLua, GetFontOrder), - - lunamethod(RenderPath2D_BindLua, AddLayer), - lunamethod(RenderPath2D_BindLua, GetLayers), - lunamethod(RenderPath2D_BindLua, SetLayerOrder), - lunamethod(RenderPath2D_BindLua, SetSpriteOrder), - lunamethod(RenderPath2D_BindLua, SetFontOrder), - - lunamethod(RenderPath_BindLua, GetLayerMask), - lunamethod(RenderPath_BindLua, SetLayerMask), - - lunamethod(RenderPath3D_BindLua, SetAO), - lunamethod(RenderPath3D_BindLua, SetSSREnabled), - lunamethod(RenderPath3D_BindLua, SetRaytracedReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetShadowsEnabled), - lunamethod(RenderPath3D_BindLua, SetReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetFXAAEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomThreshold), - lunamethod(RenderPath3D_BindLua, SetColorGradingEnabled), - lunamethod(RenderPath3D_BindLua, SetVolumeLightsEnabled), - lunamethod(RenderPath3D_BindLua, SetLightShaftsEnabled), - lunamethod(RenderPath3D_BindLua, SetLensFlareEnabled), - lunamethod(RenderPath3D_BindLua, SetMotionBlurEnabled), - lunamethod(RenderPath3D_BindLua, SetSSSEnabled), - lunamethod(RenderPath3D_BindLua, SetDitherEnabled), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldEnabled), - lunamethod(RenderPath3D_BindLua, SetEyeAdaptionEnabled), - lunamethod(RenderPath3D_BindLua, SetMSAASampleCount), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterAmount), - lunamethod(RenderPath3D_BindLua, SetMotionBlurStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldFocus), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldAspect), - { NULL, NULL } -}; -Luna::PropertyType RenderPath3D_Forward_BindLua::properties[] = { - { NULL, NULL } -}; - -void RenderPath3D_Forward_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetLuaState()); - } -} diff --git a/WickedEngine/RenderPath3D_Forward_BindLua.h b/WickedEngine/RenderPath3D_Forward_BindLua.h deleted file mode 100644 index 1074e8ceb..000000000 --- a/WickedEngine/RenderPath3D_Forward_BindLua.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "wiLua.h" -#include "wiLuna.h" -#include "RenderPath3D_Forward.h" -#include "RenderPath3D_BindLua.h" - -class RenderPath3D_Forward_BindLua : public RenderPath3D_BindLua -{ -public: - static const char className[]; - static Luna::FunctionType methods[]; - static Luna::PropertyType properties[]; - - RenderPath3D_Forward_BindLua() = default; - RenderPath3D_Forward_BindLua(RenderPath3D_Forward* component) - { - this->component = component; - } - RenderPath3D_Forward_BindLua(lua_State* L) - { - component = new RenderPath3D_Forward; - owning = true; - } - - static void Bind(); -}; - diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp deleted file mode 100644 index 6c066ae4e..000000000 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "RenderPath3D_TiledDeferred.h" -#include "wiRenderer.h" -#include "wiImage.h" -#include "wiHelper.h" -#include "wiTextureHelper.h" -#include "wiSprite.h" -#include "ResourceMapping.h" -#include "wiProfiler.h" -#include "wiBackLog.h" - -using namespace wiGraphics; - -void RenderPath3D_TiledDeferred::ResizeBuffers() -{ - RenderPath3D_Deferred::ResizeBuffers(); - - GraphicsDevice* device = wiRenderer::GetDevice(); - - // Workaround textures if R11G11B10 UAV loads are not supported by the GPU: - if(!device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_UAV_LOAD_FORMAT_R11G11B10_FLOAT)) - { - wiBackLog::post("\nWARNING: GRAPHICSDEVICE_CAPABILITY_UAV_LOAD_FORMAT_R11G11B10_FLOAT not supported, Tiled deferred will be using workaround slow path!\n"); - - TextureDesc desc; - desc = lightbuffer_diffuse.GetDesc(); - desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture(&desc, nullptr, &lightbuffer_diffuse_noR11G11B10supportavailable); - device->SetName(&lightbuffer_diffuse_noR11G11B10supportavailable, "lightbuffer_diffuse_noR11G11B10supportavailable"); - - desc = lightbuffer_specular.GetDesc(); - desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture(&desc, nullptr, &lightbuffer_specular_noR11G11B10supportavailable); - device->SetName(&lightbuffer_specular_noR11G11B10supportavailable, "lightbuffer_specular_noR11G11B10supportavailable"); - } -} - -void RenderPath3D_TiledDeferred::Render() const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - wiJobSystem::context ctx; - CommandList cmd; - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderFrameSetUp(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderShadows(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderReflections(cmd); }); - - static const uint32_t drawscene_flags = - wiRenderer::DRAWSCENE_OPAQUE | - wiRenderer::DRAWSCENE_HAIRPARTICLE | - wiRenderer::DRAWSCENE_TESSELLATION | - wiRenderer::DRAWSCENE_OCCLUSIONCULLING - ; - - // Main scene: - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - - { - auto range = wiProfiler::BeginRangeGPU("Opaque Scene", cmd); - - device->RenderPassBegin(&renderpass_gbuffer, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd); - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_DEFERRED, cmd, drawscene_flags); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); // Opaque Scene - } - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_COPY_SRC), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - RenderLinearDepth(cmd); - - RenderAO(cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - RenderDecals(cmd); - - device->BindResource(CS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd); - device->BindResource(CS, getSSREnabled() || getRaytracedReflectionEnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, cmd); - - - if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_UAV_LOAD_FORMAT_R11G11B10_FLOAT)) - { - wiRenderer::ComputeTiledLightCulling( - depthBuffer_Copy, - cmd, - &rtGBuffer[0], - &rtGBuffer[1], - &rtGBuffer[2], - &lightbuffer_diffuse, - &lightbuffer_specular - ); - } - else - { - // This workaround if R11G11B10_FLOAT can't be used with UAV loads copies into R16G16B16A16_FLOAT, does the tiled deferred then copies back: - device->EventBegin("WARNING: GRAPHICSDEVICE_CAPABILITY_UAV_LOAD_FORMAT_R11G11B10_FLOAT not supported workaround!", cmd); - - wiRenderer::CopyTexture2D(lightbuffer_diffuse_noR11G11B10supportavailable, 0, 0, 0, lightbuffer_diffuse, 0, cmd); - wiRenderer::CopyTexture2D(lightbuffer_specular_noR11G11B10supportavailable, 0, 0, 0, lightbuffer_specular, 0, cmd); - - wiRenderer::ComputeTiledLightCulling( - depthBuffer_Copy, - cmd, - &rtGBuffer[0], - &rtGBuffer[1], - &rtGBuffer[2], - &lightbuffer_diffuse_noR11G11B10supportavailable, - &lightbuffer_specular_noR11G11B10supportavailable - ); - - wiRenderer::CopyTexture2D(lightbuffer_diffuse, 0, 0, 0, lightbuffer_diffuse_noR11G11B10supportavailable, 0, cmd); - wiRenderer::CopyTexture2D(lightbuffer_specular, 0, 0, 0, lightbuffer_specular_noR11G11B10supportavailable, 0, cmd); - - device->EventEnd(cmd); - } - - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - RenderSSS(cmd); - - RenderDeferredComposition(cmd); - - DownsampleDepthBuffer(cmd); - - RenderLightShafts(cmd); - - RenderVolumetrics(cmd); - - RenderSceneMIPChain(rtDeferred, cmd); - - RenderSSR(rtGBuffer[1], rtGBuffer[2], cmd); - - RenderTransparents(renderpass_transparent, RENDERPASS_TILEDFORWARD, cmd); - - RenderPostprocessChain(rtDeferred, rtGBuffer[1], cmd); - - }); - - RenderPath2D::Render(); - - wiJobSystem::Wait(ctx); -} diff --git a/WickedEngine/RenderPath3D_TiledDeferred.h b/WickedEngine/RenderPath3D_TiledDeferred.h deleted file mode 100644 index 06f9c1184..000000000 --- a/WickedEngine/RenderPath3D_TiledDeferred.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "RenderPath3D_Deferred.h" - -class RenderPath3D_TiledDeferred : - public RenderPath3D_Deferred -{ -private: - wiGraphics::Texture lightbuffer_diffuse_noR11G11B10supportavailable; - wiGraphics::Texture lightbuffer_specular_noR11G11B10supportavailable; -protected: - void ResizeBuffers() override; -public: - void Render() const override; -}; - diff --git a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp b/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp deleted file mode 100644 index 791572c75..000000000 --- a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "RenderPath3D_TiledDeferred_BindLua.h" - -const char RenderPath3D_TiledDeferred_BindLua::className[] = "RenderPath3D_TiledDeferred"; - -Luna::FunctionType RenderPath3D_TiledDeferred_BindLua::methods[] = { - lunamethod(RenderPath2D_BindLua, AddSprite), - lunamethod(RenderPath2D_BindLua, AddFont), - lunamethod(RenderPath2D_BindLua, RemoveSprite), - lunamethod(RenderPath2D_BindLua, RemoveFont), - lunamethod(RenderPath2D_BindLua, ClearSprites), - lunamethod(RenderPath2D_BindLua, ClearFonts), - lunamethod(RenderPath2D_BindLua, GetSpriteOrder), - lunamethod(RenderPath2D_BindLua, GetFontOrder), - - lunamethod(RenderPath2D_BindLua, AddLayer), - lunamethod(RenderPath2D_BindLua, GetLayers), - lunamethod(RenderPath2D_BindLua, SetLayerOrder), - lunamethod(RenderPath2D_BindLua, SetSpriteOrder), - lunamethod(RenderPath2D_BindLua, SetFontOrder), - - lunamethod(RenderPath_BindLua, GetLayerMask), - lunamethod(RenderPath_BindLua, SetLayerMask), - - lunamethod(RenderPath3D_BindLua, SetAO), - lunamethod(RenderPath3D_BindLua, SetSSREnabled), - lunamethod(RenderPath3D_BindLua, SetRaytracedReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetShadowsEnabled), - lunamethod(RenderPath3D_BindLua, SetReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetFXAAEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomThreshold), - lunamethod(RenderPath3D_BindLua, SetColorGradingEnabled), - lunamethod(RenderPath3D_BindLua, SetVolumeLightsEnabled), - lunamethod(RenderPath3D_BindLua, SetLightShaftsEnabled), - lunamethod(RenderPath3D_BindLua, SetLensFlareEnabled), - lunamethod(RenderPath3D_BindLua, SetMotionBlurEnabled), - lunamethod(RenderPath3D_BindLua, SetSSSEnabled), - lunamethod(RenderPath3D_BindLua, SetDitherEnabled), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldEnabled), - lunamethod(RenderPath3D_BindLua, SetEyeAdaptionEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterAmount), - lunamethod(RenderPath3D_BindLua, SetMotionBlurStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldFocus), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldAspect), - - { NULL, NULL } -}; -Luna::PropertyType RenderPath3D_TiledDeferred_BindLua::properties[] = { - { NULL, NULL } -}; - -void RenderPath3D_TiledDeferred_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetLuaState()); - } -} diff --git a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.h b/WickedEngine/RenderPath3D_TiledDeferred_BindLua.h deleted file mode 100644 index b04aac6b9..000000000 --- a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "wiLua.h" -#include "wiLuna.h" -#include "RenderPath3D_TiledDeferred.h" -#include "RenderPath3D_BindLua.h" - -class RenderPath3D_TiledDeferred_BindLua : public RenderPath3D_BindLua -{ -public: - static const char className[]; - static Luna::FunctionType methods[]; - static Luna::PropertyType properties[]; - - RenderPath3D_TiledDeferred_BindLua() = default; - RenderPath3D_TiledDeferred_BindLua(RenderPath3D_TiledDeferred* component) - { - this->component = component; - } - RenderPath3D_TiledDeferred_BindLua(lua_State* L) - { - component = new RenderPath3D_TiledDeferred; - owning = true; - } - - static void Bind(); -}; - diff --git a/WickedEngine/RenderPath3D_TiledForward.cpp b/WickedEngine/RenderPath3D_TiledForward.cpp deleted file mode 100644 index fdfd4f75b..000000000 --- a/WickedEngine/RenderPath3D_TiledForward.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "RenderPath3D_TiledForward.h" -#include "wiRenderer.h" -#include "wiImage.h" -#include "wiHelper.h" -#include "wiProfiler.h" -#include "wiTextureHelper.h" -#include "wiEvent.h" - -using namespace wiGraphics; - - -void RenderPath3D_TiledForward::Render() const -{ - GraphicsDevice* device = wiRenderer::GetDevice(); - wiJobSystem::context ctx; - CommandList cmd; - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderFrameSetUp(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderShadows(cmd); }); - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { RenderReflections(cmd); }); - - - static const uint32_t drawscene_flags = - wiRenderer::DRAWSCENE_OPAQUE | - wiRenderer::DRAWSCENE_HAIRPARTICLE | - wiRenderer::DRAWSCENE_TESSELLATION | - wiRenderer::DRAWSCENE_OCCLUSIONCULLING - ; - - // Main scene: - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - - // depth prepass - { - auto range = wiProfiler::BeginRangeGPU("Z-Prepass", cmd); - - device->RenderPassBegin(&renderpass_depthprepass, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_DEPTHONLY, cmd, drawscene_flags); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); - } - - if (getMSAASampleCount() > 1) - { - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_SHADER_RESOURCE), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_GENERAL) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - wiRenderer::ResolveMSAADepthBuffer(depthBuffer_Copy, depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_GENERAL, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - } - else - { - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, IMAGE_LAYOUT_COPY_SRC), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - - device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); - - { - GPUBarrier barriers[] = { - GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), - GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) - }; - device->Barrier(barriers, arraysize(barriers), cmd); - } - } - - RenderLinearDepth(cmd); - - RenderAO(cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::ComputeTiledLightCulling( - depthBuffer_Copy, - cmd - ); - - if (wiRenderer::GetVariableRateShadingClassification() && device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2)) - { - wiRenderer::ComputeShadingRateClassification(*GetSceneRT_Read(1), rtLinearDepth, rtShadingRate, cmd); - device->BindShadingRate(SHADING_RATE_1X1, cmd); - device->BindShadingRateImage(&rtShadingRate, cmd); - } - - device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd); - - // Opaque scene: - { - auto range = wiProfiler::BeginRangeGPU("Opaque Scene", cmd); - - device->RenderPassBegin(&renderpass_main, cmd); - - Viewport vp; - vp.Width = (float)depthBuffer.GetDesc().Width; - vp.Height = (float)depthBuffer.GetDesc().Height; - device->BindViewports(1, &vp, cmd); - - device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd); - device->BindResource(PS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd); - device->BindResource(PS, getSSREnabled() || getRaytracedReflectionEnabled() ? &rtSSR : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_SSR, cmd); - wiRenderer::DrawScene(wiRenderer::GetCamera(), RENDERPASS_TILEDFORWARD, cmd, drawscene_flags); - wiRenderer::DrawSky(cmd); - - RenderOutline(cmd); - - device->RenderPassEnd(cmd); - - wiProfiler::EndRange(range); // Opaque Scene - } - - device->BindShadingRateImage(nullptr, cmd); - }); - - cmd = device->BeginCommandList(); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - - GraphicsDevice* device = wiRenderer::GetDevice(); - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), cmd); - wiRenderer::BindCommonResources(cmd); - - DownsampleDepthBuffer(cmd); - - RenderLightShafts(cmd); - - RenderVolumetrics(cmd); - - RenderSceneMIPChain(*GetSceneRT_Read(0), cmd); - - RenderSSR(*GetSceneRT_Read(1), *GetSceneRT_Read(2), cmd); - - RenderTransparents(renderpass_transparent, RENDERPASS_TILEDFORWARD, cmd); - - RenderPostprocessChain(*GetSceneRT_Read(0), *GetSceneRT_Read(1), cmd); - }); - - RenderPath2D::Render(); - - wiJobSystem::Wait(ctx); -} diff --git a/WickedEngine/RenderPath3D_TiledForward.h b/WickedEngine/RenderPath3D_TiledForward.h deleted file mode 100644 index d01e58eb5..000000000 --- a/WickedEngine/RenderPath3D_TiledForward.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include "RenderPath3D_Forward.h" - -class RenderPath3D_TiledForward : - public RenderPath3D_Forward -{ -private: - void Render() const override; -}; - diff --git a/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp b/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp deleted file mode 100644 index 9e2d48f43..000000000 --- a/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "RenderPath3D_TiledForward_BindLua.h" - -const char RenderPath3D_TiledForward_BindLua::className[] = "RenderPath3D_TiledForward"; - -Luna::FunctionType RenderPath3D_TiledForward_BindLua::methods[] = { - lunamethod(RenderPath2D_BindLua, AddSprite), - lunamethod(RenderPath2D_BindLua, AddFont), - lunamethod(RenderPath2D_BindLua, RemoveSprite), - lunamethod(RenderPath2D_BindLua, RemoveFont), - lunamethod(RenderPath2D_BindLua, ClearSprites), - lunamethod(RenderPath2D_BindLua, ClearFonts), - lunamethod(RenderPath2D_BindLua, GetSpriteOrder), - lunamethod(RenderPath2D_BindLua, GetFontOrder), - - lunamethod(RenderPath2D_BindLua, AddLayer), - lunamethod(RenderPath2D_BindLua, GetLayers), - lunamethod(RenderPath2D_BindLua, SetLayerOrder), - lunamethod(RenderPath2D_BindLua, SetSpriteOrder), - lunamethod(RenderPath2D_BindLua, SetFontOrder), - - lunamethod(RenderPath_BindLua, GetLayerMask), - lunamethod(RenderPath_BindLua, SetLayerMask), - - lunamethod(RenderPath3D_BindLua, SetAO), - lunamethod(RenderPath3D_BindLua, SetSSREnabled), - lunamethod(RenderPath3D_BindLua, SetRaytracedReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetShadowsEnabled), - lunamethod(RenderPath3D_BindLua, SetReflectionsEnabled), - lunamethod(RenderPath3D_BindLua, SetFXAAEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomEnabled), - lunamethod(RenderPath3D_BindLua, SetBloomThreshold), - lunamethod(RenderPath3D_BindLua, SetColorGradingEnabled), - lunamethod(RenderPath3D_BindLua, SetVolumeLightsEnabled), - lunamethod(RenderPath3D_BindLua, SetLightShaftsEnabled), - lunamethod(RenderPath3D_BindLua, SetLensFlareEnabled), - lunamethod(RenderPath3D_BindLua, SetMotionBlurEnabled), - lunamethod(RenderPath3D_BindLua, SetSSSEnabled), - lunamethod(RenderPath3D_BindLua, SetDitherEnabled), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldEnabled), - lunamethod(RenderPath3D_BindLua, SetEyeAdaptionEnabled), - lunamethod(RenderPath3D_BindLua, SetMSAASampleCount), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterEnabled), - lunamethod(RenderPath3D_BindLua, SetSharpenFilterAmount), - lunamethod(RenderPath3D_BindLua, SetMotionBlurStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldFocus), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldStrength), - lunamethod(RenderPath3D_BindLua, SetDepthOfFieldAspect), - - { NULL, NULL } -}; -Luna::PropertyType RenderPath3D_TiledForward_BindLua::properties[] = { - { NULL, NULL } -}; - -void RenderPath3D_TiledForward_BindLua::Bind() -{ - static bool initialized = false; - if (!initialized) - { - initialized = true; - Luna::Register(wiLua::GetLuaState()); - } -} diff --git a/WickedEngine/RenderPath3D_TiledForward_BindLua.h b/WickedEngine/RenderPath3D_TiledForward_BindLua.h deleted file mode 100644 index f3124f89e..000000000 --- a/WickedEngine/RenderPath3D_TiledForward_BindLua.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "wiLua.h" -#include "wiLuna.h" -#include "RenderPath3D_TiledForward.h" -#include "RenderPath3D_BindLua.h" - -class RenderPath3D_TiledForward_BindLua : public RenderPath3D_BindLua -{ -public: - static const char className[]; - static Luna::FunctionType methods[]; - static Luna::PropertyType properties[]; - - RenderPath3D_TiledForward_BindLua() = default; - RenderPath3D_TiledForward_BindLua(RenderPath3D_TiledForward* component) - { - this->component = component; - } - RenderPath3D_TiledForward_BindLua(lua_State* L) - { - component = new RenderPath3D_TiledForward; - owning = true; - } - - static void Bind(); -}; - diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 16fa0d648..7c74c2751 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -13,7 +13,6 @@ #define TEXSLOT_GBUFFER0 2 #define TEXSLOT_GBUFFER1 3 -#define TEXSLOT_GBUFFER2 4 #define TEXSLOT_ACCELERATION_STRUCTURE 5 #define TEXSLOT_GLOBALENVMAP 6 @@ -68,8 +67,9 @@ // Skinning: #define SKINNINGSLOT_IN_VERTEX_POS TEXSLOT_ONDEMAND0 -#define SKINNINGSLOT_IN_VERTEX_BON TEXSLOT_ONDEMAND1 -#define SKINNINGSLOT_IN_BONEBUFFER TEXSLOT_ONDEMAND2 +#define SKINNINGSLOT_IN_VERTEX_TAN TEXSLOT_ONDEMAND1 +#define SKINNINGSLOT_IN_VERTEX_BON TEXSLOT_ONDEMAND2 +#define SKINNINGSLOT_IN_BONEBUFFER TEXSLOT_ONDEMAND3 // wiRenderer object shader resources: diff --git a/WickedEngine/ShaderInterop_Font.h b/WickedEngine/ShaderInterop_Font.h index 6b3a4c3db..1132ae653 100644 --- a/WickedEngine/ShaderInterop_Font.h +++ b/WickedEngine/ShaderInterop_Font.h @@ -7,6 +7,8 @@ CBUFFER(FontCB, CBSLOT_FONT) { float4x4 g_xFont_Transform; float4 g_xFont_Color; + uint g_xFont_BufferOffset; + float3 g_xFont_padding; }; diff --git a/WickedEngine/ShaderInterop_Postprocess.h b/WickedEngine/ShaderInterop_Postprocess.h index 41c2c26e3..93bf922a5 100644 --- a/WickedEngine/ShaderInterop_Postprocess.h +++ b/WickedEngine/ShaderInterop_Postprocess.h @@ -38,6 +38,8 @@ static const uint POSTPROCESS_HBAO_THREADCOUNT = 320; #define hbao_uv_to_view_A xPPParams1.xy #define hbao_uv_to_view_B xPPParams1.zw +#define sss_step xPPParams0 + static const uint POSTPROCESS_MSAO_BLOCKSIZE = 16; CBUFFER(MSAOCB, CBSLOT_RENDERER_POSTPROCESS) { diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index cd2ff662c..d62071661 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -20,10 +20,10 @@ struct ShaderMaterial float metalness; float refractionIndex; - float subsurfaceScattering; float normalMapStrength; - float normalMapFlip; float parallaxOcclusionMapping; + float padding0; + float padding1; float displacementMapping; int uvset_baseColorMap; @@ -276,6 +276,8 @@ CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) float g_xCamera_ZFarP_rcp; float g_xCamera_ZRange; float g_xCamera_ZRange_rcp; + + float4 g_xCamera_FrustumPlanes[6]; }; CBUFFER(APICB, CBSLOT_API) diff --git a/WickedEngine/Shaders_SOURCE.vcxitems b/WickedEngine/Shaders_SOURCE.vcxitems index ec3cd982f..8f224e500 100644 --- a/WickedEngine/Shaders_SOURCE.vcxitems +++ b/WickedEngine/Shaders_SOURCE.vcxitems @@ -21,7 +21,6 @@ - @@ -42,6 +41,7 @@ + @@ -426,26 +426,6 @@ Vertex Vertex - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Pixel Pixel @@ -456,6 +436,17 @@ Pixel Pixel + + Compute + 5.0 + Compute + Compute + Compute + Compute + Compute + Compute + Compute + Compute Compute @@ -566,36 +557,6 @@ Compute Compute - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Compute Compute @@ -616,6 +577,16 @@ Pixel Pixel + + Compute + Compute + Compute + Compute + Compute + Compute + Compute + Compute + Compute 5.0 @@ -627,6 +598,68 @@ Compute Compute + + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Pixel + 5.0 + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Pixel + 5.0 + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Compute Compute @@ -647,6 +680,46 @@ Compute Compute + + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + Pixel + + + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + + + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + + + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Vertex + Compute 4.0 @@ -999,16 +1072,6 @@ Compute Compute - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel @@ -1289,36 +1352,6 @@ Pixel Pixel - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel @@ -1329,17 +1362,7 @@ Pixel Pixel - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - + Pixel Pixel Pixel @@ -1348,6 +1371,7 @@ Pixel Pixel Pixel + Document Vertex @@ -1459,26 +1483,6 @@ Pixel Pixel - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel @@ -1489,7 +1493,7 @@ Pixel Pixel - + Pixel Pixel Pixel @@ -1498,6 +1502,7 @@ Pixel Pixel Pixel + Document Pixel @@ -1589,46 +1594,6 @@ Compute Compute - - Compute - Compute - Compute - Compute - Compute - Compute - Compute - Compute - - - Compute - Compute - Compute - Compute - Compute - Compute - Compute - Compute - - - Compute - Compute - Compute - Compute - Compute - Compute - Compute - Compute - - - Compute - Compute - Compute - Compute - Compute - Compute - Compute - Compute - Compute Compute @@ -1889,216 +1854,6 @@ Pixel Pixel - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel @@ -2139,7 +1894,7 @@ Pixel Pixel - + Pixel Pixel Pixel @@ -2148,8 +1903,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2158,8 +1914,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2168,8 +1925,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2178,8 +1936,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2188,8 +1947,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2198,8 +1958,9 @@ Pixel Pixel Pixel + Document - + Pixel Pixel Pixel @@ -2208,68 +1969,9 @@ Pixel Pixel Pixel + Document - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - + Pixel Pixel Pixel @@ -2278,6 +1980,7 @@ Pixel Pixel Pixel + Document Pixel @@ -2449,26 +2152,6 @@ Compute Compute - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Compute Compute @@ -2539,16 +2222,6 @@ Compute Compute - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel @@ -2719,16 +2392,6 @@ Vertex Vertex - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Vertex Vertex @@ -2739,26 +2402,6 @@ Vertex Vertex - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - - - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Vertex - Compute Compute @@ -2879,16 +2522,6 @@ Vertex Vertex - - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel - Pixel Pixel diff --git a/WickedEngine/Shaders_SOURCE.vcxitems.filters b/WickedEngine/Shaders_SOURCE.vcxitems.filters index c781f04dd..032a63db3 100644 --- a/WickedEngine/Shaders_SOURCE.vcxitems.filters +++ b/WickedEngine/Shaders_SOURCE.vcxitems.filters @@ -96,9 +96,6 @@ HF - - HF - HF @@ -129,6 +126,9 @@ LIB + + HF + @@ -323,12 +323,6 @@ CS - - CS - - - CS - CS @@ -338,12 +332,6 @@ CS - - CS - - - CS - CS @@ -554,18 +542,6 @@ PS - - PS - - - PS - - - PS - - - PS - PS @@ -584,9 +560,6 @@ PS - - PS - PS @@ -596,12 +569,6 @@ PS - - PS - - - PS - PS @@ -617,81 +584,27 @@ PS - - PS - PS PS - - PS - PS PS - - PS - - - PS - PS PS - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - PS - - PS - - - PS - - - PS - - - PS - - - PS - PS @@ -701,69 +614,12 @@ PS - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - - - PS - PS PS - - PS - - - PS - - - PS - PS @@ -776,24 +632,12 @@ PS - - PS - PS PS - - PS - - - PS - - - PS - PS @@ -806,9 +650,6 @@ PS - - PS - PS @@ -830,15 +671,6 @@ PS - - PS - - - PS - - - PS - PS @@ -896,9 +728,6 @@ VS - - VS - VS @@ -920,9 +749,6 @@ VS - - VS - VS @@ -965,12 +791,6 @@ VS - - VS - - - VS - VS @@ -1031,5 +851,71 @@ CS + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + VS + + + VS + + + VS + + + CS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + PS + + + CS + \ No newline at end of file diff --git a/WickedEngine/WickedEngine.h b/WickedEngine/WickedEngine.h index 767212cf9..21de99760 100644 --- a/WickedEngine/WickedEngine.h +++ b/WickedEngine/WickedEngine.h @@ -12,10 +12,6 @@ #include "RenderPath.h" #include "RenderPath2D.h" #include "RenderPath3D.h" -#include "RenderPath3D_Forward.h" -#include "RenderPath3D_Deferred.h" -#include "RenderPath3D_TiledForward.h" -#include "RenderPath3D_TiledDeferred.h" #include "RenderPath3D_PathTracing.h" #include "LoadingScreen.h" #include "MainComponent.h" diff --git a/WickedEngine/WickedEngine_SOURCE.vcxitems b/WickedEngine/WickedEngine_SOURCE.vcxitems index 84f7ad8b9..7b15eefba 100644 --- a/WickedEngine/WickedEngine_SOURCE.vcxitems +++ b/WickedEngine/WickedEngine_SOURCE.vcxitems @@ -230,10 +230,6 @@ - - - - @@ -250,10 +246,6 @@ - - - - @@ -535,15 +527,7 @@ - - - - - - - - diff --git a/WickedEngine/WickedEngine_SOURCE.vcxitems.filters b/WickedEngine/WickedEngine_SOURCE.vcxitems.filters index 2953795f4..f6d8e59cc 100644 --- a/WickedEngine/WickedEngine_SOURCE.vcxitems.filters +++ b/WickedEngine/WickedEngine_SOURCE.vcxitems.filters @@ -990,18 +990,6 @@ UTILITY - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - ENGINE\Scripting\LuaBindings @@ -1014,9 +1002,6 @@ ENGINE\Scripting\LuaBindings - - ENGINE\High level interface - ENGINE\High level interface @@ -1026,18 +1011,9 @@ ENGINE\High level interface - - ENGINE\High level interface - - - ENGINE\High level interface - ENGINE\High level interface - - ENGINE\High level interface - ENGINE\High level interface @@ -1850,18 +1826,6 @@ ENGINE\Graphics - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - - - ENGINE\Scripting\LuaBindings - ENGINE\Scripting\LuaBindings @@ -1880,21 +1844,9 @@ ENGINE\High level interface - - ENGINE\High level interface - - - ENGINE\High level interface - ENGINE\High level interface - - ENGINE\High level interface - - - ENGINE\High level interface - ENGINE\High level interface diff --git a/WickedEngine/brdf.hlsli b/WickedEngine/brdf.hlsli index d78f1329f..5b6ba4f4a 100644 --- a/WickedEngine/brdf.hlsli +++ b/WickedEngine/brdf.hlsli @@ -36,8 +36,12 @@ struct Surface float metalness; // metalness [0:dielectric -> 1:metal] float reflectance; // reflectivity [0:diffuse -> 1:specular] float4 emissiveColor; // light emission [0 -> 1] - float sss; // subsurface scattering [0 -> 1] float4 refraction; // refraction color (rgb), refraction amount (a) + float2 pixel; // pixel coordinate (used for randomization effects) + float2 screenUV; // pixel coordinate in UV space [0 -> 1] (used for randomization effects) + float3 T; // tangent + float3 B; // bitangent + float anisotropy; // anisotropy factor [0 -> 1] float alphaRoughness; // roughness remapped from perceptual to a "more linear change in roughness" float alphaRoughnessSq; // roughness input to brdf functions @@ -48,6 +52,12 @@ struct Surface float3 R; // reflection vector float3 F; // fresnel term computed from NdotV + // Aniso params: + float TdotV; + float BdotV; + float at; + float ab; + inline void Update() { alphaRoughness = roughness * roughness; @@ -61,6 +71,11 @@ struct Surface R = -reflect(V, N); f90 = saturate(50.0 * dot(f0, 0.33)); F = F_Schlick(f0, f90, NdotV); + + TdotV = dot(T, V); + BdotV = dot(B, V); + at = max(0, alphaRoughness * (1.0 + anisotropy)); + ab = max(0, alphaRoughness * (1.0 - anisotropy)); } }; inline Surface CreateSurface( @@ -72,8 +87,10 @@ inline Surface CreateSurface( in float occlusion, in float metalness, in float reflectance, - in float4 emissiveColor = 0, - in float sss = 0) + in float4 emissiveColor = 0, + in float anisotropy = 0, + in float3 T = 0, + in float3 B = 0) { Surface surface; @@ -86,8 +103,12 @@ inline Surface CreateSurface( surface.metalness = metalness; surface.reflectance = reflectance; surface.emissiveColor = emissiveColor; - surface.sss = sss; surface.refraction = 0; + surface.pixel = 0; + surface.screenUV = 0; + surface.anisotropy = anisotropy; + surface.T = T; + surface.B = B; surface.Update(); @@ -104,6 +125,12 @@ struct SurfaceToLight float LdotH; // cos angle between light direction and half vector float VdotH; // cos angle between view direction and half vector float3 F; // fresnel term computed from VdotH + + // Aniso params: + float TdotL; + float BdotL; + float TdotH; + float BdotH; }; inline SurfaceToLight CreateSurfaceToLight(in Surface surface, in float3 L) { @@ -120,6 +147,11 @@ inline SurfaceToLight CreateSurfaceToLight(in Surface surface, in float3 L) surfaceToLight.F = F_Schlick(surface.f0, surface.f90, surfaceToLight.VdotH); + surfaceToLight.TdotL = dot(surface.T, L); + surfaceToLight.BdotL = dot(surface.B, L); + surfaceToLight.TdotH = dot(surface.T, surfaceToLight.H); + surfaceToLight.BdotH = dot(surface.B, surfaceToLight.H); + return surfaceToLight; } @@ -150,15 +182,72 @@ float microfacetDistribution(in Surface surface, in SurfaceToLight surfaceToLigh return surface.alphaRoughnessSq / (PI * f * f); } + +// Aniso functions source: https://github.com/google/filament/blob/main/shaders/src/brdf.fs + +float D_GGX_Anisotropic(float at, float ab, float ToH, float BoH, float NoH) { + // Burley 2012, "Physically-Based Shading at Disney" + + // The values at and ab are perceptualRoughness^2, a2 is therefore perceptualRoughness^4 + // The dot product below computes perceptualRoughness^8. We cannot fit in fp16 without clamping + // the roughness to too high values so we perform the dot product and the division in fp32 + float a2 = at * ab; + float3 d = float3(ab * ToH, at * BoH, a2 * NoH); + float d2 = dot(d, d); + float b2 = a2 / d2; + return a2 * b2 * b2 * (1.0 / PI); +} +float V_SmithGGXCorrelated_Anisotropic(float at, float ab, float ToV, float BoV, + float ToL, float BoL, float NoV, float NoL) { + // Heitz 2014, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs" + // TODO: lambdaV can be pre-computed for all the lights, it should be moved out of this function + float lambdaV = NoL * length(float3(at * ToV, ab * BoV, NoV)); + float lambdaL = NoV * length(float3(at * ToL, ab * BoL, NoL)); + float v = 0.5 / (lambdaV + lambdaL); + return saturate(v); +} + +float distributionAnisotropic(float at, float ab, float ToH, float BoH, float NoH) { + return D_GGX_Anisotropic(at, ab, ToH, BoH, NoH); +} + +float visibilityAnisotropic(float at, float ab, + float ToV, float BoV, float ToL, float BoL, float NoV, float NoL) { + return V_SmithGGXCorrelated_Anisotropic(at, ab, ToV, BoV, ToL, BoL, NoV, NoL); +} + + +// These are the functions that will be used by shaders: float3 BRDF_GetSpecular(in Surface surface, in SurfaceToLight surfaceToLight) { +#ifdef BRDF_ANISOTROPIC + float Vis = visibilityAnisotropic( + surface.at, + surface.ab, + surface.TdotV, + surface.BdotV, + surfaceToLight.TdotL, + surfaceToLight.BdotL, + surface.NdotV, + surfaceToLight.NdotL + ); + float D = distributionAnisotropic( + surface.at, + surface.ab, + surfaceToLight.TdotH, + surfaceToLight.BdotH, + surfaceToLight.NdotH + ); +#else float Vis = visibilityOcclusion(surface, surfaceToLight); float D = microfacetDistribution(surface, surfaceToLight); - return surfaceToLight.F * Vis * D * surfaceToLight.NdotL; +#endif // BRDF_ANISOTROPIC + + return surfaceToLight.F * Vis * D; } float3 BRDF_GetDiffuse(in Surface surface, in SurfaceToLight surfaceToLight) { - return (1.0 - surfaceToLight.F) / PI * surfaceToLight.NdotL; + return (1.0 - surfaceToLight.F) / PI; } #endif // WI_BRDF_HF \ No newline at end of file diff --git a/WickedEngine/captureImpostorPS_normal.hlsl b/WickedEngine/captureImpostorPS_normal.hlsl index d7e12e342..d0778c007 100644 --- a/WickedEngine/captureImpostorPS_normal.hlsl +++ b/WickedEngine/captureImpostorPS_normal.hlsl @@ -11,8 +11,7 @@ float4 main(PixelInputType input) : SV_Target0 if (g_xMaterial.uvset_normalMap >= 0) { float3 bumpColor; - const float2 UV_normalMap = g_xMaterial.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; - NormalMapping(UV_normalMap, P, N, TBN, bumpColor); + NormalMapping(input.uvsets, P, N, TBN, bumpColor); } return float4(N * 0.5f + 0.5f, 1); diff --git a/WickedEngine/decalPS.hlsl b/WickedEngine/decalPS.hlsl deleted file mode 100644 index 0f1d87c8d..000000000 --- a/WickedEngine/decalPS.hlsl +++ /dev/null @@ -1,57 +0,0 @@ -#include "globals.hlsli" - - -struct VertexToPixel{ - float4 pos : SV_POSITION; - float4 pos2D : POSITION2D; -}; -struct PixelOutputType -{ - float4 col : SV_TARGET0; - //float4 nor : SV_TARGET1; -}; - -PixelOutputType main(VertexToPixel PSIn) -{ - PixelOutputType Out = (PixelOutputType)0; - - float2 screenPos = PSIn.pos2D.xy / PSIn.pos2D.w * float2(0.5f,-0.5f) + 0.5f; - float depth = texture_depth[PSIn.pos.xy]; - float3 pos3D = reconstructPosition(screenPos, depth); - - float3 clipSpace = mul(xDecalVP, float4(pos3D, 1)).xyz; - float3 projTex = clipSpace.xyz*float3(0.5f, -0.5f, 0.5f) + 0.5f; - - clip(is_saturated(projTex) ? 1 : -1); - - //if (hasTexNor & 0x0000010){ - // float3 normal = normalize(cross(ddx(pos3D), ddy(pos3D))); - // //clip( dot(normal,front)>-0.2?-1:1 ); //clip at oblique angle - // float4 nortex=texture_1.Sample(sampler_aniso_clamp,projTex.xy); - // float3 eyevector = normalize( eye - pos3D ); - // if(nortex.a>0){ - // float3 T, B; - // float3x3 tangentFrame = compute_tangent_frame(normal, eyevector, -projTex.xy, T, B); - // float3 bumpColor = 2.0f * nortex.rgb - 1.0f; - // //bumpColor.g*=-1; - // normal = normalize(mul(bumpColor, tangentFrame)); - // } - // Out.nor.a=min(nortex.b,nortex.a); - // Out.nor.xyz=normal; - //} - if(hasTexNor & 0x0000001){ - Out.col=texture_0.Sample(sampler_objectshader,projTex.xy); - Out.col.a*=opacity; - float3 edgeBlend = clipSpace.xyz; - edgeBlend = abs(edgeBlend); - Out.col.a *= 1 - pow(max(max(edgeBlend.x, edgeBlend.y), edgeBlend.z), 8); - //Out.col.a *= pow(saturate(-dot(normal,front)), 4); - //ALPHATEST(Out.col.a) - //if(hasTexNor & 0x0000010) - // Out.nor.a=Out.col.a; - } - - //Out.nor = float4(encode(Out.nor.xyz), 0, Out.nor.a); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/decalVS.hlsl b/WickedEngine/decalVS.hlsl deleted file mode 100644 index 214e9d793..000000000 --- a/WickedEngine/decalVS.hlsl +++ /dev/null @@ -1,16 +0,0 @@ -#include "globals.hlsli" - -struct VertexToPixel{ - float4 pos : SV_POSITION; - float4 pos2D : POSITION2D; -}; - -VertexToPixel main( uint vid : SV_VERTEXID ) -{ - VertexToPixel Out = (VertexToPixel)0; - - float4 pos = float4(CreateCube(vid) * 2 - 1, 1); - Out.pos = Out.pos2D = mul(g_xTransform, pos); - - return Out; -} \ No newline at end of file diff --git a/WickedEngine/deferredLightHF.hlsli b/WickedEngine/deferredLightHF.hlsli deleted file mode 100644 index 394d2a50d..000000000 --- a/WickedEngine/deferredLightHF.hlsli +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef WI_DEFERREDLIGHT_HF -#define WI_DEFERREDLIGHT_HF -#include "globals.hlsli" -#include "brdf.hlsli" -#include "lightingHF.hlsli" - -struct VertexToPixel{ - float4 pos : SV_POSITION; - float4 pos2D : POSITION2D; -}; - - -struct LightOutputType -{ - float4 diffuse : SV_TARGET0; - float4 specular: SV_TARGET1; -}; - - -// MACROS - -#define DEFERREDLIGHT_MAKEPARAMS \ - ShaderEntity light = EntityArray[(uint)g_xColor.x]; \ - Lighting lighting = CreateLighting(0, 0, 0, 0); \ - float diffuse_alpha = 1; \ - float specular_alpha = 1; \ - float2 ScreenCoord = PSIn.pos2D.xy / PSIn.pos2D.w * float2(0.5f, -0.5f) + 0.5f; \ - float depth = texture_depth[PSIn.pos.xy]; \ - float4 g0 = texture_gbuffer0[PSIn.pos.xy]; \ - float4 g1 = texture_gbuffer1[PSIn.pos.xy]; \ - float4 g2 = texture_gbuffer2[PSIn.pos.xy]; \ - float3 N = decodeNormal(g1.xy); \ - float2 velocity = g1.zw; \ - float2 ReprojectedScreenCoord = ScreenCoord + velocity; \ - float3 P = reconstructPosition(ScreenCoord, depth); \ - float3 V = normalize(g_xCamera_CamPos - P); \ - Surface surface = CreateSurface(P, N, V, float4(g0.rgb, 1), g2.r, g2.g, g2.b, g2.a); - - -#define DEFERREDLIGHT_DIRECTIONAL \ - DirectionalLight(light, surface, lighting); - -#define DEFERREDLIGHT_SPOT \ - SpotLight(light, surface, lighting); - -#define DEFERREDLIGHT_POINT \ - PointLight(light, surface, lighting); - -#define DEFERREDLIGHT_SPHERE \ - SphereLight(light, surface, lighting); - -#define DEFERREDLIGHT_DISC \ - DiscLight(light, surface, lighting); - -#define DEFERREDLIGHT_RECTANGLE \ - RectangleLight(light, surface, lighting); - -#define DEFERREDLIGHT_TUBE \ - TubeLight(light, surface, lighting); - - -#define DEFERREDLIGHT_RETURN \ - LightingPart combined_lighting = CombineLighting(surface, lighting); \ - LightOutputType Out; \ - Out.diffuse = float4(combined_lighting.diffuse, diffuse_alpha); \ - Out.specular = float4(combined_lighting.specular, specular_alpha); \ - return Out; - -#endif // WI_DEFERREDLIGHT_HF - - - diff --git a/WickedEngine/deferredPS.hlsl b/WickedEngine/deferredPS.hlsl index 22b38d9bf..a6888285e 100644 --- a/WickedEngine/deferredPS.hlsl +++ b/WickedEngine/deferredPS.hlsl @@ -6,9 +6,7 @@ float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_TARGET { - float4 g0 = texture_gbuffer0[pos.xy]; - float4 g2 = texture_gbuffer2[pos.xy]; - float3 albedo = ComputeAlbedo(float4(g0.rgb, 1), g2.b, g2.a); + float3 albedo = texture_gbuffer0[pos.xy].rgb; float depth = texture_depth[pos.xy]; diff --git a/WickedEngine/denoiseCS.hlsl b/WickedEngine/denoiseCS.hlsl new file mode 100644 index 000000000..725a09a34 --- /dev/null +++ b/WickedEngine/denoiseCS.hlsl @@ -0,0 +1,140 @@ +#include "globals.hlsli" +#include "stochasticSSRHF.hlsli" +#include "ShaderInterop_Postprocess.h" + +TEXTURE2D(resolve_current, float4, TEXSLOT_ONDEMAND0); +TEXTURE2D(resolve_history, float4, TEXSLOT_ONDEMAND1); +TEXTURE2D(texture_depth_history, float, TEXSLOT_ONDEMAND2); + +RWTEXTURE2D(output, float4, 0); + +static const float temporalResponseMin = 0.9; +static const float temporalResponseMax = 1.0f; +static const float temporalScale = 50.0; +static const float temporalExposure = 10.0f; + +inline float Luma4(float3 color) +{ + return (color.g * 2) + (color.r + color.b); +} + +inline float HdrWeight4(float3 color, float exposure) +{ + return rcp(Luma4(color) * exposure + 4.0f); +} + +float4 clip_aabb(float3 aabb_min, float3 aabb_max, float4 p, float4 q) +{ + float3 p_clip = 0.5 * (aabb_max + aabb_min); + float3 e_clip = 0.5 * (aabb_max - aabb_min) + 0.00000001f; + + float4 v_clip = q - float4(p_clip, p.w); + float3 v_unit = v_clip.xyz / e_clip; + float3 a_unit = abs(v_unit); + float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); + + if (ma_unit > 1.0) + return float4(p_clip, p.w) + v_clip / ma_unit; + else + return q; // point inside aabb +} + +inline void ResolverAABB(Texture2D currentColor, SamplerState currentSampler, float sharpness, float exposureScale, float AABBScale, float2 uv, float2 texelSize, inout float4 currentMin, inout float4 currentMax, inout float4 currentAverage, inout float4 currentOutput) +{ + const int2 SampleOffset[9] = { int2(-1.0, -1.0), int2(0.0, -1.0), int2(1.0, -1.0), int2(-1.0, 0.0), int2(0.0, 0.0), int2(1.0, 0.0), int2(-1.0, 1.0), int2(0.0, 1.0), int2(1.0, 1.0) }; + + // Modulate Luma HDR + + float4 sampleColors[9]; + [unroll] + for (uint i = 0; i < 9; i++) + { + sampleColors[i] = currentColor.SampleLevel(currentSampler, uv + (SampleOffset[i] / texelSize), 0.0f); + } + + float sampleWeights[9]; + [unroll] + for (uint j = 0; j < 9; j++) + { + sampleWeights[j] = HdrWeight4(sampleColors[j].rgb, exposureScale); + } + + float totalWeight = 0; + [unroll] + for (uint k = 0; k < 9; k++) + { + totalWeight += sampleWeights[k]; + } + sampleColors[4] = (sampleColors[0] * sampleWeights[0] + sampleColors[1] * sampleWeights[1] + sampleColors[2] * sampleWeights[2] + sampleColors[3] * sampleWeights[3] + sampleColors[4] * sampleWeights[4] + + sampleColors[5] * sampleWeights[5] + sampleColors[6] * sampleWeights[6] + sampleColors[7] * sampleWeights[7] + sampleColors[8] * sampleWeights[8]) / totalWeight; + + // Variance Clipping (AABB) + + float4 m1 = 0.0; + float4 m2 = 0.0; + [unroll] + for (uint x = 0; x < 9; x++) + { + m1 += sampleColors[x]; + m2 += sampleColors[x] * sampleColors[x]; + } + + float4 mean = m1 / 9.0; + float4 stddev = sqrt((m2 / 9.0) - sqr(mean)); + + currentMin = mean - AABBScale * stddev; + currentMax = mean + AABBScale * stddev; + + currentOutput = sampleColors[4]; + currentMin = min(currentMin, currentOutput); + currentMax = max(currentMax, currentOutput); + currentAverage = mean; +} + +[numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)] +void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 Gid : SV_GroupID, uint groupIndex : SV_GroupIndex) +{ + const float2 uv = (DTid.xy + 0.5f) * xPPResolution_rcp; + + float2 velocity = texture_gbuffer1.SampleLevel(sampler_linear_clamp, uv, 0).zw; + float2 prevUV = uv + velocity; + + // Disocclusion fallback: + float depth_current = texture_lineardepth[DTid.xy] * g_xCamera_ZFarP; + float depth_history = getLinearDepth(texture_depth_history.SampleLevel(sampler_point_clamp, prevUV, 0)); + if (length(velocity) > 0.0025 && abs(depth_current - depth_history) > 1) + { + output[DTid.xy] = resolve_current.SampleLevel(sampler_point_clamp, uv, 0); + return; + } + + float4 previous = resolve_history.SampleLevel(sampler_linear_clamp, prevUV, 0); + + // Luma HDR and AABB minmax + + float4 current = 0; + float4 currentMin, currentMax, currentAverage; + ResolverAABB(resolve_current, sampler_linear_clamp, 0, temporalExposure, temporalScale, uv, xPPResolution, currentMin, currentMax, currentAverage, current); + + previous.xyz = clip_aabb(currentMin.xyz, currentMax.xyz, clamp(currentAverage, currentMin, currentMax), previous).xyz; + previous.a = clamp(previous.a, currentMin.a, currentMax.a); + + // Blend color & history + // Feedback weight from unbiased luminance difference (Timothy Lottes) + + float lumFiltered = Luminance(current.rgb); // Luma4(current.rgb) + float lumHistory = Luminance(previous.rgb); + + float lumDifference = abs(lumFiltered - lumHistory) / max(lumFiltered, max(lumHistory, 0.2f)); + float lumWeight = sqr(1.0f - lumDifference); + float blendFinal = lerp(temporalResponseMin, temporalResponseMax, lumWeight); + + // Reduce ghosting by refreshing the blend by velocity (Unreal) + float2 velocityScreen = velocity * xPPResolution; + float velocityBlend = sqrt(dot(velocityScreen, velocityScreen)); + blendFinal = lerp(blendFinal, 0.2, saturate(velocityBlend / 100.0)); + + float4 result = lerp(current, previous, blendFinal); + + output[DTid.xy] = max(0, result); +} diff --git a/WickedEngine/dirLightPS.hlsl b/WickedEngine/dirLightPS.hlsl deleted file mode 100644 index 136f1dcea..000000000 --- a/WickedEngine/dirLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main( VertexToPixel PSIn ) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_DIRECTIONAL - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/discLightPS.hlsl b/WickedEngine/discLightPS.hlsl deleted file mode 100644 index 1dbf99a55..000000000 --- a/WickedEngine/discLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_DISC - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/emittedparticleHF.hlsli b/WickedEngine/emittedparticleHF.hlsli index 8a14da6c0..0bd0f5e4f 100644 --- a/WickedEngine/emittedparticleHF.hlsli +++ b/WickedEngine/emittedparticleHF.hlsli @@ -4,10 +4,9 @@ struct VertextoPixel { float4 pos : SV_POSITION; - float4 pos2D : TEXCOORD0; - float4 tex : TEXCOORD1; - nointerpolation float size : TEXCOORD2; - nointerpolation uint color : TEXCOORD3; + float4 tex : TEXCOORD0; + nointerpolation float size : TEXCOORD1; + nointerpolation uint color : TEXCOORD2; float3 P : WORLDPOSITION; nointerpolation float frameBlend : FRAMEBLEND; float2 unrotated_uv : UNROTATED_UV; diff --git a/WickedEngine/emittedparticleMS.hlsl b/WickedEngine/emittedparticleMS.hlsl index 0ccb95d43..9a1cbbfe2 100644 --- a/WickedEngine/emittedparticleMS.hlsl +++ b/WickedEngine/emittedparticleMS.hlsl @@ -105,7 +105,6 @@ void main( Out.tex = float4(uv, uv2); Out.size = size; Out.color = (particle.color_mirror & 0x00FFFFFF) | (uint(opacity * 255.0f) << 24); - Out.pos2D = Out.pos; Out.unrotated_uv = quadPos.xy * float2(1, -1) / size * 0.5f + 0.5f; Out.frameBlend = frameBlend; diff --git a/WickedEngine/emittedparticlePS_soft.hlsl b/WickedEngine/emittedparticlePS_soft.hlsl index 440b9c26a..0e02ece40 100644 --- a/WickedEngine/emittedparticlePS_soft.hlsl +++ b/WickedEngine/emittedparticlePS_soft.hlsl @@ -1,10 +1,14 @@ #include "globals.hlsli" #include "emittedparticleHF.hlsli" #include "ShaderInterop_EmittedParticle.h" -#include "lightingHF.hlsli" +#include "objectHF.hlsli" float4 main(VertextoPixel input) : SV_TARGET { +#ifdef SPIRV + input.pos.w = rcp(input.pos.w); +#endif // SPIRV + float4 color = texture_0.Sample(sampler_linear_clamp, input.tex.xy); [branch] @@ -16,9 +20,10 @@ float4 main(VertextoPixel input) : SV_TARGET clip(color.a - 1.0f / 255.0f); - float2 pTex = input.pos2D.xy / input.pos2D.w * float2(0.5f, -0.5f) + 0.5f; - float4 depthScene = texture_lineardepth.GatherRed(sampler_linear_clamp, pTex) * g_xCamera_ZFarP; - float depthFragment = input.pos2D.w; + float2 pixel = input.pos.xy; + float2 ScreenCoord = pixel * g_xFrame_InternalResolution_rcp; + float4 depthScene = texture_lineardepth.GatherRed(sampler_linear_clamp, ScreenCoord) * g_xCamera_ZFarP; + float depthFragment = input.pos.w; float fade = saturate(1.0 / input.size*(max(max(depthScene.x, depthScene.y), max(depthScene.z, depthScene.w)) - depthFragment)); float4 inputColor; @@ -48,56 +53,9 @@ float4 main(VertextoPixel input) : SV_TARGET Lighting lighting = CreateLighting(0, 0, GetAmbient(N), 0); Surface surface = CreateSurface(input.P, N, 0, color, 1, 1, 0, 0); + surface.pixel = pixel; - [loop] - for (uint iterator = 0; iterator < g_xFrame_LightArrayCount; iterator++) - { - ShaderEntity light = EntityArray[g_xFrame_LightArrayOffset + iterator]; - - if (light.GetFlags() & ENTITY_FLAG_LIGHT_STATIC) - { - continue; // static lights will be skipped (they are used in lightmap baking) - } - - switch (light.GetType()) - { - case ENTITY_TYPE_DIRECTIONALLIGHT: - { - DirectionalLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_POINTLIGHT: - { - PointLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_SPOTLIGHT: - { - SpotLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_SPHERELIGHT: - { - SphereLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_DISCLIGHT: - { - DiscLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_RECTANGLELIGHT: - { - RectangleLight(light, surface, lighting); - } - break; - case ENTITY_TYPE_TUBELIGHT: - { - TubeLight(light, surface, lighting); - } - break; - } - } + TiledLighting(surface, lighting); color.rgb *= lighting.direct.diffuse + lighting.indirect.diffuse; diff --git a/WickedEngine/emittedparticleVS.hlsl b/WickedEngine/emittedparticleVS.hlsl index ebc732e2c..bf67d001d 100644 --- a/WickedEngine/emittedparticleVS.hlsl +++ b/WickedEngine/emittedparticleVS.hlsl @@ -6,22 +6,16 @@ static const float3 BILLBOARD[] = { float3(-1, -1, 0), // 0 float3(1, -1, 0), // 1 float3(-1, 1, 0), // 2 - float3(-1, 1, 0), // 3 - float3(1, -1, 0), // 4 - float3(1, 1, 0), // 5 + float3(1, 1, 0), // 4 }; STRUCTUREDBUFFER(particleBuffer, Particle, TEXSLOT_ONDEMAND21); STRUCTUREDBUFFER(aliveList, uint, TEXSLOT_ONDEMAND22); -VertextoPixel main(uint fakeIndex : SV_VERTEXID) +VertextoPixel main(uint vertexID : SV_VERTEXID, uint instanceID : SV_INSTANCEID) { VertextoPixel Out; - // bypass the geometry shader, and instead expand the particle here in the VS: - uint vertexID = fakeIndex % 6; - uint instanceID = fakeIndex / 6; - // load particle data: Particle particle = particleBuffer[aliveList[instanceID]]; @@ -77,7 +71,6 @@ VertextoPixel main(uint fakeIndex : SV_VERTEXID) Out.tex = float4(uv, uv2); Out.size = size; Out.color = (particle.color_mirror & 0x00FFFFFF) | (uint(opacity * 255.0f) << 24); - Out.pos2D = Out.pos; Out.unrotated_uv = quadPos.xy * float2(1, -1) / size * 0.5f + 0.5f; Out.frameBlend = frameBlend; diff --git a/WickedEngine/emittedparticle_finishUpdateCS.hlsl b/WickedEngine/emittedparticle_finishUpdateCS.hlsl index f0bf8bb92..0d8b5f641 100644 --- a/WickedEngine/emittedparticle_finishUpdateCS.hlsl +++ b/WickedEngine/emittedparticle_finishUpdateCS.hlsl @@ -18,6 +18,6 @@ void main( uint3 DTid : SV_DispatchThreadID ) else { // Create draw argument buffer (VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation): - indirectBuffers.Store4(ARGUMENTBUFFER_OFFSET_DRAWPARTICLES, uint4(particleCount * 6, 1, 0, 0)); + indirectBuffers.Store4(ARGUMENTBUFFER_OFFSET_DRAWPARTICLES, uint4(4, particleCount, 0, 0)); } } diff --git a/WickedEngine/envMapHF.hlsli b/WickedEngine/envMapHF.hlsli index db5d5bbe2..d85f600fa 100644 --- a/WickedEngine/envMapHF.hlsli +++ b/WickedEngine/envMapHF.hlsli @@ -10,6 +10,7 @@ struct PSIn_EnvmapRendering float4 uvsets : UVSETS; float2 atl : ATLAS; float3 nor : NORMAL; + float4 tan : TANGENT; float3 pos3D : WORLDPOSITION; uint RTIndex : SV_RenderTargetArrayIndex; }; diff --git a/WickedEngine/envMapVS.hlsl b/WickedEngine/envMapVS.hlsl index 4e36592d9..13e1c23a6 100644 --- a/WickedEngine/envMapVS.hlsl +++ b/WickedEngine/envMapVS.hlsl @@ -9,6 +9,9 @@ PSIn_EnvmapRendering main(Input_Object_ALL input) float4x4 WORLD = MakeWorldMatrixFromInstance(input.inst); VertexSurface surface = MakeVertexSurfaceFromInput(input); + surface.normal = normalize(mul((float3x3)WORLD, surface.normal)); + surface.tangent.xyz = normalize(mul((float3x3)WORLD, surface.tangent.xyz)); + uint frustum_index = input.inst.userdata.y; output.RTIndex = xCubemapRenderCams[frustum_index].properties.x; output.pos = mul(WORLD, surface.position); @@ -17,7 +20,8 @@ PSIn_EnvmapRendering main(Input_Object_ALL input) output.color = surface.color; output.uvsets = surface.uvsets; output.atl = surface.atlas; - output.nor = normalize(mul((float3x3)WORLD, surface.normal)); + output.nor = surface.normal; + output.tan = surface.tangent; return output; } diff --git a/WickedEngine/environmentalLightPS.hlsl b/WickedEngine/environmentalLightPS.hlsl deleted file mode 100644 index b76657a70..000000000 --- a/WickedEngine/environmentalLightPS.hlsl +++ /dev/null @@ -1,30 +0,0 @@ -#include "deferredLightHF.hlsli" - -TEXTURE2D(texture_ao, float, TEXSLOT_RENDERPATH_AO); -TEXTURE2D(texture_ssr, float4, TEXSLOT_RENDERPATH_SSR); - - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - float envMapMIP = surface.roughness * g_xFrame_EnvProbeMipCount; - lighting.indirect.specular = max(0, EnvironmentReflection_Global(surface, envMapMIP)); - - LightingContribution vxgi_contribution = VoxelGI(surface, lighting); - - float4 ssr = texture_ssr.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0); - lighting.indirect.specular = lerp(lighting.indirect.specular, ssr.rgb, ssr.a); - - float ao = texture_ao.SampleLevel(sampler_linear_clamp, ScreenCoord, 0).r; - surface.occlusion = ao; - - // Blend factor modulation: - // Alpha is not written, but blending will multiply the dest rgb with 1-alpha - // Modulate alpha to overwrite dest (which contains ambient and light map before this pass) - ao = saturate(1 - ao); - diffuse_alpha = max(vxgi_contribution.diffuse, ao); - specular_alpha = max(max(vxgi_contribution.specular, ssr.a), ao); - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/fontVS.hlsl b/WickedEngine/fontVS.hlsl index 88740cfd2..ecc2eabe6 100644 --- a/WickedEngine/fontVS.hlsl +++ b/WickedEngine/fontVS.hlsl @@ -7,13 +7,16 @@ struct VertextoPixel float2 tex : TEXCOORD0; }; -VertextoPixel main(float2 inPos : POSITION, float2 inTex : TEXCOORD0) +RAWBUFFER(vertexBuffer, 0); + +VertextoPixel main(uint vertexID : SV_VERTEXID, uint instanceID : SV_InstanceID) { VertextoPixel Out; - Out.pos = mul(g_xFont_Transform, float4(inPos, 0, 1)); - - Out.tex = inTex; + uint vID = instanceID * 4 + vertexID; + uint3 raw = vertexBuffer.Load3(g_xFont_BufferOffset + vID * 12); + Out.pos = mul(g_xFont_Transform, float4(asfloat(raw.xy), 0, 1)); + Out.tex = unpack_half2(raw.z); return Out; } diff --git a/WickedEngine/globals.hlsli b/WickedEngine/globals.hlsli index c3d3c7dfa..c7050f9df 100644 --- a/WickedEngine/globals.hlsli +++ b/WickedEngine/globals.hlsli @@ -7,7 +7,6 @@ TEXTURE2D(texture_depth, float, TEXSLOT_DEPTH); TEXTURE2D(texture_lineardepth, float, TEXSLOT_LINEARDEPTH); TEXTURE2D(texture_gbuffer0, float4, TEXSLOT_GBUFFER0); TEXTURE2D(texture_gbuffer1, float4, TEXSLOT_GBUFFER1); -TEXTURE2D(texture_gbuffer2, float4, TEXSLOT_GBUFFER2); RAYTRACINGACCELERATIONSTRUCTURE(scene_acceleration_structure, TEXSLOT_ACCELERATION_STRUCTURE); TEXTURECUBE(texture_globalenvmap, float4, TEXSLOT_GLOBALENVMAP); TEXTURE2D(texture_globallightmap, float4, TEXSLOT_GLOBALLIGHTMAP); @@ -199,7 +198,25 @@ inline void FullScreenTriangle(in uint vertexID, out float4 pos, out float2 uv) // Computes a tangent-basis matrix for a surface using screen-space derivatives inline float3x3 compute_tangent_frame(float3 N, float3 P, float2 UV) { - // ddx_coarse can be faster than ddx, but could result in artifacts. Haven't observed any artifacts yet. +#if 1 + // http://www.thetenthplanet.de/archives/1180 + // get edge vectors of the pixel triangle + float3 dp1 = ddx_coarse(P); + float3 dp2 = ddy_coarse(P); + float2 duv1 = ddx_coarse(UV); + float2 duv2 = ddy_coarse(UV); + + // solve the linear system + float3 dp2perp = cross(dp2, N); + float3 dp1perp = cross(N, dp1); + float3 T = dp2perp * duv1.x + dp1perp * duv2.x; + float3 B = dp2perp * duv1.y + dp1perp * duv2.y; + + // construct a scale-invariant frame + float invmax = rcp(sqrt(max(dot(T, T), dot(B, B)))); + return float3x3(T * invmax, B * invmax, N); +#else + // Old version float3 dp1 = ddx_coarse(P); float3 dp2 = ddy_coarse(P); float2 duv1 = ddx_coarse(UV); @@ -211,6 +228,7 @@ inline float3x3 compute_tangent_frame(float3 N, float3 P, float2 UV) float3 B = normalize(mul(float2(duv1.y, duv2.y), inverseM)); return float3x3(T, B, N); +#endif } // Computes linear depth from post-projection depth @@ -255,7 +273,7 @@ float3 hemispherepoint_cos(float u, float v) { // Get random hemisphere sample in world-space along the normal (uniform distribution) inline float3 SampleHemisphere_uniform(in float3 normal, inout float seed, in float2 pixel) { - return mul(hemispherepoint_cos(rand(seed, pixel), rand(seed, pixel)), GetTangentSpace(normal)); + return mul(hemispherepoint_uniform(rand(seed, pixel), rand(seed, pixel)), GetTangentSpace(normal)); } // Get random hemisphere sample in world-space along the normal (cosine-weighted distribution) inline float3 SampleHemisphere_cos(in float3 normal, inout float seed, in float2 pixel) @@ -425,6 +443,19 @@ inline float4 unpack_rgba(in uint value) return retVal; } +inline uint2 pack_half2(in float2 value) +{ + uint retVal = 0; + retVal = f32tof16(value.x) | (f32tof16(value.y) << 16); + return retVal; +} +inline float2 unpack_half2(in uint value) +{ + float2 retVal; + retVal.x = f16tof32(value.x); + retVal.y = f16tof32(value.x >> 16); + return retVal; +} inline uint2 pack_half3(in float3 value) { uint2 retVal = 0; diff --git a/WickedEngine/hairparticleHF.hlsli b/WickedEngine/hairparticleHF.hlsli index eb2a23f67..9b199d282 100644 --- a/WickedEngine/hairparticleHF.hlsli +++ b/WickedEngine/hairparticleHF.hlsli @@ -8,7 +8,6 @@ struct VertexToPixel float3 nor : NORMAL; float2 tex : TEXCOORD; float fade : DITHERFADE; - float4 pos2D : SCREENPOSITION; float4 pos2DPrev : SCREENPOSITIONPREV; float3 color : COLOR; }; diff --git a/WickedEngine/hairparticlePS_tiledforward.hlsl b/WickedEngine/hairparticlePS.hlsl similarity index 54% rename from WickedEngine/hairparticlePS_tiledforward.hlsl rename to WickedEngine/hairparticlePS.hlsl index 012d8024f..9104ac569 100644 --- a/WickedEngine/hairparticlePS_tiledforward.hlsl +++ b/WickedEngine/hairparticlePS.hlsl @@ -4,18 +4,12 @@ #include "objectHF.hlsli" #include "hairparticleHF.hlsli" -#ifndef TRANSPARENT [earlydepthstencil] -#endif // TRANSPARENT -GBUFFEROutputType_Thin main(VertexToPixel input) +GBUFFEROutputType main(VertexToPixel input) { float4 color = texture_0.Sample(sampler_linear_wrap, input.tex); color.rgb = DEGAMMA(color.rgb); color.rgb *= input.color; -#ifdef TRANSPARENT - color.a *= 1.0 - input.fade; - clip(color.a - 1.0f / 255.0f); // cancel heaviest overdraw for the alpha composition effect -#endif // TRANSPARENT float opacity = 1; float3 V = g_xCamera_CamPos - input.pos3D; float dist = length(V); @@ -23,16 +17,16 @@ GBUFFEROutputType_Thin main(VertexToPixel input) float emissive = 0; Surface surface = CreateSurface(input.pos3D, input.nor, V, color, 1, 1, 0, 0); Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 pixel = input.pos.xy; + surface.pixel = input.pos.xy; float depth = input.pos.z; float3 reflection = 0; - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - TiledLighting(pixel, surface, lighting); + float2 ScreenCoord = surface.pixel * g_xFrame_InternalResolution_rcp; + float2 pos2D = ScreenCoord * 2 - 1; + pos2D.y *= -1; + float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - ApplyLighting(surface, lighting, color); + TiledLighting(surface, lighting); - ApplyFog(dist, color); - - return CreateGbuffer_Thin(color, surface, velocity); -} \ No newline at end of file + return CreateGbuffer(surface, velocity, lighting); +} diff --git a/WickedEngine/hairparticlePS_deferred.hlsl b/WickedEngine/hairparticlePS_deferred.hlsl deleted file mode 100644 index 6fe2040a3..000000000 --- a/WickedEngine/hairparticlePS_deferred.hlsl +++ /dev/null @@ -1,19 +0,0 @@ -#include "globals.hlsli" -#include "objectHF.hlsli" -#include "hairparticleHF.hlsli" - -GBUFFEROutputType main(VertexToPixel input) -{ - clip(dither(input.pos.xy + GetTemporalAASampleRotation()) - input.fade); - - float4 color = texture_0.Sample(sampler_linear_clamp, input.tex); - color.rgb = DEGAMMA(color.rgb); - color.rgb *= input.color; - ALPHATEST(color.a) - float emissive = 0; - Surface surface = CreateSurface(0, input.nor, 0, color, 1, 1, 0, 0); - Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - - return CreateGbuffer(color, surface, velocity, lighting); -} \ No newline at end of file diff --git a/WickedEngine/hairparticlePS_forward.hlsl b/WickedEngine/hairparticlePS_forward.hlsl deleted file mode 100644 index 931ada915..000000000 --- a/WickedEngine/hairparticlePS_forward.hlsl +++ /dev/null @@ -1,35 +0,0 @@ -#include "globals.hlsli" -#include "objectHF.hlsli" -#include "hairparticleHF.hlsli" - -#ifndef TRANSPARENT -[earlydepthstencil] -#endif // TRANSPARENT -GBUFFEROutputType_Thin main(VertexToPixel input) -{ - float4 color = texture_0.Sample(sampler_linear_clamp, input.tex); - color.rgb = DEGAMMA(color.rgb); - color.rgb *= input.color; -#ifdef TRANSPARENT - color.a *= 1.0 - input.fade; - clip(color.a - 1.0f / 255.0f); // cancel heaviest overdraw for the alpha composition effect -#endif // TRANSPARENT - float opacity = 1; // keep edge diffuse shading - float3 V = g_xCamera_CamPos - input.pos3D; - float dist = length(V); - V /= dist; - float emissive = 0; - Surface surface = CreateSurface(input.pos3D, input.nor, V, color, 1, 1, 0, 0); - Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 pixel = input.pos.xy; - float depth = input.pos.z; - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - - ForwardLighting(surface, lighting); - - ApplyLighting(surface, lighting, color); - - ApplyFog(dist, color); - - return CreateGbuffer_Thin(color, surface, velocity); -} \ No newline at end of file diff --git a/WickedEngine/hairparticlePS_forward_transparent.hlsl b/WickedEngine/hairparticlePS_forward_transparent.hlsl deleted file mode 100644 index caa0a1bca..000000000 --- a/WickedEngine/hairparticlePS_forward_transparent.hlsl +++ /dev/null @@ -1,2 +0,0 @@ -#define TRANSPARENT -#include "hairparticlePS_forward.hlsl" diff --git a/WickedEngine/hairparticlePS_tiledforward_transparent.hlsl b/WickedEngine/hairparticlePS_tiledforward_transparent.hlsl deleted file mode 100644 index 0e14af4b7..000000000 --- a/WickedEngine/hairparticlePS_tiledforward_transparent.hlsl +++ /dev/null @@ -1,2 +0,0 @@ -#define TRANSPARENT -#include "hairparticlePS_tiledforward.hlsl" diff --git a/WickedEngine/hairparticleVS.hlsl b/WickedEngine/hairparticleVS.hlsl index 998afedd4..001bd5839 100644 --- a/WickedEngine/hairparticleVS.hlsl +++ b/WickedEngine/hairparticleVS.hlsl @@ -2,33 +2,22 @@ #include "hairparticleHF.hlsli" #include "ShaderInterop_HairParticle.h" -// billboard cross section: static const float3 HAIRPATCH[] = { float3(-1, -1, 0), float3(1, -1, 0), float3(-1, 1, 0), - float3(-1, 1, 0), - float3(1, -1, 0), float3(1, 1, 0), - - float3(0, -1, -1), - float3(0, -1, 1), - float3(0, 1, -1), - float3(0, 1, -1), - float3(0, -1, 1), - float3(0, 1, 1), }; STRUCTUREDBUFFER(particleBuffer, Patch, 0); +STRUCTUREDBUFFER(culledIndexBuffer, uint, 1); -VertexToPixel main(uint fakeIndex : SV_VERTEXID) +VertexToPixel main(uint vertexID : SV_VERTEXID, uint instanceID : SV_INSTANCEID) { VertexToPixel Out; - // bypass the geometry shader and expand the particle here: - const uint vertexID = fakeIndex % 12; - const uint segmentID = (fakeIndex / 12) % xHairSegmentCount; - const uint particleID = fakeIndex / 12; + const uint particleID = culledIndexBuffer[instanceID]; + const uint segmentID = particleID % xHairSegmentCount; float3 rootposition = particleBuffer[particleID - segmentID].position; Out.fade = saturate(distance(rootposition.xyz, g_xCamera_CamPos.xyz) / xHairViewDistance); @@ -104,7 +93,6 @@ VertexToPixel main(uint fakeIndex : SV_VERTEXID) Out.nor = normalize(normal + wind); Out.tex = uv; - Out.pos2D = Out.pos; Out.pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, float4(savedPos + windPrev, 1)); Out.color = xColor.rgb; diff --git a/WickedEngine/hairparticle_finishUpdateCS.hlsl b/WickedEngine/hairparticle_finishUpdateCS.hlsl new file mode 100644 index 000000000..7ccbabf1a --- /dev/null +++ b/WickedEngine/hairparticle_finishUpdateCS.hlsl @@ -0,0 +1,18 @@ +#include "globals.hlsli" +#include "ShaderInterop_HairParticle.h" + +RWRAWBUFFER(counterBuffer, 0); + +[numthreads(1, 1, 1)] +void main( uint3 DTid : SV_DispatchThreadID ) +{ + uint particleCount = counterBuffer.Load(0); + + AllMemoryBarrier(); + + // Reset counter for next frame: + counterBuffer.Store(0, 0); + + // Create draw argument buffer (VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation): + counterBuffer.Store4(4, uint4(4, particleCount, 0, 0)); +} diff --git a/WickedEngine/hairparticle_simulateCS.hlsl b/WickedEngine/hairparticle_simulateCS.hlsl index 02c44312c..c5889641d 100644 --- a/WickedEngine/hairparticle_simulateCS.hlsl +++ b/WickedEngine/hairparticle_simulateCS.hlsl @@ -3,6 +3,8 @@ RWSTRUCTUREDBUFFER(particleBuffer, Patch, 0); RWSTRUCTUREDBUFFER(simulationBuffer, PatchSimulationData, 1); +RWSTRUCTUREDBUFFER(indexBuffer, uint, 2); +RWRAWBUFFER(counterBuffer, 3); TYPEDBUFFER(meshIndexBuffer, uint, TEXSLOT_ONDEMAND0); RAWBUFFER(meshVertexBuffer_POS, TEXSLOT_ONDEMAND1); @@ -180,5 +182,24 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn // Offset next segment root to current tip: base = tip; + + + // Frustum culling: + float3 sphereCenter = base + tip * 0.5f; + float sphereRadius = length(sphereCenter - base); + bool infrustum = true; + infrustum = distance(sphereCenter, g_xCamera_CamPos.xyz) > xHairViewDistance ? false : infrustum; + infrustum = dot(g_xCamera_FrustumPlanes[0], float4(sphereCenter, 1)) < -sphereRadius ? false : infrustum; + infrustum = dot(g_xCamera_FrustumPlanes[2], float4(sphereCenter, 1)) < -sphereRadius ? false : infrustum; + infrustum = dot(g_xCamera_FrustumPlanes[3], float4(sphereCenter, 1)) < -sphereRadius ? false : infrustum; + infrustum = dot(g_xCamera_FrustumPlanes[4], float4(sphereCenter, 1)) < -sphereRadius ? false : infrustum; + infrustum = dot(g_xCamera_FrustumPlanes[5], float4(sphereCenter, 1)) < -sphereRadius ? false : infrustum; + + if (infrustum) + { + uint prevCount; + counterBuffer.InterlockedAdd(0, 1, prevCount); + indexBuffer[prevCount] = particleID; + } } } diff --git a/WickedEngine/impostorHF.hlsli b/WickedEngine/impostorHF.hlsli index 5962195d3..abf19fd63 100644 --- a/WickedEngine/impostorHF.hlsli +++ b/WickedEngine/impostorHF.hlsli @@ -8,7 +8,6 @@ struct VSOut nointerpolation float dither : DITHER; float3 pos3D : WORLDPOSITION; uint instanceColor : INSTANCECOLOR; - float4 pos2D : SCREENPOSITION; float4 pos2DPrev : SCREENPOSITIONPREV; }; diff --git a/WickedEngine/impostorPS_tiledforward.hlsl b/WickedEngine/impostorPS.hlsl similarity index 71% rename from WickedEngine/impostorPS_tiledforward.hlsl rename to WickedEngine/impostorPS.hlsl index 877c81793..55e886f53 100644 --- a/WickedEngine/impostorPS_tiledforward.hlsl +++ b/WickedEngine/impostorPS.hlsl @@ -3,7 +3,7 @@ #include "objectHF.hlsli" [earlydepthstencil] -GBUFFEROutputType_Thin main(VSOut input) +GBUFFEROutputType main(VSOut input) { float3 uv_col = input.tex; float3 uv_nor = uv_col; @@ -25,15 +25,14 @@ GBUFFEROutputType_Thin main(VSOut input) V /= dist; Surface surface = CreateSurface(input.pos3D, N, V, color, roughness, ao, metalness, reflectance); Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 pixel = input.pos.xy; - float depth = input.pos.z; - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); + surface.pixel = input.pos.xy; - TiledLighting(pixel, surface, lighting); + float2 ScreenCoord = surface.pixel * g_xFrame_InternalResolution_rcp; + float2 pos2D = ScreenCoord * 2 - 1; + pos2D.y *= -1; + float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - ApplyLighting(surface, lighting, color); + TiledLighting(surface, lighting); - ApplyFog(dist, color); - - return CreateGbuffer_Thin(color, surface, velocity); + return CreateGbuffer(surface, velocity, lighting); } \ No newline at end of file diff --git a/WickedEngine/impostorPS_deferred.hlsl b/WickedEngine/impostorPS_deferred.hlsl deleted file mode 100644 index 3b79c0cc1..000000000 --- a/WickedEngine/impostorPS_deferred.hlsl +++ /dev/null @@ -1,32 +0,0 @@ -#include "globals.hlsli" -#include "impostorHF.hlsli" -#include "objectHF.hlsli" - -GBUFFEROutputType main(VSOut input) -{ - clip(dither(input.pos.xy + GetTemporalAASampleRotation()) - input.dither); - - float3 uv_col = input.tex; - float3 uv_nor = uv_col; - uv_nor.z += impostorCaptureAngles; - float3 uv_sur = uv_nor; - uv_sur.z += impostorCaptureAngles; - - float4 color = impostorTex.Sample(sampler_linear_clamp, uv_col) * unpack_rgba(input.instanceColor); - ALPHATEST(color.a); - - float3 N = impostorTex.Sample(sampler_linear_clamp, uv_nor).rgb * 2 - 1; - float4 surfaceparams = impostorTex.Sample(sampler_linear_clamp, uv_sur); - - float ao = surfaceparams.r; - float roughness = surfaceparams.g; - float metalness = surfaceparams.b; - float reflectance = surfaceparams.a; - - Surface surface = CreateSurface(0, N, 0, color, roughness, ao, metalness, reflectance); - Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - - return CreateGbuffer(color, surface, velocity, lighting); -} \ No newline at end of file diff --git a/WickedEngine/impostorPS_forward.hlsl b/WickedEngine/impostorPS_forward.hlsl deleted file mode 100644 index 0093a776a..000000000 --- a/WickedEngine/impostorPS_forward.hlsl +++ /dev/null @@ -1,39 +0,0 @@ -#include "globals.hlsli" -#include "impostorHF.hlsli" -#include "objectHF.hlsli" - -[earlydepthstencil] -GBUFFEROutputType_Thin main(VSOut input) -{ - float3 uv_col = input.tex; - float3 uv_nor = uv_col; - uv_nor.z += impostorCaptureAngles; - float3 uv_sur = uv_nor; - uv_sur.z += impostorCaptureAngles; - - float4 color = impostorTex.Sample(sampler_linear_clamp, uv_col) * unpack_rgba(input.instanceColor); - float3 N = impostorTex.Sample(sampler_linear_clamp, uv_nor).rgb * 2 - 1; - float4 surfaceparams = impostorTex.Sample(sampler_linear_clamp, uv_sur); - - float ao = surfaceparams.r; - float roughness = surfaceparams.g; - float metalness = surfaceparams.b; - float reflectance = surfaceparams.a; - - float3 V = g_xCamera_CamPos - input.pos3D; - float dist = length(V); - V /= dist; - Surface surface = CreateSurface(input.pos3D, N, V, color, roughness, ao, reflectance, metalness); - Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 pixel = input.pos.xy; - float depth = input.pos.z; - float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy / input.pos2D.w - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - - ForwardLighting(surface, lighting); - - ApplyLighting(surface, lighting, color); - - ApplyFog(dist, color); - - return CreateGbuffer_Thin(color, surface, velocity); -} \ No newline at end of file diff --git a/WickedEngine/impostorVS.hlsl b/WickedEngine/impostorVS.hlsl index 5002bc5e1..8ad0b1746 100644 --- a/WickedEngine/impostorVS.hlsl +++ b/WickedEngine/impostorVS.hlsl @@ -59,7 +59,6 @@ VSOut main(uint fakeIndex : SV_VERTEXID) Out.tex = tex; Out.dither = 1 - color_dither.a; Out.instanceColor = pack_rgba(float4(color_dither.rgb, 1)); - Out.pos2D = Out.pos; Out.pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, float4(Out.pos3D, 1)); return Out; diff --git a/WickedEngine/lightCullingCS_DEFERRED.hlsl b/WickedEngine/lightCullingCS_DEFERRED.hlsl deleted file mode 100644 index a0a4332f9..000000000 --- a/WickedEngine/lightCullingCS_DEFERRED.hlsl +++ /dev/null @@ -1,2 +0,0 @@ -#define DEFERRED -#include "lightCullingCS.hlsl" diff --git a/WickedEngine/lightCullingCS_DEFERRED_ADVANCED.hlsl b/WickedEngine/lightCullingCS_DEFERRED_ADVANCED.hlsl deleted file mode 100644 index e9dd1bf80..000000000 --- a/WickedEngine/lightCullingCS_DEFERRED_ADVANCED.hlsl +++ /dev/null @@ -1,3 +0,0 @@ -#define DEFERRED -#define ADVANCED_CULLING -#include "lightCullingCS.hlsl" diff --git a/WickedEngine/lightCullingCS_DEFERRED_ADVANCED_DEBUG.hlsl b/WickedEngine/lightCullingCS_DEFERRED_ADVANCED_DEBUG.hlsl deleted file mode 100644 index 1a452c349..000000000 --- a/WickedEngine/lightCullingCS_DEFERRED_ADVANCED_DEBUG.hlsl +++ /dev/null @@ -1,4 +0,0 @@ -#define DEFERRED -#define ADVANCED_CULLING -#define DEBUG_TILEDLIGHTCULLING -#include "lightCullingCS.hlsl" diff --git a/WickedEngine/lightCullingCS_DEFERRED_DEBUG.hlsl b/WickedEngine/lightCullingCS_DEFERRED_DEBUG.hlsl deleted file mode 100644 index ad5a01243..000000000 --- a/WickedEngine/lightCullingCS_DEFERRED_DEBUG.hlsl +++ /dev/null @@ -1,3 +0,0 @@ -#define DEFERRED -#define DEBUG_TILEDLIGHTCULLING -#include "lightCullingCS.hlsl" diff --git a/WickedEngine/lightingHF.hlsli b/WickedEngine/lightingHF.hlsli index 5bf0b16a6..1592be34a 100644 --- a/WickedEngine/lightingHF.hlsli +++ b/WickedEngine/lightingHF.hlsli @@ -38,9 +38,17 @@ inline Lighting CreateLighting( // Combine the direct and indirect lighting into final contribution inline LightingPart CombineLighting(in Surface surface, in Lighting lighting) { +#ifdef LIGHTING_CARTOON + lighting.direct.diffuse = smoothstep(0.005, 0.05, lighting.direct.diffuse); + lighting.direct.specular = max(lighting.direct.specular.r, max(lighting.direct.specular.g, lighting.direct.specular.b)); + lighting.direct.specular = step(0.05, lighting.direct.specular); + lighting.indirect.specular = smoothstep(0.008, 0.098, lighting.indirect.specular); +#endif // LIGHTING_CARTOON + LightingPart result; result.diffuse = lighting.direct.diffuse + lighting.indirect.diffuse * surface.occlusion; result.specular = lighting.direct.specular + lighting.indirect.specular * surface.F * surface.occlusion; + return result; } @@ -89,7 +97,7 @@ inline float shadowCube(in ShaderEntity light, float3 Lunnormalized) return texture_shadowarray_cube.SampleCmpLevelZero(sampler_cmp_depth, float4(-Lunnormalized, light.GetShadowMapIndex()), remappedDistance + light.shadowBias).r; } -inline float shadowTrace(float3 P, float3 N, float3 L, float dist) +inline float shadowTrace(in Surface surface, in float3 L, in float dist) { #ifdef RAYTRACING_INLINE RayQuery< @@ -101,8 +109,12 @@ inline float shadowTrace(float3 P, float3 N, float3 L, float dist) RayDesc ray; ray.TMin = 0.001; ray.TMax = dist; - ray.Origin = P + N * 0.01; - ray.Direction = L; + ray.Origin = surface.P + surface.N * 0.01; + + float seed = g_xFrame_FrameCount * 0.001f; + float2 uv = surface.screenUV; + float3 sampling_offset = float3(rand(seed, uv), rand(seed, uv), rand(seed, uv)) * 2 - 1; // todo: should be specific to light surface + ray.Direction = normalize(L + sampling_offset * 0.025f); q.TraceRayInline(scene_acceleration_structure, 0, 0xFF, ray); q.Proceed(); @@ -133,7 +145,7 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - sh *= shadowTrace(surface.P, surface.N, normalize(L), 100000); + sh *= shadowTrace(surface, normalize(L), 100000); } else { @@ -210,7 +222,7 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - sh *= shadowTrace(surface.P, surface.N, L, dist); + sh *= shadowTrace(surface, L, dist); } else { @@ -264,7 +276,7 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - sh *= shadowTrace(surface.P, surface.N, L, dist); + sh *= shadowTrace(surface, L, dist); } else { @@ -400,7 +412,7 @@ inline void SphereLight(in ShaderEntity light, in Surface surface, inout Lightin [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - fLight = shadowTrace(surface.P, surface.N, L, dist); + fLight = shadowTrace(surface, L, dist); } else { @@ -456,7 +468,7 @@ inline void DiscLight(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - fLight = shadowTrace(surface.P, surface.N, L, dist); + fLight = shadowTrace(surface, L, dist); } else { @@ -519,7 +531,7 @@ inline void RectangleLight(in ShaderEntity light, in Surface surface, inout Ligh [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - fLight = shadowTrace(surface.P, surface.N, L, dist); + fLight = shadowTrace(surface, L, dist); } else { @@ -642,7 +654,7 @@ inline void TubeLight(in ShaderEntity light, in Surface surface, inout Lighting [branch] if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS) { - fLight = shadowTrace(surface.P, surface.N, L, dist); + fLight = shadowTrace(surface, L, dist); } else { diff --git a/WickedEngine/objectDS.hlsl b/WickedEngine/objectDS.hlsl index 07afbd8b6..55a0a0a66 100644 --- a/WickedEngine/objectDS.hlsl +++ b/WickedEngine/objectDS.hlsl @@ -26,6 +26,10 @@ struct ConstantOutputType float4 nor1 : NORMAL1; float4 nor2 : NORMAL2; + float4 tan0 : TANGENT0; + float4 tan1 : TANGENT1; + float4 tan2 : TANGENT2; + float4 posPrev0 : POSITIONPREV0; float4 posPrev1 : POSITIONPREV1; float4 posPrev2 : POSITIONPREV2; @@ -38,6 +42,7 @@ struct HullOutputType float4 uvsets : UVSETS; float4 atlas : ATLAS; float4 nor : NORMAL; + float4 tan : TANGENT; float4 posPrev : POSITIONPREV; }; @@ -88,6 +93,11 @@ float3 PhongNormal(float u, float v, float w, ConstantOutputType hsc) // Interpolate return normalize(w * hsc.nor0.xyz + u * hsc.nor1.xyz + v * hsc.nor2.xyz); } +float4 PhongTangent(float u, float v, float w, ConstantOutputType hsc) +{ + // Interpolate + return normalize(w * hsc.tan0 + u * hsc.tan1 + v * hsc.tan2); +} //////////////////////////////////////////////////////////////////////////////// // Domain Shader @@ -101,6 +111,7 @@ PixelInputType main(ConstantOutputType input, float3 uvwCoord : SV_DomainLocatio float4 vertexPosition; float4 vertexPositionPrev; float3 vertexNormal; + float4 vertexTangent; float4 vertexUvsets; float2 vertexAtlas; float4 vertexColor; @@ -122,6 +133,7 @@ PixelInputType main(ConstantOutputType input, float3 uvwCoord : SV_DomainLocatio vertexPositionPrev = float4(PhongGeometryPrev(fU, fV, fW, input), 1); // Compute normal vertexNormal = PhongNormal(fU, fV, fW, input); + vertexTangent = PhongTangent(fU, fV, fW, input); // Displacement float3 displacement = -g_xMaterial.displacementMapping * vertexNormal.xyz; @@ -136,13 +148,14 @@ PixelInputType main(ConstantOutputType input, float3 uvwCoord : SV_DomainLocatio Out.clip = dot(vertexPosition, g_xClipPlane); - Out.pos = Out.pos2D = mul(g_xCamera_VP, vertexPosition); + Out.pos = mul(g_xCamera_VP, vertexPosition); Out.pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, vertexPositionPrev); Out.pos3D = vertexPosition.xyz; Out.uvsets = vertexUvsets; Out.atl = vertexAtlas; Out.color = vertexColor; - Out.nor = normalize(vertexNormal.xyz); + Out.nor = vertexNormal; + Out.tan = vertexTangent; return Out; } \ No newline at end of file diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index dd6052fa1..ae0ea7b70 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -80,8 +80,8 @@ struct PixelInputType float4 uvsets : UVSETS; float2 atl : ATLAS; float3 nor : NORMAL; + float4 tan : TANGENT; float3 pos3D : WORLDPOSITION; - float4 pos2D : SCREENPOSITION; float4 pos2DPrev : SCREENPOSITIONPREV; }; @@ -89,35 +89,18 @@ struct GBUFFEROutputType { float4 g0 : SV_Target0; // texture_gbuffer0 float4 g1 : SV_Target1; // texture_gbuffer1 - float4 g2 : SV_Target2; // texture_gbuffer2 - float4 diffuse : SV_Target3; - float4 specular : SV_Target4; + float4 diffuse : SV_Target2; + float4 specular : SV_Target3; }; -inline GBUFFEROutputType CreateGbuffer(in float4 color, in Surface surface, in float2 velocity, in Lighting lighting) +inline GBUFFEROutputType CreateGbuffer(in Surface surface, in float2 velocity, in Lighting lighting) { LightingPart combined_lighting = CombineLighting(surface, lighting); GBUFFEROutputType Out; - Out.g0 = float4(color.rgb, surface.sss); /*FORMAT_R8G8B8A8_UNORM*/ - Out.g1 = float4(encodeNormal(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ - Out.g2 = float4(surface.roughness, surface.occlusion, surface.metalness, surface.reflectance); /*FORMAT_R8G8B8A8_UNORM*/ - Out.diffuse = float4(combined_lighting.diffuse, 1); /*FORMAT_R11G11B10_FLOAT*/ - Out.specular = float4(combined_lighting.specular, 1); /*FORMAT_R11G11B10_FLOAT*/ - return Out; -} - -struct GBUFFEROutputType_Thin -{ - float4 g0 : SV_Target0; // texture_gbuffer0 - float4 g1 : SV_Target1; // texture_gbuffer1 - float g2 : SV_Target2; // texture_gbuffer2 -}; -inline GBUFFEROutputType_Thin CreateGbuffer_Thin(in float4 color, in Surface surface, in float2 velocity) -{ - GBUFFEROutputType_Thin Out; - Out.g0 = color; /*FORMAT_R11G11B10_FLOAT*/ - Out.g1 = float4(encodeNormal(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ - Out.g2 = surface.roughness; /*FORMAT_R8_UNORM*/ + Out.g0 = float4(surface.albedo, surface.roughness); /*FORMAT_R8G8B8A8_UNORM*/ + Out.g1 = float4(encodeNormal(surface.N), velocity); /*FORMAT_R16G16B16A16_FLOAT*/ + Out.diffuse = float4(combined_lighting.diffuse, 1); /*FORMAT_R11G11B10_FLOAT*/ + Out.specular = float4(combined_lighting.specular, 1); /*FORMAT_R11G11B10_FLOAT*/ return Out; } @@ -132,6 +115,7 @@ inline void ApplyEmissive(in Surface surface, inout Lighting lighting) inline void LightMapping(in float2 ATLAS, inout Lighting lighting) { + [branch] if (any(ATLAS)) { #ifdef LIGHTMAP_QUALITY_BICUBIC @@ -143,13 +127,21 @@ inline void LightMapping(in float2 ATLAS, inout Lighting lighting) } } -inline void NormalMapping(in float2 UV, in float3 V, inout float3 N, in float3x3 TBN, out float3 bumpColor) +inline void NormalMapping(inout float4 uvsets, in float3 V, inout float3 N, in float3x3 TBN, out float3 bumpColor) { - float3 normalMap = texture_normalmap.Sample(sampler_objectshader, UV).rgb; - bumpColor = normalMap.rgb * 2 - 1; - bumpColor.g *= g_xMaterial.normalMapFlip; - N = normalize(lerp(N, mul(bumpColor, TBN), g_xMaterial.normalMapStrength)); - bumpColor *= g_xMaterial.normalMapStrength; + [branch] + if (g_xMaterial.normalMapStrength > 0 && g_xMaterial.uvset_normalMap >= 0) + { + const float2 UV_normalMap = g_xMaterial.uvset_normalMap == 0 ? uvsets.xy : uvsets.zw; + float3 normalMap = texture_normalmap.Sample(sampler_objectshader, UV_normalMap).rgb; + bumpColor = normalMap.rgb * 2 - 1; + N = normalize(lerp(N, mul(bumpColor, TBN), g_xMaterial.normalMapStrength)); + bumpColor *= g_xMaterial.normalMapStrength; + } + else + { + bumpColor = 0; + } } inline float3 PlanarReflection(in Surface surface, in float2 bumpColor) @@ -163,35 +155,40 @@ inline float3 PlanarReflection(in Surface surface, in float2 bumpColor) #define NUM_PARALLAX_OCCLUSION_STEPS 32 inline void ParallaxOcclusionMapping(inout float4 uvsets, in float3 V, in float3x3 TBN) { - V = mul(TBN, V); - float layerHeight = 1.0 / NUM_PARALLAX_OCCLUSION_STEPS; - float curLayerHeight = 0; - float2 dtex = g_xMaterial.parallaxOcclusionMapping * V.xy / NUM_PARALLAX_OCCLUSION_STEPS; - float2 originalTextureCoords = g_xMaterial.uvset_displacementMap == 0 ? uvsets.xy : uvsets.zw; - float2 currentTextureCoords = originalTextureCoords; - float2 derivX = ddx_coarse(currentTextureCoords); - float2 derivY = ddy_coarse(currentTextureCoords); - float heightFromTexture = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, currentTextureCoords, derivX, derivY).r; - uint iter = 0; - [loop] - while (heightFromTexture > curLayerHeight && iter < NUM_PARALLAX_OCCLUSION_STEPS) + [branch] + if (g_xMaterial.parallaxOcclusionMapping > 0) { - curLayerHeight += layerHeight; - currentTextureCoords -= dtex; - heightFromTexture = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, currentTextureCoords, derivX, derivY).r; - iter++; + V = mul(TBN, V); + float layerHeight = 1.0 / NUM_PARALLAX_OCCLUSION_STEPS; + float curLayerHeight = 0; + float2 dtex = g_xMaterial.parallaxOcclusionMapping * V.xy / NUM_PARALLAX_OCCLUSION_STEPS; + float2 originalTextureCoords = g_xMaterial.uvset_displacementMap == 0 ? uvsets.xy : uvsets.zw; + float2 currentTextureCoords = originalTextureCoords; + float2 derivX = ddx_coarse(currentTextureCoords); + float2 derivY = ddy_coarse(currentTextureCoords); + float heightFromTexture = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, currentTextureCoords, derivX, derivY).r; + uint iter = 0; + [loop] + while (heightFromTexture > curLayerHeight && iter < NUM_PARALLAX_OCCLUSION_STEPS) + { + curLayerHeight += layerHeight; + currentTextureCoords -= dtex; + heightFromTexture = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, currentTextureCoords, derivX, derivY).r; + iter++; + } + float2 prevTCoords = currentTextureCoords + dtex; + float nextH = heightFromTexture - curLayerHeight; + float prevH = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, prevTCoords, derivX, derivY).r - curLayerHeight + layerHeight; + float weight = nextH / (nextH - prevH); + float2 finalTextureCoords = prevTCoords * weight + currentTextureCoords * (1.0 - weight); + float2 difference = finalTextureCoords - originalTextureCoords; + uvsets += difference.xyxy; } - float2 prevTCoords = currentTextureCoords + dtex; - float nextH = heightFromTexture - curLayerHeight; - float prevH = 1 - texture_displacementmap.SampleGrad(sampler_linear_wrap, prevTCoords, derivX, derivY).r - curLayerHeight + layerHeight; - float weight = nextH / (nextH - prevH); - float2 finalTextureCoords = prevTCoords * weight + currentTextureCoords * (1.0 - weight); - float2 difference = finalTextureCoords - originalTextureCoords; - uvsets += difference.xyxy; } inline void Refraction(in float2 ScreenCoord, inout Surface surface, inout float4 color, inout Lighting lighting) { + [branch] if (g_xMaterial.refractionIndex > 0) { float2 size; @@ -412,9 +409,9 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting) } -inline void TiledLighting(in float2 pixel, inout Surface surface, inout Lighting lighting) +inline void TiledLighting(inout Surface surface, inout Lighting lighting) { - const uint2 tileIndex = uint2(floor(pixel / TILED_CULLING_BLOCKSIZE)); + const uint2 tileIndex = uint2(floor(surface.pixel / TILED_CULLING_BLOCKSIZE)); const uint flatTileIndex = flatten2D(tileIndex, g_xFrame_EntityCullingTileCount.xy) * SHADER_ENTITY_TILE_BUCKET_COUNT; @@ -684,12 +681,8 @@ inline void ApplyFog(in float dist, inout float4 color) // Possible switches: // ALPHATESTONLY - assemble object shader for depth only rendering + alpha test // TEXTUREONLY - assemble object shader for rendering only with base textures, no lighting -// DEFERRED - assemble object shader for deferred rendering -// FORWARD - assemble object shader for forward rendering -// TILEDFORWARD - assemble object shader for tiled forward rendering // TRANSPARENT - assemble object shader for forward or tile forward transparent rendering // ENVMAPRENDERING - modify object shader for envmap rendering -// NORMALMAP - include normal mapping computation // PLANARREFLECTION - include planar reflection sampling // POM - include parallax occlusion mapping computation // WATER - include specialized water shader code @@ -716,18 +709,21 @@ float4 main(PIXELINPUT input) : SV_TARGET float4 main(PIXELINPUT input) : SV_TARGET #elif defined(ENVMAPRENDERING) float4 main(PSIn_EnvmapRendering input) : SV_TARGET -#elif defined(DEFERRED) -GBUFFEROutputType main(PIXELINPUT input) -#elif defined(FORWARD) || defined(TILEDFORWARD) +#else [earlydepthstencil] -GBUFFEROutputType_Thin main(PIXELINPUT input) +GBUFFEROutputType main(PIXELINPUT input) #endif // ALPHATESTONLY // shader base: { +#ifdef SPIRV + input.pos.w = rcp(input.pos.w); +#endif // SPIRV + float2 pixel = input.pos.xy; + float2 ScreenCoord = pixel * g_xFrame_InternalResolution_rcp; #ifndef DISABLE_ALPHATEST #ifndef TRANSPARENT @@ -747,7 +743,15 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface.V /= dist; surface.N = normalize(input.nor); +#if 0 float3x3 TBN = compute_tangent_frame(surface.N, surface.P, input.uvsets.xy); +#else + float4 tangent = input.tan; + tangent.xyz = normalize(tangent.xyz); + float3 binormal = normalize(cross(tangent.xyz, surface.N) * tangent.w); + float3x3 TBN = float3x3(tangent.xyz, binormal, surface.N); +#endif + #endif // SIMPLE_INPUT #ifdef POM @@ -773,20 +777,20 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) float3 bumpColor = 0; float depth = input.pos.z; #ifndef ENVMAPRENDERING - input.pos2D.xy /= input.pos2D.w; + float2 pos2D = ScreenCoord * 2 - 1; + pos2D.y *= -1; input.pos2DPrev.xy /= input.pos2DPrev.w; - const float2 ScreenCoord = input.pos2D.xy * float2(0.5f, -0.5f) + 0.5f; - const float2 velocity = ((input.pos2DPrev.xy - g_xFrame_TemporalAAJitterPrev) - (input.pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); + const float2 velocity = ((input.pos2DPrev.xy - g_xFrame_TemporalAAJitterPrev) - (pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); const float2 ReprojectedScreenCoord = ScreenCoord + velocity; + +#ifndef WATER + NormalMapping(input.uvsets, surface.P, surface.N, TBN, bumpColor); +#endif // WATER + #endif // ENVMAPRENDERING #endif // SIMPLE_INPUT -#ifdef NORMALMAP - const float2 UV_normalMap = g_xMaterial.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; - NormalMapping(UV_normalMap, surface.P, surface.N, TBN, bumpColor); -#endif // NORMALMAP - // Surface map: float4 surface_occlusion_roughness_metallic_reflectance; [branch] @@ -825,31 +829,19 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) color = 0; surface_occlusion_roughness_metallic_reflectance = 0; emissiveColor = 0; - float3 triplanar_normal = 0; float4 blend_weights = input.color; blend_weights /= blend_weights.x + blend_weights.y + blend_weights.z + blend_weights.w; - float3 triplanar = abs(surface.N); - triplanar /= triplanar.x + triplanar.y + triplanar.z; - float4 sam, sam_x, sam_y, sam_z; - float2 uv_x, uv_y, uv_z; + float4 sam; [branch] if (blend_weights.x > 0) { - uv_x = surface.P.yz * g_xMaterial.texMulAdd.xy + g_xMaterial.texMulAdd.zw; - uv_y = surface.P.xz * g_xMaterial.texMulAdd.xy + g_xMaterial.texMulAdd.zw; - uv_z = surface.P.xy * g_xMaterial.texMulAdd.xy + g_xMaterial.texMulAdd.zw; - [branch] if (g_xMaterial.uvset_baseColorMap >= 0) { - sam_x = texture_basecolormap.Sample(sampler_objectshader, uv_x); - sam_y = texture_basecolormap.Sample(sampler_objectshader, uv_y); - sam_z = texture_basecolormap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial.uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_basecolormap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); } else { @@ -860,10 +852,8 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) [branch] if (g_xMaterial.uvset_surfaceMap >= 0) { - sam_x = texture_surfacemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_surfacemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_surfacemap.Sample(sampler_objectshader, uv_z); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial.uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_surfacemap.Sample(sampler_objectshader, uv); } else { @@ -872,56 +862,33 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance += sam * float4(1, g_xMaterial.roughness, g_xMaterial.metalness, g_xMaterial.reflectance) * blend_weights.x; [branch] - if (g_xMaterial.uvset_normalMap >= 0) + if (g_xMaterial.normalMapStrength > 0 && g_xMaterial.uvset_normalMap >= 0) { - sam_x.xyz = texture_normalmap.Sample(sampler_objectshader, uv_x).rgb; - sam_y.xyz = texture_normalmap.Sample(sampler_objectshader, uv_y).rgb; - sam_z.xyz = texture_normalmap.Sample(sampler_objectshader, uv_z).rgb; - bumpColor = (sam_x.xyz * triplanar.x + sam_y.xyz * triplanar.y + sam_z.xyz * triplanar.z); - bumpColor = bumpColor.rgb * 2 - 1; - bumpColor.g *= g_xMaterial.normalMapFlip; - triplanar_normal += normalize(lerp(surface.N, mul(bumpColor, TBN), g_xMaterial.normalMapStrength)) * blend_weights.x; - } - else - { - triplanar_normal += surface.N * blend_weights.x; + float2 uv = g_xMaterial.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam.rgb = texture_normalmap.Sample(sampler_objectshader, uv); + sam.rgb = sam.rgb * 2 - 1; + surface.N += lerp(surface.N, mul(sam.rgb, TBN), g_xMaterial.normalMapStrength) * blend_weights.x; } [branch] - if (g_xMaterial.uvset_emissiveMap >= 0) + if (g_xMaterial.uvset_emissiveMap >= 0 && any(g_xMaterial.emissiveColor)) { - sam_x = texture_emissivemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_emissivemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_emissivemap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial.uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_emissivemap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); + emissiveColor += sam * g_xMaterial.emissiveColor * blend_weights.x; } - else - { - sam = 1; - } - emissiveColor += sam * g_xMaterial.emissiveColor * blend_weights.x; } [branch] if (blend_weights.y > 0) { - uv_x = surface.P.yz * g_xMaterial_blend1.texMulAdd.xy + g_xMaterial_blend1.texMulAdd.zw; - uv_y = surface.P.xz * g_xMaterial_blend1.texMulAdd.xy + g_xMaterial_blend1.texMulAdd.zw; - uv_z = surface.P.xy * g_xMaterial_blend1.texMulAdd.xy + g_xMaterial_blend1.texMulAdd.zw; - [branch] if (g_xMaterial_blend1.uvset_baseColorMap >= 0) { - sam_x = texture_blend1_basecolormap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend1_basecolormap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend1_basecolormap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend1.uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend1_basecolormap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); } else { @@ -932,10 +899,8 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) [branch] if (g_xMaterial_blend1.uvset_surfaceMap >= 0) { - sam_x = texture_blend1_surfacemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend1_surfacemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend1_surfacemap.Sample(sampler_objectshader, uv_z); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend1.uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend1_surfacemap.Sample(sampler_objectshader, uv); } else { @@ -944,56 +909,33 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance += sam * float4(1, g_xMaterial_blend1.roughness, g_xMaterial_blend1.metalness, g_xMaterial_blend1.reflectance) * blend_weights.y; [branch] - if (g_xMaterial_blend1.uvset_normalMap >= 0) + if (g_xMaterial_blend1.normalMapStrength > 0 && g_xMaterial_blend1.uvset_normalMap >= 0) { - sam_x.xyz = texture_blend1_normalmap.Sample(sampler_objectshader, uv_x).rgb; - sam_y.xyz = texture_blend1_normalmap.Sample(sampler_objectshader, uv_y).rgb; - sam_z.xyz = texture_blend1_normalmap.Sample(sampler_objectshader, uv_z).rgb; - bumpColor = (sam_x.xyz * triplanar.x + sam_y.xyz * triplanar.y + sam_z.xyz * triplanar.z); - bumpColor = bumpColor.rgb * 2 - 1; - bumpColor.g *= g_xMaterial_blend1.normalMapFlip; - triplanar_normal += normalize(lerp(surface.N, mul(bumpColor, TBN), g_xMaterial_blend1.normalMapStrength)) * blend_weights.y; - } - else - { - triplanar_normal += surface.N * blend_weights.y; + float2 uv = g_xMaterial_blend1.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam.rgb = texture_blend1_normalmap.Sample(sampler_objectshader, uv); + sam.rgb = sam.rgb * 2 - 1; + surface.N += lerp(surface.N, mul(sam.rgb, TBN), g_xMaterial_blend1.normalMapStrength) * blend_weights.y; } [branch] - if (g_xMaterial_blend1.uvset_emissiveMap >= 0) + if (g_xMaterial_blend1.uvset_emissiveMap >= 0 && any(g_xMaterial_blend1.emissiveColor)) { - sam_x = texture_blend1_emissivemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend1_emissivemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend1_emissivemap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend1.uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend1_emissivemap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); + emissiveColor += sam * g_xMaterial_blend1.emissiveColor * blend_weights.y; } - else - { - sam = 1; - } - emissiveColor += sam * g_xMaterial_blend1.emissiveColor * blend_weights.y; } [branch] if (blend_weights.z > 0) { - uv_x = surface.P.yz * g_xMaterial_blend2.texMulAdd.xy + g_xMaterial_blend2.texMulAdd.zw; - uv_y = surface.P.xz * g_xMaterial_blend2.texMulAdd.xy + g_xMaterial_blend2.texMulAdd.zw; - uv_z = surface.P.xy * g_xMaterial_blend2.texMulAdd.xy + g_xMaterial_blend2.texMulAdd.zw; - [branch] if (g_xMaterial_blend2.uvset_baseColorMap >= 0) { - sam_x = texture_blend2_basecolormap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend2_basecolormap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend2_basecolormap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend2.uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend2_basecolormap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); } else { @@ -1004,10 +946,8 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) [branch] if (g_xMaterial_blend2.uvset_surfaceMap >= 0) { - sam_x = texture_blend2_surfacemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend2_surfacemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend2_surfacemap.Sample(sampler_objectshader, uv_z); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend2.uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend2_surfacemap.Sample(sampler_objectshader, uv); } else { @@ -1016,56 +956,33 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance += sam * float4(1, g_xMaterial_blend2.roughness, g_xMaterial_blend2.metalness, g_xMaterial_blend2.reflectance) * blend_weights.z; [branch] - if (g_xMaterial_blend2.uvset_normalMap >= 0) + if (g_xMaterial_blend2.normalMapStrength > 0 && g_xMaterial_blend2.uvset_normalMap >= 0) { - sam_x.xyz = texture_blend2_normalmap.Sample(sampler_objectshader, uv_x).rgb; - sam_y.xyz = texture_blend2_normalmap.Sample(sampler_objectshader, uv_y).rgb; - sam_z.xyz = texture_blend2_normalmap.Sample(sampler_objectshader, uv_z).rgb; - bumpColor = (sam_x.xyz * triplanar.x + sam_y.xyz * triplanar.y + sam_z.xyz * triplanar.z); - bumpColor = bumpColor.rgb * 2 - 1; - bumpColor.g *= g_xMaterial_blend2.normalMapFlip; - triplanar_normal += normalize(lerp(surface.N, mul(bumpColor, TBN), g_xMaterial_blend2.normalMapStrength)) * blend_weights.z; - } - else - { - triplanar_normal += surface.N * blend_weights.z; + float2 uv = g_xMaterial_blend2.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam.rgb = texture_blend2_normalmap.Sample(sampler_objectshader, uv); + sam.rgb = sam.rgb * 2 - 1; + surface.N += lerp(surface.N, mul(sam.rgb, TBN), g_xMaterial_blend2.normalMapStrength) * blend_weights.z; } [branch] - if (g_xMaterial_blend2.uvset_emissiveMap >= 0) + if (g_xMaterial_blend2.uvset_emissiveMap >= 0 && any(g_xMaterial_blend2.emissiveColor)) { - sam_x = texture_blend2_emissivemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend2_emissivemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend2_emissivemap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend2.uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend2_emissivemap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); + emissiveColor += sam * g_xMaterial_blend2.emissiveColor * blend_weights.z; } - else - { - sam = 1; - } - emissiveColor += sam * g_xMaterial_blend2.emissiveColor * blend_weights.z; } [branch] if (blend_weights.w > 0) { - uv_x = surface.P.yz * g_xMaterial_blend3.texMulAdd.xy + g_xMaterial_blend3.texMulAdd.zw; - uv_y = surface.P.xz * g_xMaterial_blend3.texMulAdd.xy + g_xMaterial_blend3.texMulAdd.zw; - uv_z = surface.P.xy * g_xMaterial_blend3.texMulAdd.xy + g_xMaterial_blend3.texMulAdd.zw; - [branch] if (g_xMaterial_blend3.uvset_baseColorMap >= 0) { - sam_x = texture_blend3_basecolormap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend3_basecolormap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend3_basecolormap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend3.uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend3_basecolormap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); } else { @@ -1076,10 +993,8 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) [branch] if (g_xMaterial_blend3.uvset_surfaceMap >= 0) { - sam_x = texture_blend3_surfacemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend3_surfacemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend3_surfacemap.Sample(sampler_objectshader, uv_z); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend3.uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend3_surfacemap.Sample(sampler_objectshader, uv); } else { @@ -1088,41 +1003,26 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance += sam * float4(1, g_xMaterial_blend3.roughness, g_xMaterial_blend3.metalness, g_xMaterial_blend3.reflectance) * blend_weights.w; [branch] - if (g_xMaterial_blend3.uvset_normalMap >= 0) + if (g_xMaterial_blend3.normalMapStrength > 0 && g_xMaterial_blend3.uvset_normalMap >= 0) { - sam_x.xyz = texture_blend3_normalmap.Sample(sampler_objectshader, uv_x).rgb; - sam_y.xyz = texture_blend3_normalmap.Sample(sampler_objectshader, uv_y).rgb; - sam_z.xyz = texture_blend3_normalmap.Sample(sampler_objectshader, uv_z).rgb; - bumpColor = (sam_x.xyz * triplanar.x + sam_y.xyz * triplanar.y + sam_z.xyz * triplanar.z); - bumpColor = bumpColor.rgb * 2 - 1; - bumpColor.g *= g_xMaterial_blend3.normalMapFlip; - triplanar_normal += normalize(lerp(surface.N, mul(bumpColor, TBN), g_xMaterial_blend3.normalMapStrength)) * blend_weights.w; - } - else - { - triplanar_normal += surface.N * blend_weights.w; + float2 uv = g_xMaterial_blend3.uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam.rgb = texture_blend3_normalmap.Sample(sampler_objectshader, uv); + sam.rgb = sam.rgb * 2 - 1; + surface.N += lerp(surface.N, mul(sam.rgb, TBN), g_xMaterial_blend3.normalMapStrength) * blend_weights.w; } [branch] - if (g_xMaterial_blend3.uvset_emissiveMap >= 0) + if (g_xMaterial_blend3.uvset_emissiveMap >= 0 && any(g_xMaterial_blend3.emissiveColor)) { - sam_x = texture_blend3_emissivemap.Sample(sampler_objectshader, uv_x); - sam_y = texture_blend3_emissivemap.Sample(sampler_objectshader, uv_y); - sam_z = texture_blend3_emissivemap.Sample(sampler_objectshader, uv_z); - sam_x.rgb = DEGAMMA(sam_x.rgb); - sam_y.rgb = DEGAMMA(sam_y.rgb); - sam_z.rgb = DEGAMMA(sam_z.rgb); - sam = (sam_x * triplanar.x + sam_y * triplanar.y + sam_z * triplanar.z); + float2 uv = g_xMaterial_blend3.uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw; + sam = texture_blend3_emissivemap.Sample(sampler_objectshader, uv); + sam.rgb = DEGAMMA(sam.rgb); + emissiveColor += sam * g_xMaterial_blend3.emissiveColor * blend_weights.w; } - else - { - sam = 1; - } - emissiveColor += sam * g_xMaterial_blend3.emissiveColor * blend_weights.w; } color.a = 1; - surface.N = triplanar_normal; + surface.N = normalize(surface.N); #endif // TERRAIN @@ -1134,7 +1034,6 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance.r *= texture_occlusionmap.Sample(sampler_objectshader, UV_occlusionMap).r; } -#ifndef DEFERRED #ifndef SIMPLE_INPUT #ifndef ENVMAPRENDERING #ifndef TRANSPARENT @@ -1142,8 +1041,6 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #endif // TRANSPARENT #endif // ENVMAPRENDERING #endif // SIMPLE_INPUT -#endif - surface = CreateSurface( surface.P, @@ -1154,10 +1051,17 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface_occlusion_roughness_metallic_reflectance.r, surface_occlusion_roughness_metallic_reflectance.b, surface_occlusion_roughness_metallic_reflectance.a, - emissiveColor, - g_xMaterial.subsurfaceScattering + emissiveColor +#ifdef BRDF_ANISOTROPIC + , g_xMaterial.parallaxOcclusionMapping, + tangent.xyz, + normalize(cross(tangent.xyz, surface.N) * tangent.w) // Compute bitangent again after normal mapping +#endif // BRDF_ANISOTROPIC ); + surface.pixel = pixel; + surface.screenUV = ScreenCoord; + Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); #ifndef SIMPLE_INPUT @@ -1201,15 +1105,13 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) -#ifndef DEFERRED - #ifdef FORWARD ForwardLighting(surface, lighting); #endif // FORWARD #ifdef TILEDFORWARD - TiledLighting(pixel, surface, lighting); + TiledLighting(surface, lighting); #endif // TILEDFORWARD @@ -1226,7 +1128,7 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) #ifdef WATER // WATER REFRACTION - const float lineardepth = input.pos2D.w; + float lineardepth = input.pos.w; float sampled_lineardepth = texture_lineardepth.SampleLevel(sampler_point_clamp, ScreenCoord.xy + bumpColor.rg, 0) * g_xCamera_ZFarP; float depth_difference = sampled_lineardepth - lineardepth; surface.refraction.rgb = texture_refraction.SampleLevel(sampler_linear_mirror, ScreenCoord.xy + bumpColor.rg * saturate(0.5 * depth_difference), 0).rgb; @@ -1240,13 +1142,18 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) surface.refraction.a = 1 - saturate(surface.baseColor.a * 0.1f * depth_difference); #endif // WATER +#ifdef UNLIT + lighting.direct.diffuse = 1; + lighting.indirect.diffuse = 0; + lighting.direct.specular = 0; + lighting.indirect.specular = 0; +#endif // UNLIT + ApplyLighting(surface, lighting, color); ApplyFog(dist, color); -#endif // DEFERRED - #endif // SIMPLE_INPUT @@ -1263,15 +1170,13 @@ GBUFFEROutputType_Thin main(PIXELINPUT input) // end point: -#if defined(TRANSPARENT) || defined(TEXTUREONLY) || defined(ENVMAPRENDERING) - return color; +#ifndef ALPHATESTONLY +#ifdef OUTPUT_GBUFFER + return CreateGbuffer(surface, velocity, lighting); #else -#if defined(DEFERRED) - return CreateGbuffer(color, surface, velocity, lighting); -#elif defined(FORWARD) || defined(TILEDFORWARD) - return CreateGbuffer_Thin(color, surface, velocity); -#endif // DEFERRED -#endif // TRANSPARENT + return color; +#endif // OUTPUT_GBUFFER +#endif // ALPHATESTONLY } diff --git a/WickedEngine/objectHS.hlsl b/WickedEngine/objectHS.hlsl index 9e3720002..5475f9c3b 100644 --- a/WickedEngine/objectHS.hlsl +++ b/WickedEngine/objectHS.hlsl @@ -9,6 +9,7 @@ struct HullInputType float4 uvsets : UVSETS; float4 atlas : ATLAS; float4 nor : NORMAL; + float4 tan : TANGENT; float4 posPrev : POSITIONPREV; }; @@ -38,6 +39,10 @@ struct ConstantOutputType float4 nor1 : NORMAL1; float4 nor2 : NORMAL2; + float4 tan0 : TANGENT0; + float4 tan1 : TANGENT1; + float4 tan2 : TANGENT2; + float4 posPrev0 : POSITIONPREV0; float4 posPrev1 : POSITIONPREV1; float4 posPrev2 : POSITIONPREV2; @@ -51,6 +56,7 @@ struct HullOutputType float4 uvsets : UVSETS; float4 atlas : ATLAS; float4 nor : NORMAL; + float4 tan : TANGENT; float4 posPrev : POSITIONPREV; }; @@ -131,6 +137,10 @@ ConstantOutputType PatchConstantFunction(InputPatch I) Out.nor1 = I[1].nor; Out.nor2 = I[2].nor; + Out.tan0 = I[0].tan; + Out.tan1 = I[1].tan; + Out.tan2 = I[2].tan; + Out.posPrev0 = I[0].posPrev; Out.posPrev1 = I[1].posPrev; Out.posPrev2 = I[2].posPrev; @@ -155,6 +165,7 @@ HullOutputType main(InputPatch patch, uint pointId : SV_Output Out.uvsets = patch[pointId].uvsets; Out.atlas = patch[pointId].atlas; Out.nor = patch[pointId].nor; + Out.tan = patch[pointId].tan; Out.posPrev = patch[pointId].posPrev; return Out; diff --git a/WickedEngine/objectInputLayoutHF.hlsli b/WickedEngine/objectInputLayoutHF.hlsli index c35fbb164..db61a2a80 100644 --- a/WickedEngine/objectInputLayoutHF.hlsli +++ b/WickedEngine/objectInputLayoutHF.hlsli @@ -40,6 +40,7 @@ struct Input_Object_ALL float2 uv1 : UVSET1; float2 atl : ATLAS; float4 col : COLOR; + float4 tan : TANGENT; float4 pre : PREVPOS; Input_Instance inst; Input_InstancePrev instPrev; @@ -72,6 +73,7 @@ struct VertexSurface float2 atlas; float4 color; float3 normal; + float4 tangent; float4 prevPos; }; inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input) @@ -83,13 +85,13 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input) surface.color = g_xMaterial.baseColor * unpack_rgba(input.inst.userdata.x); uint normal_wind = asuint(input.pos.w); - surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.x = (float)((normal_wind >> 0) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0xFF) / 255.0f * 2.0f - 1.0f; if (g_xMaterial.IsUsingWind()) { - const float windweight = ((normal_wind >> 24) & 0x000000FF) / 255.0f; + const float windweight = ((normal_wind >> 24) & 0xFF) / 255.0f; const float waveoffset = dot(surface.position.xyz, g_xFrame_WindDirection) * g_xFrame_WindWaveSize + (surface.position.x + surface.position.y + surface.position.z) * g_xFrame_WindRandomness; const float3 wavedir = g_xFrame_WindDirection * windweight; const float3 wind = sin(g_xFrame_Time * g_xFrame_WindSpeed + waveoffset) * wavedir; @@ -109,13 +111,13 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS_TEX input) surface.color = g_xMaterial.baseColor * unpack_rgba(input.inst.userdata.x); uint normal_wind = asuint(input.pos.w); - surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.x = (float)((normal_wind >> 0) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0xFF) / 255.0f * 2.0f - 1.0f; if (g_xMaterial.IsUsingWind()) { - const float windweight = ((normal_wind >> 24) & 0x000000FF) / 255.0f; + const float windweight = ((normal_wind >> 24) & 0xFF) / 255.0f; const float waveoffset = dot(surface.position.xyz, g_xFrame_WindDirection) * g_xFrame_WindWaveSize + (surface.position.x + surface.position.y + surface.position.z) * g_xFrame_WindRandomness; const float3 wavedir = g_xFrame_WindDirection * windweight; const float3 wind = sin(g_xFrame_Time * g_xFrame_WindSpeed + waveoffset) * wavedir; @@ -142,13 +144,15 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_ALL input) } uint normal_wind = asuint(input.pos.w); - surface.normal.x = (float)((normal_wind >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.y = (float)((normal_wind >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; - surface.normal.z = (float)((normal_wind >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + surface.normal.x = (float)((normal_wind >> 0) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.y = (float)((normal_wind >> 8) & 0xFF) / 255.0f * 2.0f - 1.0f; + surface.normal.z = (float)((normal_wind >> 16) & 0xFF) / 255.0f * 2.0f - 1.0f; + + surface.tangent = input.tan * 2 - 1; if (g_xMaterial.IsUsingWind()) { - const float windweight = ((normal_wind >> 24) & 0x000000FF) / 255.0f; + const float windweight = ((normal_wind >> 24) & 0xFF) / 255.0f; const float waveoffset = dot(surface.position.xyz, g_xFrame_WindDirection) * g_xFrame_WindWaveSize + (surface.position.x + surface.position.y + surface.position.z) * g_xFrame_WindRandomness; const float3 wavedir = g_xFrame_WindDirection * windweight; const float3 wind = sin(g_xFrame_Time * g_xFrame_WindSpeed + waveoffset) * wavedir; diff --git a/WickedEngine/objectPS_tiledforward.hlsl b/WickedEngine/objectPS.hlsl similarity index 77% rename from WickedEngine/objectPS_tiledforward.hlsl rename to WickedEngine/objectPS.hlsl index 2348603c5..2a1be5ff5 100644 --- a/WickedEngine/objectPS_tiledforward.hlsl +++ b/WickedEngine/objectPS.hlsl @@ -1,4 +1,5 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_normalmap_pom.hlsl b/WickedEngine/objectPS_anisotropic.hlsl similarity index 62% rename from WickedEngine/objectPS_tiledforward_normalmap_pom.hlsl rename to WickedEngine/objectPS_anisotropic.hlsl index 8e56b7c3d..ab75a8658 100644 --- a/WickedEngine/objectPS_tiledforward_normalmap_pom.hlsl +++ b/WickedEngine/objectPS_anisotropic.hlsl @@ -1,6 +1,6 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD -#define NORMALMAP -#define POM +#define BRDF_ANISOTROPIC #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_cartoon.hlsl b/WickedEngine/objectPS_cartoon.hlsl new file mode 100644 index 000000000..b4cf91b1d --- /dev/null +++ b/WickedEngine/objectPS_cartoon.hlsl @@ -0,0 +1,6 @@ +#define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER +#define TILEDFORWARD +#define LIGHTING_CARTOON +#include "objectHF.hlsli" + diff --git a/WickedEngine/objectPS_deferred.hlsl b/WickedEngine/objectPS_deferred.hlsl deleted file mode 100644 index e38fb3010..000000000 --- a/WickedEngine/objectPS_deferred.hlsl +++ /dev/null @@ -1,4 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_normalmap.hlsl b/WickedEngine/objectPS_deferred_normalmap.hlsl deleted file mode 100644 index ac98823f6..000000000 --- a/WickedEngine/objectPS_deferred_normalmap.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define NORMALMAP -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_normalmap_planarreflection.hlsl b/WickedEngine/objectPS_deferred_normalmap_planarreflection.hlsl deleted file mode 100644 index 043a13cc2..000000000 --- a/WickedEngine/objectPS_deferred_normalmap_planarreflection.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define NORMALMAP -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_normalmap_pom.hlsl b/WickedEngine/objectPS_deferred_normalmap_pom.hlsl deleted file mode 100644 index 36e20e445..000000000 --- a/WickedEngine/objectPS_deferred_normalmap_pom.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define NORMALMAP -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_planarreflection.hlsl b/WickedEngine/objectPS_deferred_planarreflection.hlsl deleted file mode 100644 index d48075c6f..000000000 --- a/WickedEngine/objectPS_deferred_planarreflection.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_pom.hlsl b/WickedEngine/objectPS_deferred_pom.hlsl deleted file mode 100644 index e158fb562..000000000 --- a/WickedEngine/objectPS_deferred_pom.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_deferred_terrain.hlsl b/WickedEngine/objectPS_deferred_terrain.hlsl deleted file mode 100644 index bb1b0d8db..000000000 --- a/WickedEngine/objectPS_deferred_terrain.hlsl +++ /dev/null @@ -1,4 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DEFERRED -#define TERRAIN -#include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_forward.hlsl b/WickedEngine/objectPS_forward.hlsl deleted file mode 100644 index 854d85ce2..000000000 --- a/WickedEngine/objectPS_forward.hlsl +++ /dev/null @@ -1,4 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_normalmap.hlsl b/WickedEngine/objectPS_forward_normalmap.hlsl deleted file mode 100644 index 503e16d92..000000000 --- a/WickedEngine/objectPS_forward_normalmap.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define NORMALMAP -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_normalmap_planarreflection.hlsl b/WickedEngine/objectPS_forward_normalmap_planarreflection.hlsl deleted file mode 100644 index 0278e31ca..000000000 --- a/WickedEngine/objectPS_forward_normalmap_planarreflection.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define NORMALMAP -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_normalmap_pom.hlsl b/WickedEngine/objectPS_forward_normalmap_pom.hlsl deleted file mode 100644 index 5fa638881..000000000 --- a/WickedEngine/objectPS_forward_normalmap_pom.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define NORMALMAP -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_planarreflection.hlsl b/WickedEngine/objectPS_forward_planarreflection.hlsl deleted file mode 100644 index c29186a77..000000000 --- a/WickedEngine/objectPS_forward_planarreflection.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_pom.hlsl b/WickedEngine/objectPS_forward_pom.hlsl deleted file mode 100644 index 4f93ee9d8..000000000 --- a/WickedEngine/objectPS_forward_pom.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_terrain.hlsl b/WickedEngine/objectPS_forward_terrain.hlsl deleted file mode 100644 index 7b260a991..000000000 --- a/WickedEngine/objectPS_forward_terrain.hlsl +++ /dev/null @@ -1,4 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TERRAIN -#include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_forward_transparent.hlsl b/WickedEngine/objectPS_forward_transparent.hlsl deleted file mode 100644 index 9b494700f..000000000 --- a/WickedEngine/objectPS_forward_transparent.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_transparent_normalmap.hlsl b/WickedEngine/objectPS_forward_transparent_normalmap.hlsl deleted file mode 100644 index 84fe6958d..000000000 --- a/WickedEngine/objectPS_forward_transparent_normalmap.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#define NORMALMAP -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_transparent_normalmap_planarreflection.hlsl b/WickedEngine/objectPS_forward_transparent_normalmap_planarreflection.hlsl deleted file mode 100644 index 4c514bd21..000000000 --- a/WickedEngine/objectPS_forward_transparent_normalmap_planarreflection.hlsl +++ /dev/null @@ -1,7 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#define NORMALMAP -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_transparent_normalmap_pom.hlsl b/WickedEngine/objectPS_forward_transparent_normalmap_pom.hlsl deleted file mode 100644 index 1f808495d..000000000 --- a/WickedEngine/objectPS_forward_transparent_normalmap_pom.hlsl +++ /dev/null @@ -1,7 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#define NORMALMAP -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_transparent_planarreflection.hlsl b/WickedEngine/objectPS_forward_transparent_planarreflection.hlsl deleted file mode 100644 index 61455c169..000000000 --- a/WickedEngine/objectPS_forward_transparent_planarreflection.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_transparent_pom.hlsl b/WickedEngine/objectPS_forward_transparent_pom.hlsl deleted file mode 100644 index 4db95f563..000000000 --- a/WickedEngine/objectPS_forward_transparent_pom.hlsl +++ /dev/null @@ -1,6 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define FORWARD -#define TRANSPARENT -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_forward_water.hlsl b/WickedEngine/objectPS_forward_water.hlsl deleted file mode 100644 index 9f4819c43..000000000 --- a/WickedEngine/objectPS_forward_water.hlsl +++ /dev/null @@ -1,9 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define DISABLE_DECALS -#define DISABLE_ENVMAPS -#define DISABLE_ALPHATEST -#define FORWARD -#define TRANSPARENT -#define WATER -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_tiledforward_normalmap_planarreflection.hlsl b/WickedEngine/objectPS_planarreflection.hlsl similarity index 82% rename from WickedEngine/objectPS_tiledforward_normalmap_planarreflection.hlsl rename to WickedEngine/objectPS_planarreflection.hlsl index 314a534bb..0fe7c0f57 100644 --- a/WickedEngine/objectPS_tiledforward_normalmap_planarreflection.hlsl +++ b/WickedEngine/objectPS_planarreflection.hlsl @@ -1,6 +1,6 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD -#define NORMALMAP #define PLANARREFLECTION #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_pom.hlsl b/WickedEngine/objectPS_pom.hlsl similarity index 80% rename from WickedEngine/objectPS_tiledforward_pom.hlsl rename to WickedEngine/objectPS_pom.hlsl index 263c25c8a..7bd584680 100644 --- a/WickedEngine/objectPS_tiledforward_pom.hlsl +++ b/WickedEngine/objectPS_pom.hlsl @@ -1,4 +1,5 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD #define POM #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_terrain.hlsl b/WickedEngine/objectPS_terrain.hlsl similarity index 80% rename from WickedEngine/objectPS_tiledforward_terrain.hlsl rename to WickedEngine/objectPS_terrain.hlsl index 24ebf9612..7de8e7eff 100644 --- a/WickedEngine/objectPS_tiledforward_terrain.hlsl +++ b/WickedEngine/objectPS_terrain.hlsl @@ -1,4 +1,5 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD #define TERRAIN #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_planarreflection.hlsl b/WickedEngine/objectPS_tiledforward_planarreflection.hlsl deleted file mode 100644 index 843b114d9..000000000 --- a/WickedEngine/objectPS_tiledforward_planarreflection.hlsl +++ /dev/null @@ -1,5 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define TILEDFORWARD -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_tiledforward_transparent_normalmap_planarreflection.hlsl b/WickedEngine/objectPS_tiledforward_transparent_normalmap_planarreflection.hlsl deleted file mode 100644 index ba807fc1f..000000000 --- a/WickedEngine/objectPS_tiledforward_transparent_normalmap_planarreflection.hlsl +++ /dev/null @@ -1,7 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define TILEDFORWARD -#define TRANSPARENT -#define NORMALMAP -#define PLANARREFLECTION -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_tiledforward_transparent_normalmap_pom.hlsl b/WickedEngine/objectPS_tiledforward_transparent_normalmap_pom.hlsl deleted file mode 100644 index 50173bf00..000000000 --- a/WickedEngine/objectPS_tiledforward_transparent_normalmap_pom.hlsl +++ /dev/null @@ -1,7 +0,0 @@ -#define COMPILE_OBJECTSHADER_PS -#define TILEDFORWARD -#define TRANSPARENT -#define NORMALMAP -#define POM -#include "objectHF.hlsli" - diff --git a/WickedEngine/objectPS_tiledforward_transparent.hlsl b/WickedEngine/objectPS_transparent.hlsl similarity index 100% rename from WickedEngine/objectPS_tiledforward_transparent.hlsl rename to WickedEngine/objectPS_transparent.hlsl diff --git a/WickedEngine/objectPS_transparent_anisotropic.hlsl b/WickedEngine/objectPS_transparent_anisotropic.hlsl new file mode 100644 index 000000000..eb1c103cd --- /dev/null +++ b/WickedEngine/objectPS_transparent_anisotropic.hlsl @@ -0,0 +1,6 @@ +#define COMPILE_OBJECTSHADER_PS +#define TILEDFORWARD +#define TRANSPARENT +#define BRDF_ANISOTROPIC +#include "objectHF.hlsli" + diff --git a/WickedEngine/objectPS_transparent_cartoon.hlsl b/WickedEngine/objectPS_transparent_cartoon.hlsl new file mode 100644 index 000000000..6b51a068f --- /dev/null +++ b/WickedEngine/objectPS_transparent_cartoon.hlsl @@ -0,0 +1,6 @@ +#define COMPILE_OBJECTSHADER_PS +#define TILEDFORWARD +#define TRANSPARENT +#define LIGHTING_CARTOON +#include "objectHF.hlsli" + diff --git a/WickedEngine/objectPS_tiledforward_transparent_planarreflection.hlsl b/WickedEngine/objectPS_transparent_planarreflection.hlsl similarity index 100% rename from WickedEngine/objectPS_tiledforward_transparent_planarreflection.hlsl rename to WickedEngine/objectPS_transparent_planarreflection.hlsl diff --git a/WickedEngine/objectPS_tiledforward_transparent_pom.hlsl b/WickedEngine/objectPS_transparent_pom.hlsl similarity index 100% rename from WickedEngine/objectPS_tiledforward_transparent_pom.hlsl rename to WickedEngine/objectPS_transparent_pom.hlsl diff --git a/WickedEngine/objectPS_tiledforward_transparent_normalmap.hlsl b/WickedEngine/objectPS_transparent_unlit.hlsl similarity index 84% rename from WickedEngine/objectPS_tiledforward_transparent_normalmap.hlsl rename to WickedEngine/objectPS_transparent_unlit.hlsl index 16d6cfdf4..886e424b2 100644 --- a/WickedEngine/objectPS_tiledforward_transparent_normalmap.hlsl +++ b/WickedEngine/objectPS_transparent_unlit.hlsl @@ -1,6 +1,6 @@ #define COMPILE_OBJECTSHADER_PS #define TILEDFORWARD #define TRANSPARENT -#define NORMALMAP +#define UNLIT #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_normalmap.hlsl b/WickedEngine/objectPS_unlit.hlsl similarity index 68% rename from WickedEngine/objectPS_tiledforward_normalmap.hlsl rename to WickedEngine/objectPS_unlit.hlsl index 2375b7126..820eec794 100644 --- a/WickedEngine/objectPS_tiledforward_normalmap.hlsl +++ b/WickedEngine/objectPS_unlit.hlsl @@ -1,5 +1,6 @@ #define COMPILE_OBJECTSHADER_PS +#define OUTPUT_GBUFFER #define TILEDFORWARD -#define NORMALMAP +#define UNLIT #include "objectHF.hlsli" diff --git a/WickedEngine/objectPS_tiledforward_water.hlsl b/WickedEngine/objectPS_water.hlsl similarity index 100% rename from WickedEngine/objectPS_tiledforward_water.hlsl rename to WickedEngine/objectPS_water.hlsl diff --git a/WickedEngine/objectVS_common.hlsl b/WickedEngine/objectVS_common.hlsl index ba7f9b123..f56178324 100644 --- a/WickedEngine/objectVS_common.hlsl +++ b/WickedEngine/objectVS_common.hlsl @@ -13,16 +13,18 @@ PixelInputType main(Input_Object_ALL input) surface.position = mul(WORLD, surface.position); surface.prevPos = mul(WORLDPREV, surface.prevPos); surface.normal = normalize(mul((float3x3)WORLD, surface.normal)); + surface.tangent.xyz = normalize(mul((float3x3)WORLD, surface.tangent.xyz)); Out.clip = dot(surface.position, g_xClipPlane); - Out.pos = Out.pos2D = mul(g_xCamera_VP, surface.position); + Out.pos = mul(g_xCamera_VP, surface.position); Out.pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, surface.prevPos); Out.pos3D = surface.position.xyz; Out.color = surface.color; Out.uvsets = surface.uvsets; Out.atl = surface.atlas; Out.nor = surface.normal; + Out.tan = surface.tangent; return Out; } \ No newline at end of file diff --git a/WickedEngine/objectVS_common_tessellation.hlsl b/WickedEngine/objectVS_common_tessellation.hlsl index 87bdb3582..1567f9efe 100644 --- a/WickedEngine/objectVS_common_tessellation.hlsl +++ b/WickedEngine/objectVS_common_tessellation.hlsl @@ -8,6 +8,7 @@ struct HullInputType float4 uvsets : UVSETS; float4 atlas : ATLAS; float4 nor : NORMAL; + float4 tan : TANGENT; float4 posPrev : POSITIONPREV; }; @@ -23,12 +24,14 @@ HullInputType main(Input_Object_ALL input) surface.position = mul(WORLD, surface.position); surface.prevPos = mul(WORLDPREV, surface.prevPos); surface.normal = normalize(mul((float3x3)WORLD, surface.normal)); + surface.tangent.xyz = normalize(mul((float3x3)WORLD, surface.tangent.xyz)); Out.pos = surface.position; Out.color = surface.color; Out.uvsets = surface.uvsets; Out.atlas = surface.atlas.xyxy; Out.nor = float4(surface.normal, 1); + Out.tan = surface.tangent; Out.posPrev = surface.prevPos; return Out; diff --git a/WickedEngine/oceanSurfaceHF.hlsli b/WickedEngine/oceanSurfaceHF.hlsli index 0f381a2cc..71208c57a 100644 --- a/WickedEngine/oceanSurfaceHF.hlsli +++ b/WickedEngine/oceanSurfaceHF.hlsli @@ -7,7 +7,6 @@ struct PSIn { float4 pos : SV_POSITION; - float4 pos2D : SCREENPOSITION; float3 pos3D : WORLDPOSITION; float2 uv : TEXCOORD0; float4 ReflectionMapSamplingPos : REFLECTIONPOS; diff --git a/WickedEngine/oceanSurfacePS.hlsl b/WickedEngine/oceanSurfacePS.hlsl index 1183bde4a..27a7c2a5b 100644 --- a/WickedEngine/oceanSurfacePS.hlsl +++ b/WickedEngine/oceanSurfacePS.hlsl @@ -6,12 +6,16 @@ #include "oceanSurfaceHF.hlsli" #include "objectHF.hlsli" -#define xGradientMap texture_0 +TEXTURE2D(texture_gradientmap, float4, TEXSLOT_ONDEMAND1); [earlydepthstencil] float4 main(PSIn input) : SV_TARGET { - float2 gradient = xGradientMap.Sample(sampler_aniso_wrap, input.uv).xy; +#ifdef SPIRV + input.pos.w = rcp(input.pos.w); +#endif // SPIRV + + float2 gradient = texture_gradientmap.Sample(sampler_aniso_wrap, input.uv).xy; float4 color = float4(xOceanWaterColor, 1); float opacity = 1; // keep edge diffuse shading @@ -21,11 +25,11 @@ float4 main(PSIn input) : SV_TARGET float emissive = 0; Surface surface = CreateSurface(input.pos3D, normalize(float3(gradient.x, xOceanTexelLength * 2, gradient.y)), V, color, 0.1, 1, 0, 0.02); Lighting lighting = CreateLighting(0, 0, GetAmbient(surface.N), 0); - float2 pixel = input.pos.xy; + surface.pixel = input.pos.xy; float depth = input.pos.z; float2 refUV = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w * 0.5f + 0.5f; - float2 ScreenCoord = float2(1, -1) * input.pos2D.xy / input.pos2D.w * 0.5f + 0.5f; + float2 ScreenCoord = surface.pixel * g_xFrame_InternalResolution_rcp; //REFLECTION float2 RefTex = float2(1, -1)*input.ReflectionMapSamplingPos.xy / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f; @@ -35,10 +39,10 @@ float4 main(PSIn input) : SV_TARGET reflectiveColor.rgb = lerp(float3(0.38f, 0.45f, 0.56f), reflectiveColor.rgb, ramp); // skycolor hack lighting.indirect.specular += reflectiveColor.rgb; - TiledLighting(pixel, surface, lighting); + TiledLighting(surface, lighting); // WATER REFRACTION - const float lineardepth = input.pos2D.w; + float lineardepth = input.pos.w; float sampled_lineardepth = texture_lineardepth.SampleLevel(sampler_point_clamp, ScreenCoord.xy + surface.N.xz * 0.04f, 0) * g_xCamera_ZFarP; float depth_difference = sampled_lineardepth - lineardepth; surface.refraction.rgb = texture_refraction.SampleLevel(sampler_linear_mirror, ScreenCoord.xy + surface.N.xz * 0.04f * saturate(0.5 * depth_difference), 0).rgb; diff --git a/WickedEngine/oceanSurfaceVS.hlsl b/WickedEngine/oceanSurfaceVS.hlsl index 962850eba..c6c0e1a39 100644 --- a/WickedEngine/oceanSurfaceVS.hlsl +++ b/WickedEngine/oceanSurfaceVS.hlsl @@ -57,7 +57,6 @@ PSIn main(uint fakeIndex : SV_VERTEXID) // Reproject displaced surface and output: Out.pos = mul(g_xCamera_VP, float4(worldPos, 1)); - Out.pos2D = Out.pos; Out.pos3D = worldPos; Out.uv = uv; Out.ReflectionMapSamplingPos = mul(g_xFrame_MainCamera_ReflVP, float4(worldPos, 1)); diff --git a/WickedEngine/pointLightPS.hlsl b/WickedEngine/pointLightPS.hlsl deleted file mode 100644 index 33883a0a7..000000000 --- a/WickedEngine/pointLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_POINT - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/raytrace_shadeCS.hlsl b/WickedEngine/raytrace_shadeCS.hlsl index 26525d409..ee5fda058 100644 --- a/WickedEngine/raytrace_shadeCS.hlsl +++ b/WickedEngine/raytrace_shadeCS.hlsl @@ -93,7 +93,6 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) const float2 UV_normalMap = material.uvset_normalMap == 0 ? uvsets.xy : uvsets.zw; float3 normalMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_normalMap * material.normalMapAtlasMulAdd.xy + material.normalMapAtlasMulAdd.zw, 0).rgb; normalMap = normalMap.rgb * 2 - 1; - normalMap.g *= material.normalMapFlip; const float3x3 TBN = float3x3(tri.tangent, tri.binormal, N); N = normalize(lerp(N, mul(normalMap, TBN), material.normalMapStrength)); } diff --git a/WickedEngine/rectangleLightPS.hlsl b/WickedEngine/rectangleLightPS.hlsl deleted file mode 100644 index ed4769c4b..000000000 --- a/WickedEngine/rectangleLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_RECTANGLE - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/renderlightmapPS.hlsl b/WickedEngine/renderlightmapPS.hlsl index 90adfd117..74add5453 100644 --- a/WickedEngine/renderlightmapPS.hlsl +++ b/WickedEngine/renderlightmapPS.hlsl @@ -16,7 +16,7 @@ float4 main(Input input) : SV_TARGET float3 N = normalize(input.normal); float2 uv = input.uv; float seed = xTraceRandomSeed; - float3 direction = SampleHemisphere_uniform(N, seed, uv); // uniform because we care about only diffuse here + float3 direction = SampleHemisphere_cos(N, seed, uv); Ray ray = CreateRay(trace_bias_position(P, N), direction); const uint bounces = xTraceUserData.x; @@ -253,7 +253,6 @@ float4 main(Input input) : SV_TARGET const float2 UV_normalMap = material.uvset_normalMap == 0 ? uvsets.xy : uvsets.zw; float3 normalMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_normalMap * material.normalMapAtlasMulAdd.xy + material.normalMapAtlasMulAdd.zw, 0).rgb; normalMap = normalMap.rgb * 2 - 1; - normalMap.g *= material.normalMapFlip; const float3x3 TBN = float3x3(tri.tangent, tri.binormal, N); N = normalize(lerp(N, mul(normalMap, TBN), material.normalMapStrength)); } diff --git a/WickedEngine/rtao_denoise_temporalCS.hlsl b/WickedEngine/rtao_denoise_temporalCS.hlsl index 10efeb6db..89a5d34ae 100644 --- a/WickedEngine/rtao_denoise_temporalCS.hlsl +++ b/WickedEngine/rtao_denoise_temporalCS.hlsl @@ -4,6 +4,7 @@ TEXTURE2D(resolve_current, float, TEXSLOT_ONDEMAND0); TEXTURE2D(resolve_history, float, TEXSLOT_ONDEMAND1); +TEXTURE2D(texture_depth_history, float, TEXSLOT_ONDEMAND2); RWTEXTURE2D(output, unorm float, 0); @@ -66,6 +67,15 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 float2 prevUV = uv - velocity; + // Disocclusion fallback: + float depth_current = getLinearDepth(depth); + float depth_history = getLinearDepth(texture_depth_history.SampleLevel(sampler_point_clamp, prevUV, 0)); + if (length(velocity) > 0.0025 && abs(depth_current - depth_history) > 1) + { + output[DTid.xy] = resolve_current.SampleLevel(sampler_linear_clamp, uv, 0); + return; + } + float previous = resolve_history.SampleLevel(sampler_linear_clamp, prevUV, 0); float current = 0; diff --git a/WickedEngine/rtreflectionLIB.hlsl b/WickedEngine/rtreflectionLIB.hlsl index 8b2cd0026..238d0ed79 100644 --- a/WickedEngine/rtreflectionLIB.hlsl +++ b/WickedEngine/rtreflectionLIB.hlsl @@ -30,7 +30,7 @@ void RTReflection_Raygen() if (depth == 0.0f) return; - const float roughness = texture_gbuffer2.SampleLevel(sampler_linear_clamp, uv, 0).r; + const float roughness = texture_gbuffer0.SampleLevel(sampler_linear_clamp, uv, 0).a; const float3 P = reconstructPosition(uv, depth); const float3 N = decodeNormal(texture_gbuffer1.SampleLevel(sampler_point_clamp, uv, 0).xy); diff --git a/WickedEngine/shaders/CMakeLists.txt b/WickedEngine/shaders/CMakeLists.txt index fef595d1c..3dd9d5a6d 100644 --- a/WickedEngine/shaders/CMakeLists.txt +++ b/WickedEngine/shaders/CMakeLists.txt @@ -4,6 +4,7 @@ set(OUTPUT_DIR spirv) set(SHADERS_CS "hairparticle_simulateCS.hlsl" + "hairparticle_finishUpdateCS.hlsl" "emittedparticle_simulateCS.hlsl" "generateMIPChainCubeCS_float4.hlsl" "generateMIPChainCubeCS_unorm4.hlsl" @@ -67,13 +68,9 @@ set(SHADERS_CS "motionblurCS_earlyexit.hlsl" "lineardepthCS.hlsl" "luminancePass1CS.hlsl" - "lightCullingCS_DEFERRED_ADVANCED_DEBUG.hlsl" - "lightCullingCS_DEFERRED_DEBUG.hlsl" "lightShaftsCS.hlsl" "lightCullingCS_ADVANCED_DEBUG.hlsl" "lightCullingCS_DEBUG.hlsl" - "lightCullingCS_DEFERRED.hlsl" - "lightCullingCS_DEFERRED_ADVANCED.hlsl" "lightCullingCS.hlsl" "lightCullingCS_ADVANCED.hlsl" "hbaoCS.hlsl" @@ -143,6 +140,7 @@ set(SHADERS_CS "volumetricCloud_finalCS.hlsl" "shadingRateClassificationCS.hlsl" "shadingRateClassificationCS_DEBUG.hlsl" + "denoiseCS.hlsl" ) set(SHADERS_DS @@ -161,91 +159,59 @@ set(SHADERS_PS "emittedparticlePS_soft_lighting.hlsl" "oceanSurfacePS.hlsl" "deferredPS.hlsl" - "hairparticlePS_forward.hlsl" - "hairparticlePS_tiledforward.hlsl" - "impostorPS_forward.hlsl" - "impostorPS_tiledforward.hlsl" + "hairparticlePS.hlsl" + "impostorPS.hlsl" "volumetricLight_SpotPS.hlsl" "volumetricLight_PointPS.hlsl" "volumetricLight_DirectionalPS.hlsl" "voxelPS.hlsl" "vertexcolorPS.hlsl" "trailPS.hlsl" - "tubeLightPS.hlsl" "upsample_bilateralPS.hlsl" "sunPS.hlsl" "sssPS.hlsl" - "sphereLightPS.hlsl" - "spotLightPS.hlsl" + "sssPS_snow.hlsl" "skyPS_dynamic.hlsl" "skyPS_static.hlsl" "shadowPS_transparent.hlsl" "shadowPS_water.hlsl" "shadowPS_alphatest.hlsl" - "rectangleLightPS.hlsl" "renderlightmapPS.hlsl" "raytrace_debugbvhPS.hlsl" - "pointLightPS.hlsl" "outlinePS.hlsl" "oceanSurfaceSimplePS.hlsl" - "objectPS_tiledforward_transparent_pom.hlsl" - "objectPS_tiledforward_water.hlsl" + "objectPS_transparent_pom.hlsl" + "objectPS_water.hlsl" "objectPS_voxelizer.hlsl" "objectPS_voxelizer_terrain.hlsl" - "objectPS_tiledforward_transparent.hlsl" - "objectPS_tiledforward_transparent_normalmap.hlsl" - "objectPS_tiledforward_transparent_normalmap_planarreflection.hlsl" - "objectPS_tiledforward_transparent_normalmap_pom.hlsl" - "objectPS_tiledforward_transparent_planarreflection.hlsl" - "objectPS_tiledforward_normalmap_pom.hlsl" - "objectPS_tiledforward_planarreflection.hlsl" - "objectPS_tiledforward_pom.hlsl" - "objectPS_tiledforward_terrain.hlsl" + "objectPS_transparent.hlsl" + "objectPS_transparent_planarreflection.hlsl" + "objectPS_planarreflection.hlsl" + "objectPS_pom.hlsl" + "objectPS_terrain.hlsl" "objectPS_textureonly.hlsl" - "objectPS_tiledforward.hlsl" - "objectPS_tiledforward_normalmap.hlsl" - "objectPS_tiledforward_normalmap_planarreflection.hlsl" - "objectPS_forward_transparent_pom.hlsl" - "objectPS_forward_water.hlsl" + "objectPS.hlsl" "objectPS_hologram.hlsl" "objectPS_paintradius.hlsl" "objectPS_simplest.hlsl" - "objectPS_forward_transparent_normalmap_planarreflection.hlsl" - "objectPS_forward_transparent_normalmap_pom.hlsl" - "objectPS_forward_transparent_planarreflection.hlsl" - "objectPS_forward_pom.hlsl" - "objectPS_forward_terrain.hlsl" - "objectPS_forward_transparent.hlsl" - "objectPS_forward_transparent_normalmap.hlsl" - "objectPS_forward.hlsl" - "objectPS_forward_normalmap.hlsl" - "objectPS_forward_normalmap_planarreflection.hlsl" - "objectPS_forward_normalmap_pom.hlsl" - "objectPS_forward_planarreflection.hlsl" - "objectPS_deferred_normalmap_pom.hlsl" - "objectPS_deferred_planarreflection.hlsl" - "objectPS_deferred_pom.hlsl" - "objectPS_deferred_terrain.hlsl" "objectPS_blackout.hlsl" "objectPS_debug.hlsl" - "objectPS_deferred.hlsl" - "objectPS_deferred_normalmap.hlsl" - "objectPS_deferred_normalmap_planarreflection.hlsl" "objectPS_alphatestonly.hlsl" + "objectPS_anisotropic.hlsl" + "objectPS_transparent_anisotropic.hlsl" + "objectPS_cartoon.hlsl" + "objectPS_transparent_cartoon.hlsl" + "objectPS_unlit.hlsl" + "objectPS_transparent_unlit.hlsl" "lightVisualizerPS.hlsl" "lensFlarePS.hlsl" "impostorPS_wire.hlsl" - "impostorPS_deferred.hlsl" "impostorPS_simple.hlsl" "impostorPS_alphatestonly.hlsl" - "hairparticlePS_tiledforward_transparent.hlsl" - "hairparticlePS_deferred.hlsl" - "hairparticlePS_forward_transparent.hlsl" "hairparticlePS_simplest.hlsl" "hairparticlePS_alphatestonly.hlsl" "forceFieldVisualizerPS.hlsl" "fontPS.hlsl" - "environmentalLightPS.hlsl" "envMap_skyPS_static.hlsl" "envMap_skyPS_dynamic.hlsl" "envMapPS.hlsl" @@ -253,9 +219,6 @@ set(SHADERS_PS "emittedparticlePS_soft_distortion.hlsl" "downsampleDepthBuffer4xPS.hlsl" "emittedparticlePS_simplest.hlsl" - "dirLightPS.hlsl" - "discLightPS.hlsl" - "decalPS.hlsl" "cubeMapPS.hlsl" "circlePS.hlsl" "captureImpostorPS_normal.hlsl" @@ -270,6 +233,9 @@ set(SHADERS_VS "fontVS.hlsl" "voxelVS.hlsl" "vertexcolorVS.hlsl" + "volumetriclight_directionalVS.hlsl" + "volumetriclight_pointVS.hlsl" + "volumetriclight_spotVS.hlsl" "vSpotLightVS.hlsl" "vTubeLightVS.hlsl" "vDiscLightVS.hlsl" @@ -278,7 +244,6 @@ set(SHADERS_VS "vSphereLightVS.hlsl" "trailVS.hlsl" "sphereVS.hlsl" - "spotLightVS.hlsl" "skyVS.hlsl" "shadowVS_transparent.hlsl" "shadowVS.hlsl" @@ -286,7 +251,6 @@ set(SHADERS_VS "screenVS.hlsl" "renderlightmapVS.hlsl" "raytrace_screenVS.hlsl" - "pointLightVS.hlsl" "oceanSurfaceVS.hlsl" "objectVS_simple.hlsl" "objectVS_simple_tessellation.hlsl" @@ -301,8 +265,6 @@ set(SHADERS_VS "forceFieldPlaneVisualizerVS.hlsl" "envMap_skyVS.hlsl" "envMapVS.hlsl" - "dirLightVS.hlsl" - "decalVS.hlsl" "cubeShadowVS.hlsl" "cubeShadowVS_alphatest.hlsl" "cubeVS.hlsl" diff --git a/WickedEngine/skinningCS.hlsl b/WickedEngine/skinningCS.hlsl index d1f09bd4b..52166072b 100644 --- a/WickedEngine/skinningCS.hlsl +++ b/WickedEngine/skinningCS.hlsl @@ -17,17 +17,20 @@ groupshared Bone LDS_BoneList[SKINNING_COMPUTE_THREADCOUNT]; #endif // USE_LDS RAWBUFFER(vertexBuffer_POS, SKINNINGSLOT_IN_VERTEX_POS); +RAWBUFFER(vertexBuffer_TAN, SKINNINGSLOT_IN_VERTEX_TAN); RAWBUFFER(vertexBuffer_BON, SKINNINGSLOT_IN_VERTEX_BON); RWRAWBUFFER(streamoutBuffer_POS, 0); +RWRAWBUFFER(streamoutBuffer_TAN, 1); -inline void Skinning(inout float3 pos, inout float3 nor, in float4 inBon, in float4 inWei) +inline void Skinning(inout float3 pos, inout float3 nor, inout float3 tan, in float4 inBon, in float4 inWei) { if (any(inWei)) { float4 p = 0; float3 n = 0; + float3 t = 0; float weisum = 0; // force loop to reduce register pressure @@ -48,14 +51,16 @@ inline void Skinning(inout float3 pos, inout float3 nor, in float4 inBon, in flo float4(0, 0, 0, 1) ); - p += mul(m, float4(pos.xyz, 1))*inWei[i]; - n += mul((float3x3)m, nor.xyz)*inWei[i]; + p += mul(m, float4(pos.xyz, 1)) * inWei[i]; + n += mul((float3x3)m, nor.xyz) * inWei[i]; + t += mul((float3x3)m, tan.xyz) * inWei[i]; weisum += inWei[i]; } pos.xyz = p.xyz; nor.xyz = normalize(n.xyz); + tan.xyz = normalize(t.xyz); } } @@ -68,16 +73,18 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID) #endif // USE_LDS const uint stride_POS_NOR = 16; + const uint stride_TAN = 4; const uint stride_BON_IND = 8; const uint stride_BON_WEI = 8; const uint fetchAddress_POS_NOR = DTid.x * stride_POS_NOR; + const uint fetchAddress_TAN = DTid.x * stride_TAN; const uint fetchAddress_BON = DTid.x * (stride_BON_IND + stride_BON_WEI); // Manual type-conversion for pos: uint4 pos_nor_u = vertexBuffer_POS.Load4(fetchAddress_POS_NOR); float3 pos = asfloat(pos_nor_u.xyz); - + uint vtan = vertexBuffer_TAN.Load(fetchAddress_TAN); // Manual type-conversion for normal: float4 nor = 0; @@ -88,6 +95,14 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID) nor.w = (float)((pos_nor_u.w >> 24) & 0x000000FF) / 255.0f; // wind } + // Manual type-conversion for tangent: + float4 tan = 0; + { + tan.x = (float)((vtan >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + tan.y = (float)((vtan >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + tan.z = (float)((vtan >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + tan.w = (float)((vtan >> 24) & 0x000000FF) / 255.0f * 2.0f - 1.0f; + } // Manual type-conversion for bone props: uint4 ind_wei_u = vertexBuffer_BON.Load4(fetchAddress_BON); @@ -111,7 +126,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID) // Perform skinning: - Skinning(pos, nor.xyz, ind, wei); + Skinning(pos, nor.xyz, tan.xyz, ind, wei); @@ -128,6 +143,16 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID) pos_nor_u.w |= (uint)(nor.w * 255.0f) << 24; // wind } + // Manual type-conversion for tangent: + vtan = 0; + { + vtan |= (uint)((tan.x * 0.5f + 0.5f) * 255.0f) << 0; + vtan |= (uint)((tan.y * 0.5f + 0.5f) * 255.0f) << 8; + vtan |= (uint)((tan.z * 0.5f + 0.5f) * 255.0f) << 16; + vtan |= (uint)((tan.w * 0.5f + 0.5f) * 255.0f) << 24; + } + // Store data: streamoutBuffer_POS.Store4(fetchAddress_POS_NOR, pos_nor_u); + streamoutBuffer_TAN.Store(fetchAddress_TAN, vtan); } \ No newline at end of file diff --git a/WickedEngine/skyPS_dynamic.hlsl b/WickedEngine/skyPS_dynamic.hlsl index 3f3e6ae8d..95071ef77 100644 --- a/WickedEngine/skyPS_dynamic.hlsl +++ b/WickedEngine/skyPS_dynamic.hlsl @@ -1,7 +1,7 @@ #include "objectHF.hlsli" #include "skyHF.hlsli" -GBUFFEROutputType_Thin main(float4 pos : SV_POSITION, float2 clipspace : TEXCOORD) +GBUFFEROutputType main(float4 pos : SV_POSITION, float2 clipspace : TEXCOORD) { float4 unprojected = mul(g_xCamera_InvVP, float4(clipspace, 0.0f, 1.0f)); unprojected.xyz /= unprojected.w; @@ -13,9 +13,8 @@ GBUFFEROutputType_Thin main(float4 pos : SV_POSITION, float2 clipspace : TEXCOOR float4 pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, float4(unprojected.xyz, 1)); float2 velocity = ((pos2DPrev.xy / pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (clipspace - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - GBUFFEROutputType_Thin Out; + GBUFFEROutputType Out = (GBUFFEROutputType)0; Out.g0 = color; Out.g1 = float4(0, 0, velocity); - Out.g2 = 0; return Out; } diff --git a/WickedEngine/skyPS_static.hlsl b/WickedEngine/skyPS_static.hlsl index e88018876..e032a16f8 100644 --- a/WickedEngine/skyPS_static.hlsl +++ b/WickedEngine/skyPS_static.hlsl @@ -1,7 +1,7 @@ #include "objectHF.hlsli" #include "skyHF.hlsli" -GBUFFEROutputType_Thin main(float4 pos : SV_POSITION, float2 clipspace : TEXCOORD) +GBUFFEROutputType main(float4 pos : SV_POSITION, float2 clipspace : TEXCOORD) { float4 unprojected = mul(g_xCamera_InvVP, float4(clipspace, 0.0f, 1.0f)); unprojected.xyz /= unprojected.w; @@ -14,10 +14,9 @@ GBUFFEROutputType_Thin main(float4 pos : SV_POSITION, float2 clipspace : TEXCOOR float4 pos2DPrev = mul(g_xFrame_MainCamera_PrevVP, float4(unprojected.xyz, 1)); float2 velocity = ((pos2DPrev.xy / pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (clipspace - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f); - GBUFFEROutputType_Thin Out; + GBUFFEROutputType Out = (GBUFFEROutputType)0; Out.g0 = color; Out.g1 = float4(0, 0, velocity); - Out.g2 = 0; return Out; } diff --git a/WickedEngine/sphereLightPS.hlsl b/WickedEngine/sphereLightPS.hlsl deleted file mode 100644 index 08c5aaaf7..000000000 --- a/WickedEngine/sphereLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_SPHERE - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/spotLightPS.hlsl b/WickedEngine/spotLightPS.hlsl deleted file mode 100644 index 034700ba7..000000000 --- a/WickedEngine/spotLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_SPOT - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/ssr_raytraceCS.hlsl b/WickedEngine/ssr_raytraceCS.hlsl index 659f5198a..17e145a1c 100644 --- a/WickedEngine/ssr_raytraceCS.hlsl +++ b/WickedEngine/ssr_raytraceCS.hlsl @@ -224,7 +224,7 @@ void main(uint3 DTid : SV_DispatchThreadID) const float3 N = mul((float3x3)g_xCamera_View, decodeNormal(texture_gbuffer1.SampleLevel(sampler_point_clamp, uv, 0).xy)).xyz; const float3 V = normalize(-P); - const float roughness = GetRoughness(texture_gbuffer2.SampleLevel(sampler_point_clamp, uv, 0).r); + const float roughness = GetRoughness(texture_gbuffer0.SampleLevel(sampler_point_clamp, uv, 0).a); const float roughnessFade = GetRoughnessFade(roughness, SSRMaxRoughness); if (roughnessFade <= 0.0f) diff --git a/WickedEngine/ssr_resolveCS.hlsl b/WickedEngine/ssr_resolveCS.hlsl index c2e585d1a..f05ce76d0 100644 --- a/WickedEngine/ssr_resolveCS.hlsl +++ b/WickedEngine/ssr_resolveCS.hlsl @@ -72,7 +72,7 @@ void main(uint3 DTid : SV_DispatchThreadID) const float3 V = normalize(-P); const float NdotV = saturate(dot(N, V)); - const float roughness = GetRoughness(texture_gbuffer2.SampleLevel(sampler_point_clamp, uv, 0).r); + const float roughness = GetRoughness(texture_gbuffer0.SampleLevel(sampler_point_clamp, uv, 0).a); const float roughnessSequenceSize = resolveSequenceSize * roughness + 1.0f; // Early out, useless if the roughness is out of range diff --git a/WickedEngine/ssr_temporalCS.hlsl b/WickedEngine/ssr_temporalCS.hlsl index 7c6b75d5b..bdd18687b 100644 --- a/WickedEngine/ssr_temporalCS.hlsl +++ b/WickedEngine/ssr_temporalCS.hlsl @@ -147,5 +147,5 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 float4 result = lerp(current, previous, blendFinal); - output[DTid.xy] = result; -} \ No newline at end of file + output[DTid.xy] = max(0, result); +} diff --git a/WickedEngine/sssPS.hlsl b/WickedEngine/sssPS.hlsl index 144397032..c4f582ccc 100644 --- a/WickedEngine/sssPS.hlsl +++ b/WickedEngine/sssPS.hlsl @@ -9,25 +9,43 @@ #define SSSS_N_SAMPLES 11 + +#ifdef SSS_PROFILE_SNOW +// snow: static const float4 kernel[] = { - float4(0.560479, 0.669086, 0.784728, 0), - float4(0.00471691, 0.000184771, 5.07566e-005, -2), - float4(0.0192831, 0.00282018, 0.00084214, -1.28), - float4(0.03639, 0.0130999, 0.00643685, -0.72), - float4(0.0821904, 0.0358608, 0.0209261, -0.32), - float4(0.0771802, 0.113491, 0.0793803, -0.08), - float4(0.0771802, 0.113491, 0.0793803, 0.08), - float4(0.0821904, 0.0358608, 0.0209261, 0.32), - float4(0.03639, 0.0130999, 0.00643685, 0.72), - float4(0.0192831, 0.00282018, 0.00084214, 1.28), - float4(0.00471691, 0.000184771, 5.07565e-005, 2), + float4(0.784728, 0.669086, 0.560479, 0), + float4(5.07566e-005, 0.000184771, 0.00471691, -2), + float4(0.00084214, 0.00282018, 0.0192831, -1.28), + float4(0.00643685, 0.0130999, 0.03639, -0.72), + float4(0.0209261, 0.0358608, 0.0821904, -0.32), + float4(0.0793803, 0.113491, 0.0771802, -0.08), + float4(0.0793803, 0.113491, 0.0771802, 0.08), + float4(0.0209261, 0.0358608, 0.0821904, 0.32), + float4(0.00643685, 0.0130999, 0.03639, 0.72), + float4(0.00084214, 0.00282018, 0.0192831, 1.28), + float4(5.07565e-005, 0.000184771, 0.00471691, 2), }; +#else +// skin: +static const float4 kernel[] = { + float4(0.560479, 0.669086, 0.784728, 0), + float4(0.00471691, 0.000184771, 5.07566e-005, -2), + float4(0.0192831, 0.00282018, 0.00084214, -1.28), + float4(0.03639, 0.0130999, 0.00643685, -0.72), + float4(0.0821904, 0.0358608, 0.0209261, -0.32), + float4(0.0771802, 0.113491, 0.0793803, -0.08), + float4(0.0771802, 0.113491, 0.0793803, 0.08), + float4(0.0821904, 0.0358608, 0.0209261, 0.32), + float4(0.03639, 0.0130999, 0.00643685, 0.72), + float4(0.0192831, 0.00282018, 0.00084214, 1.28), + float4(0.00471691, 0.000184771, 5.07565e-005, 2), +}; +#endif // SSS_PROFILE_SNOW float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_TARGET { const float4 color_ref = texture_0[pos.xy]; const float depth_ref = texture_lineardepth[pos.xy] * g_xCamera_ZFarP; - const float sss_ref = texture_gbuffer0[pos.xy].a; // Accumulate center sample, multiplying it with its gaussian weight: float4 colorBlurred = color_ref; @@ -38,16 +56,13 @@ float4 main(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_TARGET // step = sssStrength * gaussianWidth * pixelSize * dir // The closer the pixel, the stronger the effect needs to be, hence // the factor 1.0 / depthM. - float2 step = xPPParams0.xy * sss_ref; - float2 finalStep = color_ref.a * step / depth_ref; + float2 finalStep = color_ref.a * sss_step.xy / depth_ref; // Accumulate the other samples: for (int i = 1; i < SSSS_N_SAMPLES; i++) { // Fetch color and depth for current sample: float2 offset = uv + kernel[i].a * finalStep; - float sss = texture_gbuffer0.SampleLevel(sampler_point_clamp, offset, 0).a; - offset = sss == sss_ref ? offset : uv; // don't blur into non-sss region float3 color = texture_0.SampleLevel(sampler_linear_clamp, offset, 0).rgb; float depth = texture_lineardepth.SampleLevel(sampler_point_clamp, offset, 0) * g_xCamera_ZFarP; diff --git a/WickedEngine/sssPS_snow.hlsl b/WickedEngine/sssPS_snow.hlsl new file mode 100644 index 000000000..e988d2b80 --- /dev/null +++ b/WickedEngine/sssPS_snow.hlsl @@ -0,0 +1,2 @@ +#define SSS_PROFILE_SNOW +#include "sssPS.hlsl" diff --git a/WickedEngine/temporalaaCS.hlsl b/WickedEngine/temporalaaCS.hlsl index 9d644a482..5ab33dbb9 100644 --- a/WickedEngine/temporalaaCS.hlsl +++ b/WickedEngine/temporalaaCS.hlsl @@ -3,6 +3,7 @@ TEXTURE2D(input_current, float3, TEXSLOT_ONDEMAND0); TEXTURE2D(input_history, float3, TEXSLOT_ONDEMAND1); +TEXTURE2D(texture_depth_history, float, TEXSLOT_ONDEMAND2); RWTEXTURE2D(output, float3, 0); @@ -99,6 +100,18 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 const float2 prevUV = uv + velocity; +#if 0 + // Disocclusion fallback: + float depth_current = texture_lineardepth[DTid.xy] * g_xCamera_ZFarP; + float depth_history = getLinearDepth(texture_depth_history.SampleLevel(sampler_point_clamp, prevUV, 0)); + if (length(velocity) > 0.01 && abs(depth_current - depth_history) > 1) + { + output[DTid.xy] = current; + output[DTid.xy] = float3(1, 0, 0); + return; + } +#endif + // we cannot avoid the linear filter here because point sampling could sample irrelevant pixels but we try to correct it later: float3 history = input_history.SampleLevel(sampler_linear_clamp, prevUV, 0).rgb; diff --git a/WickedEngine/tubeLightPS.hlsl b/WickedEngine/tubeLightPS.hlsl deleted file mode 100644 index 465567346..000000000 --- a/WickedEngine/tubeLightPS.hlsl +++ /dev/null @@ -1,10 +0,0 @@ -#include "deferredLightHF.hlsli" - -LightOutputType main(VertexToPixel PSIn) -{ - DEFERREDLIGHT_MAKEPARAMS - - DEFERREDLIGHT_TUBE - - DEFERREDLIGHT_RETURN -} \ No newline at end of file diff --git a/WickedEngine/volumetricLightHF.hlsli b/WickedEngine/volumetricLightHF.hlsli new file mode 100644 index 000000000..c316fe8d1 --- /dev/null +++ b/WickedEngine/volumetricLightHF.hlsli @@ -0,0 +1,13 @@ +#ifndef WI_VOLUMETRICLIGHT_HF +#define WI_VOLUMETRICLIGHT_HF +#include "globals.hlsli" +#include "brdf.hlsli" +#include "lightingHF.hlsli" + +struct VertexToPixel { + float4 pos : SV_POSITION; + float4 pos2D : POSITION2D; +}; + + +#endif // WI_VOLUMETRICLIGHT_HF diff --git a/WickedEngine/volumetricLight_DirectionalPS.hlsl b/WickedEngine/volumetricLight_DirectionalPS.hlsl index 0235a0784..f27cdbea9 100644 --- a/WickedEngine/volumetricLight_DirectionalPS.hlsl +++ b/WickedEngine/volumetricLight_DirectionalPS.hlsl @@ -1,6 +1,6 @@ #define DISABLE_TRANSPARENT_SHADOWMAP #define DISABLE_SOFT_SHADOWMAP -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" float4 main(VertexToPixel input) : SV_TARGET { diff --git a/WickedEngine/volumetricLight_PointPS.hlsl b/WickedEngine/volumetricLight_PointPS.hlsl index d67732ba6..2285f61e8 100644 --- a/WickedEngine/volumetricLight_PointPS.hlsl +++ b/WickedEngine/volumetricLight_PointPS.hlsl @@ -1,5 +1,5 @@ #define DISABLE_TRANSPARENT_SHADOWMAP -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" float4 main(VertexToPixel input) : SV_TARGET { diff --git a/WickedEngine/volumetricLight_SpotPS.hlsl b/WickedEngine/volumetricLight_SpotPS.hlsl index 114739c08..8f33118e4 100644 --- a/WickedEngine/volumetricLight_SpotPS.hlsl +++ b/WickedEngine/volumetricLight_SpotPS.hlsl @@ -1,5 +1,5 @@ #define DISABLE_TRANSPARENT_SHADOWMAP -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" float4 main(VertexToPixel input) : SV_TARGET { diff --git a/WickedEngine/dirLightVS.hlsl b/WickedEngine/volumetriclight_directionalVS.hlsl similarity index 78% rename from WickedEngine/dirLightVS.hlsl rename to WickedEngine/volumetriclight_directionalVS.hlsl index 80a0913b1..38178d3c9 100644 --- a/WickedEngine/dirLightVS.hlsl +++ b/WickedEngine/volumetriclight_directionalVS.hlsl @@ -1,12 +1,12 @@ -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) { VertexToPixel Out; FullScreenTriangle(vid, Out.pos); - + Out.pos2D = Out.pos; return Out; -} \ No newline at end of file +} diff --git a/WickedEngine/pointLightVS.hlsl b/WickedEngine/volumetriclight_pointVS.hlsl similarity index 83% rename from WickedEngine/pointLightVS.hlsl rename to WickedEngine/volumetriclight_pointVS.hlsl index abdb1af17..e90a57c04 100644 --- a/WickedEngine/pointLightVS.hlsl +++ b/WickedEngine/volumetriclight_pointVS.hlsl @@ -1,10 +1,10 @@ -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" #include "icosphere.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) { VertexToPixel Out; - + float4 pos = ICOSPHERE[vid]; Out.pos = Out.pos2D = mul(g_xTransform, pos); return Out; diff --git a/WickedEngine/spotLightVS.hlsl b/WickedEngine/volumetriclight_spotVS.hlsl similarity index 82% rename from WickedEngine/spotLightVS.hlsl rename to WickedEngine/volumetriclight_spotVS.hlsl index 24d0f8a08..d1eec8f85 100644 --- a/WickedEngine/spotLightVS.hlsl +++ b/WickedEngine/volumetriclight_spotVS.hlsl @@ -1,12 +1,12 @@ -#include "deferredLightHF.hlsli" +#include "volumetricLightHF.hlsli" #include "cone.hlsli" VertexToPixel main(uint vid : SV_VERTEXID) { VertexToPixel Out; - + float4 pos = CONE[vid]; Out.pos = Out.pos2D = mul(g_xTransform, pos); return Out; -} \ No newline at end of file +} diff --git a/WickedEngine/wiArchive.cpp b/WickedEngine/wiArchive.cpp index e8738b336..dd8a65879 100644 --- a/WickedEngine/wiArchive.cpp +++ b/WickedEngine/wiArchive.cpp @@ -7,7 +7,7 @@ using namespace std; // this should always be only INCREMENTED and only if a new serialization is implemeted somewhere! -uint64_t __archiveVersion = 49; +uint64_t __archiveVersion = 52; // this is the version number of which below the archive is not compatible with the current version uint64_t __archiveVersionBarrier = 22; diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 82c2f4398..22f41d5ba 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -609,6 +609,7 @@ namespace wiEmittedParticle_Internal for (int i = 0; i < BLENDMODE_COUNT; ++i) { PipelineStateDesc desc; + desc.pt = TRIANGLESTRIP; if (wiRenderer::GetDevice()->CheckCapability(GRAPHICSDEVICE_CAPABILITY_MESH_SHADER)) { desc.ms = &meshShader; diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index 79e38cf34..b234dc6ca 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -10,22 +10,29 @@ enum BLENDMODE BLENDMODE_COUNT }; +enum GBUFFER +{ + GBUFFER_ALBEDO_ROUGHNESS, + GBUFFER_NORMAL_VELOCITY, + GBUFFER_LIGHTBUFFER_DIFFUSE, + GBUFFER_LIGHTBUFFER_SPECULAR, + GBUFFER_COUNT +}; + // Do not alter order or value because it is bound to lua manually! enum RENDERTYPE { RENDERTYPE_VOID = 0, - RENDERTYPE_OPAQUE = 1, - RENDERTYPE_TRANSPARENT = 2, - RENDERTYPE_WATER = 4, + RENDERTYPE_OPAQUE = 1 << 0, + RENDERTYPE_TRANSPARENT = 1 << 1, + RENDERTYPE_WATER = 1 << 2, RENDERTYPE_ALL = RENDERTYPE_OPAQUE | RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER }; enum RENDERPASS { RENDERPASS_TEXTURE, - RENDERPASS_DEFERRED, - RENDERPASS_FORWARD, - RENDERPASS_TILEDFORWARD, + RENDERPASS_MAIN, RENDERPASS_DEPTHONLY, RENDERPASS_ENVMAPCAPTURE, RENDERPASS_SHADOW, @@ -49,9 +56,10 @@ enum STENCILREF_MASK enum STENCILREF { STENCILREF_EMPTY = 0, - STENCILREF_SKY = 1, - STENCILREF_DEFAULT = 2, + STENCILREF_DEFAULT = 1, + STENCILREF_CUSTOMSHADER = 2, STENCILREF_SKIN = 3, + STENCILREF_SNOW = 4, STENCILREF_LAST = 15 }; @@ -62,7 +70,6 @@ enum CBTYPES CBTYPE_CAMERA, CBTYPE_MISC, CBTYPE_VOLUMELIGHT, - CBTYPE_DECAL, CBTYPE_CUBEMAPRENDER, CBTYPE_API, CBTYPE_TESSELLATION, @@ -120,9 +127,9 @@ enum VSTYPES VSTYPE_IMPOSTOR, VSTYPE_VERTEXCOLOR, VSTYPE_TRAIL, - VSTYPE_DIRLIGHT, - VSTYPE_POINTLIGHT, - VSTYPE_SPOTLIGHT, + VSTYPE_VOLUMETRICLIGHT_DIRECTIONAL, + VSTYPE_VOLUMETRICLIGHT_POINT, + VSTYPE_VOLUMETRICLIGHT_SPOT, VSTYPE_LIGHTVISUALIZER_SPOTLIGHT, VSTYPE_LIGHTVISUALIZER_POINTLIGHT, VSTYPE_LIGHTVISUALIZER_SPHERELIGHT, @@ -130,7 +137,6 @@ enum VSTYPES VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT, VSTYPE_LIGHTVISUALIZER_TUBELIGHT, VSTYPE_SKY, - VSTYPE_DECAL, VSTYPE_ENVMAP, VSTYPE_ENVMAP_SKY, VSTYPE_SPHERE, @@ -148,46 +154,21 @@ enum VSTYPES // pixel shaders enum PSTYPES { - PSTYPE_OBJECT_DEFERRED, - PSTYPE_OBJECT_DEFERRED_NORMALMAP, - PSTYPE_OBJECT_DEFERRED_POM, - PSTYPE_OBJECT_DEFERRED_PLANARREFLECTION, - PSTYPE_OBJECT_DEFERRED_NORMALMAP_POM, - PSTYPE_OBJECT_DEFERRED_NORMALMAP_PLANARREFLECTION, - PSTYPE_OBJECT_DEFERRED_TERRAIN, - PSTYPE_IMPOSTOR_DEFERRED, - - PSTYPE_OBJECT_FORWARD, - PSTYPE_OBJECT_FORWARD_NORMALMAP, - PSTYPE_OBJECT_FORWARD_TRANSPARENT, - PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP, - PSTYPE_OBJECT_FORWARD_PLANARREFLECTION, - PSTYPE_OBJECT_FORWARD_NORMALMAP_PLANARREFLECTION, - PSTYPE_OBJECT_FORWARD_TRANSPARENT_PLANARREFLECTION, - PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION, - PSTYPE_OBJECT_FORWARD_POM, - PSTYPE_OBJECT_FORWARD_NORMALMAP_POM, - PSTYPE_OBJECT_FORWARD_TRANSPARENT_POM, - PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_POM, - PSTYPE_OBJECT_FORWARD_WATER, - PSTYPE_OBJECT_FORWARD_TERRAIN, - PSTYPE_IMPOSTOR_FORWARD, - - PSTYPE_OBJECT_TILEDFORWARD, - PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP, - PSTYPE_OBJECT_TILEDFORWARD_PLANARREFLECTION, - PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_PLANARREFLECTION, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_PLANARREFLECTION, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION, - PSTYPE_OBJECT_TILEDFORWARD_POM, - PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_POM, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_POM, - PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_POM, - PSTYPE_OBJECT_TILEDFORWARD_WATER, - PSTYPE_OBJECT_TILEDFORWARD_TERRAIN, - PSTYPE_IMPOSTOR_TILEDFORWARD, + PSTYPE_OBJECT, + PSTYPE_OBJECT_TRANSPARENT, + PSTYPE_OBJECT_PLANARREFLECTION, + PSTYPE_OBJECT_TRANSPARENT_PLANARREFLECTION, + PSTYPE_OBJECT_POM, + PSTYPE_OBJECT_TRANSPARENT_POM, + PSTYPE_OBJECT_ANISOTROPIC, + PSTYPE_OBJECT_TRANSPARENT_ANISOTROPIC, + PSTYPE_OBJECT_CARTOON, + PSTYPE_OBJECT_TRANSPARENT_CARTOON, + PSTYPE_OBJECT_UNLIT, + PSTYPE_OBJECT_TRANSPARENT_UNLIT, + PSTYPE_OBJECT_WATER, + PSTYPE_OBJECT_TERRAIN, + PSTYPE_IMPOSTOR, PSTYPE_OBJECT_HOLOGRAM, @@ -207,19 +188,10 @@ enum PSTYPES PSTYPE_VERTEXCOLOR, PSTYPE_TRAIL, - PSTYPE_ENVIRONMENTALLIGHT, - PSTYPE_DIRLIGHT, - PSTYPE_POINTLIGHT, - PSTYPE_SPOTLIGHT, - PSTYPE_SPHERELIGHT, - PSTYPE_DISCLIGHT, - PSTYPE_RECTANGLELIGHT, - PSTYPE_TUBELIGHT, PSTYPE_LIGHTVISUALIZER, PSTYPE_VOLUMETRICLIGHT_DIRECTIONAL, PSTYPE_VOLUMETRICLIGHT_POINT, PSTYPE_VOLUMETRICLIGHT_SPOT, - PSTYPE_DECAL, PSTYPE_SKY_STATIC, PSTYPE_SKY_DYNAMIC, PSTYPE_SUN, @@ -239,7 +211,8 @@ enum PSTYPES PSTYPE_RAYTRACE_DEBUGBVH, PSTYPE_DOWNSAMPLEDEPTHBUFFER, PSTYPE_DEFERREDCOMPOSITION, - PSTYPE_POSTPROCESS_SSS, + PSTYPE_POSTPROCESS_SSS_SKIN, + PSTYPE_POSTPROCESS_SSS_SNOW, PSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL, PSTYPE_POSTPROCESS_OUTLINE, PSTYPE_LENSFLARE, @@ -375,6 +348,7 @@ enum CSTYPES CSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL_UNORM4, CSTYPE_POSTPROCESS_DOWNSAMPLE4X, CSTYPE_POSTPROCESS_NORMALSFROMDEPTH, + CSTYPE_POSTPROCESS_DENOISE, CSTYPE_COUNT }; // raytracing shaders @@ -423,7 +397,6 @@ enum DSSTYPES DSSTYPE_SHADOW, DSSTYPE_XRAY, DSSTYPE_DEPTHREAD, - DSSTYPE_DEFERREDLIGHT, DSSTYPE_DEPTHREADEQUAL, DSSTYPE_ENVMAP, DSSTYPE_CAPTUREIMPOSTOR, @@ -441,7 +414,6 @@ enum BSTYPES BSTYPE_ADDITIVE, BSTYPE_PREMULTIPLIED, BSTYPE_COLORWRITEDISABLE, - BSTYPE_DEFERREDLIGHT, BSTYPE_ENVIRONMENTALLIGHT, BSTYPE_DECAL, BSTYPE_MULTIPLY, diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 09cef5c89..e71dcd7ab 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -25,7 +25,6 @@ using namespace std; using namespace wiGraphics; using namespace wiRectPacker; -#define MAX_TEXT 10000 #define WHITESPACE_SIZE ((float(params.size) + params.spacingX) * params.scaling * 0.25f) #define TAB_SIZE (WHITESPACE_SIZE * 4) #define LINEBREAK_SIZE ((float(params.size) + params.spacingY) * params.scaling) @@ -33,7 +32,6 @@ using namespace wiRectPacker; namespace wiFont_Internal { string FONTPATH = wiHelper::GetOriginalWorkingDirectory() + "../WickedEngine/fonts/"; - GPUBuffer indexBuffer; GPUBuffer constantBuffer; BlendState blendState; RasterizerState rasterizerState; @@ -239,14 +237,7 @@ void LoadShaders() { std::string path = wiRenderer::GetShaderPath(); - InputLayoutDesc layout[] = - { - { "POSITION", 0, FORMAT_R32G32_FLOAT, 0, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, FORMAT_R16G16_FLOAT, 0, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - }; wiRenderer::LoadShader(VS, vertexShader, "fontVS.cso"); - wiRenderer::GetDevice()->CreateInputLayout(layout, arraysize(layout), &vertexShader, &inputLayout); - wiRenderer::LoadShader(PS, pixelShader, "fontPS.cso"); @@ -254,10 +245,10 @@ void LoadShaders() PipelineStateDesc desc; desc.vs = &vertexShader; desc.ps = &pixelShader; - desc.il = &inputLayout; desc.bs = &blendState; desc.dss = &depthStencilState; desc.rs = &rasterizerState; + desc.pt = TRIANGLESTRIP; wiRenderer::GetDevice()->CreatePipelineState(&desc, &PSO); } void Initialize() @@ -275,29 +266,6 @@ void Initialize() GraphicsDevice* device = wiRenderer::GetDevice(); - { - std::vector indices(MAX_TEXT * 6); - for (uint16_t i = 0; i < MAX_TEXT * 4; i += 4) - { - indices[size_t(i) / 4 * 6 + 0] = i + 0; - indices[size_t(i) / 4 * 6 + 1] = i + 2; - indices[size_t(i) / 4 * 6 + 2] = i + 1; - indices[size_t(i) / 4 * 6 + 3] = i + 1; - indices[size_t(i) / 4 * 6 + 4] = i + 2; - indices[size_t(i) / 4 * 6 + 5] = i + 3; - } - - GPUBufferDesc bd; - bd.Usage = USAGE_IMMUTABLE; - bd.ByteWidth = uint32_t(sizeof(uint16_t) * indices.size()); - bd.BindFlags = BIND_INDEX_BUFFER; - bd.CPUAccessFlags = 0; - SubresourceData InitData; - InitData.pSysMem = indices.data(); - - device->CreateBuffer(&bd, &InitData, &indexBuffer); - } - { GPUBufferDesc bd; bd.Usage = USAGE_DYNAMIC; @@ -312,7 +280,7 @@ void Initialize() RasterizerStateDesc rs; rs.FillMode = FILL_SOLID; - rs.CullMode = CULL_BACK; + rs.CullMode = CULL_FRONT; rs.FrontCounterClockwise = true; rs.DepthBias = 0; rs.DepthBiasClamp = 0; @@ -626,21 +594,10 @@ void Draw_internal(const T* text, size_t text_length, const wiFontParams& params device->BindResource(PS, &texture, TEXSLOT_FONTATLAS, cmd); device->BindSampler(PS, &sampler, SSLOT_ONDEMAND1, cmd); - const GPUBuffer* vbs[] = { - mem.buffer, - }; - const uint32_t strides[] = { - sizeof(FontVertex), - }; - const uint32_t offsets[] = { - mem.offset, - }; - device->BindVertexBuffers(vbs, 0, arraysize(vbs), strides, offsets, cmd); - - assert(text_length * 4 < 65536 && "The index buffer currently only supports so many characters!"); - device->BindIndexBuffer(&indexBuffer, INDEXFORMAT_16BIT, 0, cmd); + device->BindResource(VS, mem.buffer, 0, cmd); FontCB cb; + cb.g_xFont_BufferOffset = mem.offset; XMMATRIX Projection = device->GetScreenProjection(); @@ -654,7 +611,7 @@ void Draw_internal(const T* text, size_t text_length, const wiFontParams& params cb.g_xFont_Color = newProps.shadowColor.toFloat4(); device->UpdateBuffer(&constantBuffer, &cb, cmd); - device->DrawIndexed(quadCount * 6, 0, 0, cmd); + device->DrawInstanced(4, quadCount, 0, 0, cmd); } // font base render: @@ -665,7 +622,7 @@ void Draw_internal(const T* text, size_t text_length, const wiFontParams& params cb.g_xFont_Color = newProps.color.toFloat4(); device->UpdateBuffer(&constantBuffer, &cb, cmd); - device->DrawIndexed(quadCount * 6, 0, 0, cmd); + device->DrawInstanced(4, quadCount, 0, 0, cmd); device->EventEnd(cmd); diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index f82e00a79..3d162cae4 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -144,7 +144,8 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd for (auto& subset : mesh.subsets) { const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); - ShaderMaterial global_material = material.CreateShaderMaterial(); + ShaderMaterial global_material; + material.WriteShaderMaterial(&global_material); // Add extended properties: const TextureDesc& desc = globalMaterialAtlas.GetDesc(); diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index d686ae3e7..a785b6034 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -59,16 +59,6 @@ void wiGUIElement::ApplyScissor(const Rect rect, CommandList cmd, bool constrain device->BindScissorRects(1, &scissor, cmd); } - - -wiGUI::~wiGUI() -{ - for (auto& widget : widgets) - { - delete widget; - } -} - void wiGUI::Update(float dt) { if (!visible) @@ -93,21 +83,14 @@ void wiGUI::Update(float dt) focus = false; for (auto& widget : widgets) { - if (widget->parent == this) - { - // the contained child widgets will be updated by the containers - widget->Update(this, dt); + // the contained child widgets will be updated by the containers + widget->Update(this, dt); - if (widget->IsVisible() && widget->hitBox.intersects(pointerhitbox)) - { - // hitbox can only intersect with one element (avoid detecting multiple overlapping elements) - pointerhitbox.pos = XMFLOAT2(-FLT_MAX, -FLT_MAX); - pointerhitbox.siz = XMFLOAT2(0, 0); - } - } - - if (widget->IsEnabled() && widget->IsVisible() && widget->GetState() > wiWidget::WIDGETSTATE::IDLE) + if (widget->IsVisible() && widget->hitBox.intersects(pointerhitbox)) { + // hitbox can only intersect with one element (avoid detecting multiple overlapping elements) + pointerhitbox.pos = XMFLOAT2(-FLT_MAX, -FLT_MAX); + pointerhitbox.siz = XMFLOAT2(0, 0); focus = true; } @@ -145,9 +128,8 @@ void wiGUI::Render(CommandList cmd) const for (auto it = widgets.rbegin(); it != widgets.rend(); ++it) { const wiWidget* widget = (*it); - if (widget->parent == this && widget != activeWidget) + if (widget != activeWidget) { - // the contained child widgets will be rendered by the containers ApplyScissor(scissorRect, cmd); widget->Render(this, cmd); } @@ -161,9 +143,12 @@ void wiGUI::Render(CommandList cmd) const ApplyScissor(scissorRect, cmd); - for (auto&x : widgets) + if (activeWidget == nullptr) { - x->RenderTooltip(this, cmd); + for (auto& x : widgets) + { + x->RenderTooltip(this, cmd); + } } wiRenderer::GetDevice()->EventEnd(cmd); @@ -171,14 +156,21 @@ void wiGUI::Render(CommandList cmd) const void wiGUI::AddWidget(wiWidget* widget) { - widget->AttachTo(this); - widgets.push_back(widget); + if (widget != nullptr) + { + assert(std::find(widgets.begin(), widgets.end(), widget) == widgets.end()); // don't attach one widget twice! + widget->AttachTo(this); + widgets.push_back(widget); + } } void wiGUI::RemoveWidget(wiWidget* widget) { - widget->Detach(); - widgets.remove(widget); + if (widget != nullptr) + { + widget->Detach(); + widgets.remove(widget); + } } wiWidget* wiGUI::GetWidget(const std::string& name) diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 3c24bafc4..095455aaa 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -31,7 +31,6 @@ private: XMFLOAT2 pointerpos = XMFLOAT2(0, 0); Hitbox2D pointerhitbox; public: - ~wiGUI(); void Update(float dt); void Render(wiGraphics::CommandList cmd) const; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index bd16da5d9..6445cf587 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -2647,7 +2647,6 @@ void GraphicsDevice_DX11::RenderPassBegin(const RenderPass* renderpass, CommandL uint32_t rt_count = 0; ID3D11RenderTargetView* RTVs[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {}; ID3D11DepthStencilView* DSV = nullptr; - assert(desc.attachments.size() < arraysize(RTVs) + 1); for (auto& attachment : desc.attachments) { const Texture* texture = attachment.texture; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index e9a4b7b09..66b278b76 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1248,6 +1248,11 @@ using namespace DX12_Internal; buffer.desc.Usage = USAGE_DYNAMIC; buffer.desc.BindFlags = BIND_VERTEX_BUFFER | BIND_INDEX_BUFFER | BIND_SHADER_RESOURCE; buffer.desc.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; + internal_state->srv.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + internal_state->srv.Format = DXGI_FORMAT_R32_TYPELESS; + internal_state->srv.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW; + internal_state->srv.Buffer.NumElements = buffer.desc.ByteWidth / sizeof(uint32_t); + internal_state->srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; } uint8_t* GraphicsDevice_DX12::FrameResources::ResourceFrameAllocator::allocate(size_t dataSize, size_t alignment) { diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 972730a60..45117ef4b 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -1170,6 +1170,7 @@ using namespace Vulkan_Internal; dataEnd = dataBegin + size; // Because the "buffer" is created by hand in this, fill the desc to indicate how it can be used: + this->buffer.type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; this->buffer.desc.ByteWidth = (uint32_t)((size_t)dataEnd - (size_t)dataBegin); this->buffer.desc.Usage = USAGE_DYNAMIC; this->buffer.desc.BindFlags = BIND_VERTEX_BUFFER | BIND_INDEX_BUFFER | BIND_SHADER_RESOURCE; @@ -5013,7 +5014,7 @@ using namespace Vulkan_Internal; { if (texture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) { - if (texture->desc.ArraySize > 6) + if (texture->desc.ArraySize > 6 && sliceCount > 6) { view_desc.viewType = VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; } @@ -5082,6 +5083,11 @@ using namespace Vulkan_Internal; break; case wiGraphics::UAV: { + if (view_desc.viewType == VK_IMAGE_VIEW_TYPE_CUBE || view_desc.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) + { + view_desc.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + } + VkImageView uav; VkResult res = vkCreateImageView(device, &view_desc, nullptr, &uav); diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index 962566971..27865b69c 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -21,17 +21,14 @@ namespace wiScene static Shader vs; static Shader ps_alphatestonly; -static Shader ps_deferred; -static Shader ps_forward; -static Shader ps_forward_transparent; -static Shader ps_tiledforward; -static Shader ps_tiledforward_transparent; +static Shader ps; static Shader ps_simplest; static Shader cs_simulate; -static DepthStencilState dss_default, dss_equal, dss_rejectopaque_keeptransparent; +static Shader cs_finishUpdate; +static DepthStencilState dss_default, dss_equal; static RasterizerState rs, ncrs, wirers; -static BlendState bs[2]; -static PipelineState PSO[RENDERPASS_COUNT][2]; +static BlendState bs; +static PipelineState PSO[RENDERPASS_COUNT]; static PipelineState PSO_wire; void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshComponent& mesh, float dt) @@ -54,14 +51,14 @@ void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshCo if (dt > 0) { + GraphicsDevice* device = wiRenderer::GetDevice(); + _flags &= ~REGENERATE_FRAME; if (_flags & REBUILD_BUFFERS || !cb.IsValid() || (strandCount * segmentCount) != particleBuffer.GetDesc().ByteWidth / sizeof(Patch)) { _flags &= ~REBUILD_BUFFERS; _flags |= REGENERATE_FRAME; - GraphicsDevice* device = wiRenderer::GetDevice(); - GPUBufferDesc bd; bd.Usage = USAGE_DEFAULT; bd.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; @@ -77,6 +74,10 @@ void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshCo bd.StructureByteStride = sizeof(PatchSimulationData); bd.ByteWidth = bd.StructureByteStride * strandCount * segmentCount; device->CreateBuffer(&bd, nullptr, &simulationBuffer); + + bd.StructureByteStride = sizeof(uint); + bd.ByteWidth = bd.StructureByteStride * strandCount * segmentCount; + device->CreateBuffer(&bd, nullptr, &culledIndexBuffer); } bd.Usage = USAGE_DEFAULT; @@ -139,6 +140,15 @@ void wiHairParticle::UpdateCPU(const TransformComponent& transform, const MeshCo } } + + if (!indirectBuffer.IsValid()) + { + GPUBufferDesc desc; + desc.ByteWidth = sizeof(uint) + sizeof(IndirectDrawArgsInstanced); // counter + draw args + desc.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | RESOURCE_MISC_INDIRECT_ARGS; + desc.BindFlags = BIND_UNORDERED_ACCESS; + device->CreateBuffer(&desc, nullptr, &indirectBuffer); + } } } @@ -152,8 +162,6 @@ void wiHairParticle::UpdateGPU(const MeshComponent& mesh, const MaterialComponen GraphicsDevice* device = wiRenderer::GetDevice(); device->EventBegin("HairParticle - UpdateRenderData", cmd); - device->BindComputeShader(&cs_simulate, cmd); - const TextureDesc& desc = material.GetBaseColorMap()->GetDesc(); HairParticleCB hcb; @@ -179,30 +187,60 @@ void wiHairParticle::UpdateGPU(const MeshComponent& mesh, const MaterialComponen hcb.xHairAspect = (float)desc.Width / (float)desc.Height; device->UpdateBuffer(&cb, &hcb, cmd); - device->BindConstantBuffer(CS, &cb, CB_GETBINDSLOT(HairParticleCB), cmd); + // Simulate: + { + device->BindComputeShader(&cs_simulate, cmd); + device->BindConstantBuffer(CS, &cb, CB_GETBINDSLOT(HairParticleCB), cmd); - const GPUResource* uavs[] = { - &particleBuffer, - &simulationBuffer - }; - device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); + const GPUResource* uavs[] = { + &particleBuffer, + &simulationBuffer, + &culledIndexBuffer, + &indirectBuffer + }; + device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); - const GPUResource* res[] = { - indexBuffer.IsValid() ? &indexBuffer : &mesh.indexBuffer, - mesh.streamoutBuffer_POS.IsValid() ? &mesh.streamoutBuffer_POS : &mesh.vertexBuffer_POS, - &vertexBuffer_length - }; - device->BindResources(CS, res, TEXSLOT_ONDEMAND0, arraysize(res), cmd); + const GPUResource* res[] = { + indexBuffer.IsValid() ? &indexBuffer : &mesh.indexBuffer, + mesh.streamoutBuffer_POS.IsValid() ? &mesh.streamoutBuffer_POS : &mesh.vertexBuffer_POS, + &vertexBuffer_length + }; + device->BindResources(CS, res, TEXSLOT_ONDEMAND0, arraysize(res), cmd); - device->Dispatch(hcb.xHairNumDispatchGroups, 1, 1, cmd); + device->Dispatch(hcb.xHairNumDispatchGroups, 1, 1, cmd); - device->UnbindUAVs(0, arraysize(uavs), cmd); - device->UnbindResources(TEXSLOT_ONDEMAND0, arraysize(res), cmd); + GPUBarrier barriers[] = { + GPUBarrier::Memory() + }; + device->Barrier(barriers, arraysize(barriers), cmd); + + device->UnbindUAVs(0, arraysize(uavs), cmd); + device->UnbindResources(TEXSLOT_ONDEMAND0, arraysize(res), cmd); + } + + // Finish update (reset counter, create indirect draw args): + { + device->BindComputeShader(&cs_finishUpdate, cmd); + + const GPUResource* uavs[] = { + &indirectBuffer + }; + device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); + + device->Dispatch(1, 1, 1, cmd); + + GPUBarrier barriers[] = { + GPUBarrier::Memory() + }; + device->Barrier(barriers, arraysize(barriers), cmd); + + device->UnbindUAVs(0, arraysize(uavs), cmd); + } device->EventEnd(cmd); } -void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent& material, RENDERPASS renderPass, bool transparent, CommandList cmd) const +void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent& material, RENDERPASS renderPass, CommandList cmd) const { if (strandCount == 0 || !cb.IsValid()) { @@ -216,7 +254,7 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent if (wiRenderer::IsWireRender()) { - if (transparent || renderPass == RENDERPASS_DEPTHONLY) + if (renderPass == RENDERPASS_DEPTHONLY) { return; } @@ -225,7 +263,7 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent } else { - device->BindPipelineState(&PSO[renderPass][transparent], cmd); + device->BindPipelineState(&PSO[renderPass], cmd); const GPUResource* res[] = { material.GetBaseColorMap() @@ -242,8 +280,9 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent device->BindConstantBuffer(VS, &cb, CB_GETBINDSLOT(HairParticleCB), cmd); device->BindResource(VS, &particleBuffer, 0, cmd); + device->BindResource(VS, &culledIndexBuffer, 1, cmd); - device->Draw(strandCount * 12 * std::max(segmentCount, 1u), 0, cmd); + device->DrawInstancedIndirect(&indirectBuffer, 4, cmd); device->EventEnd(cmd); } @@ -315,72 +354,36 @@ namespace wiHairParticle_Internal wiRenderer::LoadShader(PS, ps_simplest, "hairparticlePS_simplest.cso"); wiRenderer::LoadShader(PS, ps_alphatestonly, "hairparticlePS_alphatestonly.cso"); - wiRenderer::LoadShader(PS, ps_deferred, "hairparticlePS_deferred.cso"); - wiRenderer::LoadShader(PS, ps_forward, "hairparticlePS_forward.cso"); - wiRenderer::LoadShader(PS, ps_forward_transparent, "hairparticlePS_forward_transparent.cso"); - wiRenderer::LoadShader(PS, ps_tiledforward, "hairparticlePS_tiledforward.cso"); - wiRenderer::LoadShader(PS, ps_tiledforward_transparent, "hairparticlePS_tiledforward_transparent.cso"); + wiRenderer::LoadShader(PS, ps, "hairparticlePS.cso"); wiRenderer::LoadShader(CS, cs_simulate, "hairparticle_simulateCS.cso"); + wiRenderer::LoadShader(CS, cs_finishUpdate, "hairparticle_finishUpdateCS.cso"); GraphicsDevice* device = wiRenderer::GetDevice(); for (int i = 0; i < RENDERPASS_COUNT; ++i) { - if (i == RENDERPASS_DEPTHONLY || i == RENDERPASS_DEFERRED || i == RENDERPASS_FORWARD || i == RENDERPASS_TILEDFORWARD) + if (i == RENDERPASS_DEPTHONLY || i == RENDERPASS_MAIN) { - for (int j = 0; j < 2; ++j) + PipelineStateDesc desc; + desc.vs = &vs; + desc.bs = &bs; + desc.rs = &ncrs; + desc.dss = &dss_default; + desc.pt = TRIANGLESTRIP; + + switch (i) { - if ((i == RENDERPASS_DEPTHONLY || i == RENDERPASS_DEFERRED) && j == 1) - { - continue; - } - - PipelineStateDesc desc; - desc.vs = &vs; - desc.bs = &bs[j]; - desc.rs = &ncrs; - desc.dss = &dss_default; - - switch (i) - { - case RENDERPASS_DEPTHONLY: - desc.ps = &ps_alphatestonly; - break; - case RENDERPASS_DEFERRED: - desc.ps = &ps_deferred; - break; - case RENDERPASS_FORWARD: - if (j == 0) - { - desc.ps = &ps_forward; - desc.dss = &dss_equal; - } - else - { - desc.ps = &ps_forward_transparent; - } - break; - case RENDERPASS_TILEDFORWARD: - if (j == 0) - { - desc.ps = &ps_tiledforward; - desc.dss = &dss_equal; - } - else - { - desc.ps = &ps_tiledforward_transparent; - } - break; - } - - if (j == 1) - { - desc.dss = &dss_rejectopaque_keeptransparent; // transparent - } - - device->CreatePipelineState(&desc, &PSO[i][j]); + case RENDERPASS_DEPTHONLY: + desc.ps = &ps_alphatestonly; + break; + case RENDERPASS_MAIN: + desc.ps = &ps; + desc.dss = &dss_equal; + break; } + + device->CreatePipelineState(&desc, &PSO[i]); } } @@ -388,7 +391,7 @@ namespace wiHairParticle_Internal PipelineStateDesc desc; desc.vs = &vs; desc.ps = &ps_simplest; - desc.bs = &bs[0]; + desc.bs = &bs; desc.rs = &wirers; desc.dss = &dss_default; device->CreatePipelineState(&desc, &PSO_wire); @@ -457,26 +460,12 @@ void wiHairParticle::Initialize() dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; dsd.DepthFunc = COMPARISON_EQUAL; wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &dss_equal); - dsd.DepthFunc = COMPARISON_GREATER; - wiRenderer::GetDevice()->CreateDepthStencilState(&dsd, &dss_rejectopaque_keeptransparent); BlendStateDesc bld; bld.RenderTarget[0].BlendEnable = false; bld.AlphaToCoverageEnable = false; // maybe for msaa - wiRenderer::GetDevice()->CreateBlendState(&bld, &bs[0]); - - bld.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA; - bld.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA; - bld.RenderTarget[0].BlendOp = BLEND_OP_ADD; - bld.RenderTarget[0].SrcBlendAlpha = BLEND_ONE; - bld.RenderTarget[0].DestBlendAlpha = BLEND_ONE; - bld.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD; - bld.RenderTarget[0].BlendEnable = true; - bld.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL; - bld.AlphaToCoverageEnable = false; - bld.IndependentBlendEnable = false; - wiRenderer::GetDevice()->CreateBlendState(&bld, &bs[1]); + wiRenderer::GetDevice()->CreateBlendState(&bld, &bs); static wiEvent::Handle handle = wiEvent::Subscribe(SYSTEM_EVENT_RELOAD_SHADERS, [](uint64_t userdata) { wiHairParticle_Internal::LoadShaders(); }); wiHairParticle_Internal::LoadShaders(); diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index 7fedf6252..54fce6e61 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -19,6 +19,8 @@ private: wiGraphics::GPUBuffer cb; wiGraphics::GPUBuffer particleBuffer; wiGraphics::GPUBuffer simulationBuffer; + wiGraphics::GPUBuffer culledIndexBuffer; + wiGraphics::GPUBuffer indirectBuffer; wiGraphics::GPUBuffer indexBuffer; wiGraphics::GPUBuffer vertexBuffer_length; @@ -26,7 +28,7 @@ public: void UpdateCPU(const TransformComponent& transform, const MeshComponent& mesh, float dt); void UpdateGPU(const MeshComponent& mesh, const MaterialComponent& material, wiGraphics::CommandList cmd) const; - void Draw(const CameraComponent& camera, const MaterialComponent& material, RENDERPASS renderPass, bool transparent, wiGraphics::CommandList cmd) const; + void Draw(const CameraComponent& camera, const MaterialComponent& material, RENDERPASS renderPass, wiGraphics::CommandList cmd) const; enum FLAGS { diff --git a/WickedEngine/wiIntersect.h b/WickedEngine/wiIntersect.h index cd45a850d..5e4fec832 100644 --- a/WickedEngine/wiIntersect.h +++ b/WickedEngine/wiIntersect.h @@ -106,11 +106,10 @@ struct RAY bool intersects(const SPHERE& b) const; }; -class Frustum +struct Frustum { -private: XMFLOAT4 planes[6]; -public: + void Create(const XMMATRIX& viewProjection); bool CheckPoint(const XMFLOAT3&) const; diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 44d1d20d4..e9cf2f682 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -7,10 +7,6 @@ #include "RenderPath2D_BindLua.h" #include "LoadingScreen_BindLua.h" #include "RenderPath3D_BindLua.h" -#include "RenderPath3D_Deferred_BindLua.h" -#include "RenderPath3D_Forward_BindLua.h" -#include "RenderPath3D_TiledForward_BindLua.h" -#include "RenderPath3D_TiledDeferred_BindLua.h" #include "Texture_BindLua.h" #include "wiRenderer_BindLua.h" #include "wiAudio_BindLua.h" @@ -101,11 +97,6 @@ namespace wiLua RenderPath2D_BindLua::Bind(); LoadingScreen_BindLua::Bind(); RenderPath3D_BindLua::Bind(); - // Note: when all render paths are registered, heap corruptions start happening!!! - //RenderPath3D_Forward_BindLua::Bind(); - RenderPath3D_Deferred_BindLua::Bind(); - RenderPath3D_TiledForward_BindLua::Bind(); - RenderPath3D_TiledDeferred_BindLua::Bind(); Texture_BindLua::Bind(); wiRenderer_BindLua::Bind(); wiAudio_BindLua::Bind(); diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 2c38847ee..bef2c542b 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -386,7 +386,7 @@ void wiOcean::Render(const CameraComponent& camera, const WeatherComponent& weat device->BindConstantBuffer(PS, &shadingCB, CB_GETBINDSLOT(Ocean_RenderCB), cmd); device->BindResource(VS, &displacementMap, TEXSLOT_ONDEMAND0, cmd); - device->BindResource(PS, &gradientMap, TEXSLOT_ONDEMAND0, cmd); + device->BindResource(PS, &gradientMap, TEXSLOT_ONDEMAND1, cmd); device->Draw(dim.x*dim.y*6, 0, cmd); diff --git a/WickedEngine/wiPhysicsEngine_Bullet.cpp b/WickedEngine/wiPhysicsEngine_Bullet.cpp index 42de44c2d..338149961 100644 --- a/WickedEngine/wiPhysicsEngine_Bullet.cpp +++ b/WickedEngine/wiPhysicsEngine_Bullet.cpp @@ -481,6 +481,77 @@ namespace wiPhysicsEngine normal.z = -node.m_n.getZ(); vertex.MakeFromParams(normal); } + + // Update tangent vectors: + if (!mesh.vertex_uvset_0.empty()) + { + for (size_t i = 0; i < mesh.indices.size(); i += 3) + { + const uint32_t i0 = mesh.indices[i + 0]; + const uint32_t i1 = mesh.indices[i + 1]; + const uint32_t i2 = mesh.indices[i + 2]; + + const XMFLOAT3 v0 = physicscomponent->vertex_positions_simulation[i0].pos; + const XMFLOAT3 v1 = physicscomponent->vertex_positions_simulation[i1].pos; + const XMFLOAT3 v2 = physicscomponent->vertex_positions_simulation[i2].pos; + + const XMFLOAT2 u0 = mesh.vertex_uvset_0[i0]; + const XMFLOAT2 u1 = mesh.vertex_uvset_0[i1]; + const XMFLOAT2 u2 = mesh.vertex_uvset_0[i2]; + + const XMVECTOR nor0 = physicscomponent->vertex_positions_simulation[i0].LoadNOR(); + const XMVECTOR nor1 = physicscomponent->vertex_positions_simulation[i1].LoadNOR(); + const XMVECTOR nor2 = physicscomponent->vertex_positions_simulation[i2].LoadNOR(); + + const XMVECTOR facenormal = XMVector3Normalize(XMVectorAdd(XMVectorAdd(nor0, nor1), nor2)); + + const float x1 = v1.x - v0.x; + const float x2 = v2.x - v0.x; + const float y1 = v1.y - v0.y; + const float y2 = v2.y - v0.y; + const float z1 = v1.z - v0.z; + const float z2 = v2.z - v0.z; + + const float s1 = u1.x - u0.x; + const float s2 = u2.x - u0.x; + const float t1 = u1.y - u0.y; + const float t2 = u2.y - u0.y; + + const float r = 1.0f / (s1 * t2 - s2 * t1); + const XMVECTOR sdir = XMVectorSet((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, + (t2 * z1 - t1 * z2) * r, 0); + const XMVECTOR tdir = XMVectorSet((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, + (s1 * z2 - s2 * z1) * r, 0); + + XMVECTOR tangent; + tangent = XMVector3Normalize(XMVectorSubtract(sdir, XMVectorMultiply(facenormal, XMVector3Dot(facenormal, sdir)))); + float sign = XMVectorGetX(XMVector3Dot(XMVector3Cross(tangent, facenormal), tdir)) < 0.0f ? -1.0f : 1.0f; + + XMFLOAT3 t; + XMStoreFloat3(&t, tangent); + + physicscomponent->vertex_tangents_tmp[i0].x += t.x; + physicscomponent->vertex_tangents_tmp[i0].y += t.y; + physicscomponent->vertex_tangents_tmp[i0].z += t.z; + physicscomponent->vertex_tangents_tmp[i0].w = sign; + + physicscomponent->vertex_tangents_tmp[i1].x += t.x; + physicscomponent->vertex_tangents_tmp[i1].y += t.y; + physicscomponent->vertex_tangents_tmp[i1].z += t.z; + physicscomponent->vertex_tangents_tmp[i1].w = sign; + + physicscomponent->vertex_tangents_tmp[i2].x += t.x; + physicscomponent->vertex_tangents_tmp[i2].y += t.y; + physicscomponent->vertex_tangents_tmp[i2].z += t.z; + physicscomponent->vertex_tangents_tmp[i2].w = sign; + } + + for (size_t i = 0; i < physicscomponent->vertex_tangents_simulation.size(); ++i) + { + physicscomponent->vertex_tangents_simulation[i].FromFULL(physicscomponent->vertex_tangents_tmp[i]); + } + } + } } } diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 8d065dab3..29fc8da9d 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -88,7 +88,6 @@ uint32_t SHADOWCOUNT_2D = 5 + 3 + 3; uint32_t SHADOWCOUNT_CUBE = 5; uint32_t SOFTSHADOWQUALITY_2D = 2; bool TRANSPARENTSHADOWSENABLED = false; -bool ALPHACOMPOSITIONENABLED = false; bool wireRender = false; bool debugBoneLines = false; bool debugPartitionTree = false; @@ -158,7 +157,7 @@ std::vector renderpasses_shadow2D; std::vector renderpasses_shadow2DTransparent; std::vector renderpasses_shadowCube; -deque waterRipples; +deque waterRipples; std::vector> renderableBoxes; std::vector> renderableSpheres; @@ -210,8 +209,8 @@ struct RenderBatch hash = 0; assert(meshIndex < 0x00FFFFFF); - hash |= (uint32_t)(meshIndex & 0x00FFFFFF) << 8; - hash |= ((uint32_t)(_distance)) & 0xFF; + hash |= (uint32_t)(meshIndex & 0x00FFFFFF); + hash |= ((uint32_t)_distance & 0xFF) << 24; instance = (uint32_t)instanceIndex; distance = _distance; @@ -219,7 +218,7 @@ struct RenderBatch inline uint32_t GetMeshIndex() const { - return (hash >> 8) & 0x00FFFFFF; + return hash & 0x00FFFFFF; } inline uint32_t GetInstanceIndex() const { @@ -471,71 +470,16 @@ enum OBJECTRENDERING_ALPHATEST OBJECTRENDERING_ALPHATEST_ENABLED, OBJECTRENDERING_ALPHATEST_COUNT }; -enum OBJECTRENDERING_NORMALMAP -{ - OBJECTRENDERING_NORMALMAP_DISABLED, - OBJECTRENDERING_NORMALMAP_ENABLED, - OBJECTRENDERING_NORMALMAP_COUNT -}; -enum OBJECTRENDERING_PLANARREFLECTION -{ - OBJECTRENDERING_PLANARREFLECTION_DISABLED, - OBJECTRENDERING_PLANARREFLECTION_ENABLED, - OBJECTRENDERING_PLANARREFLECTION_COUNT -}; -enum OBJECTRENDERING_POM -{ - OBJECTRENDERING_POM_DISABLED, - OBJECTRENDERING_POM_ENABLED, - OBJECTRENDERING_POM_COUNT -}; -PipelineState PSO_object[RENDERPASS_COUNT][BLENDMODE_COUNT][OBJECTRENDERING_DOUBLESIDED_COUNT][OBJECTRENDERING_TESSELLATION_COUNT][OBJECTRENDERING_ALPHATEST_COUNT][OBJECTRENDERING_NORMALMAP_COUNT][OBJECTRENDERING_PLANARREFLECTION_COUNT][OBJECTRENDERING_POM_COUNT]; -PipelineState PSO_object_water[RENDERPASS_COUNT]; +PipelineState PSO_object + [MaterialComponent::SHADERTYPE_COUNT] + [RENDERPASS_COUNT] + [BLENDMODE_COUNT] + [OBJECTRENDERING_DOUBLESIDED_COUNT] + [OBJECTRENDERING_TESSELLATION_COUNT] + [OBJECTRENDERING_ALPHATEST_COUNT]; PipelineState PSO_object_terrain[RENDERPASS_COUNT]; PipelineState PSO_object_wire; -inline const PipelineState* GetObjectPSO( - RENDERPASS renderPass, - const MeshComponent& mesh, - const MaterialComponent& material, - bool tessellation, - bool forceAlphaTestForDithering -) -{ - if (IsWireRender()) - { - switch (renderPass) - { - case RENDERPASS_TEXTURE: - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: - return &PSO_object_wire; - } - return nullptr; - } - if (material.IsWater()) - { - return &PSO_object_water[renderPass]; - } - else if (mesh.IsTerrain()) - { - return &PSO_object_terrain[renderPass]; - } - - const bool doublesided = mesh.IsDoubleSided(); - const bool alphatest = material.IsAlphaTestEnabled() || forceAlphaTestForDithering; - const bool normalmap = material.GetNormalMap() != nullptr; - const bool planarreflection = material.HasPlanarReflection(); - const bool pom = material.parallaxOcclusionMapping > 0; - const BLENDMODE blendMode = material.GetBlendMode(); - - const PipelineState& pso = PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][normalmap][planarreflection][pom]; - assert(pso.IsValid()); - return &pso; -} - -PipelineState PSO_object_hologram; std::vector customShaders; int RegisterCustomShader(const CustomShader& customShader) { @@ -547,18 +491,53 @@ const std::vector& GetCustomShaders() { return customShaders; } -inline const PipelineState* GetCustomShaderPSO(RENDERPASS renderPass, uint32_t renderTypeFlags, int customShaderID) + +inline const PipelineState* GetObjectPSO( + RENDERPASS renderPass, + uint32_t renderTypeFlags, + const MeshComponent& mesh, + const MaterialComponent& material, + bool tessellation, + bool forceAlphaTestForDithering +) { - if (customShaderID >= 0 && customShaderID < (int)customShaders.size()) + if (IsWireRender()) { - const CustomShader& customShader = customShaders[customShaderID]; - const CustomShader::Pass& customPass = customShader.passes[renderPass]; - if (customPass.renderTypeFlags & renderTypeFlags) + switch (renderPass) { - return customPass.pso; + case RENDERPASS_TEXTURE: + case RENDERPASS_MAIN: + return &PSO_object_wire; + } + return nullptr; + } + + if (mesh.IsTerrain()) + { + return &PSO_object_terrain[renderPass]; + } + + + if (material.customShaderID >= 0 && material.customShaderID < (int)customShaders.size()) + { + const CustomShader& customShader = customShaders[material.customShaderID]; + if (renderTypeFlags & customShader.renderTypeFlags) + { + return &customShader.pso[renderPass]; + } + else + { + return nullptr; } } - return nullptr; + + const BLENDMODE blendMode = material.GetBlendMode(); + const bool doublesided = mesh.IsDoubleSided(); + const bool alphatest = material.IsAlphaTestEnabled() || forceAlphaTestForDithering; + + const PipelineState& pso = PSO_object[material.shaderType][renderPass][blendMode][doublesided][tessellation][alphatest]; + assert(pso.IsValid()); + return &pso; } ILTYPES GetILTYPE(RENDERPASS renderPass, bool tessellation, bool alphatest, bool transparent) @@ -577,9 +556,7 @@ ILTYPES GetILTYPE(RENDERPASS renderPass, bool tessellation, bool alphatest, bool realVL = ILTYPE_OBJECT_POS_TEX; } break; - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: + case RENDERPASS_MAIN: case RENDERPASS_ENVMAPCAPTURE: case RENDERPASS_VOXELIZE: realVL = ILTYPE_OBJECT_ALL; @@ -632,9 +609,7 @@ VSTYPES GetVSTYPE(RENDERPASS renderPass, bool tessellation, bool alphatest, bool realVS = VSTYPE_OBJECT_SIMPLE; } break; - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: + case RENDERPASS_MAIN: if (tessellation) { realVS = VSTYPE_OBJECT_COMMON_TESSELLATION; @@ -718,9 +693,7 @@ HSTYPES GetHSTYPE(RENDERPASS renderPass, bool tessellation) { case RENDERPASS_TEXTURE: case RENDERPASS_DEPTHONLY: - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: + case RENDERPASS_MAIN: return tessellation ? HSTYPE_OBJECT : HSTYPE_COUNT; break; } @@ -733,188 +706,62 @@ DSTYPES GetDSTYPE(RENDERPASS renderPass, bool tessellation) { case RENDERPASS_TEXTURE: case RENDERPASS_DEPTHONLY: - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: + case RENDERPASS_MAIN: return tessellation ? DSTYPE_OBJECT : DSTYPE_COUNT; break; } return DSTYPE_COUNT; } -PSTYPES GetPSTYPE(RENDERPASS renderPass, bool alphatest, bool transparent, bool normalmap, bool planarreflection, bool pom) +PSTYPES GetPSTYPE(RENDERPASS renderPass, bool alphatest, bool transparent, MaterialComponent::SHADERTYPE shaderType) { - PSTYPES realPS = PSTYPE_OBJECT_SIMPLEST; + PSTYPES realPS = PSTYPE_COUNT; switch (renderPass) { - case RENDERPASS_DEFERRED: - if (normalmap) + case RENDERPASS_TEXTURE: + realPS = PSTYPE_OBJECT_TEXTUREONLY; + break; + case RENDERPASS_MAIN: + switch (shaderType) { - if (pom) - { - realPS = PSTYPE_OBJECT_DEFERRED_NORMALMAP_POM; - } - else - { - realPS = PSTYPE_OBJECT_DEFERRED_NORMALMAP; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_DEFERRED_NORMALMAP_PLANARREFLECTION; - } - } - else - { - if (pom) - { - realPS = PSTYPE_OBJECT_DEFERRED_POM; - } - else - { - realPS = PSTYPE_OBJECT_DEFERRED; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_DEFERRED_PLANARREFLECTION; - } + case wiScene::MaterialComponent::SHADERTYPE_PBR: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT : PSTYPE_OBJECT; + break; + case wiScene::MaterialComponent::SHADERTYPE_PBR_PLANARREFLECTION: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT_PLANARREFLECTION : PSTYPE_OBJECT_PLANARREFLECTION; + break; + case wiScene::MaterialComponent::SHADERTYPE_PBR_PARALLAXOCCLUSIONMAPPING: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT_POM : PSTYPE_OBJECT_POM; + break; + case wiScene::MaterialComponent::SHADERTYPE_PBR_ANISOTROPIC: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT_ANISOTROPIC : PSTYPE_OBJECT_ANISOTROPIC; + break; + case wiScene::MaterialComponent::SHADERTYPE_WATER: + realPS = transparent ? PSTYPE_OBJECT_WATER : PSTYPE_COUNT; + break; + case wiScene::MaterialComponent::SHADERTYPE_CARTOON: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT_CARTOON : PSTYPE_OBJECT_CARTOON; + break; + case wiScene::MaterialComponent::SHADERTYPE_UNLIT: + realPS = transparent ? PSTYPE_OBJECT_TRANSPARENT_UNLIT : PSTYPE_OBJECT_UNLIT; + break; + default: + break; } break; - case RENDERPASS_FORWARD: - if (transparent) + case RENDERPASS_DEPTHONLY: + if (alphatest) { - if (normalmap) - { - if (pom) - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_POM; - } - else - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION; - } - } - else - { - if (pom) - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT_POM; - } - else - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_FORWARD_TRANSPARENT_PLANARREFLECTION; - } - } + realPS = PSTYPE_OBJECT_ALPHATESTONLY; } else { - if (normalmap) - { - if (pom) - { - realPS = PSTYPE_OBJECT_FORWARD_NORMALMAP_POM; - } - else - { - realPS = PSTYPE_OBJECT_FORWARD_NORMALMAP; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_FORWARD_NORMALMAP_PLANARREFLECTION; - } - } - else - { - if (pom) - { - realPS = PSTYPE_OBJECT_FORWARD_POM; - } - else - { - realPS = PSTYPE_OBJECT_FORWARD; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_FORWARD_PLANARREFLECTION; - } - } + realPS = PSTYPE_COUNT; } break; - case RENDERPASS_TILEDFORWARD: - if (transparent) - { - if (normalmap) - { - if (pom) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_POM; - } - else - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION; - } - } - else - { - if (pom) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_POM; - } - else - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_PLANARREFLECTION; - } - } - } - else - { - if (normalmap) - { - if (pom) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_POM; - } - else - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_PLANARREFLECTION; - } - } - else - { - if (pom) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_POM; - } - else - { - realPS = PSTYPE_OBJECT_TILEDFORWARD; - } - if (planarreflection) - { - realPS = PSTYPE_OBJECT_TILEDFORWARD_PLANARREFLECTION; - } - } - } + case RENDERPASS_ENVMAPCAPTURE: + realPS = PSTYPE_ENVMAP; break; case RENDERPASS_SHADOW: if (transparent) @@ -943,24 +790,10 @@ PSTYPES GetPSTYPE(RENDERPASS renderPass, bool alphatest, bool transparent, bool realPS = PSTYPE_COUNT; } break; - case RENDERPASS_ENVMAPCAPTURE: - realPS = PSTYPE_ENVMAP; - break; - case RENDERPASS_DEPTHONLY: - if (alphatest) - { - realPS = PSTYPE_OBJECT_ALPHATESTONLY; - } - else - { - realPS = PSTYPE_COUNT; - } - break; case RENDERPASS_VOXELIZE: realPS = PSTYPE_VOXELIZER; break; - case RENDERPASS_TEXTURE: - realPS = PSTYPE_OBJECT_TEXTUREONLY; + default: break; } @@ -981,9 +814,7 @@ inline const PipelineState* GetImpostorPSO(RENDERPASS renderPass) switch (renderPass) { case RENDERPASS_TEXTURE: - case RENDERPASS_DEFERRED: - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: + case RENDERPASS_MAIN: return &PSO_impostor_wire; } return nullptr; @@ -992,10 +823,8 @@ inline const PipelineState* GetImpostorPSO(RENDERPASS renderPass) return &PSO_impostor[renderPass]; } -PipelineState PSO_deferredlight[LightComponent::LIGHTTYPE_COUNT]; PipelineState PSO_lightvisualizer[LightComponent::LIGHTTYPE_COUNT]; PipelineState PSO_volumetriclight[LightComponent::LIGHTTYPE_COUNT]; -PipelineState PSO_enviromentallight; PipelineState PSO_renderlightmap; @@ -1003,7 +832,8 @@ PipelineState PSO_lensflare; PipelineState PSO_downsampledepthbuffer; PipelineState PSO_deferredcomposition; -PipelineState PSO_sss; +PipelineState PSO_sss_skin; +PipelineState PSO_sss_snow; PipelineState PSO_upsample_bilateral; PipelineState PSO_outline; @@ -1036,12 +866,6 @@ enum DEBUGRENDERING }; PipelineState PSO_debug[DEBUGRENDERING_COUNT]; -enum TILEDLIGHTING_TYPE -{ - TILEDLIGHTING_TYPE_FORWARD, - TILEDLIGHTING_TYPE_DEFERRED, - TILEDLIGHTING_TYPE_COUNT -}; enum TILEDLIGHTING_CULLING { TILEDLIGHTING_CULLING_BASIC, @@ -1054,7 +878,7 @@ enum TILEDLIGHTING_DEBUG TILEDLIGHTING_DEBUG_ENABLED, TILEDLIGHTING_DEBUG_COUNT }; -Shader tiledLightingCS[TILEDLIGHTING_TYPE_COUNT][TILEDLIGHTING_CULLING_COUNT][TILEDLIGHTING_DEBUG_COUNT]; +Shader tiledLightingCS[TILEDLIGHTING_CULLING_COUNT][TILEDLIGHTING_DEBUG_COUNT]; bool LoadShader(SHADERSTAGE stage, wiGraphics::Shader& shader, const std::string& filename) @@ -1091,16 +915,17 @@ void LoadShaders() { "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, 2, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 3, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, MeshComponent::Vertex_COL::FORMAT, 4, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, 5, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "TANGENT", 0, MeshComponent::Vertex_TAN::FORMAT, 5, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, + { "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 }, - { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, - { "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, 6, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, + { "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, 7, InputLayoutDesc::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 }, }; LoadShader(VS, vertexShaders[VSTYPE_OBJECT_COMMON], "objectVS_common.cso"); device->CreateInputLayout(layout, arraysize(layout), &vertexShaders[VSTYPE_OBJECT_COMMON], &inputLayouts[ILTYPE_OBJECT_ALL]); @@ -1210,16 +1035,15 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_OBJECT_COMMON_TESSELLATION], "objectVS_common_tessellation.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_OBJECT_SIMPLE_TESSELLATION], "objectVS_simple_tessellation.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_IMPOSTOR], "impostorVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_DIRLIGHT], "dirLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_POINTLIGHT], "pointLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_SPOTLIGHT], "spotLightVS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_VOLUMETRICLIGHT_DIRECTIONAL], "volumetriclight_directionalVS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_VOLUMETRICLIGHT_POINT], "volumetriclight_pointVS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_VOLUMETRICLIGHT_SPOT], "volumetriclight_spotVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_SPOTLIGHT], "vSpotLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_POINTLIGHT], "vPointLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_SPHERELIGHT], "vSphereLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_DISCLIGHT], "vDiscLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_RECTANGLELIGHT], "vRectangleLightVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LIGHTVISUALIZER_TUBELIGHT], "vTubeLightVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_DECAL], "decalVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_ENVMAP], "envMapVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_ENVMAP_SKY], "envMap_skyVS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_SPHERE], "sphereVS.cso"); }); @@ -1236,46 +1060,21 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(VS, vertexShaders[VSTYPE_LENSFLARE], "lensFlareVS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED], "objectPS_deferred.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP], "objectPS_deferred_normalmap.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_POM], "objectPS_deferred_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_PLANARREFLECTION], "objectPS_deferred_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP_POM], "objectPS_deferred_normalmap_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_NORMALMAP_PLANARREFLECTION], "objectPS_deferred_normalmap_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_DEFERRED_TERRAIN], "objectPS_deferred_terrain.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_DEFERRED], "impostorPS_deferred.cso"); }); - - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD], "objectPS_forward.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP], "objectPS_forward_normalmap.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT], "objectPS_forward_transparent.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP], "objectPS_forward_transparent_normalmap.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_PLANARREFLECTION], "objectPS_forward_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_PLANARREFLECTION], "objectPS_forward_normalmap_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_PLANARREFLECTION], "objectPS_forward_transparent_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION], "objectPS_forward_transparent_normalmap_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_POM], "objectPS_forward_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_NORMALMAP_POM], "objectPS_forward_normalmap_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_POM], "objectPS_forward_transparent_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TRANSPARENT_NORMALMAP_POM], "objectPS_forward_transparent_normalmap_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_WATER], "objectPS_forward_water.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_FORWARD_TERRAIN], "objectPS_forward_terrain.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_FORWARD], "impostorPS_forward.cso"); }); - - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD], "objectPS_tiledforward.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP], "objectPS_tiledforward_normalmap.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT], "objectPS_tiledforward_transparent.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP], "objectPS_tiledforward_transparent_normalmap.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_PLANARREFLECTION], "objectPS_tiledforward_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_PLANARREFLECTION], "objectPS_tiledforward_normalmap_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_PLANARREFLECTION], "objectPS_tiledforward_transparent_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_PLANARREFLECTION], "objectPS_tiledforward_transparent_normalmap_planarreflection.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_POM], "objectPS_tiledforward_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_NORMALMAP_POM], "objectPS_tiledforward_normalmap_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_POM], "objectPS_tiledforward_transparent_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TRANSPARENT_NORMALMAP_POM], "objectPS_tiledforward_transparent_normalmap_pom.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_WATER], "objectPS_tiledforward_water.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TERRAIN], "objectPS_tiledforward_terrain.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_TILEDFORWARD], "impostorPS_tiledforward.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT], "objectPS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT], "objectPS_transparent.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_PLANARREFLECTION], "objectPS_planarreflection.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT_PLANARREFLECTION], "objectPS_transparent_planarreflection.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_POM], "objectPS_pom.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT_POM], "objectPS_transparent_pom.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_ANISOTROPIC], "objectPS_anisotropic.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT_ANISOTROPIC], "objectPS_transparent_anisotropic.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_CARTOON], "objectPS_cartoon.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT_CARTOON], "objectPS_transparent_cartoon.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_UNLIT], "objectPS_unlit.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TRANSPARENT_UNLIT], "objectPS_transparent_unlit.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_WATER], "objectPS_water.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_TERRAIN], "objectPS_terrain.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR], "impostorPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_OBJECT_HOLOGRAM], "objectPS_hologram.cso"); }); @@ -1288,19 +1087,10 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_ALPHATESTONLY], "impostorPS_alphatestonly.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_SIMPLE], "impostorPS_simple.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_IMPOSTOR_WIRE], "impostorPS_wire.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_ENVIRONMENTALLIGHT], "environmentalLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_DIRLIGHT], "dirLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POINTLIGHT], "pointLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_SPOTLIGHT], "spotLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_SPHERELIGHT], "sphereLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_DISCLIGHT], "discLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_RECTANGLELIGHT], "rectangleLightPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_TUBELIGHT], "tubeLightPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_LIGHTVISUALIZER], "lightVisualizerPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_VOLUMETRICLIGHT_DIRECTIONAL], "volumetricLight_DirectionalPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_VOLUMETRICLIGHT_POINT], "volumetricLight_PointPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_VOLUMETRICLIGHT_SPOT], "volumetricLight_SpotPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_DECAL], "decalPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_ENVMAP], "envMapPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_ENVMAP_TERRAIN], "envMapPS_terrain.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_ENVMAP_SKY_STATIC], "envMap_skyPS_static.cso"); }); @@ -1325,7 +1115,8 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_RAYTRACE_DEBUGBVH], "raytrace_debugbvhPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_DOWNSAMPLEDEPTHBUFFER], "downsampleDepthBuffer4xPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_DEFERREDCOMPOSITION], "deferredPS.cso"); }); - wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POSTPROCESS_SSS], "sssPS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POSTPROCESS_SSS_SKIN], "sssPS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POSTPROCESS_SSS_SNOW], "sssPS_snow.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL], "upsample_bilateralPS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_POSTPROCESS_OUTLINE], "outlinePS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(PS, pixelShaders[PSTYPE_LENSFLARE], "lensFlarePS.cso"); }); @@ -1442,6 +1233,7 @@ void LoadShaders() wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(CS, computeShaders[CSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL_UNORM4], "upsample_bilateral_unorm4CS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(CS, computeShaders[CSTYPE_POSTPROCESS_DOWNSAMPLE4X], "downsample4xCS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(CS, computeShaders[CSTYPE_POSTPROCESS_NORMALSFROMDEPTH], "normalsfromdepthCS.cso"); }); + wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(CS, computeShaders[CSTYPE_POSTPROCESS_DENOISE], "denoiseCS.cso"); }); wiJobSystem::Execute(ctx, [](wiJobArgs args) { LoadShader(HS, hullShaders[HSTYPE_OBJECT], "objectHS.cso"); }); @@ -1451,142 +1243,134 @@ void LoadShaders() wiJobSystem::Wait(ctx); // default objectshaders: - for (int renderPass = 0; renderPass < RENDERPASS_COUNT; ++renderPass) - { - for (int blendMode = 0; blendMode < BLENDMODE_COUNT; ++blendMode) + wiJobSystem::Dispatch(ctx, MaterialComponent::SHADERTYPE_COUNT, 1, [device](wiJobArgs args) { + MaterialComponent::SHADERTYPE shaderType = (MaterialComponent::SHADERTYPE)args.jobIndex; + + for (int renderPass = 0; renderPass < RENDERPASS_COUNT; ++renderPass) { - for (int doublesided = 0; doublesided < OBJECTRENDERING_DOUBLESIDED_COUNT; ++doublesided) + for (int blendMode = 0; blendMode < BLENDMODE_COUNT; ++blendMode) { - for (int tessellation = 0; tessellation < OBJECTRENDERING_TESSELLATION_COUNT; ++tessellation) + for (int doublesided = 0; doublesided < OBJECTRENDERING_DOUBLESIDED_COUNT; ++doublesided) { - for (int alphatest = 0; alphatest < OBJECTRENDERING_ALPHATEST_COUNT; ++alphatest) + for (int tessellation = 0; tessellation < OBJECTRENDERING_TESSELLATION_COUNT; ++tessellation) { - for (int normalmap = 0; normalmap < OBJECTRENDERING_NORMALMAP_COUNT; ++normalmap) + for (int alphatest = 0; alphatest < OBJECTRENDERING_ALPHATEST_COUNT; ++alphatest) { - for (int planarreflection = 0; planarreflection < OBJECTRENDERING_PLANARREFLECTION_COUNT; ++planarreflection) + const bool transparency = blendMode != BLENDMODE_OPAQUE; + VSTYPES realVS = GetVSTYPE((RENDERPASS)renderPass, tessellation, alphatest, transparency); + ILTYPES realVL = GetILTYPE((RENDERPASS)renderPass, tessellation, alphatest, transparency); + HSTYPES realHS = GetHSTYPE((RENDERPASS)renderPass, tessellation); + DSTYPES realDS = GetDSTYPE((RENDERPASS)renderPass, tessellation); + GSTYPES realGS = GetGSTYPE((RENDERPASS)renderPass, alphatest); + PSTYPES realPS = GetPSTYPE((RENDERPASS)renderPass, alphatest, transparency, shaderType); + + if (tessellation && (realHS == HSTYPE_COUNT || realDS == DSTYPE_COUNT)) { - for (int pom = 0; pom < OBJECTRENDERING_POM_COUNT; ++pom) - { - wiJobSystem::Execute(ctx, [device, renderPass, blendMode, doublesided, tessellation, alphatest, normalmap, planarreflection, pom](wiJobArgs args) { - const bool transparency = blendMode != BLENDMODE_OPAQUE; - VSTYPES realVS = GetVSTYPE((RENDERPASS)renderPass, tessellation, alphatest, transparency); - ILTYPES realVL = GetILTYPE((RENDERPASS)renderPass, tessellation, alphatest, transparency); - HSTYPES realHS = GetHSTYPE((RENDERPASS)renderPass, tessellation); - DSTYPES realDS = GetDSTYPE((RENDERPASS)renderPass, tessellation); - GSTYPES realGS = GetGSTYPE((RENDERPASS)renderPass, alphatest); - PSTYPES realPS = GetPSTYPE((RENDERPASS)renderPass, alphatest, transparency, normalmap, planarreflection, pom); - - if (tessellation && (realHS == HSTYPE_COUNT || realDS == DSTYPE_COUNT)) - { - return; // if no job, this must be continue!! - } - - PipelineStateDesc desc; - desc.il = realVL < ILTYPE_COUNT ? &inputLayouts[realVL] : nullptr; - desc.vs = realVS < VSTYPE_COUNT ? &vertexShaders[realVS] : nullptr; - desc.hs = realHS < HSTYPE_COUNT ? &hullShaders[realHS] : nullptr; - desc.ds = realDS < DSTYPE_COUNT ? &domainShaders[realDS] : nullptr; - desc.gs = realGS < GSTYPE_COUNT ? &geometryShaders[realGS] : nullptr; - desc.ps = realPS < PSTYPE_COUNT ? &pixelShaders[realPS] : nullptr; - - switch (blendMode) - { - case BLENDMODE_OPAQUE: - desc.bs = &blendStates[BSTYPE_OPAQUE]; - break; - case BLENDMODE_ALPHA: - desc.bs = &blendStates[BSTYPE_TRANSPARENT]; - break; - case BLENDMODE_ADDITIVE: - desc.bs = &blendStates[BSTYPE_ADDITIVE]; - break; - case BLENDMODE_PREMULTIPLIED: - desc.bs = &blendStates[BSTYPE_PREMULTIPLIED]; - break; - default: - assert(0); - break; - } - - switch (renderPass) - { - case RENDERPASS_DEPTHONLY: - case RENDERPASS_SHADOW: - case RENDERPASS_SHADOWCUBE: - desc.bs = &blendStates[transparency ? BSTYPE_TRANSPARENTSHADOWMAP : BSTYPE_COLORWRITEDISABLE]; - break; - default: - break; - } - - switch (renderPass) - { - case RENDERPASS_SHADOW: - case RENDERPASS_SHADOWCUBE: - desc.dss = &depthStencils[transparency ? DSSTYPE_DEPTHREAD : DSSTYPE_SHADOW]; - break; - case RENDERPASS_FORWARD: - case RENDERPASS_TILEDFORWARD: - if (blendMode == BLENDMODE_ADDITIVE) - { - desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; - } - else - { - desc.dss = &depthStencils[transparency ? DSSTYPE_DEFAULT : DSSTYPE_DEPTHREADEQUAL]; - } - break; - case RENDERPASS_ENVMAPCAPTURE: - desc.dss = &depthStencils[DSSTYPE_ENVMAP]; - break; - case RENDERPASS_VOXELIZE: - desc.dss = &depthStencils[DSSTYPE_XRAY]; - break; - default: - if (blendMode == BLENDMODE_ADDITIVE) - { - desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; - } - else - { - desc.dss = &depthStencils[DSSTYPE_DEFAULT]; - } - break; - } - - switch (renderPass) - { - case RENDERPASS_SHADOW: - case RENDERPASS_SHADOWCUBE: - desc.rs = &rasterizers[doublesided ? RSTYPE_SHADOW_DOUBLESIDED : RSTYPE_SHADOW]; - break; - case RENDERPASS_VOXELIZE: - desc.rs = &rasterizers[RSTYPE_VOXELIZE]; - break; - default: - desc.rs = &rasterizers[doublesided ? RSTYPE_DOUBLESIDED : RSTYPE_FRONT]; - break; - } - - if (tessellation) - { - desc.pt = PATCHLIST; - } - else - { - desc.pt = TRIANGLELIST; - } - - device->CreatePipelineState(&desc, &PSO_object[renderPass][blendMode][doublesided][tessellation][alphatest][normalmap][planarreflection][pom]); - }); - } + continue; } + + PipelineStateDesc desc; + desc.il = realVL < ILTYPE_COUNT ? &inputLayouts[realVL] : nullptr; + desc.vs = realVS < VSTYPE_COUNT ? &vertexShaders[realVS] : nullptr; + desc.hs = realHS < HSTYPE_COUNT ? &hullShaders[realHS] : nullptr; + desc.ds = realDS < DSTYPE_COUNT ? &domainShaders[realDS] : nullptr; + desc.gs = realGS < GSTYPE_COUNT ? &geometryShaders[realGS] : nullptr; + desc.ps = realPS < PSTYPE_COUNT ? &pixelShaders[realPS] : nullptr; + + switch (blendMode) + { + case BLENDMODE_OPAQUE: + desc.bs = &blendStates[BSTYPE_OPAQUE]; + break; + case BLENDMODE_ALPHA: + desc.bs = &blendStates[BSTYPE_TRANSPARENT]; + break; + case BLENDMODE_ADDITIVE: + desc.bs = &blendStates[BSTYPE_ADDITIVE]; + break; + case BLENDMODE_PREMULTIPLIED: + desc.bs = &blendStates[BSTYPE_PREMULTIPLIED]; + break; + default: + assert(0); + break; + } + + switch (renderPass) + { + case RENDERPASS_DEPTHONLY: + case RENDERPASS_SHADOW: + case RENDERPASS_SHADOWCUBE: + desc.bs = &blendStates[transparency ? BSTYPE_TRANSPARENTSHADOWMAP : BSTYPE_COLORWRITEDISABLE]; + break; + default: + break; + } + + switch (renderPass) + { + case RENDERPASS_SHADOW: + case RENDERPASS_SHADOWCUBE: + desc.dss = &depthStencils[transparency ? DSSTYPE_DEPTHREAD : DSSTYPE_SHADOW]; + break; + case RENDERPASS_MAIN: + if (blendMode == BLENDMODE_ADDITIVE) + { + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + } + else + { + desc.dss = &depthStencils[transparency ? DSSTYPE_DEFAULT : DSSTYPE_DEPTHREADEQUAL]; + } + break; + case RENDERPASS_ENVMAPCAPTURE: + desc.dss = &depthStencils[DSSTYPE_ENVMAP]; + break; + case RENDERPASS_VOXELIZE: + desc.dss = &depthStencils[DSSTYPE_XRAY]; + break; + default: + if (blendMode == BLENDMODE_ADDITIVE) + { + desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + } + else + { + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; + } + break; + } + + switch (renderPass) + { + case RENDERPASS_SHADOW: + case RENDERPASS_SHADOWCUBE: + desc.rs = &rasterizers[doublesided ? RSTYPE_SHADOW_DOUBLESIDED : RSTYPE_SHADOW]; + break; + case RENDERPASS_VOXELIZE: + desc.rs = &rasterizers[RSTYPE_VOXELIZE]; + break; + default: + desc.rs = &rasterizers[doublesided ? RSTYPE_DOUBLESIDED : RSTYPE_FRONT]; + break; + } + + if (tessellation) + { + desc.pt = PATCHLIST; + } + else + { + desc.pt = TRIANGLELIST; + } + + device->CreatePipelineState(&desc, &PSO_object[shaderType][renderPass][blendMode][doublesided][tessellation][alphatest]); } } } } } - } + }); wiJobSystem::Dispatch(ctx, RENDERPASS_COUNT, 1, [device](wiJobArgs args) { @@ -1605,16 +1389,9 @@ void LoadShaders() case RENDERPASS_TEXTURE: desc.ps = &pixelShaders[PSTYPE_OBJECT_TEXTUREONLY]; // textureonly doesn't have worldpos or normal inputs, so it will not use terrain blending break; - case RENDERPASS_DEFERRED: - desc.ps = &pixelShaders[PSTYPE_OBJECT_DEFERRED_TERRAIN]; - break; - case RENDERPASS_FORWARD: + case RENDERPASS_MAIN: desc.dss = &depthStencils[DSSTYPE_DEPTHREADEQUAL]; - desc.ps = &pixelShaders[PSTYPE_OBJECT_FORWARD_TERRAIN]; - break; - case RENDERPASS_TILEDFORWARD: - desc.dss = &depthStencils[DSSTYPE_DEPTHREADEQUAL]; - desc.ps = &pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_TERRAIN]; + desc.ps = &pixelShaders[PSTYPE_OBJECT_TERRAIN]; break; case RENDERPASS_DEPTHONLY: desc.ps = nullptr; @@ -1647,8 +1424,8 @@ void LoadShaders() // Hologram sample shader will be registered as custom shader: wiJobSystem::Execute(ctx, [device](wiJobArgs args) { - VSTYPES realVS = GetVSTYPE(RENDERPASS_FORWARD, false, false, true); - ILTYPES realVL = GetILTYPE(RENDERPASS_FORWARD, false, false, true); + VSTYPES realVS = GetVSTYPE(RENDERPASS_MAIN, false, false, true); + ILTYPES realVL = GetILTYPE(RENDERPASS_MAIN, false, false, true); PipelineStateDesc desc; desc.vs = &vertexShaders[realVS]; @@ -1656,50 +1433,21 @@ void LoadShaders() desc.ps = &pixelShaders[PSTYPE_OBJECT_HOLOGRAM]; desc.bs = &blendStates[BSTYPE_ADDITIVE]; - desc.rs = &rasterizers[DSSTYPE_DEFAULT]; - desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; + desc.rs = &rasterizers[RSTYPE_FRONT]; + desc.dss = &depthStencils[DSSTYPE_DEFAULT]; desc.pt = TRIANGLELIST; - device->CreatePipelineState(&desc, &PSO_object_hologram); + PipelineState pso; + device->CreatePipelineState(&desc, &pso); CustomShader customShader; customShader.name = "Hologram"; - customShader.passes[RENDERPASS_FORWARD].pso = &PSO_object_hologram; - customShader.passes[RENDERPASS_TILEDFORWARD].pso = &PSO_object_hologram; + customShader.renderTypeFlags = RENDERTYPE_TRANSPARENT; + customShader.pso[RENDERPASS_MAIN] = pso; RegisterCustomShader(customShader); }); - wiJobSystem::Execute(ctx, [device](wiJobArgs args) { - PipelineStateDesc desc; - desc.vs = &vertexShaders[VSTYPE_OBJECT_COMMON]; - desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = &blendStates[BSTYPE_TRANSPARENT]; - desc.dss = &depthStencils[DSSTYPE_DEFAULT]; - desc.il = &inputLayouts[ILTYPE_OBJECT_ALL]; - - desc.ps = &pixelShaders[PSTYPE_OBJECT_FORWARD_WATER]; - device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_FORWARD]); - - desc.ps = &pixelShaders[PSTYPE_OBJECT_TILEDFORWARD_WATER]; - device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_TILEDFORWARD]); - - desc.dss = &depthStencils[DSSTYPE_DEPTHREAD]; - desc.rs = &rasterizers[RSTYPE_SHADOW]; - desc.bs = &blendStates[BSTYPE_TRANSPARENTSHADOWMAP]; - desc.vs = &vertexShaders[VSTYPE_SHADOW_TRANSPARENT]; - desc.ps = &pixelShaders[PSTYPE_SHADOW_WATER]; - - device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_SHADOW]); - - desc.dss = &depthStencils[DSSTYPE_DEFAULT]; - desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; - desc.bs = &blendStates[BSTYPE_OPAQUE]; - desc.il = &inputLayouts[GetILTYPE(RENDERPASS_ENVMAPCAPTURE, false, false, true)]; - desc.vs = &vertexShaders[GetVSTYPE(RENDERPASS_ENVMAPCAPTURE, false, false, true)]; - desc.ps = &pixelShaders[GetPSTYPE(RENDERPASS_ENVMAPCAPTURE, false, true, false, false, false)]; - device->CreatePipelineState(&desc, &PSO_object_water[RENDERPASS_ENVMAPCAPTURE]); - }); wiJobSystem::Execute(ctx, [device](wiJobArgs args) { PipelineStateDesc desc; desc.vs = &vertexShaders[VSTYPE_OBJECT_SIMPLE]; @@ -1711,17 +1459,6 @@ void LoadShaders() device->CreatePipelineState(&desc, &PSO_object_wire); }); - wiJobSystem::Execute(ctx, [device](wiJobArgs args) { - PipelineStateDesc desc; - desc.vs = &vertexShaders[VSTYPE_DECAL]; - desc.ps = &pixelShaders[PSTYPE_DECAL]; - desc.rs = &rasterizers[RSTYPE_FRONT]; - desc.bs = &blendStates[BSTYPE_DECAL]; - desc.dss = &depthStencils[DSSTYPE_DEFERREDLIGHT]; - desc.pt = TRIANGLESTRIP; - - device->CreatePipelineState(&desc, &PSO_decal); - }); wiJobSystem::Execute(ctx, [device](wiJobArgs args) { PipelineStateDesc desc; desc.vs = &vertexShaders[VSTYPE_CUBE]; @@ -1751,19 +1488,10 @@ void LoadShaders() switch (args.jobIndex) { - case RENDERPASS_DEFERRED: - desc.vs = &vertexShaders[VSTYPE_IMPOSTOR]; - desc.ps = &pixelShaders[PSTYPE_IMPOSTOR_DEFERRED]; - break; - case RENDERPASS_FORWARD: + case RENDERPASS_MAIN: desc.dss = &depthStencils[DSSTYPE_DEPTHREADEQUAL]; desc.vs = &vertexShaders[VSTYPE_IMPOSTOR]; - desc.ps = &pixelShaders[PSTYPE_IMPOSTOR_FORWARD]; - break; - case RENDERPASS_TILEDFORWARD: - desc.dss = &depthStencils[DSSTYPE_DEPTHREADEQUAL]; - desc.vs = &vertexShaders[VSTYPE_IMPOSTOR]; - desc.ps = &pixelShaders[PSTYPE_IMPOSTOR_TILEDFORWARD]; + desc.ps = &pixelShaders[PSTYPE_IMPOSTOR]; break; case RENDERPASS_DEPTHONLY: desc.vs = &vertexShaders[VSTYPE_IMPOSTOR]; @@ -1812,44 +1540,6 @@ void LoadShaders() // deferred lights: desc.pt = TRIANGLELIST; - desc.rs = &rasterizers[RSTYPE_BACK]; - desc.bs = &blendStates[BSTYPE_DEFERREDLIGHT]; - desc.dss = &depthStencils[DSSTYPE_DEFERREDLIGHT]; - - switch (args.jobIndex) - { - case LightComponent::DIRECTIONAL: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_DIRLIGHT]; - break; - case LightComponent::POINT: - desc.vs = &vertexShaders[VSTYPE_POINTLIGHT]; - desc.ps = &pixelShaders[PSTYPE_POINTLIGHT]; - break; - case LightComponent::SPOT: - desc.vs = &vertexShaders[VSTYPE_SPOTLIGHT]; - desc.ps = &pixelShaders[PSTYPE_SPOTLIGHT]; - break; - case LightComponent::SPHERE: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_SPHERELIGHT]; - break; - case LightComponent::DISC: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_DISCLIGHT]; - break; - case LightComponent::RECTANGLE: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_RECTANGLELIGHT]; - break; - case LightComponent::TUBE: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_TUBELIGHT]; - break; - } - - device->CreatePipelineState(&desc, &PSO_deferredlight[args.jobIndex]); - // light visualizers: @@ -1907,15 +1597,15 @@ void LoadShaders() switch (args.jobIndex) { case LightComponent::DIRECTIONAL: - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; + desc.vs = &vertexShaders[VSTYPE_VOLUMETRICLIGHT_DIRECTIONAL]; desc.ps = &pixelShaders[PSTYPE_VOLUMETRICLIGHT_DIRECTIONAL]; break; case LightComponent::POINT: - desc.vs = &vertexShaders[VSTYPE_POINTLIGHT]; + desc.vs = &vertexShaders[VSTYPE_VOLUMETRICLIGHT_POINT]; desc.ps = &pixelShaders[PSTYPE_VOLUMETRICLIGHT_POINT]; break; case LightComponent::SPOT: - desc.vs = &vertexShaders[VSTYPE_SPOTLIGHT]; + desc.vs = &vertexShaders[VSTYPE_VOLUMETRICLIGHT_SPOT]; desc.ps = &pixelShaders[PSTYPE_VOLUMETRICLIGHT_SPOT]; break; } @@ -1924,16 +1614,6 @@ void LoadShaders() } - }); - wiJobSystem::Execute(ctx, [device](wiJobArgs args) { - PipelineStateDesc desc; - desc.vs = &vertexShaders[VSTYPE_DIRLIGHT]; - desc.ps = &pixelShaders[PSTYPE_ENVIRONMENTALLIGHT]; - desc.rs = &rasterizers[RSTYPE_BACK]; - desc.bs = &blendStates[BSTYPE_ENVIRONMENTALLIGHT]; - desc.dss = &depthStencils[DSSTYPE_DEFERREDLIGHT]; - - device->CreatePipelineState(&desc, &PSO_enviromentallight); }); wiJobSystem::Execute(ctx, [device](wiJobArgs args) { PipelineStateDesc desc; @@ -1969,12 +1649,22 @@ void LoadShaders() wiJobSystem::Execute(ctx, [device](wiJobArgs args) { PipelineStateDesc desc; desc.vs = &vertexShaders[VSTYPE_SCREEN]; - desc.ps = &pixelShaders[PSTYPE_POSTPROCESS_SSS]; + desc.ps = &pixelShaders[PSTYPE_POSTPROCESS_SSS_SKIN]; desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; desc.bs = &blendStates[BSTYPE_OPAQUE]; desc.dss = &depthStencils[DSSTYPE_SSS]; - device->CreatePipelineState(&desc, &PSO_sss); + device->CreatePipelineState(&desc, &PSO_sss_skin); + }); + wiJobSystem::Execute(ctx, [device](wiJobArgs args) { + PipelineStateDesc desc; + desc.vs = &vertexShaders[VSTYPE_SCREEN]; + desc.ps = &pixelShaders[PSTYPE_POSTPROCESS_SSS_SNOW]; + desc.rs = &rasterizers[RSTYPE_DOUBLESIDED]; + desc.bs = &blendStates[BSTYPE_OPAQUE]; + desc.dss = &depthStencils[DSSTYPE_SSS]; + + device->CreatePipelineState(&desc, &PSO_sss_snow); }); wiJobSystem::Execute(ctx, [device](wiJobArgs args) { PipelineStateDesc desc; @@ -2159,31 +1849,24 @@ void LoadShaders() }); - for (int i = 0; i < TILEDLIGHTING_TYPE_COUNT; ++i) + for (int j = 0; j < TILEDLIGHTING_CULLING_COUNT; ++j) { - for (int j = 0; j < TILEDLIGHTING_CULLING_COUNT; ++j) + for (int k = 0; k < TILEDLIGHTING_DEBUG_COUNT; ++k) { - for (int k = 0; k < TILEDLIGHTING_DEBUG_COUNT; ++k) - { - wiJobSystem::Execute(ctx, [i, j, k](wiJobArgs args) { - string name = "lightCullingCS"; - if (i == TILEDLIGHTING_TYPE_DEFERRED) - { - name += "_DEFERRED"; - } - if (j == TILEDLIGHTING_CULLING_ADVANCED) - { - name += "_ADVANCED"; - } - if (k == TILEDLIGHTING_DEBUG_ENABLED) - { - name += "_DEBUG"; - } - name += ".cso"; + wiJobSystem::Execute(ctx, [j, k](wiJobArgs args) { + string name = "lightCullingCS"; + if (j == TILEDLIGHTING_CULLING_ADVANCED) + { + name += "_ADVANCED"; + } + if (k == TILEDLIGHTING_DEBUG_ENABLED) + { + name += "_DEBUG"; + } + name += ".cso"; - LoadShader(CS, tiledLightingCS[i][j][k], name); + LoadShader(CS, tiledLightingCS[j][k], name); }); - } } } @@ -2245,10 +1928,6 @@ void LoadBuffers() device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_VOLUMELIGHT]); device->SetName(&constantBuffers[CBTYPE_VOLUMELIGHT], "VolumelightCB"); - bd.ByteWidth = sizeof(DecalCB); - device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_DECAL]); - device->SetName(&constantBuffers[CBTYPE_DECAL], "DecalCB"); - bd.ByteWidth = sizeof(CubemapRenderCB); device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_CUBEMAPRENDER]); device->SetName(&constantBuffers[CBTYPE_CUBEMAPRENDER], "CubemapRenderCB"); @@ -2570,7 +2249,7 @@ void SetUpStates() dsd.BackFace.StencilPassOp = STENCIL_OP_KEEP; dsd.BackFace.StencilFailOp = STENCIL_OP_KEEP; dsd.BackFace.StencilDepthFailOp = STENCIL_OP_KEEP; - device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFERREDLIGHT]); + //device->CreateDepthStencilState(&dsd, &depthStencils[DSSTYPE_DEFERREDLIGHT]); dsd.DepthEnable = true; dsd.DepthWriteMask = DEPTH_WRITE_MASK_ZERO; @@ -2705,7 +2384,7 @@ void SetUpStates() bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_RED | COLOR_WRITE_ENABLE_GREEN | COLOR_WRITE_ENABLE_BLUE; // alpha is not written by deferred lights! bd.IndependentBlendEnable = false, bd.AlphaToCoverageEnable = false; - device->CreateBlendState(&bd, &blendStates[BSTYPE_DEFERREDLIGHT]); + //device->CreateBlendState(&bd, &blendStates[BSTYPE_DEFERREDLIGHT]); bd.RenderTarget[0].BlendEnable = true; bd.RenderTarget[0].SrcBlend = BLEND_ONE; @@ -2845,14 +2524,17 @@ void Initialize() wiPlatform::GetWindowState().dpi = dpi; }); + TextureDesc desc; + desc.Width = 1; + desc.Height = 1; + desc.Format = FORMAT_R11G11B10_FLOAT; + desc.BindFlags = BIND_SHADER_RESOURCE; + GetDevice()->CreateTexture(&desc, nullptr, &globalLightmap); + wiBackLog::post("wiRenderer Initialized"); } void ClearWorld() { - for (wiSprite* x : waterRipples) - { - delete x; - } waterRipples.clear(); GetScene().Clear(); @@ -3043,21 +2725,18 @@ ForwardEntityMaskCB ForwardEntityCullingCPU(const FrameCulling& culling, const A cb.xForwardLightMask.x = buckets[0]; cb.xForwardLightMask.y = buckets[1]; - if (renderPass == RENDERPASS_FORWARD || renderPass == RENDERPASS_ENVMAPCAPTURE) + for (size_t i = 0; i < std::min(size_t(32), culling.culledDecals.size()); ++i) { - for (size_t i = 0; i < std::min(size_t(32), culling.culledDecals.size()); ++i) + const uint32_t decalIndex = culling.culledDecals[culling.culledDecals.size() - 1 - i]; // note: reverse order, for correct blending! + const AABB& decal_aabb = scene.aabb_decals[decalIndex]; + if (decal_aabb.intersects(batch_aabb)) { - const uint32_t decalIndex = culling.culledDecals[culling.culledDecals.size() - 1 - i]; // note: reverse order, for correct blending! - const AABB& decal_aabb = scene.aabb_decals[decalIndex]; - if (decal_aabb.intersects(batch_aabb)) - { - const uint8_t bucket_place = uint8_t(i % 32); - cb.xForwardDecalMask |= 1 << bucket_place; - } + const uint8_t bucket_place = uint8_t(i % 32); + cb.xForwardDecalMask |= 1 << bucket_place; } } - if (renderPass == RENDERPASS_FORWARD) + if (renderPass != RENDERPASS_ENVMAPCAPTURE) { for (size_t i = 0; i < std::min(size_t(32), culling.culledEnvProbes.size()); ++i) { @@ -3140,9 +2819,7 @@ void RenderMeshes( // Do we need to bind every vertex buffer or just a reduced amount for this pass? const bool advancedVBRequest = !IsWireRender() && ( - renderPass == RENDERPASS_FORWARD || - renderPass == RENDERPASS_DEFERRED || - renderPass == RENDERPASS_TILEDFORWARD || + renderPass == RENDERPASS_MAIN || renderPass == RENDERPASS_ENVMAPCAPTURE || renderPass == RENDERPASS_VOXELIZE ); @@ -3155,7 +2832,6 @@ void RenderMeshes( // Do we need to compute a light mask for this pass on the CPU? const bool forwardLightmaskRequest = - renderPass == RENDERPASS_FORWARD || renderPass == RENDERPASS_ENVMAPCAPTURE || renderPass == RENDERPASS_VOXELIZE; @@ -3314,35 +2990,8 @@ void RenderMeshes( } const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); - const PipelineState* pso = nullptr; - if (material.IsCustomShader()) - { - pso = GetCustomShaderPSO(renderPass, renderTypeFlags, material.GetCustomShaderID()); - } - else - { - pso = GetObjectPSO(renderPass, mesh, material, tessellatorRequested, forceAlphaTestForDithering); - } + bool subsetRenderable = renderTypeFlags & material.GetRenderTypes(); - if (pso == nullptr || !pso->IsValid()) - { - continue; - } - - bool subsetRenderable = false; - - if (renderTypeFlags & RENDERTYPE_OPAQUE) - { - subsetRenderable = subsetRenderable || (!material.IsTransparent() && !material.IsWater()); - } - if (renderTypeFlags & RENDERTYPE_TRANSPARENT) - { - subsetRenderable = subsetRenderable || material.IsTransparent(); - } - if (renderTypeFlags & RENDERTYPE_WATER) - { - subsetRenderable = subsetRenderable || material.IsWater(); - } if (renderPass == RENDERPASS_SHADOW || renderPass == RENDERPASS_SHADOWCUBE) { subsetRenderable = subsetRenderable && material.IsCastingShadow(); @@ -3353,6 +3002,13 @@ void RenderMeshes( continue; } + const PipelineState* pso = GetObjectPSO(renderPass, renderTypeFlags, mesh, material, tessellatorRequested, forceAlphaTestForDithering); + + if (pso == nullptr || !pso->IsValid()) + { + continue; + } + BOUNDVERTEXBUFFERTYPE boundVBType; if (advancedVBRequest || tessellatorRequested) { @@ -3363,7 +3019,7 @@ void RenderMeshes( // simple vertex buffers are used in some passes (note: tessellator requires more attributes) if ((renderPass == RENDERPASS_DEPTHONLY || renderPass == RENDERPASS_SHADOW || renderPass == RENDERPASS_SHADOWCUBE) && !material.IsAlphaTestEnabled() && !forceAlphaTestForDithering) { - if (renderPass == RENDERPASS_SHADOW && material.IsTransparent()) + if (renderPass == RENDERPASS_SHADOW && (renderTypeFlags & RENDERTYPE_TRANSPARENT)) { boundVBType = BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD; } @@ -3438,6 +3094,7 @@ void RenderMeshes( &mesh.vertexBuffer_UV1, &mesh.vertexBuffer_ATL, &mesh.vertexBuffer_COL, + mesh.streamoutBuffer_TAN.IsValid() ? &mesh.streamoutBuffer_TAN : &mesh.vertexBuffer_TAN, mesh.vertexBuffer_PRE.IsValid() ? &mesh.vertexBuffer_PRE : &mesh.vertexBuffer_POS, instances.buffer }; @@ -3447,6 +3104,7 @@ void RenderMeshes( sizeof(MeshComponent::Vertex_TEX), sizeof(MeshComponent::Vertex_TEX), sizeof(MeshComponent::Vertex_COL), + sizeof(MeshComponent::Vertex_TAN), sizeof(MeshComponent::Vertex_POS), instanceDataSize }; @@ -3457,6 +3115,7 @@ void RenderMeshes( 0, 0, 0, + 0, instancedBatch.dataOffset }; device->BindVertexBuffers(vbs, 0, arraysize(vbs), strides, offsets, cmd); @@ -3774,8 +3433,12 @@ void UpdatePerFrameData(float dt, uint32_t layerMask) if (!mesh.vertexBuffer_PRE.IsValid()) { - device->CreateBuffer(&mesh.vertexBuffer_POS.GetDesc(), nullptr, &mesh.streamoutBuffer_POS); - device->CreateBuffer(&mesh.vertexBuffer_POS.GetDesc(), nullptr, &mesh.vertexBuffer_PRE); + device->CreateBuffer(&mesh.vertexBuffer_POS.desc, nullptr, &mesh.streamoutBuffer_POS); + device->CreateBuffer(&mesh.vertexBuffer_POS.desc, nullptr, &mesh.vertexBuffer_PRE); + + GPUBufferDesc tandesc = mesh.vertexBuffer_TAN.desc; + tandesc.Usage = USAGE_DEFAULT; + device->CreateBuffer(&tandesc, nullptr, &mesh.streamoutBuffer_TAN); if (raytracing_api) { @@ -4206,7 +3869,7 @@ void UpdatePerFrameData(float dt, uint32_t layerMask) wiJobSystem::Execute(ctx, [&](wiJobArgs args) { for (auto& x : waterRipples) { - x->Update(dt * 60); + x.Update(dt * 60); } ManageWaterRipples(); }); @@ -4237,7 +3900,8 @@ void UpdateRenderData(CommandList cmd) if (materialIndex < scene.materials.GetCount()) { const MaterialComponent& material = scene.materials[materialIndex]; - ShaderMaterial materialGPUData = material.CreateShaderMaterial(); + ShaderMaterial materialGPUData; + material.WriteShaderMaterial(&materialGPUData); device->UpdateBuffer(&material.constantBuffer, &materialGPUData, cmd); } } @@ -4541,11 +4205,13 @@ void UpdateRenderData(CommandList cmd) // Do the skinning const GPUResource* vbs[] = { &mesh.vertexBuffer_POS, + &mesh.vertexBuffer_TAN, &mesh.vertexBuffer_BON, &armature.boneBuffer, }; const GPUResource* so[] = { &mesh.streamoutBuffer_POS, + &mesh.streamoutBuffer_TAN, }; device->BindResources(CS, vbs, SKINNINGSLOT_IN_VERTEX_POS, arraysize(vbs), cmd); @@ -4564,7 +4230,7 @@ void UpdateRenderData(CommandList cmd) }; device->Barrier(barriers, arraysize(barriers), cmd); device->UnbindUAVs(0, 2, cmd); - device->UnbindResources(SKINNINGSLOT_IN_VERTEX_POS, 2, cmd); + device->UnbindResources(SKINNINGSLOT_IN_VERTEX_POS, 4, cmd); } } @@ -4585,6 +4251,9 @@ void UpdateRenderData(CommandList cmd) device->UpdateBuffer(&mesh.streamoutBuffer_POS, softbody.vertex_positions_simulation.data(), cmd, (uint32_t)(sizeof(MeshComponent::Vertex_POS) * softbody.vertex_positions_simulation.size())); + + device->UpdateBuffer(&mesh.streamoutBuffer_TAN, softbody.vertex_tangents_simulation.data(), cmd, + (uint32_t)(sizeof(MeshComponent::Vertex_TAN)* softbody.vertex_tangents_simulation.size())); } // GPU Particle systems simulation/sorting/culling: @@ -4868,24 +4537,24 @@ void EndFrame() void PutWaterRipple(const std::string& image, const XMFLOAT3& pos) { - wiSprite* img = new wiSprite(image); - img->anim.fad = 0.01f; - img->anim.scaleX = 0.2f; - img->anim.scaleY = 0.2f; - img->params.pos = pos; - img->params.rotation = (wiRandom::getRandom(0, 1000)*0.001f) * 2 * 3.1415f; - img->params.siz = XMFLOAT2(1, 1); - img->params.typeFlag = WORLD; - img->params.quality = QUALITY_ANISOTROPIC; - img->params.pivot = XMFLOAT2(0.5f, 0.5f); - img->params.lookAt = waterPlane; - img->params.lookAt.w = 1; + wiSprite img(image); + img.anim.fad = 0.01f; + img.anim.scaleX = 0.2f; + img.anim.scaleY = 0.2f; + img.params.pos = pos; + img.params.rotation = (wiRandom::getRandom(0, 1000)*0.001f) * 2 * 3.1415f; + img.params.siz = XMFLOAT2(1, 1); + img.params.typeFlag = WORLD; + img.params.quality = QUALITY_ANISOTROPIC; + img.params.pivot = XMFLOAT2(0.5f, 0.5f); + img.params.lookAt = waterPlane; + img.params.lookAt.w = 1; waterRipples.push_back(img); } void ManageWaterRipples(){ while ( !waterRipples.empty() && - (waterRipples.front()->params.opacity <= 0 + FLT_EPSILON || waterRipples.front()->params.fade == 1) + (waterRipples.front().params.opacity <= 0 + FLT_EPSILON || waterRipples.front().params.fade == 1) ) { waterRipples.pop_front(); @@ -4894,9 +4563,9 @@ void ManageWaterRipples(){ void DrawWaterRipples(CommandList cmd) { GetDevice()->EventBegin("Water Ripples", cmd); - for(wiSprite* i:waterRipples) + for(auto& x : waterRipples) { - i->DrawNormal(cmd); + x.DrawNormal(cmd); } GetDevice()->EventEnd(cmd); } @@ -4954,105 +4623,6 @@ void DrawSoftParticles( GetRenderFrameAllocator(cmd).free(sizeof(uint32_t) * emitterCount); } -void DrawDeferredLights( - const CameraComponent& camera, - const Texture& depthbuffer, - const Texture& gbuffer0, - const Texture& gbuffer1, - const Texture& gbuffer2, - CommandList cmd -) -{ - GraphicsDevice* device = GetDevice(); - const FrameCulling& culling = frameCullings.at(&camera); - - const Scene& scene = GetScene(); - - device->EventBegin("DrawDeferredLights", cmd); - auto range = wiProfiler::BeginRangeGPU("Deferred Light Render", cmd); - - BindShadowmaps(PS, cmd); - BindEnvironmentTextures(PS, cmd); - - device->BindResource(PS, &depthbuffer, TEXSLOT_DEPTH, cmd); - device->BindResource(PS, &gbuffer0, TEXSLOT_GBUFFER0, cmd); - device->BindResource(PS, &gbuffer1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(PS, &gbuffer2, TEXSLOT_GBUFFER2, cmd); - - // Environmental light (envmap + voxelGI) is always drawn - { - device->BindPipelineState(&PSO_enviromentallight, cmd); - device->Draw(3, 0, cmd); // full screen triangle - } - - for (int type = 0; type < LightComponent::LIGHTTYPE_COUNT; ++type) - { - device->BindPipelineState(&PSO_deferredlight[type], cmd); - - for (size_t i = 0; i < culling.culledLights.size(); ++i) - { - const uint32_t lightIndex = culling.culledLights[i]; - const LightComponent& light = scene.lights[lightIndex]; - if (light.GetType() != type || light.IsStatic()) - continue; - - switch (type) - { - case LightComponent::DIRECTIONAL: - case LightComponent::SPHERE: - case LightComponent::DISC: - case LightComponent::RECTANGLE: - case LightComponent::TUBE: - { - MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); - device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, cmd); - device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - - device->Draw(3, 0, cmd); // full screen triangle - } - break; - case LightComponent::POINT: - { - MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); - float sca = light.GetRange() + 1; - XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection()); - device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, cmd); - device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - - device->Draw(240, 0, cmd); // icosphere - } - break; - case LightComponent::SPOT: - { - MiscCB miscCb; - miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); - const float coneS = (const float)(light.fov / XM_PIDIV4); - XMStoreFloat4x4(&miscCb.g_xTransform, - XMMatrixScaling(coneS*light.GetRange(), light.GetRange(), coneS*light.GetRange())* - XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))* - XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * - camera.GetViewProjection() - ); - device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, cmd); - device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - - device->Draw(192, 0, cmd); // cone - } - break; - } - } - - - } - - wiProfiler::EndRange(range); - device->EventEnd(cmd); -} void DrawLightVisualizers( const CameraComponent& camera, CommandList cmd @@ -5795,7 +5365,7 @@ void DrawScene( if (transparent) { - if (renderPass == RENDERPASS_TILEDFORWARD) + if (renderPass == RENDERPASS_MAIN) { device->BindResource(PS, &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], SBSLOT_ENTITYTILES, cmd); } @@ -5806,7 +5376,7 @@ void DrawScene( } else { - if (renderPass == RENDERPASS_TILEDFORWARD) + if (renderPass == RENDERPASS_MAIN) { device->BindResource(PS, &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], SBSLOT_ENTITYTILES, cmd); } @@ -5814,15 +5384,7 @@ void DrawScene( if (hairparticle) { - const bool alphacomposition = GetAlphaCompositionEnabled(); - - if (!transparent && alphacomposition) - { - // cut off most transparent areas in opaque pass (if alpha composition enabled) - SetAlphaRef(0.25f, cmd); - } - - if (!transparent || alphacomposition) + if (!transparent) { // transparent pass only renders hair when alpha composition enabled for (uint32_t hairIndex : culling.culledHairs) @@ -5831,14 +5393,7 @@ void DrawScene( Entity entity = scene.hairs.GetEntity(hairIndex); const MaterialComponent& material = *scene.materials.GetComponent(entity); - if (renderPass == RENDERPASS_FORWARD) - { - ForwardEntityMaskCB cb = ForwardEntityCullingCPU(culling, hair.aabb, renderPass); - device->UpdateBuffer(&constantBuffers[CBTYPE_FORWARDENTITYMASK], &cb, cmd); - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_FORWARDENTITYMASK], CB_GETBINDSLOT(ForwardEntityMaskCB), cmd); - } - - hair.Draw(camera, material, renderPass, transparent, cmd); + hair.Draw(camera, material, renderPass, cmd); } } } @@ -6990,69 +6545,6 @@ void DrawSun(CommandList cmd) device->EventEnd(cmd); } -void DrawDeferredDecals( - const CameraComponent& camera, - const Texture& depthbuffer, - CommandList cmd -) -{ - const FrameCulling& culling = frameCullings.at(&camera); - - if(!culling.culledDecals.empty()) - { - GraphicsDevice* device = GetDevice(); - - device->EventBegin("DrawDeferredDecals", cmd); - - const Scene& scene = GetScene(); - - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_DECAL], CB_GETBINDSLOT(DecalCB),cmd); - - device->BindStencilRef(STENCILREF_DEFAULT, cmd); - - device->BindPipelineState(&PSO_decal, cmd); - - device->BindResource(PS, &depthbuffer, TEXSLOT_DEPTH, cmd); - - for (size_t decalIndex : culling.culledDecals) - { - const DecalComponent& decal = scene.decals[decalIndex]; - const AABB& aabb = scene.aabb_decals[decalIndex]; - - if ((decal.texture != nullptr || decal.normal != nullptr) && camera.frustum.CheckBoxFast(aabb)) - { - - device->BindResource(PS, decal.texture != nullptr ? decal.texture->texture : nullptr, TEXSLOT_ONDEMAND0, cmd); - device->BindResource(PS, decal.normal != nullptr ? decal.normal->texture : nullptr, TEXSLOT_ONDEMAND1, cmd); - - XMMATRIX decalWorld = XMLoadFloat4x4(&decal.world); - - MiscCB dcbvs; - XMStoreFloat4x4(&dcbvs.g_xTransform, decalWorld*camera.GetViewProjection()); - device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &dcbvs, cmd); - device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), cmd); - - DecalCB dcbps; - XMStoreFloat4x4(&dcbps.xDecalVP, XMMatrixInverse(nullptr, decalWorld)); // todo: cache the inverse! - dcbps.hasTexNor = 0; - if (decal.texture != nullptr) - dcbps.hasTexNor |= 0x0000001; - if (decal.normal != nullptr) - dcbps.hasTexNor |= 0x0000010; - XMStoreFloat3(&dcbps.eye, camera.GetEye()); - dcbps.opacity = decal.GetOpacity(); - dcbps.front = decal.front; - device->UpdateBuffer(&constantBuffers[CBTYPE_DECAL], &dcbps, cmd); - - device->Draw(14, 0, cmd); - - } - - } - - device->EventEnd(cmd); - } -} static const uint32_t envmapCount = 16; static const uint32_t envmapRes = 128; @@ -7129,6 +6621,7 @@ void ManageEnvProbes() desc.MipLevels = 1; desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; desc.Usage = USAGE_DEFAULT; + desc.layout = IMAGE_LAYOUT_DEPTHSTENCIL; device->CreateTexture(&desc, nullptr, &envrenderingDepthBuffer); @@ -7141,6 +6634,7 @@ void ManageEnvProbes() desc.MipLevels = envmapMIPs; desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; desc.Usage = USAGE_DEFAULT; + desc.layout = IMAGE_LAYOUT_GENERAL; device->CreateTexture(&desc, nullptr, &textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]); @@ -7463,6 +6957,7 @@ void RefreshImpostors(CommandList cmd) &mesh.vertexBuffer_UV1, &mesh.vertexBuffer_ATL, &mesh.vertexBuffer_COL, + &mesh.vertexBuffer_TAN, mesh.streamoutBuffer_POS.IsValid() ? &mesh.streamoutBuffer_POS : &mesh.vertexBuffer_POS, mem.buffer }; @@ -7472,6 +6967,7 @@ void RefreshImpostors(CommandList cmd) sizeof(MeshComponent::Vertex_TEX), sizeof(MeshComponent::Vertex_TEX), sizeof(MeshComponent::Vertex_COL), + sizeof(MeshComponent::Vertex_TAN), sizeof(MeshComponent::Vertex_POS), sizeof(InstBuf) }; @@ -7482,6 +6978,7 @@ void RefreshImpostors(CommandList cmd) 0, 0, 0, + 0, mem.offset }; device->BindVertexBuffers(vbs, 0, arraysize(vbs), strides, offsets, cmd); @@ -7746,15 +7243,9 @@ inline XMUINT3 GetEntityCullingTileCount() } void ComputeTiledLightCulling( const Texture& depthbuffer, - CommandList cmd, - const Texture* gbuffer0, - const Texture* gbuffer1, - const Texture* gbuffer2, - const Texture* lightbuffer_diffuse, - const Texture* lightbuffer_specular + CommandList cmd ) { - const bool deferred = lightbuffer_diffuse != nullptr && lightbuffer_specular != nullptr; auto range = wiProfiler::BeginRangeGPU("Entity Culling", cmd); GraphicsDevice* device = GetDevice(); @@ -7868,7 +7359,7 @@ void ComputeTiledLightCulling( device->BindResource(CS, &frustumBuffer, SBSLOT_TILEFRUSTUMS, cmd); - device->BindComputeShader(&tiledLightingCS[deferred][GetAdvancedLightCulling()][GetDebugLightCulling()], cmd); + device->BindComputeShader(&tiledLightingCS[GetAdvancedLightCulling()][GetDebugLightCulling()], cmd); if (GetDebugLightCulling()) { @@ -7893,38 +7384,14 @@ void ComputeTiledLightCulling( device->BindResource(CS, &depthbuffer, TEXSLOT_DEPTH, cmd); - if (deferred) - { - const GPUResource* uavs[] = { - &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], - lightbuffer_diffuse, - lightbuffer_specular, - }; - device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); - - const GPUResource* res[] = { - gbuffer0, - gbuffer1, - gbuffer2, - }; - device->BindResources(CS, res, TEXSLOT_GBUFFER0, arraysize(res), cmd); - - BindShadowmaps(CS, cmd); - BindEnvironmentTextures(CS, cmd); - - device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, cmd); - } - else - { - GPUResource* uavs[] = { - &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], - &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], - }; - device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); - - device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, cmd); - } + GPUResource* uavs[] = { + &resourceBuffers[RBTYPE_ENTITYTILES_TRANSPARENT], + &resourceBuffers[RBTYPE_ENTITYTILES_OPAQUE], + }; + device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); + device->Dispatch(dispatchParams.xDispatchParams_numThreadGroups.x, dispatchParams.xDispatchParams_numThreadGroups.y, dispatchParams.xDispatchParams_numThreadGroups.z, cmd); + GPUBarrier barriers[] = { GPUBarrier::Memory(), }; @@ -9078,11 +8545,7 @@ void RefreshLightmapAtlas(CommandList cmd) const Texture* GetGlobalLightmap() { - if (globalLightmap.IsValid()) - { - return &globalLightmap; - } - return wiTextureHelper::getTransparent(); + return &globalLightmap; } void BindCommonResources(CommandList cmd) @@ -9285,6 +8748,12 @@ void UpdateCameraCB(const CameraComponent& camera, CommandList cmd) cb.g_xCamera_ZRange = abs(cb.g_xCamera_ZFarP - cb.g_xCamera_ZNearP); cb.g_xCamera_ZRange_rcp = 1.0f / std::max(0.0001f, cb.g_xCamera_ZRange); + static_assert(arraysize(camera.frustum.planes) == arraysize(cb.g_xCamera_FrustumPlanes), "Mismatch!"); + for (int i = 0; i < arraysize(camera.frustum.planes); ++i) + { + cb.g_xCamera_FrustumPlanes[i] = camera.frustum.planes[i]; + } + GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_CAMERA], &cb, cmd); } @@ -9302,32 +8771,6 @@ void SetAlphaRef(float alphaRef, CommandList cmd) GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_API], &apiCB[cmd], cmd); } } -void BindGBufferTextures(const Texture* slot0, const Texture* slot1, const Texture* slot2, CommandList cmd) -{ - GraphicsDevice* device = GetDevice(); - - device->BindResource(PS, slot0, TEXSLOT_GBUFFER0, cmd); - device->BindResource(PS, slot1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(PS, slot2, TEXSLOT_GBUFFER2, cmd); - - device->BindResource(CS, slot0, TEXSLOT_GBUFFER0, cmd); - device->BindResource(CS, slot1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(CS, slot2, TEXSLOT_GBUFFER2, cmd); -} -void BindDepthTextures(const Texture* depth, const Texture* linearDepth, CommandList cmd) -{ - GraphicsDevice* device = GetDevice(); - - device->BindResource(PS, depth, TEXSLOT_DEPTH, cmd); - device->BindResource(VS, depth, TEXSLOT_DEPTH, cmd); - device->BindResource(GS, depth, TEXSLOT_DEPTH, cmd); - device->BindResource(CS, depth, TEXSLOT_DEPTH, cmd); - - device->BindResource(PS, linearDepth, TEXSLOT_LINEARDEPTH, cmd); - device->BindResource(VS, linearDepth, TEXSLOT_LINEARDEPTH, cmd); - device->BindResource(GS, linearDepth, TEXSLOT_LINEARDEPTH, cmd); - device->BindResource(CS, linearDepth, TEXSLOT_LINEARDEPTH, cmd); -} const Texture* ComputeLuminance(const Texture& sourceImage, CommandList cmd) { @@ -9415,7 +8858,7 @@ const Texture* ComputeLuminance(const Texture& sourceImage, CommandList cmd) } void ComputeShadingRateClassification( - const Texture& gbuffer1, + const Texture gbuffer[GBUFFER_COUNT], const Texture& lineardepth, const Texture& output, CommandList cmd @@ -9436,7 +8879,7 @@ void ComputeShadingRateClassification( device->BindComputeShader(&computeShaders[CSTYPE_SHADINGRATECLASSIFICATION], cmd); } - device->BindResource(CS, &gbuffer1, TEXSLOT_GBUFFER1, cmd); + device->BindResource(CS, &gbuffer[GBUFFER_NORMAL_VELOCITY], TEXSLOT_GBUFFER1, cmd); device->BindResource(CS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd); const TextureDesc& desc = output.GetDesc(); @@ -9474,12 +8917,7 @@ void ComputeShadingRateClassification( } void DeferredComposition( - const Texture& gbuffer0, - const Texture& gbuffer1, - const Texture& gbuffer2, - const Texture& lightmap_diffuse, - const Texture& lightmap_specular, - const Texture& ao, + const Texture gbuffer[GBUFFER_COUNT], const Texture& depth, CommandList cmd ) @@ -9490,12 +8928,9 @@ void DeferredComposition( device->BindPipelineState(&PSO_deferredcomposition, cmd); - device->BindResource(PS, &gbuffer0, TEXSLOT_GBUFFER0, cmd); - device->BindResource(PS, &gbuffer1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(PS, &gbuffer2, TEXSLOT_GBUFFER2, cmd); - device->BindResource(PS, &lightmap_diffuse, TEXSLOT_ONDEMAND0, cmd); - device->BindResource(PS, &lightmap_specular, TEXSLOT_ONDEMAND1, cmd); - device->BindResource(PS, &ao, TEXSLOT_ONDEMAND2, cmd); + device->BindResource(PS, &gbuffer[GBUFFER_ALBEDO_ROUGHNESS], TEXSLOT_GBUFFER0, cmd); + device->BindResource(PS, &gbuffer[GBUFFER_LIGHTBUFFER_DIFFUSE], TEXSLOT_ONDEMAND0, cmd); + device->BindResource(PS, &gbuffer[GBUFFER_LIGHTBUFFER_SPECULAR], TEXSLOT_ONDEMAND1, cmd); device->BindResource(PS, &depth, TEXSLOT_DEPTH, cmd); device->Draw(3, 0, cmd); @@ -10374,6 +9809,7 @@ void Postprocess_MSAO( void Postprocess_RTAO( const Texture& depthbuffer, const Texture& lineardepth, + const Texture& depth_history, const Texture& output, CommandList cmd, float range, @@ -10589,6 +10025,7 @@ void Postprocess_RTAO( device->BindResource(CS, &depthbuffer, TEXSLOT_DEPTH, cmd); device->BindResource(CS, &temp, TEXSLOT_ONDEMAND0, cmd); device->BindResource(CS, &temporal[temporal_history], TEXSLOT_ONDEMAND1, cmd); + device->BindResource(CS, &depth_history, TEXSLOT_ONDEMAND2, cmd); const GPUResource* uavs[] = { &temporal[temporal_output], @@ -10693,8 +10130,7 @@ void Postprocess_RTAO( } void Postprocess_RTReflection( const Texture& depthbuffer, - const Texture& gbuffer1, - const Texture& gbuffer2, + const Texture gbuffer[GBUFFER_COUNT], const Texture& output, CommandList cmd, float range @@ -10746,8 +10182,8 @@ void Postprocess_RTReflection( descriptorTable.resources.push_back({ RWTEXTURE2D, 0 }); descriptorTable.resources.push_back({ ACCELERATIONSTRUCTURE, TEXSLOT_ACCELERATION_STRUCTURE }); descriptorTable.resources.push_back({ TEXTURE2D, TEXSLOT_DEPTH }); + descriptorTable.resources.push_back({ TEXTURE2D, TEXSLOT_GBUFFER0 }); descriptorTable.resources.push_back({ TEXTURE2D, TEXSLOT_GBUFFER1 }); - descriptorTable.resources.push_back({ TEXTURE2D, TEXSLOT_GBUFFER2 }); descriptorTable.resources.push_back({ TEXTURECUBEARRAY, TEXSLOT_ENVMAPARRAY }); descriptorTable.resources.push_back({ TEXTURE2DARRAY, TEXSLOT_SHADOWARRAY_2D }); descriptorTable.resources.push_back({ TEXTURECUBEARRAY, TEXSLOT_SHADOWARRAY_CUBE }); @@ -10839,8 +10275,8 @@ void Postprocess_RTReflection( device->WriteDescriptor(&descriptorTable, 0, 0, &temp); device->WriteDescriptor(&descriptorTable, 1, 0, &scene.TLAS); device->WriteDescriptor(&descriptorTable, 2, 0, &depthbuffer); - device->WriteDescriptor(&descriptorTable, 3, 0, &gbuffer1); - device->WriteDescriptor(&descriptorTable, 4, 0, &gbuffer2); + device->WriteDescriptor(&descriptorTable, 3, 0, &gbuffer[GBUFFER_ALBEDO_ROUGHNESS]); + device->WriteDescriptor(&descriptorTable, 4, 0, &gbuffer[GBUFFER_NORMAL_VELOCITY]); device->WriteDescriptor(&descriptorTable, 5, 0, &textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]); device->WriteDescriptor(&descriptorTable, 6, 0, &shadowMapArray_2D); device->WriteDescriptor(&descriptorTable, 7, 0, &shadowMapArray_Cube); @@ -10967,8 +10403,7 @@ void Postprocess_SSR( const Texture& input, const Texture& depthbuffer, const Texture& lineardepth, - const Texture& gbuffer1, - const Texture& gbuffer2, + const Texture gbuffer[GBUFFER_COUNT], const Texture& output, CommandList cmd ) @@ -11033,8 +10468,8 @@ void Postprocess_SSR( device->BindResource(CS, &depthbuffer, TEXSLOT_DEPTH, cmd); device->BindResource(CS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd); - device->BindResource(CS, &gbuffer1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(CS, &gbuffer2, TEXSLOT_GBUFFER2, cmd); + device->BindResource(CS, &gbuffer[GBUFFER_ALBEDO_ROUGHNESS], TEXSLOT_GBUFFER0, cmd); + device->BindResource(CS, &gbuffer[GBUFFER_NORMAL_VELOCITY], TEXSLOT_GBUFFER1, cmd); device->BindResource(CS, &input, TEXSLOT_ONDEMAND0, cmd); const GPUResource* uavs[] = { @@ -11073,8 +10508,7 @@ void Postprocess_SSR( device->BindComputeShader(&computeShaders[CSTYPE_POSTPROCESS_SSR_RESOLVE], cmd); device->BindResource(CS, &depthbuffer, TEXSLOT_DEPTH, cmd); - device->BindResource(CS, &gbuffer1, TEXSLOT_GBUFFER1, cmd); - device->BindResource(CS, &gbuffer2, TEXSLOT_GBUFFER2, cmd); + device->BindResource(CS, &gbuffer[GBUFFER_NORMAL_VELOCITY], TEXSLOT_GBUFFER1, cmd); device->BindResource(CS, &texture_raytrace, TEXSLOT_ONDEMAND0, cmd); device->BindResource(CS, &texture_mask, TEXSLOT_ONDEMAND1, cmd); device->BindResource(CS, &input, TEXSLOT_ONDEMAND2, cmd); @@ -11167,11 +10601,12 @@ void Postprocess_SSR( } void Postprocess_SSS( const Texture& lineardepth, - const Texture& gbuffer0, + const Texture gbuffer[GBUFFER_COUNT], const RenderPass& input_output_lightbuffer_diffuse, const RenderPass& input_output_temp1, const RenderPass& input_output_temp2, - CommandList cmd + CommandList cmd, + float amount ) { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -11179,71 +10614,93 @@ void Postprocess_SSS( device->EventBegin("Postprocess_SSS", cmd); auto range = wiProfiler::BeginRangeGPU("SSS", cmd); - device->BindStencilRef(STENCILREF_SKIN, cmd); - device->BindPipelineState(&PSO_sss, cmd); - device->BindResource(PS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd); - device->BindResource(PS, &gbuffer0, TEXSLOT_GBUFFER0, cmd); - const RenderPass* rt_read = &input_output_lightbuffer_diffuse; - const RenderPass* rt_write = &input_output_temp1; - - static int sssPassCount = 6; - for (int i = 0; i < sssPassCount; ++i) + for (uint32_t stencilref = STENCILREF_SKIN; stencilref <= STENCILREF_SNOW; ++stencilref) { - device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd); + device->BindStencilRef(stencilref, cmd); - if (i == sssPassCount - 1) + switch (stencilref) { - // last pass will write into light buffer, but still use the previous ping-pong result: - rt_write = &input_output_lightbuffer_diffuse; + case STENCILREF_SKIN: + device->BindPipelineState(&PSO_sss_skin, cmd); + break; + case STENCILREF_SNOW: + device->BindPipelineState(&PSO_sss_snow, cmd); + break; + default: + assert(0); + break; } - const TextureDesc& desc = rt_write->GetDesc().attachments[0].texture->GetDesc(); + const RenderPass* rt_read = &input_output_lightbuffer_diffuse; + const RenderPass* rt_write = &input_output_temp1; - device->RenderPassBegin(rt_write, cmd); - - Viewport vp; - vp.Width = (float)desc.Width; - vp.Height = (float)desc.Height; - device->BindViewports(1, &vp, cmd); - - - PostProcessCB cb; - cb.xPPResolution.x = desc.Width; - cb.xPPResolution.y = desc.Height; - cb.xPPResolution_rcp.x = 1.0f / cb.xPPResolution.x; - cb.xPPResolution_rcp.y = 1.0f / cb.xPPResolution.y; - const float blur_strength = 400.0f; - if (i % 2 == 0) + static int sssPassCount = 6; + for (int i = 0; i < sssPassCount; ++i) { - cb.xPPParams0.x = blur_strength * cb.xPPResolution_rcp.x; - cb.xPPParams0.y = 0; - } - else - { - cb.xPPParams0.x = 0; - cb.xPPParams0.y = blur_strength * cb.xPPResolution_rcp.y; - } - device->UpdateBuffer(&constantBuffers[CBTYPE_POSTPROCESS], &cb, cmd); - device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_POSTPROCESS], CB_GETBINDSLOT(PostProcessCB), cmd); + device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd); - device->BindResource(PS, rt_read->GetDesc().attachments[0].texture, TEXSLOT_ONDEMAND0, cmd); + if (i == sssPassCount - 1) + { + // last pass will write into light buffer, but still use the previous ping-pong result: + rt_write = &input_output_lightbuffer_diffuse; + } - device->Draw(3, 0, cmd); + const TextureDesc& desc = rt_write->GetDesc().attachments[0].texture->GetDesc(); - device->RenderPassEnd(cmd); + device->RenderPassBegin(rt_write, cmd); - if (i == 0) - { - // first pass was reading from lightbuffer, so correct here for next pass ping-pong: - rt_read = &input_output_temp1; - rt_write = &input_output_temp2; - } - else - { - // ping-pong between temp render targets: - std::swap(rt_read, rt_write); + Viewport vp; + vp.Width = (float)desc.Width; + vp.Height = (float)desc.Height; + device->BindViewports(1, &vp, cmd); + + + PostProcessCB cb; + cb.xPPResolution.x = desc.Width; + cb.xPPResolution.y = desc.Height; + cb.xPPResolution_rcp.x = 1.0f / cb.xPPResolution.x; + cb.xPPResolution_rcp.y = 1.0f / cb.xPPResolution.y; + const float blur_strength = 400.0f * amount; + if (i % 2 == 0) + { + cb.sss_step.x = blur_strength * cb.xPPResolution_rcp.x; + cb.sss_step.y = 0; + } + else + { + cb.sss_step.x = 0; + cb.sss_step.y = blur_strength * cb.xPPResolution_rcp.y; + } + device->UpdateBuffer(&constantBuffers[CBTYPE_POSTPROCESS], &cb, cmd); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_POSTPROCESS], CB_GETBINDSLOT(PostProcessCB), cmd); + + if (rt_read->GetDesc().attachments.size() > 2) + { + // resolved input! + device->BindResource(PS, rt_read->GetDesc().attachments[2].texture, TEXSLOT_ONDEMAND0, cmd); + } + else + { + device->BindResource(PS, rt_read->GetDesc().attachments[0].texture, TEXSLOT_ONDEMAND0, cmd); + } + + device->Draw(3, 0, cmd); + + device->RenderPassEnd(cmd); + + if (i == 0) + { + // first pass was reading from lightbuffer, so correct here for next pass ping-pong: + rt_read = &input_output_temp1; + rt_write = &input_output_temp2; + } + else + { + // ping-pong between temp render targets: + std::swap(rt_read, rt_write); + } } } @@ -12421,6 +11878,7 @@ void Postprocess_TemporalAA( const Texture& input_history, const Texture& velocity, const Texture& lineardepth, + const Texture& depth_history, const Texture& output, CommandList cmd ) @@ -12434,6 +11892,7 @@ void Postprocess_TemporalAA( device->BindResource(CS, &input_current, TEXSLOT_ONDEMAND0, cmd); device->BindResource(CS, &input_history, TEXSLOT_ONDEMAND1, cmd); + device->BindResource(CS, &depth_history, TEXSLOT_ONDEMAND2, cmd); device->BindResource(CS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd); device->BindResource(CS, &velocity, TEXSLOT_GBUFFER1, cmd); @@ -12856,6 +12315,82 @@ void Postprocess_NormalsFromDepth( device->UnbindUAVs(0, arraysize(uavs), cmd); device->EventEnd(cmd); } +void Postprocess_Denoise( + const Texture& input_output_current, + const Texture& temporal_history, + const Texture& temporal_current, + const Texture& velocity, + const Texture& lineardepth, + const Texture& depth_history, + CommandList cmd +) +{ + GraphicsDevice* device = wiRenderer::GetDevice(); + + device->EventBegin("Postprocess_Denoise", cmd); + device->BindComputeShader(&computeShaders[CSTYPE_POSTPROCESS_DENOISE], cmd); + + const TextureDesc& desc = input_output_current.GetDesc(); + + PostProcessCB cb; + cb.xPPResolution.x = desc.Width; + cb.xPPResolution.y = desc.Height; + cb.xPPResolution_rcp.x = 1.0f / cb.xPPResolution.x; + cb.xPPResolution_rcp.y = 1.0f / cb.xPPResolution.y; + device->UpdateBuffer(&constantBuffers[CBTYPE_POSTPROCESS], &cb, cmd); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_POSTPROCESS], CB_GETBINDSLOT(PostProcessCB), cmd); + + device->BindResource(CS, &velocity, TEXSLOT_GBUFFER1, cmd); + + { + device->BindResource(CS, &input_output_current, TEXSLOT_ONDEMAND0, cmd); + device->BindResource(CS, &temporal_history, TEXSLOT_ONDEMAND1, cmd); + device->BindResource(CS, &depth_history, TEXSLOT_ONDEMAND2, cmd); + device->BindResource(CS, &lineardepth, TEXSLOT_LINEARDEPTH, cmd); + + const GPUResource* uavs[] = { + &temporal_current, + }; + device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); + + device->Dispatch( + (desc.Width + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE, + (desc.Height + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE, + 1, + cmd + ); + + GPUBarrier barriers[] = { + GPUBarrier::Memory(), + }; + device->Barrier(barriers, arraysize(barriers), cmd); + device->UnbindUAVs(0, arraysize(uavs), cmd); + } + { + device->BindResource(CS, &temporal_current, TEXSLOT_ONDEMAND0, cmd); + device->BindResource(CS, &temporal_history, TEXSLOT_ONDEMAND1, cmd); + + const GPUResource* uavs[] = { + &input_output_current, + }; + device->BindUAVs(CS, uavs, 0, arraysize(uavs), cmd); + + device->Dispatch( + (desc.Width + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE, + (desc.Height + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE, + 1, + cmd + ); + + GPUBarrier barriers[] = { + GPUBarrier::Memory(), + }; + device->Barrier(barriers, arraysize(barriers), cmd); + device->UnbindUAVs(0, arraysize(uavs), cmd); + } + + device->EventEnd(cmd); +} const XMFLOAT4& GetWaterPlane() { @@ -12977,8 +12512,6 @@ void SetVariableRateShadingClassification(bool enabled) { variableRateShadingCla bool GetVariableRateShadingClassification() { return variableRateShadingClassification; } void SetVariableRateShadingClassificationDebug(bool enabled) { variableRateShadingClassificationDebug = enabled; } bool GetVariableRateShadingClassificationDebug() { return variableRateShadingClassificationDebug; } -void SetAlphaCompositionEnabled(bool enabled) { ALPHACOMPOSITIONENABLED = enabled; } -bool GetAlphaCompositionEnabled() { return ALPHACOMPOSITIONENABLED; } void SetOcclusionCullingEnabled(bool value) { static bool initialized = false; diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 601a95288..af690a97f 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -108,22 +108,13 @@ namespace wiRenderer void DrawShadowmaps(const wiScene::CameraComponent& camera, wiGraphics::CommandList cmd, uint32_t layerMask = ~0); // Draw debug world. You must also enable what parts to draw, eg. SetToDrawGridHelper, etc, see implementation for details what can be enabled. void DrawDebugWorld(const wiScene::CameraComponent& camera, wiGraphics::CommandList cmd); - // Draw Soft offscreen particles. Linear depth should be already readable (see BindDepthTextures()) + // Draw Soft offscreen particles. void DrawSoftParticles( const wiScene::CameraComponent& camera, const wiGraphics::Texture& lineardepth, bool distortion, wiGraphics::CommandList cmd ); - // Draw deferred lights. Gbuffer and depth textures should already be readable (see BindGBufferTextures(), BindDepthTextures()) - void DrawDeferredLights( - const wiScene::CameraComponent& camera, - const wiGraphics::Texture& depthbuffer, - const wiGraphics::Texture& gbuffer0, - const wiGraphics::Texture& gbuffer1, - const wiGraphics::Texture& gbuffer2, - wiGraphics::CommandList cmd - ); // Draw simple light visualizer geometries void DrawLightVisualizers( const wiScene::CameraComponent& camera, @@ -141,12 +132,6 @@ namespace wiRenderer const wiGraphics::Texture& depthbuffer, wiGraphics::CommandList cmd ); - // Draw deferred decals - void DrawDeferredDecals( - const wiScene::CameraComponent& camera, - const wiGraphics::Texture& depthbuffer, - wiGraphics::CommandList cmd - ); // Call once per frame to re-render out of date environment probes void RefreshEnvProbes(wiGraphics::CommandList cmd); // Call once per frame to re-render out of date impostors @@ -157,16 +142,10 @@ namespace wiRenderer void RefreshLightmapAtlas(wiGraphics::CommandList cmd); // Voxelize the scene into a voxel grid 3D texture void VoxelRadiance(wiGraphics::CommandList cmd); - // Compute light grid tiles for tiled rendering paths - // If you specify lightbuffers (diffuse, specular), then a tiled deferred lighting will be computed as well. Otherwise, only the light grid gets computed + // Compute light grid tiles void ComputeTiledLightCulling( const wiGraphics::Texture& depthbuffer, - wiGraphics::CommandList cmd, - const wiGraphics::Texture* gbuffer0 = nullptr, - const wiGraphics::Texture* gbuffer1 = nullptr, - const wiGraphics::Texture* gbuffer2 = nullptr, - const wiGraphics::Texture* lightbuffer_diffuse = nullptr, - const wiGraphics::Texture* lightbuffer_specular = nullptr + wiGraphics::CommandList cmd ); // Run a compute shader that will resolve a MSAA depth buffer to a single-sample texture void ResolveMSAADepthBuffer(const wiGraphics::Texture& dst, const wiGraphics::Texture& src, wiGraphics::CommandList cmd); @@ -175,24 +154,18 @@ namespace wiRenderer const wiGraphics::Texture* ComputeLuminance(const wiGraphics::Texture& sourceImage, wiGraphics::CommandList cmd); void ComputeShadingRateClassification( - const wiGraphics::Texture& gbuffer1, + const wiGraphics::Texture gbuffer[GBUFFER_COUNT], const wiGraphics::Texture& lineardepth, const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void DeferredComposition( - const wiGraphics::Texture& gbuffer0, - const wiGraphics::Texture& gbuffer1, - const wiGraphics::Texture& gbuffer2, - const wiGraphics::Texture& lightmap_diffuse, - const wiGraphics::Texture& lightmap_specular, - const wiGraphics::Texture& ao, + const wiGraphics::Texture gbuffer[GBUFFER_COUNT], const wiGraphics::Texture& depth, wiGraphics::CommandList cmd ); - void Postprocess_Blur_Gaussian( const wiGraphics::Texture& input, const wiGraphics::Texture& temp, @@ -237,6 +210,7 @@ namespace wiRenderer void Postprocess_RTAO( const wiGraphics::Texture& depthbuffer, const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& depth_history, const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float range = 1.0f, @@ -245,8 +219,7 @@ namespace wiRenderer ); void Postprocess_RTReflection( const wiGraphics::Texture& depthbuffer, - const wiGraphics::Texture& gbuffer1, - const wiGraphics::Texture& gbuffer2, + const wiGraphics::Texture gbuffer[GBUFFER_COUNT], const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float range = 1000.0f @@ -255,18 +228,18 @@ namespace wiRenderer const wiGraphics::Texture& input, const wiGraphics::Texture& depthbuffer, const wiGraphics::Texture& lineardepth, - const wiGraphics::Texture& gbuffer1, - const wiGraphics::Texture& gbuffer2, + const wiGraphics::Texture gbuffer[GBUFFER_COUNT], const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_SSS( const wiGraphics::Texture& lineardepth, - const wiGraphics::Texture& gbuffer0, + const wiGraphics::Texture gbuffer[GBUFFER_COUNT], const wiGraphics::RenderPass& input_output_lightbuffer_diffuse, const wiGraphics::RenderPass& input_output_temp1, const wiGraphics::RenderPass& input_output_temp2, - wiGraphics::CommandList cmd + wiGraphics::CommandList cmd, + float amount = 1.0f ); void Postprocess_LightShafts( const wiGraphics::Texture& input, @@ -325,6 +298,7 @@ namespace wiRenderer const wiGraphics::Texture& input_history, const wiGraphics::Texture& velocity, const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& depth_history, const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); @@ -373,6 +347,15 @@ namespace wiRenderer const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); + void Postprocess_Denoise( + const wiGraphics::Texture& input_output_current, + const wiGraphics::Texture& temporal_history, + const wiGraphics::Texture& temporal_current, + const wiGraphics::Texture& velocity, + const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& depth_history, + wiGraphics::CommandList cmd + ); // Build the scene BVH on GPU that can be used by ray traced rendering void BuildSceneBVH(wiGraphics::CommandList cmd); @@ -495,8 +478,6 @@ namespace wiRenderer bool GetVariableRateShadingClassification(); void SetVariableRateShadingClassificationDebug(bool enabled); bool GetVariableRateShadingClassificationDebug(); - void SetAlphaCompositionEnabled(bool enabled); - bool GetAlphaCompositionEnabled(); void SetOcclusionCullingEnabled(bool enabled); bool GetOcclusionCullingEnabled(); void SetLDSSkinningEnabled(bool enabled); @@ -607,13 +588,8 @@ namespace wiRenderer struct CustomShader { std::string name; - - struct Pass - { - uint32_t renderTypeFlags = RENDERTYPE_TRANSPARENT; - wiGraphics::PipelineState* pso = nullptr; - }; - Pass passes[RENDERPASS_COUNT] = {}; + uint32_t renderTypeFlags = RENDERTYPE_OPAQUE; + wiGraphics::PipelineState pso[RENDERPASS_COUNT] = {}; }; // Registers a custom shader that can be set to materials. // Returns the ID of the custom shader that can be used with MaterialComponent::SetCustomShaderID() diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 79b51cb42..5cf9aeab1 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -95,15 +95,6 @@ namespace wiRenderer_BindLua return 0; } - int SetAlphaCompositionEnabled(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - wiRenderer::SetAlphaCompositionEnabled(wiLua::SGetBool(L, 1)); - } - return 0; - } int SetShadowProps2D(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -422,7 +413,6 @@ namespace wiRenderer_BindLua wiLua::RegisterFunc("GetCamera", GetCamera); wiLua::RegisterFunc("AttachCamera", AttachCamera); - wiLua::RegisterFunc("SetAlphaCompositionEnabled", SetAlphaCompositionEnabled); wiLua::RegisterFunc("SetShadowProps2D", SetShadowProps2D); wiLua::RegisterFunc("SetShadowPropsCube", SetShadowPropsCube); wiLua::RegisterFunc("SetDebugBoxesEnabled", SetDebugBoxesEnabled); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 8592d99ab..d754dd531 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -271,55 +271,67 @@ namespace wiScene } return wiTextureHelper::getWhite(); } - ShaderMaterial MaterialComponent::CreateShaderMaterial() const + void MaterialComponent::WriteShaderMaterial(ShaderMaterial* dest) const { - ShaderMaterial retVal; - retVal.baseColor = baseColor; - retVal.emissiveColor = emissiveColor; - retVal.texMulAdd = texMulAdd; - retVal.roughness = roughness; - retVal.reflectance = reflectance; - retVal.metalness = metalness; - retVal.refractionIndex = refractionIndex; - retVal.subsurfaceScattering = subsurfaceScattering; - retVal.normalMapStrength = (normalMap == nullptr ? 0 : normalMapStrength); - retVal.normalMapFlip = (_flags & MaterialComponent::FLIP_NORMALMAP ? -1.0f : 1.0f); - retVal.parallaxOcclusionMapping = parallaxOcclusionMapping; - retVal.displacementMapping = displacementMapping; - retVal.uvset_baseColorMap = baseColorMap == nullptr ? -1 : (int)uvset_baseColorMap; - retVal.uvset_surfaceMap = surfaceMap == nullptr ? -1 : (int)uvset_surfaceMap; - retVal.uvset_normalMap = normalMap == nullptr ? -1 : (int)uvset_normalMap; - retVal.uvset_displacementMap = displacementMap == nullptr ? -1 : (int)uvset_displacementMap; - retVal.uvset_emissiveMap = emissiveMap == nullptr ? -1 : (int)uvset_emissiveMap; - retVal.uvset_occlusionMap = occlusionMap == nullptr ? -1 : (int)uvset_occlusionMap; - retVal.options = 0; + dest->baseColor = baseColor; + dest->emissiveColor = emissiveColor; + dest->texMulAdd = texMulAdd; + dest->roughness = roughness; + dest->reflectance = reflectance; + dest->metalness = metalness; + dest->refractionIndex = refractionIndex; + dest->normalMapStrength = (normalMap == nullptr ? 0 : normalMapStrength); + dest->parallaxOcclusionMapping = parallaxOcclusionMapping; + dest->displacementMapping = displacementMapping; + dest->uvset_baseColorMap = baseColorMap == nullptr ? -1 : (int)uvset_baseColorMap; + dest->uvset_surfaceMap = surfaceMap == nullptr ? -1 : (int)uvset_surfaceMap; + dest->uvset_normalMap = normalMap == nullptr ? -1 : (int)uvset_normalMap; + dest->uvset_displacementMap = displacementMap == nullptr ? -1 : (int)uvset_displacementMap; + dest->uvset_emissiveMap = emissiveMap == nullptr ? -1 : (int)uvset_emissiveMap; + dest->uvset_occlusionMap = occlusionMap == nullptr ? -1 : (int)uvset_occlusionMap; + dest->options = 0; if (IsUsingVertexColors()) { - retVal.options |= SHADERMATERIAL_OPTION_BIT_USE_VERTEXCOLORS; + dest->options |= SHADERMATERIAL_OPTION_BIT_USE_VERTEXCOLORS; } if (IsUsingSpecularGlossinessWorkflow()) { - retVal.options |= SHADERMATERIAL_OPTION_BIT_SPECULARGLOSSINESS_WORKFLOW; + dest->options |= SHADERMATERIAL_OPTION_BIT_SPECULARGLOSSINESS_WORKFLOW; } if (IsOcclusionEnabled_Primary()) { - retVal.options |= SHADERMATERIAL_OPTION_BIT_OCCLUSION_PRIMARY; + dest->options |= SHADERMATERIAL_OPTION_BIT_OCCLUSION_PRIMARY; } if (IsOcclusionEnabled_Secondary()) { - retVal.options |= SHADERMATERIAL_OPTION_BIT_OCCLUSION_SECONDARY; + dest->options |= SHADERMATERIAL_OPTION_BIT_OCCLUSION_SECONDARY; } if (IsUsingWind()) { - retVal.options |= SHADERMATERIAL_OPTION_BIT_USE_WIND; + dest->options |= SHADERMATERIAL_OPTION_BIT_USE_WIND; } - retVal.baseColorAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); - retVal.surfaceMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); - retVal.emissiveMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); - retVal.normalMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); - - return retVal; + dest->baseColorAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); + dest->surfaceMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); + dest->emissiveMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); + dest->normalMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); + } + uint32_t MaterialComponent::GetRenderTypes() const + { + if (IsCustomShader() && customShaderID < (int)wiRenderer::GetCustomShaders().size()) + { + auto& customShader = wiRenderer::GetCustomShaders()[customShaderID]; + return customShader.renderTypeFlags; + } + if (shaderType == SHADERTYPE_WATER) + { + return RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER; + } + if (userBlendMode == BLENDMODE_OPAQUE) + { + return RENDERTYPE_OPAQUE; + } + return RENDERTYPE_TRANSPARENT; } void MeshComponent::CreateRenderData() @@ -401,6 +413,101 @@ namespace wiScene device->SetName(&vertexBuffer_POS, "vertexBuffer_POS"); } + // vertexBuffer - TANGENTS + if(!vertex_uvset_0.empty()) + { + if (vertex_tangents.empty()) + { + // Generate tangents if not found: + vertex_tangents.resize(vertex_positions.size()); + + for (size_t i = 0; i < indices.size(); i += 3) + { + const uint32_t i0 = indices[i + 0]; + const uint32_t i1 = indices[i + 1]; + const uint32_t i2 = indices[i + 2]; + + const XMFLOAT3 v0 = vertex_positions[i0]; + const XMFLOAT3 v1 = vertex_positions[i1]; + const XMFLOAT3 v2 = vertex_positions[i2]; + + const XMFLOAT2 u0 = vertex_uvset_0[i0]; + const XMFLOAT2 u1 = vertex_uvset_0[i1]; + const XMFLOAT2 u2 = vertex_uvset_0[i2]; + + const XMFLOAT3 n0 = vertex_normals[i0]; + const XMFLOAT3 n1 = vertex_normals[i1]; + const XMFLOAT3 n2 = vertex_normals[i2]; + + const XMVECTOR nor0 = XMLoadFloat3(&n0); + const XMVECTOR nor1 = XMLoadFloat3(&n1); + const XMVECTOR nor2 = XMLoadFloat3(&n2); + + const XMVECTOR facenormal = XMVector3Normalize(nor0 + nor1 + nor2); + + const float x1 = v1.x - v0.x; + const float x2 = v2.x - v0.x; + const float y1 = v1.y - v0.y; + const float y2 = v2.y - v0.y; + const float z1 = v1.z - v0.z; + const float z2 = v2.z - v0.z; + + const float s1 = u1.x - u0.x; + const float s2 = u2.x - u0.x; + const float t1 = u1.y - u0.y; + const float t2 = u2.y - u0.y; + + const float r = 1.0f / (s1 * t2 - s2 * t1); + const XMVECTOR sdir = XMVectorSet((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, + (t2 * z1 - t1 * z2) * r, 0); + const XMVECTOR tdir = XMVectorSet((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, + (s1 * z2 - s2 * z1) * r, 0); + + XMVECTOR tangent; + tangent = XMVector3Normalize(sdir - facenormal * XMVector3Dot(facenormal, sdir)); + float sign = XMVectorGetX(XMVector3Dot(XMVector3Cross(tangent, facenormal), tdir)) < 0.0f ? -1.0f : 1.0f; + + XMFLOAT3 t; + XMStoreFloat3(&t, tangent); + + vertex_tangents[i0].x += t.x; + vertex_tangents[i0].y += t.y; + vertex_tangents[i0].z += t.z; + vertex_tangents[i0].w = sign; + + vertex_tangents[i1].x += t.x; + vertex_tangents[i1].y += t.y; + vertex_tangents[i1].z += t.z; + vertex_tangents[i1].w = sign; + + vertex_tangents[i2].x += t.x; + vertex_tangents[i2].y += t.y; + vertex_tangents[i2].z += t.z; + vertex_tangents[i2].w = sign; + } + + } + + std::vector vertices(vertex_tangents.size()); + for (size_t i = 0; i < vertex_tangents.size(); ++i) + { + vertices[i].FromFULL(vertex_tangents[i]); + } + + GPUBufferDesc bd; + bd.Usage = USAGE_IMMUTABLE; + bd.CPUAccessFlags = 0; + bd.BindFlags = BIND_VERTEX_BUFFER | BIND_SHADER_RESOURCE; + bd.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; + bd.StructureByteStride = sizeof(Vertex_TAN); + bd.ByteWidth = (uint32_t)(bd.StructureByteStride * vertices.size()); + + SubresourceData InitData; + InitData.pSysMem = vertices.data(); + device->CreateBuffer(&bd, &InitData, &vertexBuffer_TAN); + device->SetName(&vertexBuffer_TAN, "vertexBuffer_TAN"); + } + aabb = AABB(_min, _max); // skinning buffers: @@ -441,6 +548,10 @@ namespace wiScene bd.ByteWidth = (uint32_t)(sizeof(Vertex_POS) * vertex_positions.size()); device->CreateBuffer(&bd, nullptr, &streamoutBuffer_POS); device->SetName(&streamoutBuffer_POS, "streamoutBuffer_POS"); + + bd.ByteWidth = (uint32_t)(sizeof(Vertex_TAN) * vertex_tangents.size()); + device->CreateBuffer(&bd, nullptr, &streamoutBuffer_TAN); + device->SetName(&streamoutBuffer_TAN, "streamoutBuffer_TAN"); } // vertexBuffer - UV SET 0 @@ -924,6 +1035,8 @@ namespace wiScene } + vertex_tangents.clear(); // <- will be recomputed + CreateRenderData(); // <- normals will be normalized here! } void MeshComponent::FlipCulling() @@ -1024,6 +1137,8 @@ namespace wiScene void SoftBodyPhysicsComponent::CreateFromMesh(const MeshComponent& mesh) { vertex_positions_simulation.resize(mesh.vertex_positions.size()); + vertex_tangents_tmp.resize(mesh.vertex_tangents.size()); + vertex_tangents_simulation.resize(mesh.vertex_tangents.size()); XMMATRIX W = XMLoadFloat4x4(&worldMatrix); XMFLOAT3 _min = XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX); @@ -2203,7 +2318,7 @@ namespace wiScene if (mesh.BLAS.IsValid()) { uint32_t flags = mesh.BLAS.desc.bottomlevel.geometries[subsetIndex]._flags; - if (material->IsAlphaTestEnabled() || material->IsTransparent()) + if (material->IsAlphaTestEnabled() || (material->GetRenderTypes() & RENDERTYPE_TRANSPARENT)) { mesh.BLAS.desc.bottomlevel.geometries[subsetIndex]._flags &= ~RaytracingAccelerationStructureDesc::BottomLevel::Geometry::FLAG_OPAQUE; @@ -2242,10 +2357,19 @@ namespace wiScene } material.engineStencilRef = STENCILREF_DEFAULT; - if (material.subsurfaceScattering > 0) + if (material.IsCustomShader()) + { + material.engineStencilRef = STENCILREF_CUSTOMSHADER; + } + + if (material.subsurfaceProfile == MaterialComponent::SUBSURFACE_SKIN) { material.engineStencilRef = STENCILREF_SKIN; } + else if (material.subsurfaceProfile == MaterialComponent::SUBSURFACE_SNOW) + { + material.engineStencilRef = STENCILREF_SNOW; + } }); } @@ -2316,26 +2440,7 @@ namespace wiScene if (material != nullptr) { - if (material->IsCustomShader()) - { - object.rendertypeMask |= RENDERTYPE_ALL; - } - else - { - if (material->IsTransparent()) - { - object.rendertypeMask |= RENDERTYPE_TRANSPARENT; - } - else - { - object.rendertypeMask |= RENDERTYPE_OPAQUE; - } - - if (material->IsWater()) - { - object.rendertypeMask |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER; - } - } + object.rendertypeMask |= material->GetRenderTypes(); if (material->HasPlanarReflection()) { diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index 5305df4ff..77e65571f 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -110,9 +110,9 @@ namespace wiScene EMPTY = 0, DIRTY = 1 << 0, CAST_SHADOW = 1 << 1, - PLANAR_REFLECTION = 1 << 2, - WATER = 1 << 3, - FLIP_NORMALMAP = 1 << 4, + _DEPRECATED_PLANAR_REFLECTION = 1 << 2, + _DEPRECATED_WATER = 1 << 3, + _DEPRECATED_FLIP_NORMALMAP = 1 << 4, USE_VERTEXCOLORS = 1 << 5, SPECULAR_GLOSSINESS_WORKFLOW = 1 << 6, OCCLUSION_PRIMARY = 1 << 7, @@ -121,6 +121,25 @@ namespace wiScene }; uint32_t _flags = DIRTY | CAST_SHADOW; + enum SHADERTYPE + { + SHADERTYPE_PBR, + SHADERTYPE_PBR_PLANARREFLECTION, + SHADERTYPE_PBR_PARALLAXOCCLUSIONMAPPING, + SHADERTYPE_PBR_ANISOTROPIC, + SHADERTYPE_WATER, + SHADERTYPE_CARTOON, + SHADERTYPE_UNLIT, + SHADERTYPE_COUNT + } shaderType = SHADERTYPE_PBR; + + enum SUBSURFACE_PROFILE + { + SUBSURFACE_SOLID, + SUBSURFACE_SKIN, + SUBSURFACE_SNOW, + } subsurfaceProfile = SUBSURFACE_SOLID; + STENCILREF engineStencilRef = STENCILREF_DEFAULT; uint8_t userStencilRef = 0; BLENDMODE userBlendMode = BLENDMODE_OPAQUE; @@ -132,7 +151,6 @@ namespace wiScene float reflectance = 0.02f; float metalness = 0.0f; float refractionIndex = 0.0f; - float subsurfaceScattering = 0.0f; float normalMapStrength = 1.0f; float parallaxOcclusionMapping = 0.0f; float displacementMapping = 0.0f; @@ -191,22 +209,18 @@ namespace wiScene inline float GetEmissiveStrength() const { return emissiveColor.w; } inline int GetCustomShaderID() const { return customShaderID; } + inline bool HasPlanarReflection() const { return shaderType == SHADERTYPE_PBR_PLANARREFLECTION || shaderType == SHADERTYPE_WATER; } + inline void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } } inline bool IsDirty() const { return _flags & DIRTY; } inline void SetCastShadow(bool value) { if (value) { _flags |= CAST_SHADOW; } else { _flags &= ~CAST_SHADOW; } } - inline void SetPlanarReflections(bool value) { if (value) { _flags |= PLANAR_REFLECTION; } else { _flags &= ~PLANAR_REFLECTION; } } - inline void SetWater(bool value) { if (value) { _flags |= WATER; } else { _flags &= ~WATER; } } inline void SetOcclusionEnabled_Primary(bool value) { SetDirty(); if (value) { _flags |= OCCLUSION_PRIMARY; } else { _flags &= ~OCCLUSION_PRIMARY; } } inline void SetOcclusionEnabled_Secondary(bool value) { SetDirty(); if (value) { _flags |= OCCLUSION_SECONDARY; } else { _flags &= ~OCCLUSION_SECONDARY; } } - inline bool IsTransparent() const { return userBlendMode != BLENDMODE_OPAQUE || IsCustomShader() || IsWater(); } - inline BLENDMODE GetBlendMode() const { if (userBlendMode == BLENDMODE_OPAQUE && IsTransparent()) { return BLENDMODE_ALPHA; } else return userBlendMode; } - inline bool IsWater() const { return _flags & WATER; } - inline bool HasPlanarReflection() const { return (_flags & PLANAR_REFLECTION) || IsWater(); } + inline BLENDMODE GetBlendMode() const { if (userBlendMode == BLENDMODE_OPAQUE && (GetRenderTypes() & RENDERTYPE_TRANSPARENT)) return BLENDMODE_ALPHA; else return userBlendMode; } inline bool IsCastingShadow() const { return _flags & CAST_SHADOW; } inline bool IsAlphaTestEnabled() const { return alphaRef <= 1.0f - 1.0f / 256.0f; } - inline bool IsFlipNormalMap() const { return _flags & FLIP_NORMALMAP; } inline bool IsUsingVertexColors() const { return _flags & USE_VERTEXCOLORS; } inline bool IsUsingWind() const { return _flags & USE_WIND; } inline bool IsUsingSpecularGlossinessWorkflow() const { return _flags & SPECULAR_GLOSSINESS_WORKFLOW; } @@ -221,13 +235,11 @@ namespace wiScene inline void SetMetalness(float value) { SetDirty(); metalness = value; } inline void SetEmissiveStrength(float value) { SetDirty(); emissiveColor.w = value; } inline void SetRefractionIndex(float value) { SetDirty(); refractionIndex = value; } - inline void SetSubsurfaceScattering(float value) { SetDirty(); subsurfaceScattering = value; } inline void SetNormalMapStrength(float value) { SetDirty(); normalMapStrength = value; } inline void SetParallaxOcclusionMapping(float value) { SetDirty(); parallaxOcclusionMapping = value; } inline void SetDisplacementMapping(float value) { SetDirty(); displacementMapping = value; } inline void SetOpacity(float value) { SetDirty(); baseColor.w = value; } inline void SetAlphaRef(float value) { SetDirty(); alphaRef = value; } - inline void SetFlipNormalMap(bool value) { SetDirty(); if (value) { _flags |= FLIP_NORMALMAP; } else { _flags &= ~FLIP_NORMALMAP; } } inline void SetUseVertexColors(bool value) { SetDirty(); if (value) { _flags |= USE_VERTEXCOLORS; } else { _flags &= ~USE_VERTEXCOLORS; } } inline void SetUseWind(bool value) { SetDirty(); if (value) { _flags |= USE_WIND; } else { _flags &= ~USE_WIND; } } inline void SetUseSpecularGlossinessWorkflow(bool value) { SetDirty(); if (value) { _flags |= SPECULAR_GLOSSINESS_WORKFLOW; } else { _flags &= ~SPECULAR_GLOSSINESS_WORKFLOW; } } @@ -240,7 +252,8 @@ namespace wiScene inline void SetUVSet_EmissiveMap(uint32_t value) { uvset_emissiveMap = value; SetDirty(); } inline void SetUVSet_OcclusionMap(uint32_t value) { uvset_occlusionMap = value; SetDirty(); } - ShaderMaterial CreateShaderMaterial() const; + void WriteShaderMaterial(ShaderMaterial* dest) const; + uint32_t GetRenderTypes() const; void Serialize(wiArchive& archive, wiECS::Entity seed = wiECS::INVALID_ENTITY); }; @@ -259,6 +272,7 @@ namespace wiScene std::vector vertex_positions; std::vector vertex_normals; + std::vector vertex_tangents; std::vector vertex_uvset_0; std::vector vertex_uvset_1; std::vector vertex_boneindices; @@ -293,6 +307,7 @@ namespace wiScene AABB aabb; wiGraphics::GPUBuffer indexBuffer; wiGraphics::GPUBuffer vertexBuffer_POS; + wiGraphics::GPUBuffer vertexBuffer_TAN; wiGraphics::GPUBuffer vertexBuffer_UV0; wiGraphics::GPUBuffer vertexBuffer_UV1; wiGraphics::GPUBuffer vertexBuffer_BON; @@ -300,6 +315,7 @@ namespace wiScene wiGraphics::GPUBuffer vertexBuffer_ATL; wiGraphics::GPUBuffer vertexBuffer_PRE; wiGraphics::GPUBuffer streamoutBuffer_POS; + wiGraphics::GPUBuffer streamoutBuffer_TAN; wiGraphics::GPUBuffer vertexBuffer_SUB; std::vector vertex_subsets; @@ -453,6 +469,26 @@ namespace wiScene uint32_t color = 0; static const wiGraphics::FORMAT FORMAT = wiGraphics::FORMAT::FORMAT_R8G8B8A8_UNORM; }; + struct Vertex_TAN + { + uint32_t tangent = 0; + + void FromFULL(const XMFLOAT4& tan) + { + XMVECTOR T = XMLoadFloat4(&tan); + T = XMVector3Normalize(T); + XMFLOAT4 t; + XMStoreFloat4(&t, T); + t.w = tan.w; + tangent = 0; + tangent |= (uint)((t.x * 0.5f + 0.5f) * 255.0f) << 0; + tangent |= (uint)((t.y * 0.5f + 0.5f) * 255.0f) << 8; + tangent |= (uint)((t.z * 0.5f + 0.5f) * 255.0f) << 16; + tangent |= (uint)((t.w * 0.5f + 0.5f) * 255.0f) << 24; + } + + static const wiGraphics::FORMAT FORMAT = wiGraphics::FORMAT::FORMAT_R8G8B8A8_UNORM; + }; }; @@ -624,6 +660,8 @@ namespace wiScene void* physicsobject = nullptr; XMFLOAT4X4 worldMatrix = IDENTITYMATRIX; std::vector vertex_positions_simulation; // graphics vertices after simulation (world space) + std::vectorvertex_tangents_tmp; + std::vector vertex_tangents_simulation; AABB aabb; inline void SetDisableDeactivation(bool value) { if (value) { _flags |= DISABLE_DEACTIVATION; } else { _flags &= ~DISABLE_DEACTIVATION; } } diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp index b34b11481..0f7763c75 100644 --- a/WickedEngine/wiScene_BindLua.cpp +++ b/WickedEngine/wiScene_BindLua.cpp @@ -261,9 +261,10 @@ void Bind() wiLua::RunText("TUBE = 6"); wiLua::RunText("STENCILREF_EMPTY = 0"); - wiLua::RunText("STENCILREF_SKY = 1"); - wiLua::RunText("STENCILREF_DEFAULT = 2"); + wiLua::RunText("STENCILREF_DEFAULT = 1"); + wiLua::RunText("STENCILREF_CUSTOMSHADER = 2"); wiLua::RunText("STENCILREF_SKIN = 3"); + wiLua::RunText("STENCILREF_SNOW = 4"); wiLua::RegisterFunc("GetScene", GetScene); wiLua::RegisterFunc("LoadModel", LoadModel); diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index eeee1ee90..e53d77911 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -102,7 +102,15 @@ namespace wiScene archive >> emissiveColor.w; } archive >> refractionIndex; - archive >> subsurfaceScattering; + if (archive.GetVersion() < 52) + { + float subsurfaceScattering; + archive >> subsurfaceScattering; + if (subsurfaceScattering > 0) + { + subsurfaceProfile = SUBSURFACE_SKIN; + } + } archive >> normalMapStrength; archive >> parallaxOcclusionMapping; archive >> alphaRef; @@ -139,6 +147,32 @@ namespace wiScene archive >> (uint8_t&)shadingRate; } + if (archive.GetVersion() >= 50) + { + archive >> (uint32_t&)shaderType; + archive >> customShaderID; + } + else + { + if (_flags & _DEPRECATED_WATER) + { + shaderType = SHADERTYPE_WATER; + } + if (_flags & _DEPRECATED_PLANAR_REFLECTION) + { + shaderType = SHADERTYPE_PBR_PLANARREFLECTION; + } + if (parallaxOcclusionMapping > 0) + { + shaderType = SHADERTYPE_PBR_PARALLAXOCCLUSIONMAPPING; + } + } + + if (archive.GetVersion() >= 52) + { + archive >> (uint32_t&)subsurfaceProfile; + } + SetDirty(); if (!baseColorMapName.empty()) @@ -187,7 +221,11 @@ namespace wiScene archive << emissiveColor.w; } archive << refractionIndex; - archive << subsurfaceScattering; + if (archive.GetVersion() < 52) + { + float subsurfaceScattering = 0; + archive << subsurfaceScattering; + } archive << normalMapStrength; archive << parallaxOcclusionMapping; archive << alphaRef; @@ -257,6 +295,17 @@ namespace wiScene { archive << (uint8_t)shadingRate; } + + if (archive.GetVersion() >= 50) + { + archive << (uint32_t)shaderType; + archive << customShaderID; + } + + if (archive.GetVersion() >= 52) + { + archive << (uint32_t&)subsurfaceProfile; + } } } void MeshComponent::Serialize(wiArchive& archive, Entity seed) @@ -304,6 +353,11 @@ namespace wiScene archive >> vertex_windweights; } + if (archive.GetVersion() >= 51) + { + archive >> vertex_tangents; + } + CreateRenderData(); } else @@ -346,6 +400,11 @@ namespace wiScene archive << vertex_windweights; } + if (archive.GetVersion() >= 51) + { + archive << vertex_tangents; + } + } } void ImpostorComponent::Serialize(wiArchive& archive, Entity seed) diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 86c75e177..295332337 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,9 +7,9 @@ namespace wiVersion // main engine core const int major = 0; // minor features, major updates, breaking API changes - const int minor = 48; + const int minor = 49; // minor bug fixes, alterations, refactors, updates - const int revision = 3; + const int revision = 0; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision); diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index 51153f18f..3fdb05657 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -8,6 +8,7 @@ #include "wiRenderer.h" #include "ShaderInterop_Renderer.h" #include "wiEvent.h" +#include "wiBackLog.h" #include @@ -152,9 +153,9 @@ void wiWidget::SetName(const std::string& value) { if (value.length() <= 0) { - static unsigned long widgetID = 0; + static atomic widgetID{ 0 }; stringstream ss(""); - ss << "widget_" << widgetID++; + ss << "widget_" << widgetID.fetch_add(1); name = ss.str(); } else @@ -275,7 +276,7 @@ void wiWidget::Initialize() } -wiButton::wiButton(const std::string& name) :wiWidget() +void wiButton::Create(const std::string& name) { SetName(name); SetText(name); @@ -287,10 +288,6 @@ wiButton::wiButton(const std::string& name) :wiWidget() font.params.h_align = WIFALIGN_CENTER; font.params.v_align = WIFALIGN_CENTER; -} -wiButton::~wiButton() -{ - } void wiButton::Update(wiGUI* gui, float dt) { @@ -449,15 +446,11 @@ void wiButton::OnDragEnd(function func) -wiLabel::wiLabel(const std::string& name) +void wiLabel::Create(const std::string& name) { SetName(name); SetText(name); SetSize(XMFLOAT2(100, 20)); -} -wiLabel::~wiLabel() -{ - } void wiLabel::Update(wiGUI* gui, float dt) { @@ -518,7 +511,7 @@ void wiLabel::Render(const wiGUI* gui, CommandList cmd) const wiSpriteFont wiTextInputField::font_input; -wiTextInputField::wiTextInputField(const std::string& name) +void wiTextInputField::Create(const std::string& name) { SetName(name); SetText(name); @@ -529,10 +522,6 @@ wiTextInputField::wiTextInputField(const std::string& name) font_description.params = font.params; font_description.params.h_align = WIFALIGN_RIGHT; -} -wiTextInputField::~wiTextInputField() -{ - } void wiTextInputField::SetValue(const std::string& newValue) { @@ -708,17 +697,22 @@ void wiTextInputField::DeleteFromInput() -wiSlider::wiSlider(float start, float end, float defaultValue, float step, const std::string& name) : start(start), end(end), value(defaultValue), step(std::max(step, 1.0f)) +void wiSlider::Create(float start, float end, float defaultValue, float step, const std::string& name) { + this->start = start; + this->end = end; + this->value = defaultValue; + this->step = std::max(step, 1.0f); + SetName(name); SetText(name); OnSlide([](wiEventArgs args) {}); SetSize(XMFLOAT2(200, 40)); - valueInputField = new wiTextInputField(name + "_endInputField"); - valueInputField->SetTooltip("Enter number to modify value even outside slider limits. Enter \"reset\" to reset slider to initial state."); - valueInputField->SetValue(end); - valueInputField->OnInputAccepted([this, start,end,defaultValue](wiEventArgs args) { + valueInputField.Create(name + "_endInputField"); + valueInputField.SetTooltip("Enter number to modify value even outside slider limits. Enter \"reset\" to reset slider to initial state."); + valueInputField.SetValue(end); + valueInputField.OnInputAccepted([this, start,end,defaultValue](wiEventArgs args) { if (args.sValue.compare("reset") != string::npos) { this->value = defaultValue; @@ -749,15 +743,11 @@ wiSlider::wiSlider(float start, float end, float defaultValue, float step, const font.params.h_align = WIFALIGN_RIGHT; font.params.v_align = WIFALIGN_CENTER; } -wiSlider::~wiSlider() -{ - delete valueInputField; -} void wiSlider::SetValue(float value) { this->value = value; } -float wiSlider::GetValue() +float wiSlider::GetValue() const { return value; } @@ -778,10 +768,10 @@ void wiSlider::Update(wiGUI* gui, float dt) wiWidget::Update(gui, dt); - valueInputField->Detach(); - valueInputField->SetSize(XMFLOAT2(40.0f, scale.y)); - valueInputField->SetPos(XMFLOAT2(translation.x + scale.x + 2, translation.y)); - valueInputField->AttachTo(this); + valueInputField.Detach(); + valueInputField.SetSize(XMFLOAT2(scale.y * 2, scale.y)); + valueInputField.SetPos(XMFLOAT2(translation.x + scale.x + 2, translation.y)); + valueInputField.AttachTo(this); scissorRect.bottom = (int32_t)(translation.y + scale.y); scissorRect.left = (int32_t)(translation.x); @@ -791,16 +781,15 @@ void wiSlider::Update(wiGUI* gui, float dt) for (int i = 0; i < WIDGETSTATE_COUNT; ++i) { sprites_knob[i].params.siz.x = 16.0f; - valueInputField->SetColor(wiColor::fromFloat4(this->sprites_knob[i].params.color), (WIDGETSTATE)i); + valueInputField.SetColor(wiColor::fromFloat4(this->sprites_knob[i].params.color), (WIDGETSTATE)i); } - valueInputField->font.params.color = this->font.params.color; - valueInputField->font.params.shadowColor = this->font.params.shadowColor; - valueInputField->SetEnabled(IsEnabled()); - valueInputField->Update(gui, dt); + valueInputField.font.params.color = this->font.params.color; + valueInputField.font.params.shadowColor = this->font.params.shadowColor; + valueInputField.SetEnabled(IsEnabled()); + valueInputField.Update(gui, dt); if (IsEnabled() && !gui->IsWidgetDisabled(this)) { - bool dragged = false; if (state == FOCUS) @@ -871,7 +860,7 @@ void wiSlider::Update(wiGUI* gui, float dt) gui->ActivateWidget(this); } - valueInputField->SetValue(value); + valueInputField.SetValue(value); } font.params.posY = translation.y + scale.y * 0.5f; @@ -903,12 +892,12 @@ void wiSlider::Render(const wiGUI* gui, CommandList cmd) const // knob sprites_knob[state].Draw(cmd); - valueInputField->Render(gui, cmd); + valueInputField.Render(gui, cmd); } void wiSlider::RenderTooltip(const wiGUI* gui, wiGraphics::CommandList cmd) const { wiWidget::RenderTooltip(gui, cmd); - valueInputField->RenderTooltip(gui, cmd); + valueInputField.RenderTooltip(gui, cmd); } void wiSlider::OnSlide(function func) { @@ -919,7 +908,7 @@ void wiSlider::OnSlide(function func) -wiCheckBox::wiCheckBox(const std::string& name) +void wiCheckBox::Create(const std::string& name) { SetName(name); SetText(name); @@ -934,10 +923,6 @@ wiCheckBox::wiCheckBox(const std::string& name) sprites_check[i].params = sprites[i].params; sprites_check[i].params.color = wiMath::Lerp(sprites[i].params.color, wiColor::White().toFloat4(), 0.8f); } -} -wiCheckBox::~wiCheckBox() -{ - } void wiCheckBox::Update(wiGUI* gui, float dt) { @@ -1058,7 +1043,7 @@ bool wiCheckBox::GetCheck() const -wiComboBox::wiComboBox(const std::string& name) +void wiComboBox::Create(const std::string& name) { SetName(name); SetText(name); @@ -1067,10 +1052,6 @@ wiComboBox::wiComboBox(const std::string& name) font.params.h_align = WIFALIGN_RIGHT; font.params.v_align = WIFALIGN_CENTER; -} -wiComboBox::~wiComboBox() -{ - } float wiComboBox::GetItemOffset(int index) const { @@ -1456,10 +1437,8 @@ int wiComboBox::GetSelected() const static const float windowcontrolSize = 20.0f; -wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : gui(gui) +void wiWindow::Create(const std::string& name, bool window_controls) { - assert(gui != nullptr && "Ivalid GUI!"); - SetColor(wiColor::Ghost()); SetName(name); @@ -1475,9 +1454,9 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : if (window_controls) { // Add a resizer control to the upperleft corner - resizeDragger_UpperLeft = new wiButton(name + "_resize_dragger_upper_left"); - resizeDragger_UpperLeft->SetText(""); - resizeDragger_UpperLeft->OnDrag([this, gui](wiEventArgs args) { + resizeDragger_UpperLeft.Create(name + "_resize_dragger_upper_left"); + resizeDragger_UpperLeft.SetText(""); + resizeDragger_UpperLeft.OnDrag([this](wiEventArgs args) { auto saved_parent = this->parent; this->Detach(); XMFLOAT2 scaleDiff; @@ -1489,19 +1468,14 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : // Don't allow control outside of screen: this->translation_local.x = wiMath::Clamp(this->translation_local.x, 0, wiRenderer::GetDevice()->GetScreenWidth() - this->scale_local.x); this->translation_local.y = wiMath::Clamp(this->translation_local.y, 0, wiRenderer::GetDevice()->GetScreenHeight() - windowcontrolSize); - this->wiWidget::Update(gui, 0); - for (auto& x : this->childrenWidgets) - { - x->wiWidget::Update(gui, 0); - } this->AttachTo(saved_parent); }); - AddWidget(resizeDragger_UpperLeft); + AddWidget(&resizeDragger_UpperLeft); // Add a resizer control to the bottom right corner - resizeDragger_BottomRight = new wiButton(name + "_resize_dragger_bottom_right"); - resizeDragger_BottomRight->SetText(""); - resizeDragger_BottomRight->OnDrag([this, gui](wiEventArgs args) { + resizeDragger_BottomRight.Create(name + "_resize_dragger_bottom_right"); + resizeDragger_BottomRight.SetText(""); + resizeDragger_BottomRight.OnDrag([this](wiEventArgs args) { auto saved_parent = this->parent; this->Detach(); XMFLOAT2 scaleDiff; @@ -1512,60 +1486,50 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : // Don't allow control outside of screen: this->translation_local.x = wiMath::Clamp(this->translation_local.x, 0, wiRenderer::GetDevice()->GetScreenWidth() - this->scale_local.x); this->translation_local.y = wiMath::Clamp(this->translation_local.y, 0, wiRenderer::GetDevice()->GetScreenHeight() - windowcontrolSize); - this->wiWidget::Update(gui, 0); - for (auto& x : this->childrenWidgets) - { - x->wiWidget::Update(gui, 0); - } this->AttachTo(saved_parent); }); - AddWidget(resizeDragger_BottomRight); + AddWidget(&resizeDragger_BottomRight); // Add a grabber onto the title bar - moveDragger = new wiButton(name + "_move_dragger"); - moveDragger->SetText(name); - moveDragger->font.params.h_align = WIFALIGN_LEFT; - moveDragger->OnDrag([this, gui](wiEventArgs args) { + moveDragger.Create(name + "_move_dragger"); + moveDragger.SetText(name); + moveDragger.font.params.h_align = WIFALIGN_LEFT; + moveDragger.OnDrag([this](wiEventArgs args) { auto saved_parent = this->parent; this->Detach(); this->Translate(XMFLOAT3(args.deltaPos.x, args.deltaPos.y, 0)); // Don't allow control outside of screen: this->translation_local.x = wiMath::Clamp(this->translation_local.x, 0, wiRenderer::GetDevice()->GetScreenWidth() - this->scale_local.x); this->translation_local.y = wiMath::Clamp(this->translation_local.y, 0, wiRenderer::GetDevice()->GetScreenHeight() - windowcontrolSize); - this->wiWidget::Update(gui, 0); - for (auto& x : this->childrenWidgets) - { - x->wiWidget::Update(gui, 0); - } this->AttachTo(saved_parent); }); - AddWidget(moveDragger); + AddWidget(&moveDragger); // Add close button to the top right corner - closeButton = new wiButton(name + "_close_button"); - closeButton->SetText("x"); - closeButton->OnClick([this, gui](wiEventArgs args) { + closeButton.Create(name + "_close_button"); + closeButton.SetText("x"); + closeButton.OnClick([this](wiEventArgs args) { this->SetVisible(false); }); - closeButton->SetTooltip("Close window"); - AddWidget(closeButton); + closeButton.SetTooltip("Close window"); + AddWidget(&closeButton); // Add minimize button to the top right corner - minimizeButton = new wiButton(name + "_minimize_button"); - minimizeButton->SetText("-"); - minimizeButton->OnClick([this, gui](wiEventArgs args) { + minimizeButton.Create(name + "_minimize_button"); + minimizeButton.SetText("-"); + minimizeButton.OnClick([this](wiEventArgs args) { this->SetMinimized(!this->IsMinimized()); }); - minimizeButton->SetTooltip("Minimize window"); - AddWidget(minimizeButton); + minimizeButton.SetTooltip("Minimize window"); + AddWidget(&minimizeButton); } else { // Simple title bar - label = new wiLabel(name); - label->SetText(name); - label->font.params.h_align = WIFALIGN_LEFT; - AddWidget(label); + label.Create(name); + label.SetText(name); + label.font.params.h_align = WIFALIGN_LEFT; + AddWidget(&label); } @@ -1573,44 +1537,20 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : SetVisible(true); SetMinimized(false); } -wiWindow::~wiWindow() -{ - RemoveWidgets(true); -} void wiWindow::AddWidget(wiWidget* widget) { - assert(gui != nullptr && "Ivalid GUI!"); - widget->SetEnabled(this->IsEnabled()); widget->SetVisible(this->IsVisible()); - gui->AddWidget(widget); widget->AttachTo(this); childrenWidgets.push_back(widget); } void wiWindow::RemoveWidget(wiWidget* widget) { - assert(gui != nullptr && "Ivalid GUI!"); - - gui->RemoveWidget(widget); - //widget->detach(); - childrenWidgets.remove(widget); } -void wiWindow::RemoveWidgets(bool alsoDelete) +void wiWindow::RemoveWidgets() { - assert(gui != nullptr && "Ivalid GUI!"); - - for (auto& x : childrenWidgets) - { - //x->detach(); - gui->RemoveWidget(x); - if (alsoDelete) - { - delete x; - } - } - childrenWidgets.clear(); } void wiWindow::Update(wiGUI* gui, float dt) @@ -1622,49 +1562,53 @@ void wiWindow::Update(wiGUI* gui, float dt) return; } + moveDragger.Update(gui, dt); + resizeDragger_UpperLeft.Update(gui, dt); + resizeDragger_BottomRight.Update(gui, dt); + wiWidget::Update(gui, dt); - if (moveDragger != nullptr) + if (moveDragger.parent != nullptr) { - moveDragger->Detach(); - moveDragger->SetSize(XMFLOAT2(scale.x - windowcontrolSize * 3, windowcontrolSize)); - moveDragger->SetPos(XMFLOAT2(translation.x + windowcontrolSize, translation.y)); - moveDragger->AttachTo(this); + moveDragger.Detach(); + moveDragger.SetSize(XMFLOAT2(scale.x - windowcontrolSize * 3, windowcontrolSize)); + moveDragger.SetPos(XMFLOAT2(translation.x + windowcontrolSize, translation.y)); + moveDragger.AttachTo(this); } - if (closeButton != nullptr) + if (closeButton.parent != nullptr) { - closeButton->Detach(); - closeButton->SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); - closeButton->SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize, translation.y)); - closeButton->AttachTo(this); + closeButton.Detach(); + closeButton.SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); + closeButton.SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize, translation.y)); + closeButton.AttachTo(this); } - if (minimizeButton != nullptr) + if (minimizeButton.parent != nullptr) { - minimizeButton->Detach(); - minimizeButton->SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); - minimizeButton->SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize * 2, translation.y)); - minimizeButton->AttachTo(this); + minimizeButton.Detach(); + minimizeButton.SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); + minimizeButton.SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize * 2, translation.y)); + minimizeButton.AttachTo(this); } - if (resizeDragger_UpperLeft != nullptr) + if (resizeDragger_UpperLeft.parent != nullptr) { - resizeDragger_UpperLeft->Detach(); - resizeDragger_UpperLeft->SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); - resizeDragger_UpperLeft->SetPos(XMFLOAT2(translation.x, translation.y)); - resizeDragger_UpperLeft->AttachTo(this); + resizeDragger_UpperLeft.Detach(); + resizeDragger_UpperLeft.SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); + resizeDragger_UpperLeft.SetPos(XMFLOAT2(translation.x, translation.y)); + resizeDragger_UpperLeft.AttachTo(this); } - if (resizeDragger_BottomRight != nullptr) + if (resizeDragger_BottomRight.parent != nullptr) { - resizeDragger_BottomRight->Detach(); - resizeDragger_BottomRight->SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); - resizeDragger_BottomRight->SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize, translation.y + scale.y - windowcontrolSize)); - resizeDragger_BottomRight->AttachTo(this); + resizeDragger_BottomRight.Detach(); + resizeDragger_BottomRight.SetSize(XMFLOAT2(windowcontrolSize, windowcontrolSize)); + resizeDragger_BottomRight.SetPos(XMFLOAT2(translation.x + scale.x - windowcontrolSize, translation.y + scale.y - windowcontrolSize)); + resizeDragger_BottomRight.AttachTo(this); } - if (label != nullptr) + if (label.parent != nullptr) { - label->Detach(); - label->SetSize(XMFLOAT2(scale.x, windowcontrolSize)); - label->SetPos(XMFLOAT2(translation.x, translation.y)); - label->AttachTo(this); + label.Detach(); + label.SetSize(XMFLOAT2(scale.x, windowcontrolSize)); + label.SetPos(XMFLOAT2(translation.x, translation.y)); + label.AttachTo(this); } for (auto& x : childrenWidgets) @@ -1677,6 +1621,11 @@ void wiWindow::Update(wiGUI* gui, float dt) } } + if (IsMinimized()) + { + hitBox.siz.y = windowcontrolSize; + } + if (IsEnabled() && !gui->IsWidgetDisabled(this) && !IsMinimized()) { if (state == FOCUS) @@ -1762,6 +1711,14 @@ void wiWindow::Render(const wiGUI* gui, CommandList cmd) const } } +void wiWindow::RenderTooltip(const wiGUI* gui, wiGraphics::CommandList cmd) const +{ + wiWidget::RenderTooltip(gui, cmd); + for (auto& x : childrenWidgets) + { + x->RenderTooltip(gui, cmd); + } +} void wiWindow::SetVisible(bool value) { wiWidget::SetVisible(value); @@ -1776,15 +1733,15 @@ void wiWindow::SetEnabled(bool value) wiWidget::SetEnabled(value); for (auto& x : childrenWidgets) { - if (x == moveDragger) + if (x == &moveDragger) continue; - if (x == minimizeButton) + if (x == &minimizeButton) continue; - if (x == closeButton) + if (x == &closeButton) continue; - if (x == resizeDragger_UpperLeft) + if (x == &resizeDragger_UpperLeft) continue; - if (x == resizeDragger_BottomRight) + if (x == &resizeDragger_BottomRight) continue; x->SetEnabled(value); } @@ -1793,19 +1750,19 @@ void wiWindow::SetMinimized(bool value) { minimized = value; - if (resizeDragger_BottomRight != nullptr) + if (resizeDragger_BottomRight.parent != nullptr) { - resizeDragger_BottomRight->SetVisible(!value); + resizeDragger_BottomRight.SetVisible(!value); } for (auto& x : childrenWidgets) { - if (x == moveDragger) + if (x == &moveDragger) continue; - if (x == minimizeButton) + if (x == &minimizeButton) continue; - if (x == closeButton) + if (x == &closeButton) continue; - if (x == resizeDragger_UpperLeft) + if (x == &resizeDragger_UpperLeft) continue; x->SetVisible(!value); } @@ -1932,112 +1889,105 @@ rgb hsv2rgb(hsv in) static const float cp_width = 300; static const float cp_height = 260; -wiColorPicker::wiColorPicker(wiGUI* gui, const std::string& name, bool window_controls) :wiWindow(gui, name, window_controls) +void wiColorPicker::Create(const std::string& name, bool window_controls) { + wiWindow::Create(name, window_controls); + SetSize(XMFLOAT2(cp_width, cp_height)); SetColor(wiColor(100, 100, 100, 100)); - if (resizeDragger_BottomRight != nullptr) - { - RemoveWidget(resizeDragger_BottomRight); - } - if (resizeDragger_UpperLeft != nullptr) - { - RemoveWidget(resizeDragger_UpperLeft); - } - float x = 250; float y = 110; float step = 20; - text_R = new wiTextInputField(""); - text_R->SetPos(XMFLOAT2(x, y += step)); - text_R->SetSize(XMFLOAT2(40, 18)); - text_R->SetText(""); - text_R->SetTooltip("Enter value for RED channel (0-255)"); - text_R->SetDescription("R: "); - text_R->OnInputAccepted([this](wiEventArgs args) { + text_R.Create("R"); + text_R.SetPos(XMFLOAT2(x, y += step)); + text_R.SetSize(XMFLOAT2(40, 18)); + text_R.SetText(""); + text_R.SetTooltip("Enter value for RED channel (0-255)"); + text_R.SetDescription("R: "); + text_R.OnInputAccepted([this](wiEventArgs args) { wiColor color = GetPickColor(); color.setR((uint8_t)args.iValue); SetPickColor(color); FireEvents(); }); - AddWidget(text_R); + AddWidget(&text_R); - text_G = new wiTextInputField(""); - text_G->SetPos(XMFLOAT2(x, y += step)); - text_G->SetSize(XMFLOAT2(40, 18)); - text_G->SetText(""); - text_G->SetTooltip("Enter value for GREEN channel (0-255)"); - text_G->SetDescription("G: "); - text_G->OnInputAccepted([this](wiEventArgs args) { + text_G.Create("G"); + text_G.SetPos(XMFLOAT2(x, y += step)); + text_G.SetSize(XMFLOAT2(40, 18)); + text_G.SetText(""); + text_G.SetTooltip("Enter value for GREEN channel (0-255)"); + text_G.SetDescription("G: "); + text_G.OnInputAccepted([this](wiEventArgs args) { wiColor color = GetPickColor(); color.setG((uint8_t)args.iValue); SetPickColor(color); FireEvents(); }); - AddWidget(text_G); + AddWidget(&text_G); - text_B = new wiTextInputField(""); - text_B->SetPos(XMFLOAT2(x, y += step)); - text_B->SetSize(XMFLOAT2(40, 18)); - text_B->SetText(""); - text_B->SetTooltip("Enter value for BLUE channel (0-255)"); - text_B->SetDescription("B: "); - text_B->OnInputAccepted([this](wiEventArgs args) { + text_B.Create("B"); + text_B.SetPos(XMFLOAT2(x, y += step)); + text_B.SetSize(XMFLOAT2(40, 18)); + text_B.SetText(""); + text_B.SetTooltip("Enter value for BLUE channel (0-255)"); + text_B.SetDescription("B: "); + text_B.OnInputAccepted([this](wiEventArgs args) { wiColor color = GetPickColor(); color.setB((uint8_t)args.iValue); SetPickColor(color); FireEvents(); }); - AddWidget(text_B); + AddWidget(&text_B); - text_H = new wiTextInputField(""); - text_H->SetPos(XMFLOAT2(x, y += step)); - text_H->SetSize(XMFLOAT2(40, 18)); - text_H->SetText(""); - text_H->SetTooltip("Enter value for HUE channel (0-360)"); - text_H->SetDescription("H: "); - text_H->OnInputAccepted([this](wiEventArgs args) { + text_H.Create("H"); + text_H.SetPos(XMFLOAT2(x, y += step)); + text_H.SetSize(XMFLOAT2(40, 18)); + text_H.SetText(""); + text_H.SetTooltip("Enter value for HUE channel (0-360)"); + text_H.SetDescription("H: "); + text_H.OnInputAccepted([this](wiEventArgs args) { hue = wiMath::Clamp(args.fValue, 0, 360.0f); FireEvents(); }); - AddWidget(text_H); + AddWidget(&text_H); - text_S = new wiTextInputField(""); - text_S->SetPos(XMFLOAT2(x, y += step)); - text_S->SetSize(XMFLOAT2(40, 18)); - text_S->SetText(""); - text_S->SetTooltip("Enter value for SATURATION channel (0-100)"); - text_S->SetDescription("S: "); - text_S->OnInputAccepted([this](wiEventArgs args) { + text_S.Create("S"); + text_S.SetPos(XMFLOAT2(x, y += step)); + text_S.SetSize(XMFLOAT2(40, 18)); + text_S.SetText(""); + text_S.SetTooltip("Enter value for SATURATION channel (0-100)"); + text_S.SetDescription("S: "); + text_S.OnInputAccepted([this](wiEventArgs args) { saturation = wiMath::Clamp(args.fValue / 100.0f, 0, 1); FireEvents(); }); - AddWidget(text_S); + AddWidget(&text_S); - text_V = new wiTextInputField(""); - text_V->SetPos(XMFLOAT2(x, y += step)); - text_V->SetSize(XMFLOAT2(40, 18)); - text_V->SetText(""); - text_V->SetTooltip("Enter value for LUMINANCE channel (0-100)"); - text_V->SetDescription("V: "); - text_V->OnInputAccepted([this](wiEventArgs args) { + text_V.Create("V"); + text_V.SetPos(XMFLOAT2(x, y += step)); + text_V.SetSize(XMFLOAT2(40, 18)); + text_V.SetText(""); + text_V.SetTooltip("Enter value for LUMINANCE channel (0-100)"); + text_V.SetDescription("V: "); + text_V.OnInputAccepted([this](wiEventArgs args) { luminance = wiMath::Clamp(args.fValue / 100.0f, 0, 1); FireEvents(); }); - AddWidget(text_V); + AddWidget(&text_V); - alphaSlider = new wiSlider(0, 255, 255, 255, ""); - alphaSlider->SetPos(XMFLOAT2(20, 230)); - alphaSlider->SetSize(XMFLOAT2(150, 18)); - alphaSlider->SetText("A: "); - alphaSlider->SetTooltip("Value for ALPHA - TRANSPARENCY channel (0-255)"); - alphaSlider->OnSlide([this](wiEventArgs args) { + alphaSlider.Create(0, 255, 255, 255, ""); + alphaSlider.SetPos(XMFLOAT2(20, 230)); + alphaSlider.SetSize(XMFLOAT2(150, 18)); + alphaSlider.SetText("A: "); + alphaSlider.SetTooltip("Value for ALPHA - TRANSPARENCY channel (0-255)"); + alphaSlider.OnSlide([this](wiEventArgs args) { FireEvents(); }); - AddWidget(alphaSlider); + AddWidget(&alphaSlider); } static const float colorpicker_radius_triangle = 68; static const float colorpicker_radius = 75; @@ -2160,12 +2110,12 @@ void wiColorPicker::Update(wiGUI* gui, float dt) } wiColor color = GetPickColor(); - text_R->SetValue((int)color.getR()); - text_G->SetValue((int)color.getG()); - text_B->SetValue((int)color.getB()); - text_H->SetValue(int(hue)); - text_S->SetValue(int(saturation * 100)); - text_V->SetValue(int(luminance * 100)); + text_R.SetValue((int)color.getR()); + text_G.SetValue((int)color.getG()); + text_B.SetValue((int)color.getB()); + text_H.SetValue(int(hue)); + text_S.SetValue(int(saturation * 100)); + text_V.SetValue(int(luminance * 100)); if (dragged) { @@ -2562,7 +2512,7 @@ wiColor wiColorPicker::GetPickColor() const source.s = saturation; source.v = luminance; rgb result = hsv2rgb(source); - return wiColor::fromFloat4(XMFLOAT4(result.r, result.g, result.b, alphaSlider->GetValue() / 255.0f)); + return wiColor::fromFloat4(XMFLOAT4(result.r, result.g, result.b, alphaSlider.GetValue() / 255.0f)); } void wiColorPicker::SetPickColor(wiColor value) { @@ -2583,7 +2533,7 @@ void wiColorPicker::SetPickColor(wiColor value) } saturation = result.s; luminance = result.v; - alphaSlider->SetValue((float)value.getA()); + alphaSlider.SetValue((float)value.getA()); } void wiColorPicker::FireEvents() { @@ -2605,7 +2555,7 @@ void wiColorPicker::OnColorChanged(function func) inline float item_height() { return 20.0f; } inline float tree_scrollbar_width() { return 12.0f; } -wiTreeList::wiTreeList(const std::string& name) +void wiTreeList::Create(const std::string& name) { SetName(name); SetText(name); @@ -2617,10 +2567,6 @@ wiTreeList::wiTreeList(const std::string& name) sprites[i].params.color = sprites[FOCUS].params.color; } font.params.v_align = WIFALIGN_CENTER; -} -wiTreeList::~wiTreeList() -{ - } float wiTreeList::GetItemOffset(int index) const { diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h index 05e383ded..09ff05b07 100644 --- a/WickedEngine/wiWidget.h +++ b/WickedEngine/wiWidget.h @@ -54,7 +54,6 @@ protected: public: wiWidget(); - virtual ~wiWidget() {} const std::string& GetName() const; void SetName(const std::string& value); @@ -99,11 +98,10 @@ protected: XMFLOAT2 dragStart = XMFLOAT2(0, 0); XMFLOAT2 prevPos = XMFLOAT2(0, 0); public: - wiButton(const std::string& name = ""); - virtual ~wiButton(); + void Create(const std::string& name); - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; void OnClick(std::function func); void OnDragStart(std::function func); @@ -116,11 +114,10 @@ class wiLabel : public wiWidget { protected: public: - wiLabel(const std::string& name = ""); - virtual ~wiLabel(); + void Create(const std::string& name); - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; }; // Text input box @@ -131,8 +128,7 @@ protected: static wiSpriteFont font_input; public: - wiTextInputField(const std::string& name = ""); - virtual ~wiTextInputField(); + void Create(const std::string& name); wiSpriteFont font_description; @@ -147,8 +143,8 @@ public: static void AddInput(const char inputChar); static void DeleteFromInput(); - virtual void Update(wiGUI* gui, float dt) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; void OnInputAccepted(std::function func); }; @@ -162,19 +158,18 @@ protected: float step = 1000; float value = 0; - wiTextInputField* valueInputField = nullptr; + wiTextInputField valueInputField; public: // start : slider minimum value // end : slider maximum value // defaultValue : slider default Value // step : slider step size - wiSlider(float start = 0.0f, float end = 1.0f, float defaultValue = 0.5f, float step = 1000.0f, const std::string& name = ""); - virtual ~wiSlider(); - + void Create(float start, float end, float defaultValue, float step, const std::string& name); + wiSprite sprites_knob[WIDGETSTATE_COUNT]; void SetValue(float value); - float GetValue(); + float GetValue() const; void SetRange(float start, float end); void Update(wiGUI* gui, float dt ) override; @@ -191,16 +186,15 @@ protected: std::function onClick; bool checked = false; public: - wiCheckBox(const std::string& name = ""); - virtual ~wiCheckBox(); + void Create(const std::string& name); wiSprite sprites_check[WIDGETSTATE_COUNT]; void SetCheck(bool value); bool GetCheck() const; - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; void OnClick(std::function func); }; @@ -232,8 +226,7 @@ protected: float GetItemOffset(int index) const; public: - wiComboBox(const std::string& name = ""); - virtual ~wiComboBox(); + void Create(const std::string& name); void AddItem(const std::string& item); void RemoveItem(int index); @@ -245,8 +238,8 @@ public: int GetSelected() const; std::string GetItemText(int index) const; - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; void OnSelect(std::function func); }; @@ -255,28 +248,27 @@ public: class wiWindow :public wiWidget { protected: - wiGUI* gui = nullptr; - wiButton* closeButton = nullptr; - wiButton* minimizeButton = nullptr; - wiButton* resizeDragger_UpperLeft = nullptr; - wiButton* resizeDragger_BottomRight = nullptr; - wiButton* moveDragger = nullptr; - wiLabel* label = nullptr; + wiButton closeButton; + wiButton minimizeButton; + wiButton resizeDragger_UpperLeft; + wiButton resizeDragger_BottomRight; + wiButton moveDragger; + wiLabel label; std::list childrenWidgets; bool minimized = false; public: - wiWindow(wiGUI* gui, const std::string& name = "", bool window_controls = true); - virtual ~wiWindow(); + void Create(const std::string& name, bool window_controls = true); void AddWidget(wiWidget* widget); void RemoveWidget(wiWidget* widget); - void RemoveWidgets(bool alsoDelete = false); + void RemoveWidgets(); - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void RenderTooltip(const wiGUI* gui, wiGraphics::CommandList cmd) const override; - virtual void SetVisible(bool value) override; - virtual void SetEnabled(bool value) override; + void SetVisible(bool value) override; + void SetEnabled(bool value) override; void SetMinimized(bool value); bool IsMinimized() const; }; @@ -296,20 +288,20 @@ protected: float saturation = 0.0f; // [0, 1] float luminance = 1.0f; // [0, 1] - wiTextInputField* text_R = nullptr; - wiTextInputField* text_G = nullptr; - wiTextInputField* text_B = nullptr; - wiTextInputField* text_H = nullptr; - wiTextInputField* text_S = nullptr; - wiTextInputField* text_V = nullptr; - wiSlider* alphaSlider = nullptr; + wiTextInputField text_R; + wiTextInputField text_G; + wiTextInputField text_B; + wiTextInputField text_H; + wiTextInputField text_S; + wiTextInputField text_V; + wiSlider alphaSlider; void FireEvents(); public: - wiColorPicker(wiGUI* gui, const std::string& name = "", bool window_controls = true); + void Create(const std::string& name, bool window_controls = true); - virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt ) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; wiColor GetPickColor() const; void SetPickColor(wiColor value); @@ -356,8 +348,7 @@ protected: float GetItemOffset(int index) const; public: - wiTreeList(const std::string& name = ""); - virtual ~wiTreeList(); + void Create(const std::string& name); void AddItem(const Item& item); void ClearItems(); @@ -369,8 +360,8 @@ public: int GetItemCount() const { return (int)items.size(); } const Item& GetItem(int index) const; - virtual void Update(wiGUI* gui, float dt) override; - virtual void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; + void Update(wiGUI* gui, float dt) override; + void Render(const wiGUI* gui, wiGraphics::CommandList cmd) const override; void OnSelect(std::function func); }; diff --git a/models/blend_instancing_test.wiscene b/models/blend_instancing_test.wiscene new file mode 100644 index 000000000..494179a18 Binary files /dev/null and b/models/blend_instancing_test.wiscene differ diff --git a/scripts/character_controller_tps.lua b/scripts/character_controller_tps.lua index 0e72a2e45..16c8b6372 100644 --- a/scripts/character_controller_tps.lua +++ b/scripts/character_controller_tps.lua @@ -406,7 +406,7 @@ runProcess(function() -- We will override the render path so we can invoke the script from Editor and controls won't collide with editor scripts -- Also save the active component that we can restore when ESCAPE is pressed local prevPath = main.GetActivePath() - local path = RenderPath3D_TiledForward() + local path = RenderPath3D() path.SetLightShaftsEnabled(true) main.SetActivePath(path) diff --git a/scripts/fighting_game.lua b/scripts/fighting_game.lua index a5c4cbbdc..fc522ab3b 100644 --- a/scripts/fighting_game.lua +++ b/scripts/fighting_game.lua @@ -1909,7 +1909,7 @@ runProcess(function() -- We will override the render path so we can invoke the script from Editor and controls won't collide with editor scripts -- Also save the active component that we can restore when ESCAPE is pressed local prevPath = main.GetActivePath() - local path = RenderPath3D_TiledForward() + local path = RenderPath3D() main.SetActivePath(path) local help_text = ""