From 6fbfe36665b9ec1b84964ac9c32daed1f3e69d34 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Fri, 5 Apr 2019 00:05:27 +0100 Subject: [PATCH] refactor --- Documentation/ScriptingAPI-Documentation.md | 7 +- Editor/AnimationWindow.cpp | 12 +- Editor/CameraWindow.cpp | 14 +- Editor/DecalWindow.cpp | 4 +- Editor/Editor.cpp | 74 ++-- Editor/Editor.h | 6 +- Editor/EmitterWindow.cpp | 10 +- Editor/EnvProbeWindow.cpp | 10 +- Editor/ForceFieldWindow.cpp | 10 +- Editor/HairParticleWindow.cpp | 8 +- Editor/LightWindow.cpp | 30 +- Editor/MaterialWindow.cpp | 80 ++-- Editor/MeshWindow.cpp | 32 +- Editor/ObjectWindow.cpp | 24 +- Editor/OceanWindow.cpp | 46 +-- Editor/Translator.cpp | 18 +- Editor/WeatherWindow.cpp | 6 +- README.md | 10 +- Tests/Tests.cpp | 22 +- WickedEngine/ConstantBufferMapping.h | 59 ++- WickedEngine/MainComponent.cpp | 4 - WickedEngine/RenderPath3D.cpp | 2 +- WickedEngine/RenderPath3D_PathTracing.cpp | 2 +- WickedEngine/ShaderInterop_Renderer.h | 26 +- WickedEngine/screenPS.hlsl | 2 +- WickedEngine/wiFont.cpp | 22 +- WickedEngine/wiFont.h | 1 - WickedEngine/wiImage.cpp | 30 +- WickedEngine/wiImage.h | 2 - WickedEngine/wiRenderer.cpp | 398 +++++++------------- WickedEngine/wiRenderer.h | 33 +- WickedEngine/wiRenderer_BindLua.cpp | 75 ---- WickedEngine/wiSceneSystem.cpp | 189 ++++++++++ WickedEngine/wiSceneSystem.h | 35 ++ WickedEngine/wiSceneSystem_BindLua.cpp | 77 ++++ WickedEngine/wiVersion.cpp | 4 +- 36 files changed, 731 insertions(+), 653 deletions(-) diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 39c5c081a..03cf23119 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -94,7 +94,6 @@ The scripting API provides some functions which manipulate the BackLog. These fu This is the graphics renderer, which is also responsible for managing the scene graph which consists of keeping track of parent-child relationships between the scene hierarchy, updating the world, animating armatures. You can use the Renderer with the following functions, all of which are in the global scope: -- GetScene() : Scene result - GetGameSpeed() : float result - SetResolutionScale(float scale) - SetGamma(float gamma) @@ -104,7 +103,6 @@ You can use the Renderer with the following functions, all of which are in the g - GetRenderWidth() : float result - GetRenderHeight(): float result - GetCamera() : Camera result -- returns the main camera -- LoadModel(string fileName, opt Matrix transform) : int rootEntity -- Load Model from file. returns a root entity that everything in this model is attached to - DuplicateInstance(Object object) : Object result -- Copies the specified object in the scene as an instanced mesh - SetEnvironmentMap(Texture cubemap) - HairParticleSettings(opt int lod0, opt int lod1, opt int lod2) @@ -117,7 +115,6 @@ You can use the Renderer with the following functions, all of which are in the g - SetDebugForceFieldsEnabled(bool enabled) - SetVSyncEnabled(opt bool enabled) - SetOcclusionCullingEnabled(bool enabled) -- Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) : int entity, Vector position,normal, float distance -- Perform ray-picking in the scene. pickType is a bitmask specifying object types to check against. layerMask is a bitmask specifying which layers to check against - DrawLine(Vector origin,end, opt Vector color) - DrawPoint(Vector origin, opt float size, opt Vector color) - DrawBox(Matrix boxMatrix, opt Vector color) @@ -291,7 +288,9 @@ Manipulate the 3D scene with these components. An entity is just an int value and works as a handle to retrieve associated components #### Scene -- [outer]GetScene() -- returns the current scene +- [outer]GetScene() : Scene result -- returns the current scene +- [outer]LoadModel(string fileName, opt Matrix transform) : int rootEntity -- Load Model from file. returns a root entity that everything in this model is attached to +- [outer]Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) : int entity, Vector position,normal, float distance -- Perform ray-picking in the scene. pickType is a bitmask specifying object types to check against. layerMask is a bitmask specifying which layers to check against - Update() -- updates the scene and every entity and component inside the scene - Clear() -- deletes every entity and component inside the scene - Entity_FindByName(string value) : int entity -- returns an entity ID if it exists, and 0 otherwise diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index c120957f5..773eec73c 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -28,7 +28,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) animationsComboBox->SetPos(XMFLOAT2(x, y += step)); animationsComboBox->SetEnabled(false); animationsComboBox->OnSelect([&](wiEventArgs args) { - entity = wiRenderer::GetScene().animations.GetEntity(args.iValue); + entity = wiSceneSystem::GetScene().animations.GetEntity(args.iValue); }); animationsComboBox->SetTooltip("Choose an animation clip..."); animWindow->AddWidget(animationsComboBox); @@ -37,7 +37,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) loopedCheckBox->SetTooltip("Toggle animation looping behaviour."); loopedCheckBox->SetPos(XMFLOAT2(150, y += step)); loopedCheckBox->OnClick([&](wiEventArgs args) { - AnimationComponent* animation = wiRenderer::GetScene().animations.GetComponent(entity); + AnimationComponent* animation = wiSceneSystem::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->SetLooped(args.bValue); @@ -49,7 +49,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) playButton->SetTooltip("Play/Pause animation."); playButton->SetPos(XMFLOAT2(200, y)); playButton->OnClick([&](wiEventArgs args) { - AnimationComponent* animation = wiRenderer::GetScene().animations.GetComponent(entity); + AnimationComponent* animation = wiSceneSystem::GetScene().animations.GetComponent(entity); if (animation != nullptr) { if (animation->IsPlaying()) @@ -68,7 +68,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) stopButton->SetTooltip("Stop animation."); stopButton->SetPos(XMFLOAT2(310, y)); stopButton->OnClick([&](wiEventArgs args) { - AnimationComponent* animation = wiRenderer::GetScene().animations.GetComponent(entity); + AnimationComponent* animation = wiSceneSystem::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->Stop(); @@ -80,7 +80,7 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) timerSlider->SetSize(XMFLOAT2(250, 30)); timerSlider->SetPos(XMFLOAT2(x, y += step * 2)); timerSlider->OnSlide([&](wiEventArgs args) { - AnimationComponent* animation = wiRenderer::GetScene().animations.GetComponent(entity); + AnimationComponent* animation = wiSceneSystem::GetScene().animations.GetComponent(entity); if (animation != nullptr) { animation->timer = args.fValue; @@ -110,7 +110,7 @@ void AnimationWindow::Update() { animationsComboBox->ClearItems(); - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (!scene.animations.Contains(entity)) { diff --git a/Editor/CameraWindow.cpp b/Editor/CameraWindow.cpp index 93c5a907a..ebdbd818e 100644 --- a/Editor/CameraWindow.cpp +++ b/Editor/CameraWindow.cpp @@ -6,7 +6,7 @@ using namespace wiSceneSystem; void CameraWindow::ResetCam() { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); camera_transform.ClearTransform(); camera_transform.Translate(XMFLOAT3(0, 2, -10)); @@ -40,7 +40,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) farPlaneSlider->SetPos(XMFLOAT2(x, y += inc)); farPlaneSlider->SetValue(wiRenderer::GetCamera().zFarP); farPlaneSlider->OnSlide([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.zFarP = args.fValue; camera.UpdateProjection(); @@ -52,7 +52,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) nearPlaneSlider->SetPos(XMFLOAT2(x, y += inc)); nearPlaneSlider->SetValue(wiRenderer::GetCamera().zNearP); nearPlaneSlider->OnSlide([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.zNearP = args.fValue; camera.UpdateProjection(); @@ -63,7 +63,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) fovSlider->SetSize(XMFLOAT2(100, 30)); fovSlider->SetPos(XMFLOAT2(x, y += inc)); fovSlider->OnSlide([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); camera.fov = args.fValue / 180.f * XM_PI; camera.UpdateProjection(); @@ -103,7 +103,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) const CameraComponent& camera = wiRenderer::GetCamera(); - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); Entity entity = scene.Entity_CreateCamera("cam", camera.width, camera.height, camera.zNearP, camera.zFarP, camera.fov); @@ -116,7 +116,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) proxyNameField->SetSize(XMFLOAT2(140, 30)); proxyNameField->SetPos(XMFLOAT2(x + 200, y)); proxyNameField->OnInputAccepted([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); NameComponent* camera = scene.names.GetComponent(proxy); if (camera != nullptr) { @@ -156,7 +156,7 @@ void CameraWindow::SetEntity(Entity entity) { proxy = entity; - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (scene.cameras.GetComponent(entity) != nullptr) { diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index 85eeb08d5..49d3c6a81 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -24,7 +24,7 @@ DecalWindow::DecalWindow(wiGUI* gui) : GUI(gui) decalNameField->SetPos(XMFLOAT2(10, 30)); decalNameField->SetSize(XMFLOAT2(300, 20)); decalNameField->OnInputAccepted([&](wiEventArgs args) { - NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + NameComponent* name = wiSceneSystem::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; @@ -53,7 +53,7 @@ void DecalWindow::SetEntity(Entity entity) this->entity = entity; - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); const DecalComponent* decal = scene.decals.GetComponent(entity); if (decal != nullptr) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index a1d596549..13fa57b97 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -400,7 +400,7 @@ void EditorComponent::Load() wiArchive archive(fileName, false); if (archive.IsOpen()) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); scene.Serialize(archive); @@ -449,25 +449,25 @@ void EditorComponent::Load() if (!extension.compare("WISCENE")) // engine-serialized { - wiRenderer::LoadModel(fileName); + wiSceneSystem::LoadModel(fileName); } else if (!extension.compare("OBJ")) // wavefront-obj { Scene scene; ImportModel_OBJ(fileName, scene); - wiRenderer::GetScene().Merge(scene); + wiSceneSystem::GetScene().Merge(scene); } else if (!extension.compare("GLTF")) // text-based gltf { Scene scene; ImportModel_GLTF(fileName, scene); - wiRenderer::GetScene().Merge(scene); + wiSceneSystem::GetScene().Merge(scene); } else if (!extension.compare("GLB")) // binary gltf { Scene scene; ImportModel_GLTF(fileName, scene); - wiRenderer::GetScene().Merge(scene); + wiSceneSystem::GetScene().Merge(scene); } }); loader->onFinished([=] { @@ -710,7 +710,7 @@ void EditorComponent::FixedUpdate() } void EditorComponent::Update(float dt) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); CameraComponent& camera = wiRenderer::GetCamera(); animWnd->Update(); @@ -854,12 +854,12 @@ void EditorComponent::Update(float dt) UINT pickMask = rendererWnd->GetPickType(); RAY pickRay = wiRenderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y); { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); // Try to pick objects-meshes: if (pickMask & PICK_OBJECT) { - hovered = wiRenderer::RayIntersectWorld(pickRay, pickMask); + hovered = wiSceneSystem::Pick(pickRay, pickMask); } if (pickMask & PICK_LIGHT) @@ -873,7 +873,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -890,7 +890,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -907,7 +907,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -924,7 +924,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -941,7 +941,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -959,7 +959,7 @@ void EditorComponent::Update(float dt) float dis = wiMath::Distance(transform.GetPosition(), pickRay.origin); if (dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -978,7 +978,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -995,7 +995,7 @@ void EditorComponent::Update(float dt) float dis = XMVectorGetX(disV); if (dis < wiMath::Distance(transform.GetPosition(), pickRay.origin) * 0.05f && dis < hovered.distance) { - hovered = wiRenderer::RayIntersectWorldResult(); + hovered = wiSceneSystem::PickResult(); hovered.entity = entity; hovered.distance = dis; } @@ -1120,7 +1120,7 @@ void EditorComponent::Update(float dt) { Entity entity = scene.names.GetEntity(i); - wiRenderer::RayIntersectWorldResult picked; + wiSceneSystem::PickResult picked; picked.entity = entity; AddSelected(picked); } @@ -1134,9 +1134,9 @@ void EditorComponent::Update(float dt) if (!selected.empty() && wiInputManager::down(VK_LSHIFT)) { // Union selection: - list saved = selected; + list saved = selected; EndTranslate(); - for (const wiRenderer::RayIntersectWorldResult& picked : saved) + for (const wiSceneSystem::PickResult& picked : saved) { AddSelected(picked); } @@ -1188,7 +1188,7 @@ void EditorComponent::Update(float dt) } else { - const wiRenderer::RayIntersectWorldResult& picked = selected.back(); + const wiSceneSystem::PickResult& picked = selected.back(); assert(picked.entity != INVALID_ENTITY); @@ -1277,7 +1277,7 @@ void EditorComponent::Update(float dt) *clipboard >> count; for (size_t i = 0; i < count; ++i) { - wiRenderer::RayIntersectWorldResult picked; + wiSceneSystem::PickResult picked; picked.entity = scene.Entity_Serialize(*clipboard, INVALID_ENTITY, wiRandom::getRandom(1, INT_MAX), false); AddSelected(picked); } @@ -1291,7 +1291,7 @@ void EditorComponent::Update(float dt) EndTranslate(); for (auto& x : prevSel) { - wiRenderer::RayIntersectWorldResult picked; + wiSceneSystem::PickResult picked; picked.entity = scene.Entity_Duplicate(x.entity); AddSelected(picked); } @@ -1363,7 +1363,7 @@ void EditorComponent::Update(float dt) } void EditorComponent::Render() const { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); // Hovered item boxes: if (!cinemaModeCheckBox->GetCheck()) @@ -1488,7 +1488,7 @@ void EditorComponent::Compose() const const CameraComponent& camera = wiRenderer::GetCamera(); - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (rendererWnd->GetPickType() & PICK_LIGHT) { @@ -1769,7 +1769,7 @@ void EditorComponent::BeginTranslate() return; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); // Insert translator into scene: scene.transforms.Create(translator.entityID); @@ -1778,7 +1778,7 @@ void EditorComponent::BeginTranslate() savedHierarchy.Copy(scene.hierarchy); // All selected entities will be attached to translator entity: - TransformComponent* translator_transform = wiRenderer::GetScene().transforms.GetComponent(translator.entityID); + TransformComponent* translator_transform = wiSceneSystem::GetScene().transforms.GetComponent(translator.entityID); translator_transform->ClearTransform(); // Find the center of all the entities that are selected: @@ -1786,7 +1786,7 @@ void EditorComponent::BeginTranslate() float count = 0; for (auto& x : selected) { - TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(x.entity); + TransformComponent* transform = wiSceneSystem::GetScene().transforms.GetComponent(x.entity); if (transform != nullptr) { centerV = XMVectorAdd(centerV, transform->GetPositionV()); @@ -1806,7 +1806,7 @@ void EditorComponent::BeginTranslate() for (auto& x : selected) { - wiRenderer::GetScene().Component_Attach(x.entity, translator.entityID); + wiSceneSystem::GetScene().Component_Attach(x.entity, translator.entityID); } } } @@ -1817,7 +1817,7 @@ void EditorComponent::EndTranslate() return; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); // Remove translator from scene: scene.Entity_Remove(translator.entityID); @@ -1843,7 +1843,7 @@ void EditorComponent::EndTranslate() // If an attached entity got moved, then the world transform was applied to it (**), // so we need to reattach it properly to the parent matrix: - for (const wiRenderer::RayIntersectWorldResult& x : selected) + for (const wiSceneSystem::PickResult& x : selected) { HierarchyComponent* parent = scene.hierarchy.GetComponent(x.entity); if (parent != nullptr) @@ -1867,7 +1867,7 @@ void EditorComponent::EndTranslate() selected.clear(); } -void EditorComponent::AddSelected(const wiRenderer::RayIntersectWorldResult& picked) +void EditorComponent::AddSelected(const wiSceneSystem::PickResult& picked) { for (auto it = selected.begin(); it != selected.end(); ++it) { @@ -1932,7 +1932,7 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) *archive >> start >> end; translator.enabled = true; - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); TransformComponent& transform = *scene.transforms.GetComponent(translator.entityID); transform.ClearTransform(); @@ -1948,7 +1948,7 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) break; case HISTORYOP_DELETE: { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); size_t count; *archive >> count; @@ -1981,12 +1981,12 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) // Read selections states from archive: - list selectedBEFORE; + list selectedBEFORE; size_t selectionCountBEFORE; *archive >> selectionCountBEFORE; for (size_t i = 0; i < selectionCountBEFORE; ++i) { - wiRenderer::RayIntersectWorldResult sel; + wiSceneSystem::PickResult sel; *archive >> sel.entity; *archive >> sel.position; *archive >> sel.normal; @@ -1998,12 +1998,12 @@ void EditorComponent::ConsumeHistoryOperation(bool undo) ComponentManager savedHierarchyBEFORE; savedHierarchyBEFORE.Serialize(*archive); - list selectedAFTER; + list selectedAFTER; size_t selectionCountAFTER; *archive >> selectionCountAFTER; for (size_t i = 0; i < selectionCountAFTER; ++i) { - wiRenderer::RayIntersectWorldResult sel; + wiSceneSystem::PickResult sel; *archive >> sel.entity; *archive >> sel.position; *archive >> sel.normal; diff --git a/Editor/Editor.h b/Editor/Editor.h index 7dcd0e23d..8aa9c1cc4 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -84,13 +84,13 @@ public: }; Translator translator; - std::list selected; + std::list selected; wiECS::ComponentManager savedHierarchy; - wiRenderer::RayIntersectWorldResult hovered; + wiSceneSystem::PickResult hovered; void BeginTranslate(); void EndTranslate(); - void AddSelected(const wiRenderer::RayIntersectWorldResult& picked); + void AddSelected(const wiSceneSystem::PickResult& picked); diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index 7ab0e3788..01ab0cad9 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -29,7 +29,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) emitterNameField->SetPos(XMFLOAT2(x, y += step)); emitterNameField->SetSize(XMFLOAT2(300, 20)); emitterNameField->OnInputAccepted([&](wiEventArgs args) { - NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + NameComponent* name = wiSceneSystem::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; @@ -41,7 +41,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) addButton->SetPos(XMFLOAT2(x, y += step)); addButton->SetSize(XMFLOAT2(150, 30)); addButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); scene.Entity_CreateEmitter("editorEmitter"); }); addButton->SetTooltip("Add new emitter particle system."); @@ -74,7 +74,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) } else { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); emitter->meshID = scene.meshes.GetEntity(args.iValue - 1); } } @@ -492,7 +492,7 @@ wiEmittedParticle* EmitterWindow::GetEmitter() return nullptr; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); wiEmittedParticle* emitter = scene.emitters.GetComponent(entity); return emitter; @@ -506,7 +506,7 @@ void EmitterWindow::UpdateData() return; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); meshComboBox->ClearItems(); meshComboBox->AddItem("NO MESH"); diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp index b6aeadff1..69a853fb1 100644 --- a/Editor/EnvProbeWindow.cpp +++ b/Editor/EnvProbeWindow.cpp @@ -22,7 +22,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) realTimeCheckBox->SetPos(XMFLOAT2(x, y += step)); realTimeCheckBox->SetEnabled(false); realTimeCheckBox->OnClick([&](wiEventArgs args) { - EnvironmentProbeComponent* probe = wiRenderer::GetScene().probes.GetComponent(entity); + EnvironmentProbeComponent* probe = wiSceneSystem::GetScene().probes.GetComponent(entity); if (probe != nullptr) { probe->SetRealTime(args.bValue); @@ -36,7 +36,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) generateButton->OnClick([](wiEventArgs args) { XMFLOAT3 pos; XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::GetCamera().GetEye(), wiRenderer::GetCamera().GetAt() * 4)); - wiRenderer::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos); + wiSceneSystem::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos); }); envProbeWindow->AddWidget(generateButton); @@ -44,7 +44,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) refreshButton->SetPos(XMFLOAT2(x, y += step)); refreshButton->SetEnabled(false); refreshButton->OnClick([&](wiEventArgs args) { - EnvironmentProbeComponent* probe = wiRenderer::GetScene().probes.GetComponent(entity); + EnvironmentProbeComponent* probe = wiSceneSystem::GetScene().probes.GetComponent(entity); if (probe != nullptr) { probe->SetDirty(); @@ -56,7 +56,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) refreshAllButton->SetPos(XMFLOAT2(x, y += step)); refreshAllButton->SetEnabled(true); refreshAllButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); for (size_t i = 0; i < scene.probes.GetCount(); ++i) { EnvironmentProbeComponent& probe = scene.probes[i]; @@ -86,7 +86,7 @@ void EnvProbeWindow::SetEntity(Entity entity) { this->entity = entity; - const EnvironmentProbeComponent* probe = wiRenderer::GetScene().probes.GetComponent(entity); + const EnvironmentProbeComponent* probe = wiSceneSystem::GetScene().probes.GetComponent(entity); if (probe == nullptr) { diff --git a/Editor/ForceFieldWindow.cpp b/Editor/ForceFieldWindow.cpp index 793ce0791..f52973fa9 100644 --- a/Editor/ForceFieldWindow.cpp +++ b/Editor/ForceFieldWindow.cpp @@ -26,7 +26,7 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) typeComboBox->SetPos(XMFLOAT2(x, y += step)); typeComboBox->SetSize(XMFLOAT2(300, 25)); typeComboBox->OnSelect([&](wiEventArgs args) { - ForceFieldComponent* force = wiRenderer::GetScene().forces.GetComponent(entity); + ForceFieldComponent* force = wiSceneSystem::GetScene().forces.GetComponent(entity); if (force != nullptr && args.iValue >= 0) { switch (args.iValue) @@ -54,7 +54,7 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) gravitySlider->SetSize(XMFLOAT2(200, 30)); gravitySlider->SetPos(XMFLOAT2(x, y += step)); gravitySlider->OnSlide([&](wiEventArgs args) { - ForceFieldComponent* force = wiRenderer::GetScene().forces.GetComponent(entity); + ForceFieldComponent* force = wiSceneSystem::GetScene().forces.GetComponent(entity); if (force != nullptr) { force->gravity = args.fValue; @@ -69,7 +69,7 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) rangeSlider->SetSize(XMFLOAT2(200, 30)); rangeSlider->SetPos(XMFLOAT2(x, y += step)); rangeSlider->OnSlide([&](wiEventArgs args) { - ForceFieldComponent* force = wiRenderer::GetScene().forces.GetComponent(entity); + ForceFieldComponent* force = wiSceneSystem::GetScene().forces.GetComponent(entity); if (force != nullptr) { force->range = args.fValue; @@ -84,7 +84,7 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) addButton->SetSize(XMFLOAT2(150, 30)); addButton->SetPos(XMFLOAT2(x, y += step * 2)); addButton->OnClick([](wiEventArgs args) { - wiRenderer::GetScene().Entity_CreateForce("editorForce"); + wiSceneSystem::GetScene().Entity_CreateForce("editorForce"); }); addButton->SetEnabled(true); addButton->SetTooltip("Add new Force Field to the simulation."); @@ -113,7 +113,7 @@ void ForceFieldWindow::SetEntity(Entity entity) this->entity = entity; - const ForceFieldComponent* force = wiRenderer::GetScene().forces.GetComponent(entity); + const ForceFieldComponent* force = wiSceneSystem::GetScene().forces.GetComponent(entity); if (force != nullptr) { diff --git a/Editor/HairParticleWindow.cpp b/Editor/HairParticleWindow.cpp index 6440095e9..6ef261fb3 100644 --- a/Editor/HairParticleWindow.cpp +++ b/Editor/HairParticleWindow.cpp @@ -27,7 +27,7 @@ HairParticleWindow::HairParticleWindow(wiGUI* gui) : GUI(gui) addButton->SetPos(XMFLOAT2(x, y += step)); addButton->SetSize(XMFLOAT2(200, 30)); addButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); scene.Entity_CreateHair("editorHair"); }); addButton->SetTooltip("Add new hair particle system."); @@ -47,7 +47,7 @@ HairParticleWindow::HairParticleWindow(wiGUI* gui) : GUI(gui) } else { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); hair->meshID = scene.meshes.GetEntity(args.iValue - 1); } } @@ -184,7 +184,7 @@ wiHairParticle* HairParticleWindow::GetHair() return nullptr; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); wiHairParticle* hair = scene.hairs.GetComponent(entity); return hair; @@ -198,7 +198,7 @@ void HairParticleWindow::UpdateData() return; } - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); meshComboBox->ClearItems(); meshComboBox->AddItem("NO MESH"); diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 5914a6ab5..4946dd044 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -25,7 +25,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) energySlider->SetSize(XMFLOAT2(100, 30)); energySlider->SetPos(XMFLOAT2(x, y += step)); energySlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->energy = args.fValue; @@ -39,7 +39,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) rangeSlider->SetSize(XMFLOAT2(100, 30)); rangeSlider->SetPos(XMFLOAT2(x, y += step)); rangeSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->range = args.fValue; @@ -53,7 +53,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) radiusSlider->SetSize(XMFLOAT2(100, 30)); radiusSlider->SetPos(XMFLOAT2(x, y += step)); radiusSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->radius = args.fValue; @@ -67,7 +67,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) widthSlider->SetSize(XMFLOAT2(100, 30)); widthSlider->SetPos(XMFLOAT2(x, y += step)); widthSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->width = args.fValue; @@ -81,7 +81,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) heightSlider->SetSize(XMFLOAT2(100, 30)); heightSlider->SetPos(XMFLOAT2(x, y += step)); heightSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->height = args.fValue; @@ -95,7 +95,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) fovSlider->SetSize(XMFLOAT2(100, 30)); fovSlider->SetPos(XMFLOAT2(x, y += step)); fovSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->fov = args.fValue; @@ -109,7 +109,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) biasSlider->SetSize(XMFLOAT2(100, 30)); biasSlider->SetPos(XMFLOAT2(x, y += step)); biasSlider->OnSlide([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->shadowBias = args.fValue; @@ -122,7 +122,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) shadowCheckBox = new wiCheckBox("Shadow: "); shadowCheckBox->SetPos(XMFLOAT2(x, y += step)); shadowCheckBox->OnClick([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetCastShadow(args.bValue); @@ -135,7 +135,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) volumetricsCheckBox = new wiCheckBox("Volumetric Scattering: "); volumetricsCheckBox->SetPos(XMFLOAT2(x, y += step)); volumetricsCheckBox->OnClick([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetVolumetricsEnabled(args.bValue); @@ -148,7 +148,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) haloCheckBox = new wiCheckBox("Visualizer: "); haloCheckBox->SetPos(XMFLOAT2(x, y += step)); haloCheckBox->OnClick([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetVisualizerEnabled(args.bValue); @@ -161,7 +161,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) staticCheckBox = new wiCheckBox("Static: "); staticCheckBox->SetPos(XMFLOAT2(x, y += step)); staticCheckBox->OnClick([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->SetStatic(args.bValue); @@ -175,7 +175,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) addLightButton->SetPos(XMFLOAT2(x, y += step)); addLightButton->SetSize(XMFLOAT2(150, 30)); addLightButton->OnClick([&](wiEventArgs args) { - wiRenderer::GetScene().Entity_CreateLight("editorLight", XMFLOAT3(0, 3, 0), XMFLOAT3(1, 1, 1), 2, 60); + wiSceneSystem::GetScene().Entity_CreateLight("editorLight", XMFLOAT3(0, 3, 0), XMFLOAT3(1, 1, 1), 2, 60); }); addLightButton->SetTooltip("Add a light to the scene."); lightWindow->AddWidget(addLightButton); @@ -187,7 +187,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) colorPicker->SetVisible(true); colorPicker->SetEnabled(true); colorPicker->OnColorChanged([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { light->color = args.color.toFloat3(); @@ -198,7 +198,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) typeSelectorComboBox = new wiComboBox("Type: "); typeSelectorComboBox->SetPos(XMFLOAT2(x, y += step)); typeSelectorComboBox->OnSelect([&](wiEventArgs args) { - LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr && args.iValue >= 0) { light->SetType((LightComponent::LightType)args.iValue); @@ -239,7 +239,7 @@ void LightWindow::SetEntity(Entity entity) this->entity = entity; - const LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity); + const LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity); if (light != nullptr) { diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index 3a5465815..a148bc89b 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -27,7 +27,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) materialNameField->SetPos(XMFLOAT2(10, 60)); materialNameField->SetSize(XMFLOAT2(300, 20)); materialNameField->OnInputAccepted([&](wiEventArgs args) { - NameComponent* name = wiRenderer::GetScene().names.GetComponent(entity); + NameComponent* name = wiSceneSystem::GetScene().names.GetComponent(entity); if (name != nullptr) { *name = args.sValue; @@ -42,7 +42,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) waterCheckBox->SetTooltip("Set material as special water material."); waterCheckBox->SetPos(XMFLOAT2(670, y += step)); waterCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetWater(args.bValue); }); @@ -52,7 +52,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); planarReflCheckBox->SetPos(XMFLOAT2(670, y += step)); planarReflCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetPlanarReflections(args.bValue); }); @@ -62,7 +62,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); shadowCasterCheckBox->SetPos(XMFLOAT2(670, y += step)); shadowCasterCheckBox->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetCastShadow(args.bValue); }); @@ -72,7 +72,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetFlipNormalMap(args.bValue); }); @@ -82,7 +82,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetUseVertexColors(args.bValue); }); @@ -92,7 +92,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetUseSpecularGlossinessWorkflow(args.bValue); }); @@ -106,7 +106,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) normalMapSlider->SetSize(XMFLOAT2(100, 30)); normalMapSlider->SetPos(XMFLOAT2(x, y += step)); normalMapSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetNormalMapStrength(args.fValue); }); @@ -117,7 +117,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) roughnessSlider->SetSize(XMFLOAT2(100, 30)); roughnessSlider->SetPos(XMFLOAT2(x, y += step)); roughnessSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetRoughness(args.fValue); }); @@ -128,7 +128,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) reflectanceSlider->SetSize(XMFLOAT2(100, 30)); reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); reflectanceSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetReflectance(args.fValue); }); @@ -139,7 +139,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) metalnessSlider->SetSize(XMFLOAT2(100, 30)); metalnessSlider->SetPos(XMFLOAT2(x, y += step)); metalnessSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetMetalness(args.fValue); }); @@ -150,7 +150,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) alphaSlider->SetSize(XMFLOAT2(100, 30)); alphaSlider->SetPos(XMFLOAT2(x, y += step)); alphaSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetOpacity(args.fValue); }); @@ -161,7 +161,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) alphaRefSlider->SetSize(XMFLOAT2(100, 30)); alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); alphaRefSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetAlphaRef(args.fValue); }); @@ -172,7 +172,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) refractionIndexSlider->SetSize(XMFLOAT2(100, 30)); refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); refractionIndexSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetRefractionIndex(args.fValue); }); @@ -183,7 +183,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) emissiveSlider->SetSize(XMFLOAT2(100, 30)); emissiveSlider->SetPos(XMFLOAT2(x, y += step)); emissiveSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetEmissiveStrength(args.fValue); }); @@ -194,7 +194,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) sssSlider->SetSize(XMFLOAT2(100, 30)); sssSlider->SetPos(XMFLOAT2(x, y += step)); sssSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetSubsurfaceScattering(args.fValue); }); @@ -205,7 +205,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) pomSlider->SetSize(XMFLOAT2(100, 30)); pomSlider->SetPos(XMFLOAT2(x, y += step)); pomSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetParallaxOcclusionMapping(args.fValue); }); @@ -216,7 +216,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) displacementMappingSlider->SetSize(XMFLOAT2(100, 30)); displacementMappingSlider->SetPos(XMFLOAT2(x, y += step)); displacementMappingSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) material->SetDisplacementMapping(args.fValue); }); @@ -227,7 +227,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texAnimFrameRateSlider->SetSize(XMFLOAT2(100, 30)); texAnimFrameRateSlider->SetPos(XMFLOAT2(x, y += step)); texAnimFrameRateSlider->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimFrameRate = args.fValue; @@ -240,7 +240,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texAnimDirectionSliderU->SetSize(XMFLOAT2(100, 30)); texAnimDirectionSliderU->SetPos(XMFLOAT2(x, y += step)); texAnimDirectionSliderU->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimDirection.x = args.fValue; @@ -253,7 +253,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texAnimDirectionSliderV->SetSize(XMFLOAT2(100, 30)); texAnimDirectionSliderV->SetPos(XMFLOAT2(x, y += step)); texAnimDirectionSliderV->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->texAnimDirection.y = args.fValue; @@ -266,7 +266,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texMulSliderX->SetSize(XMFLOAT2(100, 30)); texMulSliderX->SetPos(XMFLOAT2(x, y += step)); texMulSliderX->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetDirty(); @@ -280,7 +280,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texMulSliderY->SetSize(XMFLOAT2(100, 30)); texMulSliderY->SetPos(XMFLOAT2(x, y += step)); texMulSliderY->OnSlide([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetDirty(); @@ -296,7 +296,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) baseColorPicker->SetVisible(true); baseColorPicker->SetEnabled(true); baseColorPicker->OnColorChanged([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { XMFLOAT3 col = args.color.toFloat3(); @@ -312,7 +312,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) emissiveColorPicker->SetVisible(true); emissiveColorPicker->SetEnabled(true); emissiveColorPicker->OnColorChanged([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { XMFLOAT3 col = args.color.toFloat3(); @@ -326,7 +326,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); blendModeComboBox->SetSize(XMFLOAT2(100, 25)); blendModeComboBox->OnSelect([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr && args.iValue >= 0) { material->blendMode = static_cast(args.iValue); @@ -346,7 +346,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); shaderTypeComboBox->SetSize(XMFLOAT2(100, 25)); shaderTypeComboBox->OnSelect([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetCustomShaderID(args.iValue - 1); @@ -378,7 +378,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); texture_baseColor_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -426,7 +426,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_BaseColorMap(args.iValue); @@ -447,7 +447,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); texture_normal_Button->SetSize(XMFLOAT2(260, 20)); texture_normal_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -495,7 +495,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_NormalMap(args.iValue); @@ -516,7 +516,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); texture_surface_Button->SetSize(XMFLOAT2(260, 20)); texture_surface_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -564,7 +564,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_SurfaceMap(args.iValue); @@ -585,7 +585,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); texture_displacement_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -633,7 +633,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_DisplacementMap(args.iValue); @@ -654,7 +654,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_emissive_Button->SetPos(XMFLOAT2(x + 122, y)); texture_emissive_Button->SetSize(XMFLOAT2(260, 20)); texture_emissive_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -702,7 +702,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_EmissiveMap(args.iValue); @@ -724,7 +724,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) texture_occlusion_Button->SetPos(XMFLOAT2(x + 122, y)); texture_occlusion_Button->SetSize(XMFLOAT2(260, 20)); texture_occlusion_Button->OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material == nullptr) return; @@ -772,7 +772,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) 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 = wiRenderer::GetScene().materials.GetComponent(entity); + MaterialComponent* material = wiSceneSystem::GetScene().materials.GetComponent(entity); if (material != nullptr) { material->SetUVSet_OcclusionMap(args.iValue); @@ -803,7 +803,7 @@ void MaterialWindow::SetEntity(Entity entity) this->entity = entity; - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); MaterialComponent* material = scene.materials.GetComponent(entity); if (material != nullptr) diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index 6f1019a37..1b14fe438 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -35,7 +35,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) doubleSidedCheckBox->SetTooltip("If enabled, the inside of the mesh will be visible."); doubleSidedCheckBox->SetPos(XMFLOAT2(x, y += step)); doubleSidedCheckBox->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->SetDoubleSided(args.bValue); @@ -48,7 +48,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) softbodyCheckBox->SetPos(XMFLOAT2(x, y += step)); softbodyCheckBox->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); SoftBodyPhysicsComponent* physicscomponent = scene.softbodies.GetComponent(entity); if (args.bValue) @@ -76,7 +76,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) massSlider->SetSize(XMFLOAT2(100, 30)); massSlider->SetPos(XMFLOAT2(x, y += step)); massSlider->OnSlide([&](wiEventArgs args) { - SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity); + SoftBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->mass = args.fValue; @@ -89,7 +89,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) frictionSlider->SetSize(XMFLOAT2(100, 30)); frictionSlider->SetPos(XMFLOAT2(x, y += step)); frictionSlider->OnSlide([&](wiEventArgs args) { - SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity); + SoftBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->friction = args.fValue; @@ -102,10 +102,10 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) impostorCreateButton->SetSize(XMFLOAT2(240, 30)); impostorCreateButton->SetPos(XMFLOAT2(x - 50, y += step)); impostorCreateButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); scene.impostors.Create(entity).swapInDistance = impostorDistanceSlider->GetValue(); } }); @@ -116,7 +116,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) impostorDistanceSlider->SetSize(XMFLOAT2(100, 30)); impostorDistanceSlider->SetPos(XMFLOAT2(x, y += step)); impostorDistanceSlider->OnSlide([&](wiEventArgs args) { - ImpostorComponent* impostor = wiRenderer::GetScene().impostors.GetComponent(entity); + ImpostorComponent* impostor = wiSceneSystem::GetScene().impostors.GetComponent(entity); if (impostor != nullptr) { impostor->swapInDistance = args.fValue; @@ -129,7 +129,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) tessellationFactorSlider->SetSize(XMFLOAT2(100, 30)); tessellationFactorSlider->SetPos(XMFLOAT2(x, y += step)); tessellationFactorSlider->OnSlide([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->tessellationFactor = args.fValue; @@ -142,7 +142,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) flipCullingButton->SetSize(XMFLOAT2(240, 30)); flipCullingButton->SetPos(XMFLOAT2(x - 50, y += step)); flipCullingButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->FlipCulling(); @@ -156,7 +156,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) flipNormalsButton->SetSize(XMFLOAT2(240, 30)); flipNormalsButton->SetPos(XMFLOAT2(x - 50, y += step)); flipNormalsButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->FlipNormals(); @@ -170,7 +170,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) computeNormalsSmoothButton->SetSize(XMFLOAT2(240, 30)); computeNormalsSmoothButton->SetPos(XMFLOAT2(x - 50, y += step)); computeNormalsSmoothButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->ComputeNormals(true); @@ -184,7 +184,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) computeNormalsHardButton->SetSize(XMFLOAT2(240, 30)); computeNormalsHardButton->SetPos(XMFLOAT2(x - 50, y += step)); computeNormalsHardButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->ComputeNormals(false); @@ -198,7 +198,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) recenterButton->SetSize(XMFLOAT2(240, 30)); recenterButton->SetPos(XMFLOAT2(x - 50, y += step)); recenterButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->Recenter(); @@ -212,7 +212,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) recenterToBottomButton->SetSize(XMFLOAT2(240, 30)); recenterToBottomButton->SetPos(XMFLOAT2(x - 50, y += step)); recenterToBottomButton->OnClick([&](wiEventArgs args) { - MeshComponent* mesh = wiRenderer::GetScene().meshes.GetComponent(entity); + MeshComponent* mesh = wiSceneSystem::GetScene().meshes.GetComponent(entity); if (mesh != nullptr) { mesh->RecenterToBottom(); @@ -242,7 +242,7 @@ void MeshWindow::SetEntity(Entity entity) { this->entity = entity; - Scene&scene = wiRenderer::GetScene(); + Scene&scene = wiSceneSystem::GetScene(); const MeshComponent* mesh = scene.meshes.GetComponent(entity); @@ -277,7 +277,7 @@ void MeshWindow::SetEntity(Entity entity) softbodyCheckBox->SetCheck(false); - SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity); + SoftBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().softbodies.GetComponent(entity); if (physicscomponent != nullptr) { softbodyCheckBox->SetCheck(true); diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 8195d7a48..dfdd76cc7 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -271,7 +271,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) renderableCheckBox->SetPos(XMFLOAT2(x, y += 30)); renderableCheckBox->SetCheck(true); renderableCheckBox->OnClick([&](wiEventArgs args) { - ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); + ObjectComponent* object = wiSceneSystem::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->SetRenderable(args.bValue); @@ -284,7 +284,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) ditherSlider->SetSize(XMFLOAT2(100, 30)); ditherSlider->SetPos(XMFLOAT2(x, y += 30)); ditherSlider->OnSlide([&](wiEventArgs args) { - ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); + ObjectComponent* object = wiSceneSystem::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->color.w = 1 - args.fValue; @@ -297,7 +297,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) cascadeMaskSlider->SetSize(XMFLOAT2(100, 30)); cascadeMaskSlider->SetPos(XMFLOAT2(x, y += 30)); cascadeMaskSlider->OnSlide([&](wiEventArgs args) { - ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); + ObjectComponent* object = wiSceneSystem::GetScene().objects.GetComponent(entity); if (object != nullptr) { object->cascadeMask = (uint32_t)args.iValue; @@ -312,7 +312,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) colorPicker->SetVisible(true); colorPicker->SetEnabled(true); colorPicker->OnColorChanged([&](wiEventArgs args) { - ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity); + ObjectComponent* object = wiSceneSystem::GetScene().objects.GetComponent(entity); if (object != nullptr) { XMFLOAT3 col = args.color.toFloat3(); @@ -337,7 +337,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) rigidBodyCheckBox->SetCheck(false); rigidBodyCheckBox->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); RigidBodyPhysicsComponent* physicscomponent = scene.rigidbodies.GetComponent(entity); if (args.bValue) @@ -366,7 +366,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) kinematicCheckBox->SetPos(XMFLOAT2(x, y += 30)); kinematicCheckBox->SetCheck(false); kinematicCheckBox->OnClick([&](wiEventArgs args) { - RigidBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().rigidbodies.GetComponent(entity); + RigidBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->SetKinematic(args.bValue); @@ -379,7 +379,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) disabledeactivationCheckBox->SetPos(XMFLOAT2(x, y += 30)); disabledeactivationCheckBox->SetCheck(false); disabledeactivationCheckBox->OnClick([&](wiEventArgs args) { - RigidBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().rigidbodies.GetComponent(entity); + RigidBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { physicscomponent->SetDisableDeactivation(args.bValue); @@ -397,7 +397,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) collisionShapeComboBox->AddItem("Triangle Mesh"); collisionShapeComboBox->OnSelect([&](wiEventArgs args) { - RigidBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().rigidbodies.GetComponent(entity); + RigidBodyPhysicsComponent* physicscomponent = wiSceneSystem::GetScene().rigidbodies.GetComponent(entity); if (physicscomponent != nullptr) { switch (args.iValue) @@ -448,7 +448,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) generateLightmapButton->SetSize(XMFLOAT2(140,30)); generateLightmapButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); std::unordered_set gen_objects; std::unordered_map gen_meshes; @@ -497,7 +497,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) stopLightmapGenButton->SetSize(XMFLOAT2(140, 30)); stopLightmapGenButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); for (auto& x : this->editor->selected) { @@ -518,7 +518,7 @@ ObjectWindow::ObjectWindow(EditorComponent* editor) : editor(editor) clearLightmapButton->SetSize(XMFLOAT2(140, 30)); clearLightmapButton->OnClick([&](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); for (auto& x : this->editor->selected) { @@ -556,7 +556,7 @@ void ObjectWindow::SetEntity(Entity entity) this->entity = entity; - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); const ObjectComponent* object = scene.objects.GetComponent(entity); diff --git a/Editor/OceanWindow.cpp b/Editor/OceanWindow.cpp index 8ebf01aaf..bb48cb8f0 100644 --- a/Editor/OceanWindow.cpp +++ b/Editor/OceanWindow.cpp @@ -33,12 +33,12 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) patchSizeSlider = new wiSlider(1, 1000, 1000, 100000, "Patch size: "); patchSizeSlider->SetSize(XMFLOAT2(100, 30)); patchSizeSlider->SetPos(XMFLOAT2(x, y += inc)); - patchSizeSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.patch_length); + patchSizeSlider->SetValue(wiSceneSystem::GetScene().weather.oceanParameters.patch_length); patchSizeSlider->SetTooltip("Adjust water tiling patch size"); patchSizeSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.patch_length = args.fValue; wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck()); } @@ -48,12 +48,12 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) waveAmplitudeSlider = new wiSlider(0, 1000, 1000, 100000, "Wave amplitude: "); waveAmplitudeSlider->SetSize(XMFLOAT2(100, 30)); waveAmplitudeSlider->SetPos(XMFLOAT2(x, y += inc)); - waveAmplitudeSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.wave_amplitude); + waveAmplitudeSlider->SetValue(wiSceneSystem::GetScene().weather.oceanParameters.wave_amplitude); waveAmplitudeSlider->SetTooltip("Adjust wave size"); waveAmplitudeSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.wave_amplitude = args.fValue; wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck()); } @@ -63,12 +63,12 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) choppyScaleSlider = new wiSlider(0, 10, 1000, 100000, "Choppiness: "); choppyScaleSlider->SetSize(XMFLOAT2(100, 30)); choppyScaleSlider->SetPos(XMFLOAT2(x, y += inc)); - choppyScaleSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.choppy_scale); + choppyScaleSlider->SetValue(wiSceneSystem::GetScene().weather.oceanParameters.choppy_scale); choppyScaleSlider->SetTooltip("Adjust wave choppiness"); choppyScaleSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.choppy_scale = args.fValue; wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck()); } @@ -78,12 +78,12 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) windDependencySlider = new wiSlider(0, 1, 1000, 100000, "Wind dependency: "); windDependencySlider->SetSize(XMFLOAT2(100, 30)); windDependencySlider->SetPos(XMFLOAT2(x, y += inc)); - windDependencySlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.wind_dependency); + windDependencySlider->SetValue(wiSceneSystem::GetScene().weather.oceanParameters.wind_dependency); windDependencySlider->SetTooltip("Adjust wind contribution"); windDependencySlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.wind_dependency = args.fValue; wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck()); } @@ -93,12 +93,12 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) timeScaleSlider = new wiSlider(0, 4, 1000, 100000, "Time scale: "); timeScaleSlider->SetSize(XMFLOAT2(100, 30)); timeScaleSlider->SetPos(XMFLOAT2(x, y += inc)); - timeScaleSlider->SetValue(wiRenderer::GetScene().weather.oceanParameters.time_scale); + timeScaleSlider->SetValue(wiSceneSystem::GetScene().weather.oceanParameters.time_scale); timeScaleSlider->SetTooltip("Adjust simulation speed"); timeScaleSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.time_scale = args.fValue; wiRenderer::SetOceanEnabled(enabledCheckBox->GetCheck()); } @@ -111,9 +111,9 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) heightSlider->SetValue(0); heightSlider->SetTooltip("Adjust water level"); heightSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.waterHeight = args.fValue; } }); @@ -125,9 +125,9 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) detailSlider->SetValue(4); detailSlider->SetTooltip("Adjust surface tessellation resolution. High values can decrease performance."); detailSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.surfaceDetail = (uint32_t)args.iValue; } }); @@ -139,9 +139,9 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) toleranceSlider->SetValue(2); toleranceSlider->SetTooltip("Big waves can introduce glitches on screen borders, this can fix that but surface detail will decrease."); toleranceSlider->OnSlide([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.surfaceDisplacementTolerance = args.fValue; } }); @@ -154,9 +154,9 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui) colorPicker->SetVisible(true); colorPicker->SetEnabled(true); colorPicker->OnColorChanged([&](wiEventArgs args) { - if (wiRenderer::GetScene().weathers.GetCount() > 0) + if (wiSceneSystem::GetScene().weathers.GetCount() > 0) { - WeatherComponent& weather = wiRenderer::GetScene().weathers[0]; + WeatherComponent& weather = wiSceneSystem::GetScene().weathers[0]; weather.oceanParameters.waterColor = args.color.toFloat3(); } }); diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index 87e2ee245..02de44683 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -196,7 +196,7 @@ Translator::~Translator() void Translator::Update() { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (!scene.transforms.Contains(entityID)) { @@ -433,7 +433,7 @@ void Translator::Update() } void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) const { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (!scene.transforms.Contains(entityID)) { @@ -471,18 +471,24 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) co XMStoreFloat4x4(&sb.g_xTransform, matX); sb.g_xColor = state == TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Plane, 0, threadID); // xz XMStoreFloat4x4(&sb.g_xTransform, matZ); sb.g_xColor = state == TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Plane, 0, threadID); // yz XMStoreFloat4x4(&sb.g_xTransform, matY); sb.g_xColor = state == TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Plane, 0, threadID); // Lines: @@ -501,18 +507,24 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) co XMStoreFloat4x4(&sb.g_xTransform, matX); sb.g_xColor = state == TRANSLATOR_X ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(1, 0, 0, 1); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Axis, 0, threadID); // y XMStoreFloat4x4(&sb.g_xTransform, matY); sb.g_xColor = state == TRANSLATOR_Y ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 1, 0, 1); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Axis, 0, threadID); // z XMStoreFloat4x4(&sb.g_xTransform, matZ); sb.g_xColor = state == TRANSLATOR_Z ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 0, 1, 1); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Axis, 0, threadID); // Origin: @@ -528,6 +540,8 @@ void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID) co XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(mat)); sb.g_xColor = state == TRANSLATOR_XYZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.25f, 0.25f, 0.25f, 1); device->UpdateBuffer(wiRenderer::GetConstantBuffer(CBTYPE_MISC), &sb, threadID); + device->BindConstantBuffer(VS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, wiRenderer::GetConstantBuffer(CBTYPE_MISC), CB_GETBINDSLOT(MiscCB), threadID); device->Draw(vertexCount_Origin, 0, threadID); } diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 641e455c4..d5b680f30 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -228,7 +228,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui) eliminateCoarseCascadesButton->SetPos(XMFLOAT2(x - 100, y += step * 3)); eliminateCoarseCascadesButton->OnClick([=](wiEventArgs args) { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); for (size_t i = 0; i < scene.objects.GetCount(); ++i) { scene.objects[i].cascadeMask = 1; @@ -304,7 +304,7 @@ void WeatherWindow::UpdateFromRenderer() WeatherComponent& WeatherWindow::GetWeather() const { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); if (scene.weathers.GetCount() == 0) { scene.weathers.Create(CreateEntity()); @@ -314,7 +314,7 @@ WeatherComponent& WeatherWindow::GetWeather() const void WeatherWindow::InvalidateProbes() const { - Scene& scene = wiRenderer::GetScene(); + Scene& scene = wiSceneSystem::GetScene(); // Also, we invalidate all environment probes to reflect the sky changes. for (size_t i = 0; i < scene.probes.GetCount(); ++i) diff --git a/README.md b/README.md index 8dea25090..5a90dbb68 100644 --- a/README.md +++ b/README.md @@ -142,9 +142,9 @@ Some basic usage examples (C++): 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 main.ActivatePath(&myGame); // Register your game to the application. It will call Start(), Update(), Render(), etc. from now on... -wiRenderer::LoadModel("myModel.wiscene"); // Simply load a model into the current render scene -wiRenderer::GetScene(); // Get the current render scene -wiRenderer::ClearWorld(); // Delete every model, etc. from the current render scene +wiSceneSystem::LoadModel("myModel.wiscene"); // Simply load a model into the current global scene +wiSceneSystem::GetScene(); // Get the current global scene +wiRenderer::ClearWorld(); // Delete every model, etc. from the current global scene myGame.setSSAOEnabled(true); // You can enable post process effects this way... @@ -176,14 +176,14 @@ main.SetActivePath(path); -- "main" is created automatically -- Load a model entity: entity = LoadModel("myModel.wiscene"); --- Get the current render scene: +-- Get the current global scene: scene = GetScene(); -- Move model to the right using the entity-component system: transform = scene.Component_GetTransform(entity); transform.Translate(Vector(2, 0, 0)); --- Clear every model from the current render scene: +-- Clear every model from the current global scene: ClearWorld(); -- Print any WickedEngine class information to the backlog: diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index 969388a64..27e253efc 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -108,7 +108,7 @@ TestsRenderer::TestsRenderer() wiRenderer::SetToDrawGridHelper(false); wiRenderer::SetTemporalAAEnabled(false); wiRenderer::ClearWorld(); - wiRenderer::GetScene().weather = WeatherComponent(); + wiSceneSystem::GetScene().weather = WeatherComponent(); this->clearSprites(); this->clearFonts(); wiLua::GetGlobal()->KillProcesses(); @@ -135,16 +135,16 @@ TestsRenderer::TestsRenderer() } case 1: wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/teapot.wiscene"); + wiSceneSystem::LoadModel("../models/teapot.wiscene"); break; case 2: - wiRenderer::LoadModel("../models/emitter_smoke.wiscene"); + wiSceneSystem::LoadModel("../models/emitter_smoke.wiscene"); break; case 3: - wiRenderer::LoadModel("../models/emitter_skinned.wiscene"); + wiSceneSystem::LoadModel("../models/emitter_skinned.wiscene"); break; case 4: - wiRenderer::LoadModel("../models/hairparticle_torus.wiscene", XMMatrixTranslation(0, 1, 0)); + wiSceneSystem::LoadModel("../models/hairparticle_torus.wiscene", XMMatrixTranslation(0, 1, 0)); break; case 5: wiRenderer::SetToDrawGridHelper(true); @@ -152,18 +152,18 @@ TestsRenderer::TestsRenderer() break; case 6: wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/water_test.wiscene", XMMatrixTranslation(0, 1, 0)); + wiSceneSystem::LoadModel("../models/water_test.wiscene", XMMatrixTranslation(0, 1, 0)); break; case 7: wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/shadows_test.wiscene", XMMatrixTranslation(0, 1, 0)); + wiSceneSystem::LoadModel("../models/shadows_test.wiscene", XMMatrixTranslation(0, 1, 0)); break; case 8: wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/physics_test.wiscene"); + wiSceneSystem::LoadModel("../models/physics_test.wiscene"); break; case 9: - wiRenderer::LoadModel("../models/cloth_test.wiscene", XMMatrixTranslation(0, 3, 4)); + wiSceneSystem::LoadModel("../models/cloth_test.wiscene", XMMatrixTranslation(0, 3, 4)); break; case 10: RunJobSystemTest(); @@ -173,7 +173,7 @@ TestsRenderer::TestsRenderer() break; case 12: wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/volumetric_test.wiscene", XMMatrixTranslation(0, 0, 4)); + wiSceneSystem::LoadModel("../models/volumetric_test.wiscene", XMMatrixTranslation(0, 0, 4)); break; case 13: RunSpriteTest(); @@ -181,7 +181,7 @@ TestsRenderer::TestsRenderer() case 14: wiRenderer::GetDevice()->SetVSyncEnabled(false); // turn off vsync if we can to accelerate the baking wiRenderer::SetTemporalAAEnabled(true); - wiRenderer::LoadModel("../models/lightmap_bake_test.wiscene", XMMatrixTranslation(0, 0, 4)); + wiSceneSystem::LoadModel("../models/lightmap_bake_test.wiscene", XMMatrixTranslation(0, 0, 4)); break; default: assert(0); diff --git a/WickedEngine/ConstantBufferMapping.h b/WickedEngine/ConstantBufferMapping.h index 8963f1a39..27dc4e036 100644 --- a/WickedEngine/ConstantBufferMapping.h +++ b/WickedEngine/ConstantBufferMapping.h @@ -4,43 +4,42 @@ // Slot matchings: //////////////////////////////////////////////////// -// Persistent buffers: -// These are bound once and are alive forever +// Common buffers: +// These are usable by all shaders #define CBSLOT_RENDERER_FRAME 0 -#define CBSLOT_RENDERER_CAMERA 1 -#define CBSLOT_RENDERER_MISC 2 +#define CBSLOT_API 1 -#define CBSLOT_IMAGE_IMAGE 3 -#define CBSLOT_IMAGE_POSTPROCESS 4 - -#define CBSLOT_FONT 5 - -#define CBSLOT_API 6 // On demand buffers: // These are bound on demand and alive until another is bound at the same slot -#define CBSLOT_RENDERER_MATERIAL 7 -#define CBSLOT_RENDERER_FORWARD_LIGHTMASK 8 -#define CBSLOT_RENDERER_CUBEMAPRENDER 8 -#define CBSLOT_RENDERER_VOLUMELIGHT 8 -#define CBSLOT_RENDERER_LENSFLARE 8 -#define CBSLOT_RENDERER_DECAL 8 -#define CBSLOT_RENDERER_TESSELLATION 8 -#define CBSLOT_RENDERER_DISPATCHPARAMS 8 -#define CBSLOT_RENDERER_VOXELIZER 8 -#define CBSLOT_RENDERER_TRACED 8 -#define CBSLOT_RENDERER_BVH 8 -#define CBSLOT_RENDERER_UTILITY 8 +#define CBSLOT_IMAGE_IMAGE 2 +#define CBSLOT_IMAGE_POSTPROCESS 3 +#define CBSLOT_FONT 4 -#define CBSLOT_OTHER_EMITTEDPARTICLE 8 -#define CBSLOT_OTHER_HAIRPARTICLE 8 -#define CBSLOT_OTHER_FFTGENERATOR 8 -#define CBSLOT_OTHER_OCEAN_SIMULATION_IMMUTABLE 8 -#define CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME 9 -#define CBSLOT_OTHER_OCEAN_RENDER 8 -#define CBSLOT_OTHER_CLOUDGENERATOR 8 -#define CBSLOT_OTHER_GPUSORTLIB 9 +#define CBSLOT_RENDERER_MISC 4 +#define CBSLOT_RENDERER_CAMERA 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 +#define CBSLOT_RENDERER_TESSELLATION 7 +#define CBSLOT_RENDERER_DISPATCHPARAMS 7 +#define CBSLOT_RENDERER_VOXELIZER 7 +#define CBSLOT_RENDERER_TRACED 7 +#define CBSLOT_RENDERER_BVH 7 +#define CBSLOT_RENDERER_UTILITY 7 + +#define CBSLOT_OTHER_EMITTEDPARTICLE 7 +#define CBSLOT_OTHER_HAIRPARTICLE 7 +#define CBSLOT_OTHER_FFTGENERATOR 7 +#define CBSLOT_OTHER_OCEAN_SIMULATION_IMMUTABLE 7 +#define CBSLOT_OTHER_OCEAN_SIMULATION_PERFRAME 8 +#define CBSLOT_OTHER_OCEAN_RENDER 7 +#define CBSLOT_OTHER_CLOUDGENERATOR 7 +#define CBSLOT_OTHER_GPUSORTLIB 8 diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 1048240ba..a801b84e6 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -115,7 +115,6 @@ void MainComponent::Run() { // Until engine is not loaded, present initialization screen... wiRenderer::GetDevice()->PresentBegin(); - wiFont::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); wiFont(wiBackLog::getText(), wiFontParams(4, 4, infoDisplay.size)).Draw(GRAPHICSTHREAD_IMMEDIATE); wiRenderer::GetDevice()->PresentEnd(); return; @@ -225,9 +224,6 @@ void MainComponent::Render() wiLua::GetGlobal()->Render(); wiProfiler::BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE); - wiRenderer::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); - wiImage::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); - wiFont::BindPersistentState(GRAPHICSTHREAD_IMMEDIATE); if (GetActivePath() != nullptr) { GetActivePath()->Render(); diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index d70074c34..648de7dd8 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -483,7 +483,7 @@ void RenderPath3D::RenderOutline(const Texture2D& dstSceneRT, GRAPHICSTHREAD thr } void RenderPath3D::RenderLightShafts(GRAPHICSTHREAD threadID) const { - XMVECTOR sunDirection = XMLoadFloat3(&wiRenderer::GetScene().weather.sunDirection); + XMVECTOR sunDirection = XMLoadFloat3(&wiSceneSystem::GetScene().weather.sunDirection); if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, wiRenderer::GetCamera().GetAt())) > 0) { GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index a0ad13aa0..f4319e172 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -45,7 +45,7 @@ void RenderPath3D_PathTracing::ResizeBuffers() void RenderPath3D_PathTracing::Update(float dt) { - const Scene& scene = wiRenderer::GetScene(); + const Scene& scene = wiSceneSystem::GetScene(); if (wiRenderer::GetCamera().IsDirty()) { diff --git a/WickedEngine/ShaderInterop_Renderer.h b/WickedEngine/ShaderInterop_Renderer.h index 3165a19c2..71499eecc 100644 --- a/WickedEngine/ShaderInterop_Renderer.h +++ b/WickedEngine/ShaderInterop_Renderer.h @@ -104,7 +104,7 @@ static const uint TILED_CULLING_GRANULARITY = TILED_CULLING_BLOCKSIZE / TILED_CU static const int impostorCaptureAngles = 12; -// ---------- Persistent Constant buffers: ----------------- +// ---------- Common Constant buffers: ----------------- CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) { @@ -214,6 +214,18 @@ CBUFFER(FrameCB, CBSLOT_RENDERER_FRAME) float3 g_xFrame_WorldBoundsExtents_Inverse; float pad3_frameCB; // world enclosing AABB 1.0f / abs(max - min) }; +CBUFFER(APICB, CBSLOT_API) +{ + float4 g_xClipPlane; + float g_xAlphaRef; + float3 g_xPadding0_APICB; +}; + + + + +// ------- On demand Constant buffers: ---------- + // The following buffer contains properties for a temporary camera (eg. main camera, reflection camera, shadow camera...) CBUFFER(CameraCB, CBSLOT_RENDERER_CAMERA) { @@ -259,18 +271,6 @@ CBUFFER(MiscCB, CBSLOT_RENDERER_MISC) float4 g_xColor; }; -CBUFFER(APICB, CBSLOT_API) -{ - float4 g_xClipPlane; - float g_xAlphaRef; - float3 g_xPadding0_APICB; -}; - - - - -// ------- On demand Constant buffers: ---------- - CBUFFER(ForwardEntityMaskCB, CBSLOT_RENDERER_FORWARD_LIGHTMASK) { uint2 xForwardLightMask; // supports indexind 64 lights diff --git a/WickedEngine/screenPS.hlsl b/WickedEngine/screenPS.hlsl index 4e5f080c5..11056aaa1 100644 --- a/WickedEngine/screenPS.hlsl +++ b/WickedEngine/screenPS.hlsl @@ -2,5 +2,5 @@ float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET { - return xTexture.SampleLevel(sampler_linear_clamp, PSIn.tex, 0); + return xTexture.SampleLevel(Sampler, PSIn.tex, 0); } \ No newline at end of file diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index f81bdaec9..abe918d56 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -324,19 +324,8 @@ void wiFont::LoadShaders() wiRenderer::GetDevice()->CreateGraphicsPSO(&desc, &PSO); } -void wiFont::BindPersistentState(GRAPHICSTHREAD threadID) +void UpdatePendingGlyphs() { - if (!initialized) - { - return; - } - - GraphicsDevice* device = wiRenderer::GetDevice(); - - device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(FontCB), threadID); - device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(FontCB), threadID); - - // If there are pending glyphs, render them and repack the atlas: if (!pendingGlyphs.empty()) { @@ -440,9 +429,6 @@ void wiFont::BindPersistentState(GRAPHICSTHREAD threadID) assert(SUCCEEDED(hr)); } } - - // Bind the whole font atlas once for the whole frame: - device->BindResource(PS, &texture, TEXSLOT_FONTATLAS, threadID); } const Texture2D* wiFont::GetAtlas() { @@ -500,6 +486,10 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) const device->EventBegin("Font", threadID); device->BindGraphicsPSO(&PSO, threadID); + + device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(FontCB), threadID); + device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(FontCB), threadID); + device->BindResource(PS, &texture, TEXSLOT_FONTATLAS, threadID); device->BindSampler(PS, &sampler, SSLOT_ONDEMAND1, threadID); const GPUBuffer* vbs[] = { @@ -542,6 +532,8 @@ void wiFont::Draw(GRAPHICSTHREAD threadID) const device->DrawIndexed(quadCount * 6, 0, 0, threadID); device->EventEnd(threadID); + + UpdatePendingGlyphs(); } diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 9dfb1f9c0..12b4b13ae 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -39,7 +39,6 @@ public: static void CleanUp(); static void LoadShaders(); - static void BindPersistentState(GRAPHICSTHREAD threadID); static const wiGraphics::Texture2D* GetAtlas(); // Returns the font path that can be modified diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index bbed377cd..79ab70479 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -231,6 +231,9 @@ namespace wiImage device->BindGraphicsPSO(&imagePSO[targetShader][params.blendFlag][params.stencilComp][params.isHDREnabled()][sampling_type], threadID); + device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); + device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); + fullScreenEffect = false; } else // Post process @@ -314,10 +317,16 @@ namespace wiImage break; } + device->BindConstantBuffer(PS, &processCb, CB_GETBINDSLOT(PostProcessCB), threadID); + } - device->BindResource(PS, params.maskMap, TEXSLOT_ONDEMAND1, threadID); - device->BindResource(PS, params.distortionMap, TEXSLOT_ONDEMAND2, threadID); - device->BindResource(PS, params.refractionSource, TEXSLOT_ONDEMAND3, threadID); + + const GPUResource* res[] = { + params.maskMap, + params.distortionMap, + params.refractionSource, + }; + device->BindResources(PS, res, TEXSLOT_ONDEMAND1, ARRAYSIZE(res), threadID); device->Draw((fullScreenEffect ? 3 : 4), 0, threadID); @@ -520,21 +529,6 @@ namespace wiImage } - void BindPersistentState(GRAPHICSTHREAD threadID) - { - if (!initialized.load()) - { - return; - } - - GraphicsDevice* device = wiRenderer::GetDevice(); - - device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); - device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(ImageCB), threadID); - - device->BindConstantBuffer(PS, &processCb, CB_GETBINDSLOT(PostProcessCB), threadID); - } - void Initialize() { GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index f436b8f85..a6c984c60 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -16,8 +16,6 @@ namespace wiImage GRAPHICSTHREAD threadID, int stencilref = 0); - void BindPersistentState(GRAPHICSTHREAD threadID); - void LoadShaders(); void Initialize(); }; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 64d63b7a7..d086a1f78 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -34,8 +34,6 @@ #include #include -#include - using namespace std; using namespace wiGraphics; using namespace wiSceneSystem; @@ -452,11 +450,6 @@ void ReloadShaders(const std::string& path) wiGPUBVH::LoadShaders(); } -Scene& GetScene() -{ - static Scene scene; - return scene; -} CameraComponent& GetCamera() { static CameraComponent camera; @@ -484,6 +477,9 @@ void Initialize() GetCamera().CreatePerspective((float)GetInternalResolution().x, (float)GetInternalResolution().y, 0.1f, 800); + frameCullings.insert(make_pair(&GetCamera(), FrameCulling())); + frameCullings.insert(make_pair(&GetRefCamera(), FrameCulling())); + SetUpStates(); LoadBuffers(); LoadShaders(); @@ -1367,6 +1363,26 @@ ForwardEntityMaskCB ForwardEntityCullingCPU(const FrameCulling& culling, const A return cb; } +void BindConstantBuffers(SHADERSTAGE stage, GRAPHICSTHREAD threadID) +{ + GraphicsDevice* device = GetDevice(); + + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); + device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); +} +void BindShadowmaps(SHADERSTAGE stage, GRAPHICSTHREAD threadID) +{ + GraphicsDevice* device = GetDevice(); + + device->BindResource(stage, &shadowMapArray_2D, TEXSLOT_SHADOWARRAY_2D, threadID); + device->BindResource(stage, &shadowMapArray_Cube, TEXSLOT_SHADOWARRAY_CUBE, threadID); + if (GetTransparentShadowsEnabled()) + { + device->BindResource(stage, &shadowMapArray_Transparent, TEXSLOT_SHADOWARRAY_TRANSPARENT, threadID); + } +} + void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT renderTypeFlags, GRAPHICSTHREAD threadID, bool tessellation = false) { if (!renderQueue.empty()) @@ -1377,6 +1393,10 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re device->EventBegin("RenderMeshes", threadID); tessellation = tessellation && device->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION); + if (tessellation) + { + BindConstantBuffers(DS, threadID); + } struct InstBuf { @@ -1702,6 +1722,8 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re } boundVBType_Prev = boundVBType; + SetAlphaRef(material.alphaRef, threadID); + device->BindStencilRef(material.GetStencilRef(), threadID); device->BindGraphicsPSO(pso, threadID); @@ -1724,8 +1746,6 @@ void RenderMeshes(const RenderQueue& renderQueue, RENDERPASS renderPass, UINT re device->BindConstantBuffer(DS, material.constantBuffer.get(), CB_GETBINDSLOT(MaterialCB), threadID); } - SetAlphaRef(material.alphaRef, threadID); - device->DrawIndexedInstanced(subset.indexCount, instancedBatch.instanceCount, subset.indexOffset, 0, 0, threadID); } } @@ -1803,6 +1823,7 @@ void RenderImpostors(const CameraComponent& camera, RENDERPASS renderPass, GRAPH MiscCB cb; cb.g_xColor.x = (float)instances.offset; device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &cb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->BindResource(VS, instances.buffer, TEXSLOT_ONDEMAND0, threadID); device->BindResource(PS, textures[TEXTYPE_2D_IMPOSTORARRAY], TEXSLOT_ONDEMAND0, threadID); @@ -2883,25 +2904,44 @@ void LoadBuffers() GraphicsDevice* device = GetDevice(); GPUBufferDesc bd; - bd.BindFlags = BIND_CONSTANT_BUFFER; - //Persistent buffers... - - // Per Frame Constant buffer will be updated only once per frame, but used by many shaders, so it should reside in DEFAULT GPU memory! + // The following buffers will be DEFAULT (long lifetime, slow update, fast read): bd.CPUAccessFlags = 0; bd.Usage = USAGE_DEFAULT; + bd.MiscFlags = 0; + bd.ByteWidth = sizeof(FrameCB); + bd.BindFlags = BIND_CONSTANT_BUFFER; device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_FRAME]); device->SetName(&constantBuffers[CBTYPE_FRAME], "FrameCB"); - // The other constant buffers will be updated frequently (more than once per frame) so they should reside in DYNAMIC GPU memory! - bd.Usage = USAGE_DYNAMIC; - bd.CPUAccessFlags = CPU_ACCESS_WRITE; - bd.ByteWidth = sizeof(CameraCB); + bd.BindFlags = BIND_CONSTANT_BUFFER; device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_CAMERA]); device->SetName(&constantBuffers[CBTYPE_CAMERA], "CameraCB"); + + bd.ByteWidth = sizeof(ShaderEntityType) * SHADER_ENTITY_COUNT; + bd.BindFlags = BIND_SHADER_RESOURCE; + bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; + bd.StructureByteStride = sizeof(ShaderEntityType); + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_ENTITYARRAY]); + device->SetName(&resourceBuffers[RBTYPE_ENTITYARRAY], "EntityArray"); + + bd.ByteWidth = sizeof(XMMATRIX) * MATRIXARRAY_COUNT; + bd.BindFlags = BIND_SHADER_RESOURCE; + bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; + bd.StructureByteStride = sizeof(XMMATRIX); + device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_MATRIXARRAY]); + device->SetName(&resourceBuffers[RBTYPE_MATRIXARRAY], "MatrixArray"); + + + // The following buffers will be DYNAMIC (short lifetime, fast update, slow read): + bd.Usage = USAGE_DYNAMIC; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; + bd.MiscFlags = 0; + bd.BindFlags = BIND_CONSTANT_BUFFER; + bd.ByteWidth = sizeof(MiscCB); device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_MISC]); device->SetName(&constantBuffers[CBTYPE_MISC], "MiscCB"); @@ -2910,9 +2950,6 @@ void LoadBuffers() device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_API]); device->SetName(&constantBuffers[CBTYPE_API], "APICB"); - - // On demand buffers... - bd.ByteWidth = sizeof(VolumeLightCB); device->CreateBuffer(&bd, nullptr, &constantBuffers[CBTYPE_VOLUMELIGHT]); device->SetName(&constantBuffers[CBTYPE_VOLUMELIGHT], "VolumelightCB"); @@ -2958,29 +2995,6 @@ void LoadBuffers() device->SetName(&constantBuffers[CBTYPE_FORWARDENTITYMASK], "ForwardEntityMaskCB"); - - - - // Resource Buffers: - - // These will be used intensively by multiple shaders, so better to place them in GPU-only (USAGE_DEFAULT) memory: - bd.Usage = USAGE_DEFAULT; - bd.CPUAccessFlags = 0; - - - bd.ByteWidth = sizeof(ShaderEntityType) * SHADER_ENTITY_COUNT; - bd.BindFlags = BIND_SHADER_RESOURCE; - bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; - bd.StructureByteStride = sizeof(ShaderEntityType); - device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_ENTITYARRAY]); - device->SetName(&resourceBuffers[RBTYPE_ENTITYARRAY], "EntityArray"); - - bd.ByteWidth = sizeof(XMMATRIX) * MATRIXARRAY_COUNT; - bd.BindFlags = BIND_SHADER_RESOURCE; - bd.MiscFlags = RESOURCE_MISC_BUFFER_STRUCTURED; - bd.StructureByteStride = sizeof(XMMATRIX); - device->CreateBuffer(&bd, nullptr, &resourceBuffers[RBTYPE_MATRIXARRAY]); - device->SetName(&resourceBuffers[RBTYPE_MATRIXARRAY], "MatrixArray"); } void SetUpStates() { @@ -3805,7 +3819,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) } - const FrameCulling& mainCameraCulling = frameCullings[&GetCamera()]; + const FrameCulling& mainCameraCulling = frameCullings.at(&GetCamera()); // Fill Entity Array with decals + envprobes + lights in the frustum: { @@ -4032,7 +4046,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID) } UpdateFrameCB(threadID); - BindPersistentState(threadID); + BindCommonResources(threadID); GetPrevCamera() = GetCamera(); @@ -4220,7 +4234,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) } GraphicsDevice* device = GetDevice(); - const FrameCulling& culling = frameCullings[&GetCamera()]; + const FrameCulling& culling = frameCullings.at(&GetCamera()); wiProfiler::BeginRange("Occlusion Culling Render", wiProfiler::DOMAIN_GPU, threadID); @@ -4276,6 +4290,7 @@ void OcclusionCulling_Render(GRAPHICSTHREAD threadID) // previous frame view*projection because these are drawn against the previous depth buffer: XMStoreFloat4x4(&cb.g_xTransform, XMMatrixTranspose(aabb.getAsBoxMatrix()*GetPrevCamera().GetViewProjection())); // todo: obb device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &cb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); // render bounding box to later read the occlusion status device->QueryBegin(query, threadID); @@ -4299,7 +4314,7 @@ void OcclusionCulling_Read() wiProfiler::BeginRange("Occlusion Culling Read", wiProfiler::DOMAIN_CPU); GraphicsDevice* device = GetDevice(); - const FrameCulling& culling = frameCullings[&GetCamera()]; + const FrameCulling& culling = frameCullings.at(&GetCamera()); if (!culling.culledObjects.empty()) { @@ -4434,7 +4449,7 @@ void DrawSoftParticles(const CameraComponent& camera, bool distortion, GRAPHICST void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); const Scene& scene = GetScene(); @@ -4469,6 +4484,8 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) MiscCB miscCb; miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(3, 0, threadID); // full screen triangle } @@ -4480,6 +4497,8 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) float sca = light.range + 1; XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(240, 0, threadID); // icosphere } @@ -4496,6 +4515,8 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) camera.GetViewProjection() )); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(192, 0, threadID); // cone } @@ -4511,7 +4532,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) } void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID) { - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); if (!culling.culledLights.empty()) { @@ -4631,7 +4652,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID } void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) { - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); if (!culling.culledLights.empty()) { @@ -4669,6 +4690,8 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) MiscCB miscCb; miscCb.g_xColor.x = float(entityArrayOffset_Lights + i); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(3, 0, threadID); // full screen triangle } @@ -4680,6 +4703,8 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) float sca = light.range + 1; XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection())); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(240, 0, threadID); // icosphere } @@ -4696,6 +4721,8 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID) camera.GetViewProjection() )); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(192, 0, threadID); // cone } @@ -4717,7 +4744,7 @@ void DrawLensFlares(const CameraComponent& camera, GRAPHICSTHREAD threadID) if (IsWireRender()) return; - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); const Scene& scene = GetScene(); @@ -4835,13 +4862,16 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui return; GraphicsDevice* device = GetDevice(); - const FrameCulling& culling = frameCullings[&GetCamera()]; + const FrameCulling& culling = frameCullings.at(&GetCamera()); if (!culling.culledLights.empty()) { device->EventBegin("ShadowMap Render", threadID); wiProfiler::BeginRange("Shadow Rendering", wiProfiler::DOMAIN_GPU, threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + const bool all_layers = layerMask == 0xFFFFFFFF; @@ -5101,6 +5131,8 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui MiscCB miscCb; miscCb.g_xColor = float4(light.position.x, light.position.y, light.position.z, 1.0f / light.GetRange()); // reciprocal range, to avoid division in shader device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); const float zNearP = 0.1f; const float zFarP = max(1.0f, light.range); @@ -5140,27 +5172,18 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui device->EventEnd(threadID); } } -void BindShadowmaps(SHADERSTAGE stage, GRAPHICSTHREAD threadID) -{ - GraphicsDevice* device = GetDevice(); - - device->BindResource(stage, &shadowMapArray_2D, TEXSLOT_SHADOWARRAY_2D, threadID); - device->BindResource(stage, &shadowMapArray_Cube, TEXSLOT_SHADOWARRAY_CUBE, threadID); - if (GetTransparentShadowsEnabled()) - { - device->BindResource(stage, &shadowMapArray_Transparent, TEXSLOT_SHADOWARRAY_TRANSPARENT, threadID); - } -} void DrawScene(const CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, RENDERPASS renderPass, bool grass, bool occlusionCulling, uint32_t layerMask) { GraphicsDevice* device = GetDevice(); const Scene& scene = GetScene(); - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); device->EventBegin("DrawScene", threadID); BindShadowmaps(PS, threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); if (renderPass == RENDERPASS_TILEDFORWARD) { @@ -5246,11 +5269,13 @@ void DrawScene_Transparent(const CameraComponent& camera, RENDERPASS renderPass, { GraphicsDevice* device = GetDevice(); const Scene& scene = GetScene(); - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); device->EventBegin("DrawScene_Transparent", threadID); BindShadowmaps(PS, threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); if (renderPass == RENDERPASS_TILEDFORWARD) { @@ -5332,6 +5357,9 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) device->EventBegin("DrawDebugWorld", threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + if (debugPartitionTree) { // Actually, there is no SPTree any more, so this will just render all aabbs... @@ -5358,6 +5386,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = XMFLOAT4(1, 0, 0, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5370,6 +5400,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = XMFLOAT4(1, 1, 0, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5382,6 +5414,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = XMFLOAT4(1, 0, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5394,6 +5428,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = XMFLOAT4(0, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5411,6 +5447,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(1, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); for (size_t i = 0; i < scene.armatures.GetCount(); ++i) { @@ -5478,6 +5516,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(1, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); struct LineSegment { @@ -5525,6 +5565,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetProjection())); // only projection, we will expand in view space on CPU below to be camera facing! sb.g_xColor = XMFLOAT4(1, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); // Will generate 2 line segments for each point forming a cross section: struct LineSegment @@ -5601,6 +5643,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = x.second; device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5624,6 +5668,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&probe.position)))); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); if (probe.textureIndex < 0) { @@ -5667,6 +5713,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = float4(0, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5726,6 +5774,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = float4(1, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); GPUBuffer* vbs[] = { grid, @@ -5751,6 +5801,9 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) sb.g_xColor = float4(1, 1, 1, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(GS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); @@ -5772,6 +5825,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(XMLoadFloat4x4(&transform.world)*camera.GetViewProjection())); sb.g_xColor = float4(0, 1, 0, 1); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); if (mesh == nullptr) { @@ -5820,6 +5875,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(camera.GetViewProjection())); sb.g_xColor = XMFLOAT4(camera.Eye.x, camera.Eye.y, camera.Eye.z, (float)i); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); switch (force.type) { @@ -5866,6 +5923,8 @@ void DrawDebugWorld(const CameraComponent& camera, GRAPHICSTHREAD threadID) XMStoreFloat4x4(&sb.g_xTransform, XMMatrixTranspose(cam.GetInvView()*camera.GetViewProjection())); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); + device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->DrawIndexed(24, 0, 0, threadID); } @@ -5905,6 +5964,9 @@ void DrawSky(GRAPHICSTHREAD threadID) } } + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + device->Draw(240, 0, threadID); // icosphere device->EventEnd(threadID); @@ -5926,6 +5988,9 @@ void DrawSun(GRAPHICSTHREAD threadID) device->BindResource(PS, textures[TEXTYPE_2D_CLOUDS], TEXSLOT_ONDEMAND0, threadID); } + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + device->Draw(240, 0, threadID); device->EventEnd(threadID); @@ -5933,7 +5998,7 @@ void DrawSun(GRAPHICSTHREAD threadID) void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) { - const FrameCulling& culling = frameCullings[&camera]; + const FrameCulling& culling = frameCullings.at(&camera); if(!culling.culledDecals.empty()) { @@ -5965,6 +6030,7 @@ void DrawDecals(const CameraComponent& camera, GRAPHICSTHREAD threadID) MiscCB dcbvs; XMStoreFloat4x4(&dcbvs.g_xTransform, XMMatrixTranspose(decalWorld*camera.GetViewProjection())); device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &dcbvs, threadID); + device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); DecalCB dcbps; XMStoreFloat4x4(&dcbps.xDecalVP, XMMatrixTranspose(XMMatrixInverse(nullptr, decalWorld))); // todo: cache the inverse! @@ -6173,6 +6239,9 @@ void RefreshEnvProbes(GRAPHICSTHREAD threadID) } } + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + if (!renderQueue.empty()) { BindShadowmaps(PS, threadID); @@ -6280,6 +6349,9 @@ void RefreshImpostors(GRAPHICSTHREAD threadID) GraphicsDevice* device = GetDevice(); device->EventBegin("Impostor Refresh", threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); + static const UINT textureArraySize = maxImpostorCount * impostorCaptureAngles * 3; static const UINT textureDim = 128; static Texture2D depthStencil; @@ -6541,6 +6613,8 @@ void VoxelRadiance(GRAPHICSTHREAD threadID) device->BindUAVs(PS, UAVs, 0, 1, threadID); BindShadowmaps(PS, threadID); + BindConstantBuffers(VS, threadID); + BindConstantBuffers(PS, threadID); RenderMeshes(renderQueue, RENDERPASS_VOXELIZE, RENDERTYPE_OPAQUE, threadID); frameAllocators[threadID].free(sizeof(RenderBatch) * renderQueue.batchCount); @@ -6754,6 +6828,8 @@ void ComputeTiledLightCulling(GRAPHICSTHREAD threadID, const Texture2D* lightbuf device->UpdateBuffer(&constantBuffers[CBTYPE_DISPATCHPARAMS], &dispatchParams, threadID); device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_DISPATCHPARAMS], CB_GETBINDSLOT(DispatchParamsCB), threadID); + BindConstantBuffers(CS, threadID); + if (deferred) { const GPUResource* uavs[] = { @@ -7871,7 +7947,7 @@ const Texture2D* GetGlobalLightmap() return wiTextureHelper::getTransparent(); } -void BindPersistentState(GRAPHICSTHREAD threadID) +void BindCommonResources(GRAPHICSTHREAD threadID) { GraphicsDevice* device = GetDevice(); @@ -7885,12 +7961,10 @@ void BindPersistentState(GRAPHICSTHREAD threadID) } device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_FRAME], CB_GETBINDSLOT(FrameCB), threadID); - device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_CAMERA], CB_GETBINDSLOT(CameraCB), threadID); - device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID); device->BindConstantBuffer(stage, &constantBuffers[CBTYPE_API], CB_GETBINDSLOT(APICB), threadID); } - } + void UpdateFrameCB(GRAPHICSTHREAD threadID) { const Scene& scene = GetScene(); @@ -8182,138 +8256,6 @@ RAY GetPickRay(long cursorX, long cursorY) return RAY(lineStart, rayDirection); } -RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask) -{ - const Scene& scene = GetScene(); - - RayIntersectWorldResult result; - - if (scene.objects.GetCount() > 0) - { - const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); - const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); - - for (size_t i = 0; i < scene.aabb_objects.GetCount(); ++i) - { - const AABB& aabb = scene.aabb_objects[i]; - if (!ray.intersects(aabb)) - { - continue; - } - - const ObjectComponent& object = scene.objects[i]; - if (object.meshID == INVALID_ENTITY) - { - continue; - } - if (!(renderTypeMask & object.GetRenderTypes())) - { - continue; - } - - Entity entity = scene.aabb_objects.GetEntity(i); - const LayerComponent& layer = *scene.layers.GetComponent(entity); - - if (layer.GetLayerMask() & layerMask) - { - const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID); - - const XMMATRIX objectMat = object.transform_index >= 0 ? XMLoadFloat4x4(&scene.transforms[object.transform_index].world) : XMMatrixIdentity(); - const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); - - const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); - const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); - - const ArmatureComponent* armature = mesh.IsSkinned() ? scene.armatures.GetComponent(mesh.armatureID) : nullptr; - - int subsetCounter = 0; - for (auto& subset : mesh.subsets) - { - for (size_t i = 0; i < subset.indexCount; i += 3) - { - const uint32_t i0 = mesh.indices[subset.indexOffset + i + 0]; - const uint32_t i1 = mesh.indices[subset.indexOffset + i + 1]; - const uint32_t i2 = mesh.indices[subset.indexOffset + i + 2]; - - XMVECTOR p0 = XMLoadFloat3(&mesh.vertex_positions[i0]); - XMVECTOR p1 = XMLoadFloat3(&mesh.vertex_positions[i1]); - XMVECTOR p2 = XMLoadFloat3(&mesh.vertex_positions[i2]); - - if (armature != nullptr) - { - const XMUINT4& ind0 = mesh.vertex_boneindices[i0]; - const XMUINT4& ind1 = mesh.vertex_boneindices[i1]; - const XMUINT4& ind2 = mesh.vertex_boneindices[i2]; - - const XMFLOAT4& wei0 = mesh.vertex_boneweights[i0]; - const XMFLOAT4& wei1 = mesh.vertex_boneweights[i1]; - const XMFLOAT4& wei2 = mesh.vertex_boneweights[i2]; - - XMMATRIX sump; - - sump = armature->boneData[ind0.x].Load() * wei0.x; - sump += armature->boneData[ind0.y].Load() * wei0.y; - sump += armature->boneData[ind0.z].Load() * wei0.z; - sump += armature->boneData[ind0.w].Load() * wei0.w; - - p0 = XMVector3Transform(p0, sump); - - sump = armature->boneData[ind1.x].Load() * wei1.x; - sump += armature->boneData[ind1.y].Load() * wei1.y; - sump += armature->boneData[ind1.z].Load() * wei1.z; - sump += armature->boneData[ind1.w].Load() * wei1.w; - - p1 = XMVector3Transform(p1, sump); - - sump = armature->boneData[ind2.x].Load() * wei2.x; - sump += armature->boneData[ind2.y].Load() * wei2.y; - sump += armature->boneData[ind2.z].Load() * wei2.z; - sump += armature->boneData[ind2.w].Load() * wei2.w; - - p2 = XMVector3Transform(p2, sump); - } - - float distance; - if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, p0, p1, p2, distance)) - { - const XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); - distance = wiMath::Distance(pos, rayOrigin); - - if (distance < result.distance) - { - const XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Cross(XMVectorSubtract(p2, p1), XMVectorSubtract(p1, p0)), objectMat)); - - result.entity = entity; - XMStoreFloat3(&result.position, pos); - XMStoreFloat3(&result.normal, nor); - result.distance = distance; - result.subsetIndex = subsetCounter; - result.vertexID0 = (int)i0; - result.vertexID1 = (int)i1; - result.vertexID2 = (int)i2; - } - } - } - subsetCounter++; - } - - } - - } - } - - // Construct a matrix that will orient to position (P) according to surface normal (N): - XMVECTOR N = XMLoadFloat3(&result.normal); - XMVECTOR P = XMLoadFloat3(&result.position); - XMVECTOR E = XMLoadFloat3(&ray.origin); - XMVECTOR T = XMVector3Normalize(XMVector3Cross(N, P - E)); - XMVECTOR B = XMVector3Normalize(XMVector3Cross(T, N)); - XMMATRIX M = { T, N, B, P }; - XMStoreFloat4x4(&result.orientation, M); - - return result; -} - void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color) { renderableBoxes.push_back(pair(boxMatrix,color)); @@ -8336,58 +8278,6 @@ void AddDeferredMIPGen(const Texture2D* tex) -Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix, bool attached) -{ - wiArchive archive(fileName, true); - if (archive.IsOpen()) - { - // Create new scene - Scene scene; - - // Serialize it from file: - scene.Serialize(archive); - - // First, create new root parent: - Entity parent = CreateEntity(); - scene.transforms.Create(parent); - scene.layers.Create(parent).layerMask = ~0; - - { - // Apply the optional transformation matrix to the new scene: - - // Parent all unparented(root) transforms to "parent" - for (size_t i = 0; i < scene.transforms.GetCount() - 1; ++i) // GetCount() - 1 because the last added was the "parent" - { - Entity entity = scene.transforms.GetEntity(i); - if (!scene.hierarchy.Contains(entity)) - { - scene.Component_Attach(entity, parent); - } - } - - // The parent component is transformed, scene is updated: - scene.transforms.GetComponent(parent)->MatrixTransform(transformMatrix); - scene.Update(0); - } - - if (!attached) - { - // In this case, we don't care about the root anymore, so delete it. This will simplify overall hierarchy - scene.Component_DetachChildren(parent); - scene.Entity_Remove(parent); - parent = INVALID_ENTITY; - } - - // Merge with the original scene: - GetScene().Merge(scene); - - return parent; - } - - return INVALID_ENTITY; -} - - void SetResolutionScale(float value) { RESOLUTIONSCALE = value; } float GetResolutionScale() { return RESOLUTIONSCALE; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index bd7b0843f..f0710084f 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -66,8 +66,6 @@ namespace wiRenderer // Reload shaders, use the argument to modify the shader path. If the argument is empty, the shader path will not be modified void ReloadShaders(const std::string& path = ""); - // Returns the main scene which is currently being used in rendering - wiSceneSystem::Scene& GetScene(); // Returns the main camera that is currently being used in rendering (and also for post processing) wiSceneSystem::CameraComponent& GetCamera(); // Returns the previous frame's camera that is currently being used in rendering to reproject @@ -80,8 +78,8 @@ namespace wiRenderer // Updates the GPU state according to the previously called UpatePerFrameData() void UpdateRenderData(GRAPHICSTHREAD threadID); - // Binds all persistent constant buffers, samplers that can used globally in all shaders for a whole frame - void BindPersistentState(GRAPHICSTHREAD threadID); + // Binds all common constant buffers and samplers that may be used in all shaders + void BindCommonResources(GRAPHICSTHREAD threadID); // Updates the per frame constant buffer (need to call at least once per frame) void UpdateFrameCB(GRAPHICSTHREAD threadID); // Updates the per camera constant buffer need to call for each different camera that is used when calling DrawScene() and the like @@ -298,26 +296,6 @@ namespace wiRenderer // Gets pick ray according to the current screen resolution and pointer coordinates. Can be used as input into RayIntersectWorld() RAY GetPickRay(long cursorX, long cursorY); - struct RayIntersectWorldResult - { - wiECS::Entity entity = wiECS::INVALID_ENTITY; - XMFLOAT3 position = XMFLOAT3(0, 0, 0); - XMFLOAT3 normal = XMFLOAT3(0, 0, 0); - float distance = FLT_MAX; - int subsetIndex = -1; - int vertexID0 = -1; - int vertexID1 = -1; - int vertexID2 = -1; - XMFLOAT4X4 orientation = IDENTITYMATRIX; - - bool operator==(const RayIntersectWorldResult& other) - { - return entity == other.entity; - } - }; - // Given a ray, finds the closest intersection point against all instances - RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0); - // Add box to render in next frame. It will be rendered in DrawDebugWorld() void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color = XMFLOAT4(1,1,1,1)); @@ -342,13 +320,6 @@ namespace wiRenderer // Add a texture that should be mipmapped whenever it is feasible to do so void AddDeferredMIPGen(const wiGraphics::Texture2D* tex); - // Helper function to open a wiscene file and add the contents to the current scene - // transformMatrix : everything will be transformed by this matrix (optional) - // attached : everything will be attached to a base entity - // - // returns INVALID_ENTITY if attached argument was false, else it returns the base entity handle - wiECS::Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix = XMMatrixIdentity(), bool attached = false); - struct CustomShader { std::string name; diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 9d9e27a53..c1d48a65d 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -3,7 +3,6 @@ #include "wiHelper.h" #include "wiSceneSystem.h" #include "wiSceneSystem_BindLua.h" -#include "wiIntersect_BindLua.h" #include "Vector_BindLua.h" #include "Matrix_BindLua.h" #include "Texture_BindLua.h" @@ -15,7 +14,6 @@ using namespace wiECS; using namespace wiGraphics; using namespace wiSceneSystem; using namespace wiSceneSystem_BindLua; -using namespace wiIntersect_BindLua; namespace wiRenderer_BindLua { @@ -75,40 +73,6 @@ namespace wiRenderer_BindLua Luna::push(L, new CameraComponent_BindLua(&wiRenderer::GetCamera())); return 1; } - int GetScene(lua_State* L) - { - Luna::push(L, new Scene_BindLua(&wiRenderer::GetScene())); - return 1; - } - int LoadModel(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - string fileName = wiLua::SGetString(L, 1); - XMMATRIX transform = XMMatrixIdentity(); - if (argc > 1) - { - Matrix_BindLua* matrix = Luna::lightcheck(L, 2); - if (matrix != nullptr) - { - transform = matrix->matrix; - } - else - { - wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!"); - } - } - Entity root = wiRenderer::LoadModel(fileName, transform, true); - wiLua::SSetInt(L, int(root)); - return 1; - } - else - { - wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) not enough arguments!"); - } - return 0; - } int SetEnvironmentMap(lua_State* L) { @@ -248,42 +212,6 @@ namespace wiRenderer_BindLua return 0; } - int Pick(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - Ray_BindLua* ray = Luna::lightcheck(L, 1); - if (ray != nullptr) - { - UINT renderTypeMask = RENDERTYPE_OPAQUE; - uint32_t layerMask = 0xFFFFFFFF; - if (argc > 1) - { - renderTypeMask = (UINT)wiLua::SGetInt(L, 2); - if (argc > 2) - { - int mask = wiLua::SGetInt(L, 3); - layerMask = *reinterpret_cast(&mask); - } - } - auto& pick = wiRenderer::RayIntersectWorld(ray->ray, renderTypeMask, layerMask); - wiLua::SSetInt(L, (int)pick.entity); - Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.position))); - Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.normal))); - wiLua::SSetFloat(L, pick.distance); - return 4; - } - - wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) first argument must be of Vector type!"); - } - else - { - wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) not enough arguments!"); - } - - return 0; - } int DrawLine(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -431,8 +359,6 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("GetScreenHeight", GetScreenHeight); wiLua::GetGlobal()->RegisterFunc("GetCamera", GetCamera); - wiLua::GetGlobal()->RegisterFunc("GetScene", GetScene); - wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel); wiLua::GetGlobal()->RegisterFunc("SetEnvironmentMap", SetEnvironmentMap); wiLua::GetGlobal()->RegisterFunc("SetAlphaCompositionEnabled", SetAlphaCompositionEnabled); @@ -448,7 +374,6 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("SetDebugLightCulling", SetDebugLightCulling); wiLua::GetGlobal()->RegisterFunc("SetOcclusionCullingEnabled", SetOcclusionCullingEnabled); - wiLua::GetGlobal()->RegisterFunc("Pick", Pick); wiLua::GetGlobal()->RegisterFunc("DrawLine", DrawLine); wiLua::GetGlobal()->RegisterFunc("DrawPoint", DrawPoint); wiLua::GetGlobal()->RegisterFunc("DrawBox", DrawBox); diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 230ad9623..e3cf93118 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -11,6 +11,8 @@ #include #include +#include + using namespace wiECS; using namespace wiGraphics; @@ -2061,4 +2063,191 @@ namespace wiSceneSystem } } + + + + + + Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix, bool attached) + { + wiArchive archive(fileName, true); + if (archive.IsOpen()) + { + // Create new scene + Scene scene; + + // Serialize it from file: + scene.Serialize(archive); + + // First, create new root parent: + Entity parent = CreateEntity(); + scene.transforms.Create(parent); + scene.layers.Create(parent).layerMask = ~0; + + { + // Apply the optional transformation matrix to the new scene: + + // Parent all unparented(root) transforms to "parent" + for (size_t i = 0; i < scene.transforms.GetCount() - 1; ++i) // GetCount() - 1 because the last added was the "parent" + { + Entity entity = scene.transforms.GetEntity(i); + if (!scene.hierarchy.Contains(entity)) + { + scene.Component_Attach(entity, parent); + } + } + + // The parent component is transformed, scene is updated: + scene.transforms.GetComponent(parent)->MatrixTransform(transformMatrix); + scene.Update(0); + } + + if (!attached) + { + // In this case, we don't care about the root anymore, so delete it. This will simplify overall hierarchy + scene.Component_DetachChildren(parent); + scene.Entity_Remove(parent); + parent = INVALID_ENTITY; + } + + // Merge with the original scene: + GetScene().Merge(scene); + + return parent; + } + + return INVALID_ENTITY; + } + + PickResult Pick(const RAY& ray, UINT renderTypeMask, uint32_t layerMask) + { + const Scene& scene = GetScene(); + + PickResult result; + + if (scene.objects.GetCount() > 0) + { + const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); + const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); + + for (size_t i = 0; i < scene.aabb_objects.GetCount(); ++i) + { + const AABB& aabb = scene.aabb_objects[i]; + if (!ray.intersects(aabb)) + { + continue; + } + + const ObjectComponent& object = scene.objects[i]; + if (object.meshID == INVALID_ENTITY) + { + continue; + } + if (!(renderTypeMask & object.GetRenderTypes())) + { + continue; + } + + Entity entity = scene.aabb_objects.GetEntity(i); + const LayerComponent& layer = *scene.layers.GetComponent(entity); + + if (layer.GetLayerMask() & layerMask) + { + const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID); + + const XMMATRIX objectMat = object.transform_index >= 0 ? XMLoadFloat4x4(&scene.transforms[object.transform_index].world) : XMMatrixIdentity(); + const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); + + const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); + const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); + + const ArmatureComponent* armature = mesh.IsSkinned() ? scene.armatures.GetComponent(mesh.armatureID) : nullptr; + + int subsetCounter = 0; + for (auto& subset : mesh.subsets) + { + for (size_t i = 0; i < subset.indexCount; i += 3) + { + const uint32_t i0 = mesh.indices[subset.indexOffset + i + 0]; + const uint32_t i1 = mesh.indices[subset.indexOffset + i + 1]; + const uint32_t i2 = mesh.indices[subset.indexOffset + i + 2]; + + XMVECTOR p0 = XMLoadFloat3(&mesh.vertex_positions[i0]); + XMVECTOR p1 = XMLoadFloat3(&mesh.vertex_positions[i1]); + XMVECTOR p2 = XMLoadFloat3(&mesh.vertex_positions[i2]); + + if (armature != nullptr) + { + const XMUINT4& ind0 = mesh.vertex_boneindices[i0]; + const XMUINT4& ind1 = mesh.vertex_boneindices[i1]; + const XMUINT4& ind2 = mesh.vertex_boneindices[i2]; + + const XMFLOAT4& wei0 = mesh.vertex_boneweights[i0]; + const XMFLOAT4& wei1 = mesh.vertex_boneweights[i1]; + const XMFLOAT4& wei2 = mesh.vertex_boneweights[i2]; + + XMMATRIX sump; + + sump = armature->boneData[ind0.x].Load() * wei0.x; + sump += armature->boneData[ind0.y].Load() * wei0.y; + sump += armature->boneData[ind0.z].Load() * wei0.z; + sump += armature->boneData[ind0.w].Load() * wei0.w; + + p0 = XMVector3Transform(p0, sump); + + sump = armature->boneData[ind1.x].Load() * wei1.x; + sump += armature->boneData[ind1.y].Load() * wei1.y; + sump += armature->boneData[ind1.z].Load() * wei1.z; + sump += armature->boneData[ind1.w].Load() * wei1.w; + + p1 = XMVector3Transform(p1, sump); + + sump = armature->boneData[ind2.x].Load() * wei2.x; + sump += armature->boneData[ind2.y].Load() * wei2.y; + sump += armature->boneData[ind2.z].Load() * wei2.z; + sump += armature->boneData[ind2.w].Load() * wei2.w; + + p2 = XMVector3Transform(p2, sump); + } + + float distance; + if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, p0, p1, p2, distance)) + { + const XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); + distance = wiMath::Distance(pos, rayOrigin); + + if (distance < result.distance) + { + const XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Cross(XMVectorSubtract(p2, p1), XMVectorSubtract(p1, p0)), objectMat)); + + result.entity = entity; + XMStoreFloat3(&result.position, pos); + XMStoreFloat3(&result.normal, nor); + result.distance = distance; + result.subsetIndex = subsetCounter; + result.vertexID0 = (int)i0; + result.vertexID1 = (int)i1; + result.vertexID2 = (int)i2; + } + } + } + subsetCounter++; + } + + } + + } + } + + // Construct a matrix that will orient to position (P) according to surface normal (N): + XMVECTOR N = XMLoadFloat3(&result.normal); + XMVECTOR P = XMLoadFloat3(&result.position); + XMVECTOR E = XMLoadFloat3(&ray.origin); + XMVECTOR T = XMVector3Normalize(XMVector3Cross(N, P - E)); + XMVECTOR B = XMVector3Normalize(XMVector3Cross(T, N)); + XMMATRIX M = { T, N, B, P }; + XMStoreFloat4x4(&result.orientation, M); + + return result; + } } diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 3d6ccb411..3f265acc5 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -1115,5 +1115,40 @@ namespace wiSceneSystem WeatherComponent& weather ); + + + // Helper that manages a global scene + inline Scene& GetScene() + { + static Scene scene; + return scene; + } + + // Helper function to open a wiscene file and add the contents to the global scene + // transformMatrix : everything will be transformed by this matrix (optional) + // attached : everything will be attached to a base entity + // + // returns INVALID_ENTITY if attached argument was false, else it returns the base entity handle + wiECS::Entity LoadModel(const std::string& fileName, const XMMATRIX& transformMatrix = XMMatrixIdentity(), bool attached = false); + + struct PickResult + { + wiECS::Entity entity = wiECS::INVALID_ENTITY; + XMFLOAT3 position = XMFLOAT3(0, 0, 0); + XMFLOAT3 normal = XMFLOAT3(0, 0, 0); + float distance = FLT_MAX; + int subsetIndex = -1; + int vertexID0 = -1; + int vertexID1 = -1; + int vertexID2 = -1; + XMFLOAT4X4 orientation = IDENTITYMATRIX; + + bool operator==(const PickResult& other) + { + return entity == other.entity; + } + }; + // Given a ray, finds the closest intersection point against all instances + PickResult Pick(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = ~0); } diff --git a/WickedEngine/wiSceneSystem_BindLua.cpp b/WickedEngine/wiSceneSystem_BindLua.cpp index 86d11e4bd..09fef5d07 100644 --- a/WickedEngine/wiSceneSystem_BindLua.cpp +++ b/WickedEngine/wiSceneSystem_BindLua.cpp @@ -4,10 +4,12 @@ #include "Matrix_BindLua.h" #include "wiEmittedParticle.h" #include "Texture_BindLua.h" +#include "wiIntersect_BindLua.h" using namespace std; using namespace wiECS; using namespace wiSceneSystem; +using namespace wiIntersect_BindLua; namespace wiSceneSystem_BindLua { @@ -19,6 +21,77 @@ int CreateEntity_BindLua(lua_State* L) return 1; } +int GetScene(lua_State* L) +{ + Luna::push(L, new Scene_BindLua(&wiSceneSystem::GetScene())); + return 1; +} +int LoadModel(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + string fileName = wiLua::SGetString(L, 1); + XMMATRIX transform = XMMatrixIdentity(); + if (argc > 1) + { + Matrix_BindLua* matrix = Luna::lightcheck(L, 2); + if (matrix != nullptr) + { + transform = matrix->matrix; + } + else + { + wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!"); + } + } + Entity root = wiSceneSystem::LoadModel(fileName, transform, true); + wiLua::SSetInt(L, int(root)); + return 1; + } + else + { + wiLua::SError(L, "LoadModel(string fileName, opt Matrix transform) not enough arguments!"); + } + return 0; +} +int Pick(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Ray_BindLua* ray = Luna::lightcheck(L, 1); + if (ray != nullptr) + { + UINT renderTypeMask = RENDERTYPE_OPAQUE; + uint32_t layerMask = 0xFFFFFFFF; + if (argc > 1) + { + renderTypeMask = (UINT)wiLua::SGetInt(L, 2); + if (argc > 2) + { + int mask = wiLua::SGetInt(L, 3); + layerMask = *reinterpret_cast(&mask); + } + } + auto& pick = wiSceneSystem::Pick(ray->ray, renderTypeMask, layerMask); + wiLua::SSetInt(L, (int)pick.entity); + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.position))); + Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.normal))); + wiLua::SSetFloat(L, pick.distance); + return 4; + } + + wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) first argument must be of Vector type!"); + } + else + { + wiLua::SError(L, "Pick(Ray ray, opt PICKTYPE pickType, opt uint layerMask) not enough arguments!"); + } + + return 0; +} + void Bind() { static bool initialized = false; @@ -31,6 +104,10 @@ void Bind() wiLua::GetGlobal()->RegisterFunc("CreateEntity", CreateEntity_BindLua); wiLua::GetGlobal()->RunText("INVALID_ENTITY = 0"); + wiLua::GetGlobal()->RegisterFunc("GetScene", GetScene); + wiLua::GetGlobal()->RegisterFunc("LoadModel", LoadModel); + wiLua::GetGlobal()->RegisterFunc("Pick", Pick); + Luna::Register(L); Luna::Register(L); Luna::Register(L); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index f145942fe..b9576568b 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 - const int minor = 25; + const int minor = 26; // minor bug fixes, alterations, refactors, updates - const int revision = 8; + const int revision = 0; long GetVersion()