diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 384261a0a..aadeea171 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -120,7 +120,6 @@ You can use the Renderer with the following functions, all of which are in the g - LoadWorldInfo(string fileName) -- Loads world information from file - DuplicateInstance(Object object) : Object result -- Copies the specified object in the scene as an instanced mesh - SetEnvironmentMap(Texture cubemap) -- SetColorGrading(Texture texture2D) - HairParticleSettings(opt int lod0, opt int lod1, opt int lod2) - SetAlphaCompositionEnabled(opt bool enabled) - SetShadowProps2D(int resolution, int count, int softShadowQuality) @@ -454,7 +453,6 @@ The main component which holds information and manages the running of the curren - SetWatermarkDisplay(bool active) - SetFPSDisplay(bool active) - SetCPUDisplay(bool active) -- SetColorGradePaletteDisplay(bool active) - [outer]SetProfilerEnabled(bool enabled) ### RenderableComponent @@ -502,6 +500,7 @@ It inherits functions from Renderable2DComponent, so it can render a 2D overlay. - SetFXAAEnabled(bool value) - SetBloomEnabled(bool value) - SetColorGradingEnabled(bool value) +- SetColorGradingTexture(Texture value) - SetEmitterParticlesEnabled(bool value) - SetHairParticlesEnabled(bool value) - SetHairParticlesReflectionEnabled(bool value) @@ -513,7 +512,6 @@ It inherits functions from Renderable2DComponent, so it can render a 2D overlay. - SetDepthOfFieldEnabled(bool value) - SetDepthOfFieldFocus(float value) - SetDepthOfFieldStrength(float value) -- SetPreferredThreadingCount(int value) - SetTessellationEnabled(bool value) - SetMSAASampleCount(int count) - SetStereogramEnabled(bool value) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 80ff77007..ca67a1f95 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -32,7 +32,6 @@ Editor::Editor() SAFE_INIT(loader); } - Editor::~Editor() { //SAFE_DELETE(renderComponent); @@ -135,11 +134,61 @@ void ConsumeHistoryOperation(bool undo); +struct Picked +{ + Transform* transform; + Object* object; + Light* light; + Decal* decal; + EnvironmentProbe* envProbe; + ForceField* forceField; + Camera* camera; + Armature* armature; + XMFLOAT3 position, normal; + float distance; + int subsetIndex; + + Picked() + { + Clear(); + } + + // Subset index, position, normal, distance don't distinguish between pickeds! + bool operator==(const Picked& other) + { + return + transform == other.transform && + object == other.object && + light == other.light && + decal == other.decal && + envProbe == other.envProbe && + forceField == other.forceField && + camera == other.camera && + armature == other.armature + ; + } + void Clear() + { + distance = FLT_MAX; + subsetIndex = -1; + SAFE_INIT(transform); + SAFE_INIT(object); + SAFE_INIT(light); + SAFE_INIT(decal); + SAFE_INIT(envProbe); + SAFE_INIT(forceField); + SAFE_INIT(camera); + SAFE_INIT(armature); + } +}; + + + wiTranslator* translator = nullptr; bool translator_active = false; -list selected; +list selected; std::map savedParents; -wiRenderer::Picked hovered; +Picked hovered; void BeginTranslate() { translator_active = true; @@ -206,9 +255,9 @@ void ClearSelected() selected.clear(); savedParents.clear(); } -void AddSelected(wiRenderer::Picked* picked, bool deselectIfAlreadySelected = false) +void AddSelected(Picked* picked, bool deselectIfAlreadySelected = false) { - list::iterator it = selected.begin(); + list::iterator it = selected.begin(); for (; it != selected.end(); ++it) { if ((**it) == *picked) @@ -323,10 +372,6 @@ void EditorComponent::DeleteWindows() SAFE_DELETE(forceFieldWnd); SAFE_DELETE(oceanWnd); } -void EditorComponent::UpdateFromPrimarySelection(const wiRenderer::Picked& sel) -{ - -} void EditorComponent::Initialize() { @@ -860,11 +905,11 @@ void EditorComponent::Load() if (helpLabel == nullptr) { stringstream ss(""); - ss << "Help: " << endl << "############" << endl << endl; + ss << "Help: " << endl << "############" << endl << endl; ss << "Move camera: WASD" << endl; ss << "Look: Middle mouse button / arrow keys" << endl; ss << "Select: Right mouse button" << endl; - ss << "Place decal/interact: Left mouse button when nothing is selected" << endl; + ss << "Place decal, interact with water: Left mouse button when nothing is selected" << endl; ss << "Camera speed: SHIFT button" << endl; ss << "Camera up: E, down: Q" << endl; ss << "Duplicate entity (with instancing): Ctrl + D" << endl; @@ -877,9 +922,10 @@ void EditorComponent::Load() ss << "Script Console / backlog: HOME button" << endl; ss << endl; ss << "You can find sample models in the models directory. Try to load one." << endl; - ss << "You can also import models from .OBJ files." << endl; + ss << "You can also import models from .OBJ, .GLTF, .GLB, .WIO files." << endl; ss << "You can also export models from Blender with the io_export_wicked_wi_bin.py script." << endl; ss << "You can find a program configuration file at Editor/config.ini" << endl; + ss << "You can find sample LUA scripts in the scripts directory. Try to load one." << endl; ss << "You can find a startup script at Editor/startup.lua (this will be executed on program start)" << endl; ss << endl << endl << "For questions, bug reports, feedback, requests, please open an issue at:" << endl; ss << "https://github.com/turanszkij/WickedEngine" << endl; @@ -1065,7 +1111,146 @@ void EditorComponent::Update(float dt) } } - hovered = wiRenderer::Pick((long)currentMouse.x, (long)currentMouse.y, rendererWnd->GetPickType()); + // Begin picking: + UINT pickMask = rendererWnd->GetPickType(); + RAY pickRay = wiRenderer::getPickRay((long)currentMouse.x, (long)currentMouse.y); + { + hovered.Clear(); + + // Try to pick objects-meshes: + if (pickMask & PICK_OBJECT) + { + auto& picked = wiRenderer::RayIntersectWorld(pickRay, pickMask); + + hovered.object = picked.object; + hovered.distance = picked.distance; + hovered.subsetIndex = picked.subsetIndex; + hovered.position = picked.position; + hovered.normal = picked.normal; + + hovered.transform = picked.object; + } + + for (auto& model : wiRenderer::GetScene().models) + { + if (pickMask & PICK_LIGHT) + { + for (auto& light : model->lights) + { + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&light->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(light->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = light; + hovered.light = light; + hovered.distance = dis; + } + } + } + if (pickMask & PICK_DECAL) + { + for (auto& decal : model->decals) + { + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&decal->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(decal->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = decal; + hovered.decal = decal; + hovered.distance = dis; + } + } + } + if (pickMask & PICK_FORCEFIELD) + { + for (auto& force : model->forces) + { + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&force->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(force->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = force; + hovered.forceField = force; + hovered.distance = dis; + } + } + } + if (pickMask & PICK_EMITTER) + { + for (auto& object : model->objects) + { + if (object->eParticleSystems.empty()) + { + continue; + } + + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&object->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(object->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = object; + hovered.object = object; + hovered.distance = dis; + } + } + } + + if (pickMask & PICK_ENVPROBE) + { + for (auto& x : model->environmentProbes) + { + if (SPHERE(x->translation, 1).intersects(pickRay)) + { + float dis = wiMath::Distance(x->translation, pickRay.origin); + if (dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = x; + hovered.envProbe = x; + hovered.distance = dis; + } + } + } + } + if (pickMask & PICK_CAMERA) + { + for (auto& camera : model->cameras) + { + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&camera->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(camera->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = camera; + hovered.camera = camera; + hovered.distance = dis; + } + } + } + if (pickMask & PICK_ARMATURE) + { + for (auto& armature : model->armatures) + { + XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&armature->translation)); + float dis = XMVectorGetX(disV); + if (dis < wiMath::Distance(armature->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + { + hovered.Clear(); + hovered.transform = armature; + hovered.armature = armature; + hovered.distance = dis; + } + } + } + } + + } + + // Interact: if (hovered.object != nullptr && selected.empty()) @@ -1136,7 +1321,7 @@ void EditorComponent::Update(float dt) { for (auto& x : model->objects) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->object = x; picked->transform = x; @@ -1144,7 +1329,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->lights) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->light = x; picked->transform = x; @@ -1152,7 +1337,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->forces) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->forceField = x; picked->transform = x; @@ -1160,7 +1345,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->armatures) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->armature = x; picked->transform = x; @@ -1168,7 +1353,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->cameras) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->camera = x; picked->transform = x; @@ -1176,7 +1361,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->environmentProbes) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->envProbe = x; picked->transform = x; @@ -1184,7 +1369,7 @@ void EditorComponent::Update(float dt) } for (auto& x : model->decals) { - wiRenderer::Picked* picked = new wiRenderer::Picked; + Picked* picked = new Picked; picked->decal = x; picked->transform = x; @@ -1197,7 +1382,7 @@ void EditorComponent::Update(float dt) else if (hovered.transform != nullptr) { // Add the hovered item to the selection: - wiRenderer::Picked* picked = new wiRenderer::Picked(hovered); + Picked* picked = new Picked(hovered); if (!selected.empty() && wiInputManager::GetInstance()->down(VK_LSHIFT)) { AddSelected(picked, true); @@ -1261,7 +1446,7 @@ void EditorComponent::Update(float dt) } else { - wiRenderer::Picked* picked = selected.back(); + Picked* picked = selected.back(); assert(picked->transform != nullptr); @@ -2002,7 +2187,7 @@ void 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) @@ -2010,7 +2195,7 @@ void ConsumeHistoryOperation(bool undo) uint64_t id; *archive >> id; - wiRenderer::Picked* sel = new wiRenderer::Picked; + Picked* sel = new Picked; sel->transform = wiRenderer::getTransformByID(id); assert(sel->transform != nullptr); *archive >> sel->position; @@ -2034,7 +2219,7 @@ void ConsumeHistoryOperation(bool undo) savedParentsBEFORE.insert(pair(t1, t2)); } - list selectedAFTER; + list selectedAFTER; size_t selectionCountAFTER; *archive >> selectionCountAFTER; for (size_t i = 0; i < selectionCountAFTER; ++i) @@ -2042,7 +2227,7 @@ void ConsumeHistoryOperation(bool undo) uint64_t id; *archive >> id; - wiRenderer::Picked* sel = new wiRenderer::Picked; + Picked* sel = new Picked; sel->transform = wiRenderer::getTransformByID(id); assert(sel->transform != nullptr); *archive >> sel->position; @@ -2069,7 +2254,7 @@ void ConsumeHistoryOperation(bool undo) // Restore proper selection state: - list* selectedCURRENT = nullptr; + list* selectedCURRENT = nullptr; if (undo) { selectedCURRENT = &selectedBEFORE; diff --git a/Editor/Editor.h b/Editor/Editor.h index 9b119876f..c3b7b00ad 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -64,7 +64,6 @@ public: }; void ChangeRenderPath(RENDERPATH path); void DeleteWindows(); - void UpdateFromPrimarySelection(const wiRenderer::Picked& sel); void Initialize() override; void Load() override; diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp index 9a37feb8e..b62ab0952 100644 --- a/Editor/PostprocessWindow.cpp +++ b/Editor/PostprocessWindow.cpp @@ -160,7 +160,8 @@ PostprocessWindow::PostprocessWindow(wiGUI* gui, Renderable3DComponent* comp) : colorGradingButton->SetPos(XMFLOAT2(x + 35, y)); colorGradingButton->SetSize(XMFLOAT2(200, 18)); colorGradingButton->OnClick([=](wiEventArgs args) { - auto x = wiRenderer::GetColorGrading(); + //auto x = wiRenderer::GetColorGrading(); + auto x = component->getColorGradingTexture(); if (x == nullptr) { @@ -184,14 +185,19 @@ PostprocessWindow::PostprocessWindow(wiGUI* gui, Renderable3DComponent* comp) : ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileNameA(&ofn) == TRUE) { string fileName = ofn.lpstrFile; - wiRenderer::SetColorGrading((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); - colorGradingButton->SetText(fileName); + //wiRenderer::SetColorGrading((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); + component->setColorGradingTexture((Texture2D*)wiResourceManager::GetGlobal()->add(fileName)); + if (component->getColorGradingTexture() != nullptr) + { + colorGradingButton->SetText(fileName); + } } }).detach(); } else { - wiRenderer::SetColorGrading(nullptr); + //wiRenderer::SetColorGrading(nullptr); + component->setColorGradingTexture(nullptr); colorGradingButton->SetText("Load Color Grading LUT..."); } diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp index 093e9b376..8f96f4a9a 100644 --- a/Editor/RendererWindow.cpp +++ b/Editor/RendererWindow.cpp @@ -547,14 +547,12 @@ RendererWindow::~RendererWindow() SAFE_DELETE(rendererWindow); } -int RendererWindow::GetPickType() +UINT RendererWindow::GetPickType() { - int pickType = PICK_VOID; + UINT pickType = PICK_VOID; if (pickTypeObjectCheckBox->GetCheck()) { - pickType |= PICK_OPAQUE; - pickType |= PICK_TRANSPARENT; - pickType |= PICK_WATER; + pickType |= PICK_OBJECT; } if (pickTypeEnvProbeCheckBox->GetCheck()) { diff --git a/Editor/RendererWindow.h b/Editor/RendererWindow.h index a4c4764a6..f1f852285 100644 --- a/Editor/RendererWindow.h +++ b/Editor/RendererWindow.h @@ -7,6 +7,19 @@ class wiCheckBox; class wiSlider; class wiComboBox; +enum PICKTYPE +{ + PICK_VOID = 0, + PICK_OBJECT = RENDERTYPE_OPAQUE | RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER, + PICK_LIGHT = 8, + PICK_DECAL = 16, + PICK_ENVPROBE = 32, + PICK_FORCEFIELD = 64, + PICK_EMITTER = 128, + PICK_CAMERA = 256, + PICK_ARMATURE = 512, +}; + class RendererWindow { public: @@ -61,6 +74,6 @@ public: wiCheckBox* freezeCullingCameraCheckBox; - int GetPickType(); + UINT GetPickType(); }; diff --git a/README.md b/README.md index 19304c4e1..fbee8a42c 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,11 @@ Test model and scene files are now available in the WickedEngine/models director ### Model import/export: -The only common model format supported right now is Wavefront OBJ.
+The Editor supports the importing of some common model formats (the list will potentially grow): OBJ, GLTF 2.0 +The Engine itself can open the serialized model format (WIMF) only. The preferred workflow is to import models into the editor, and save them out to WIMF, then any WickedEngine application can open them. -For advanced model format capabilities, like skeletal animations, particle systems, physics, etc. use the provided Blender exporter python script: io_export_wicked_wi_bin.py
+There is an additional model format designed for Blender supporting like skeletal animations, particle systems, physics, etc... Use the provided Blender exporter python script: io_export_wicked_wi_bin.py
+The Editor can open WIO files exported from Blender, and save them as WIMF models. Notes on exporting: - Names should not contain spaces inside Blender
diff --git a/WickedEngine/DeferredRenderableComponent.cpp b/WickedEngine/DeferredRenderableComponent.cpp index a51e5f650..f0ddae85d 100644 --- a/WickedEngine/DeferredRenderableComponent.cpp +++ b/WickedEngine/DeferredRenderableComponent.cpp @@ -84,29 +84,12 @@ void DeferredRenderableComponent::Start() } void DeferredRenderableComponent::Render() { - if (getThreadingCount() > 1) - { - for (auto workerThread : workerThreads) - { - workerThread->wakeup(); - } - - for (auto workerThread : workerThreads) - { - workerThread->wait(); - } - - wiRenderer::GetDevice()->ExecuteDeferredContexts(); - } - else - { - RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); - RenderShadows(GRAPHICSTHREAD_IMMEDIATE); - RenderReflections(GRAPHICSTHREAD_IMMEDIATE); - RenderScene(GRAPHICSTHREAD_IMMEDIATE); - RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_IMMEDIATE); - RenderComposition(GetFinalRT(), rtGBuffer, GRAPHICSTHREAD_IMMEDIATE); - } + RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); + RenderShadows(GRAPHICSTHREAD_IMMEDIATE); + RenderReflections(GRAPHICSTHREAD_IMMEDIATE); + RenderScene(GRAPHICSTHREAD_IMMEDIATE); + RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_IMMEDIATE); + RenderComposition(GetFinalRT(), rtGBuffer, GRAPHICSTHREAD_IMMEDIATE); Renderable2DComponent::Render(); } @@ -146,7 +129,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); + wiRenderer::BindDepthTextures(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); if (getStereogramEnabled()) { @@ -160,7 +143,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } rtGBuffer.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), rtGBuffer.GetTexture(3), nullptr, threadID); + wiRenderer::BindGBufferTextures(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), rtGBuffer.GetTexture(3), nullptr, threadID); @@ -294,97 +277,3 @@ wiDepthTarget* DeferredRenderableComponent::GetDepthBuffer() { return rtGBuffer.depth; } - -void DeferredRenderableComponent::setPreferredThreadingCount(unsigned short value) -{ - Renderable3DComponent::setPreferredThreadingCount(value); - - if (!wiRenderer::GetDevice()->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_MULTITHREADED_RENDERING)) - { - if (value > 1) - wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); - return; - } - - switch (value){ - case 2: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_SCENE); - RenderComposition(GetFinalRT(), rtGBuffer, GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - break; - case 3: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC1); - RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_MISC1); - RenderComposition(GetFinalRT(), rtGBuffer, GRAPHICSTHREAD_MISC1); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); - })); - break; - case 4: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC1); - RenderSecondaryScene(rtGBuffer, GetFinalRT(), GRAPHICSTHREAD_MISC1); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC2); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC2); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC2); - wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC2); - RenderComposition(GetFinalRT(), rtGBuffer, GRAPHICSTHREAD_MISC2); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); - })); - break; - }; -} - diff --git a/WickedEngine/DeferredRenderableComponent.h b/WickedEngine/DeferredRenderableComponent.h index bea658ca3..e55ea9750 100644 --- a/WickedEngine/DeferredRenderableComponent.h +++ b/WickedEngine/DeferredRenderableComponent.h @@ -19,8 +19,6 @@ public: virtual wiDepthTarget* GetDepthBuffer() override; - virtual void setPreferredThreadingCount(unsigned short value) override; - virtual void Initialize() override; virtual void Load() override; virtual void Start() override; diff --git a/WickedEngine/DeferredRenderableComponent_BindLua.cpp b/WickedEngine/DeferredRenderableComponent_BindLua.cpp index 79f5fc180..05a41c899 100644 --- a/WickedEngine/DeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/DeferredRenderableComponent_BindLua.cpp @@ -40,6 +40,7 @@ Luna::FunctionType DeferredRenderableCompon lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingTexture), lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesReflectionEnabled), @@ -58,7 +59,6 @@ Luna::FunctionType DeferredRenderableCompon lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus), lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength), - lunamethod(Renderable3DComponent_BindLua, SetPreferredThreadingCount), { NULL, NULL } }; Luna::PropertyType DeferredRenderableComponent_BindLua::properties[] = { diff --git a/WickedEngine/ForwardRenderableComponent.cpp b/WickedEngine/ForwardRenderableComponent.cpp index 00d25ca90..098e28b5d 100644 --- a/WickedEngine/ForwardRenderableComponent.cpp +++ b/WickedEngine/ForwardRenderableComponent.cpp @@ -15,8 +15,6 @@ ForwardRenderableComponent::ForwardRenderableComponent() setSSREnabled(false); setSSAOEnabled(false); setShadowsEnabled(false); - - setPreferredThreadingCount(0); } ForwardRenderableComponent::~ForwardRenderableComponent() { @@ -68,30 +66,12 @@ void ForwardRenderableComponent::Start() } void ForwardRenderableComponent::Render() { - if (getThreadingCount() > 1) - { - - for (auto workerThread : workerThreads) - { - workerThread->wakeup(); - } - - for (auto workerThread : workerThreads) - { - workerThread->wait(); - } - - wiRenderer::GetDevice()->ExecuteDeferredContexts(); - } - else - { - RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); - RenderShadows(GRAPHICSTHREAD_IMMEDIATE); - RenderReflections(GRAPHICSTHREAD_IMMEDIATE); - RenderScene(GRAPHICSTHREAD_IMMEDIATE); - RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_IMMEDIATE); - RenderComposition(rtMain, rtMain, GRAPHICSTHREAD_IMMEDIATE); - } + RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); + RenderShadows(GRAPHICSTHREAD_IMMEDIATE); + RenderReflections(GRAPHICSTHREAD_IMMEDIATE); + RenderScene(GRAPHICSTHREAD_IMMEDIATE); + RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_IMMEDIATE); + RenderComposition(rtMain, rtMain, GRAPHICSTHREAD_IMMEDIATE); Renderable2DComponent::Render(); } @@ -117,7 +97,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::DrawSky(threadID); } rtMain.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtMain.GetTextureResolvedMSAA(threadID, 0), rtMain.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); + wiRenderer::BindGBufferTextures(rtMain.GetTextureResolvedMSAA(threadID, 0), rtMain.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID); @@ -135,7 +115,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } rtLinearDepth.Deactivate(threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTextureResolvedMSAA(threadID), rtLinearDepth.GetTexture(), threadID); + wiRenderer::BindDepthTextures(dtDepthCopy.GetTextureResolvedMSAA(threadID), rtLinearDepth.GetTexture(), threadID); if (getSSAOEnabled()) { @@ -190,98 +170,3 @@ wiDepthTarget* ForwardRenderableComponent::GetDepthBuffer() { return rtMain.depth; } - -void ForwardRenderableComponent::setPreferredThreadingCount(unsigned short value) -{ - Renderable3DComponent::setPreferredThreadingCount(value); - - if (!wiRenderer::GetDevice()->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_MULTITHREADED_RENDERING)) - { - if (value > 1) - wiHelper::messageBox("Multithreaded rendering not supported by your hardware! Falling back to single threading!", "Caution"); - return; - } - - - switch (value) { - case 2: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_SCENE); - RenderComposition(rtMain, rtMain, GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - break; - case 3: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateGBuffer(rtMain.GetTexture(0), rtMain.GetTexture(1), rtMain.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC1); - RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_MISC1); - RenderComposition(rtMain, rtMain, GRAPHICSTHREAD_MISC1); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); - })); - break; - case 4: - workerThreads.push_back(new wiTaskThread([&] - { - RenderFrameSetUp(GRAPHICSTHREAD_REFLECTIONS); - RenderReflections(GRAPHICSTHREAD_REFLECTIONS); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_REFLECTIONS); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_SCENE); - wiImage::BindPersistentState(GRAPHICSTHREAD_SCENE); - RenderShadows(GRAPHICSTHREAD_SCENE); - RenderScene(GRAPHICSTHREAD_SCENE); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_SCENE); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC1); - wiRenderer::UpdateGBuffer(rtMain.GetTexture(0), rtMain.GetTexture(1), rtMain.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC1); - RenderSecondaryScene(rtMain, rtMain, GRAPHICSTHREAD_MISC1); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC1); - })); - workerThreads.push_back(new wiTaskThread([&] - { - wiRenderer::BindPersistentState(GRAPHICSTHREAD_MISC2); - wiImage::BindPersistentState(GRAPHICSTHREAD_MISC2); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), GRAPHICSTHREAD_MISC2); - wiRenderer::UpdateGBuffer(rtMain.GetTexture(0), rtMain.GetTexture(1), rtMain.GetTexture(2), nullptr, nullptr, GRAPHICSTHREAD_MISC2); - RenderComposition(rtMain, rtMain, GRAPHICSTHREAD_MISC2); - wiRenderer::GetDevice()->FinishCommandList(GRAPHICSTHREAD_MISC2); - })); - break; - }; - -} diff --git a/WickedEngine/ForwardRenderableComponent.h b/WickedEngine/ForwardRenderableComponent.h index 489c4b930..a9184fd60 100644 --- a/WickedEngine/ForwardRenderableComponent.h +++ b/WickedEngine/ForwardRenderableComponent.h @@ -18,9 +18,6 @@ public: virtual wiDepthTarget* GetDepthBuffer() override; - - virtual void setPreferredThreadingCount(unsigned short value) override; - virtual void Initialize() override; virtual void Load() override; virtual void Start() override; diff --git a/WickedEngine/ForwardRenderableComponent_BindLua.cpp b/WickedEngine/ForwardRenderableComponent_BindLua.cpp index cb6766248..c9abfc303 100644 --- a/WickedEngine/ForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/ForwardRenderableComponent_BindLua.cpp @@ -40,6 +40,7 @@ Luna::FunctionType ForwardRenderableComponen lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingTexture), lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesReflectionEnabled), @@ -58,8 +59,6 @@ Luna::FunctionType ForwardRenderableComponen lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus), lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength), - - lunamethod(Renderable3DComponent_BindLua, SetPreferredThreadingCount), { NULL, NULL } }; Luna::PropertyType ForwardRenderableComponent_BindLua::properties[] = { diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index c409079bc..1d7b3ef63 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -38,8 +38,7 @@ MainComponent::MainComponent() setTargetFrameRate(60); setApplicationControlLostThreshold(10); - infoDisplay = InfoDisplayer(); - colorGradingPaletteDisplayEnabled = false; + infoDisplay = InfoDisplayer(); fadeManager.Clear(); } @@ -282,14 +281,6 @@ void MainComponent::Compose() wiProfiler::GetInstance().DrawData(4, 120, GRAPHICSTHREAD_IMMEDIATE); - // Draw the color grading palette - if (colorGradingPaletteDisplayEnabled) - { - //wiImage::BatchBegin(); - wiImage::Draw(wiTextureHelper::getInstance()->getColorGradeDefault(), wiImageEffects(0, 0, 256, 16), GRAPHICSTHREAD_IMMEDIATE); - wiImage::Draw(wiRenderer::GetColorGrading(), wiImageEffects(screenW-256.f, 0, 256, 16), GRAPHICSTHREAD_IMMEDIATE); - } - wiBackLog::Draw(); } diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index dd979363f..398d7655e 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -77,8 +77,5 @@ public: }; // display all-time engine information text InfoDisplayer infoDisplay; - - // display the default color grading palette - bool colorGradingPaletteDisplayEnabled; }; diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index 2acbd7648..1442da97a 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -22,7 +22,6 @@ Luna::FunctionType MainComponent_BindLua::methods[] = { lunamethod(MainComponent_BindLua, SetFPSDisplay), lunamethod(MainComponent_BindLua, SetCPUDisplay), lunamethod(MainComponent_BindLua, SetResolutionDisplay), - lunamethod(MainComponent_BindLua, SetColorGradePaletteDisplay), { NULL, NULL } }; Luna::PropertyType MainComponent_BindLua::properties[] = { @@ -317,22 +316,6 @@ int MainComponent_BindLua::SetResolutionDisplay(lua_State *L) wiLua::SError(L, "SetResolutionDisplay(bool active) not enough arguments!"); return 0; } -int MainComponent_BindLua::SetColorGradePaletteDisplay(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "SetColorGradePaletteDisplay() component is empty!"); - return 0; - } - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - component->colorGradingPaletteDisplayEnabled = wiLua::SGetBool(L, 1); - } - else - wiLua::SError(L, "SetColorGradePaletteDisplay(bool active) not enough arguments!"); - return 0; -} int SetProfilerEnabled(lua_State* L) diff --git a/WickedEngine/MainComponent_BindLua.h b/WickedEngine/MainComponent_BindLua.h index dbc97b9dd..a78e7b902 100644 --- a/WickedEngine/MainComponent_BindLua.h +++ b/WickedEngine/MainComponent_BindLua.h @@ -25,7 +25,6 @@ public: int SetFPSDisplay(lua_State *L); int SetCPUDisplay(lua_State *L); int SetResolutionDisplay(lua_State *L); - int SetColorGradePaletteDisplay(lua_State* L); static void Bind(); }; diff --git a/WickedEngine/Renderable3DComponent.cpp b/WickedEngine/Renderable3DComponent.cpp index 5ab4d353a..a3b79e6d9 100644 --- a/WickedEngine/Renderable3DComponent.cpp +++ b/WickedEngine/Renderable3DComponent.cpp @@ -15,10 +15,6 @@ Renderable3DComponent::Renderable3DComponent() : Renderable2DComponent() } Renderable3DComponent::~Renderable3DComponent() { - for (auto& wt : workerThreads) - { - delete wt; - } } wiRenderTarget @@ -195,8 +191,6 @@ void Renderable3DComponent::setProperties() setSharpenFilterEnabled(false); setMSAASampleCount(1); - - setPreferredThreadingCount(0); } void Renderable3DComponent::Initialize() @@ -220,7 +214,6 @@ void Renderable3DComponent::Start() void Renderable3DComponent::FixedUpdate() { wiRenderer::FixedUpdate(); - wiRenderer::UpdateImages(); Renderable2DComponent::FixedUpdate(); } @@ -443,18 +436,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende wiRenderer::DrawLensFlares(threadID); } - wiRenderer::GetDevice()->EventBegin("Debug Geometry", threadID); - wiRenderer::DrawDebugGridHelper(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugVoxels(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugEnvProbes(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugBoneLines(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugLines(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugBoxes(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugForceFields(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugEmitters(wiRenderer::getCamera(), threadID); - wiRenderer::DrawDebugCameras(wiRenderer::getCamera(), threadID); - wiRenderer::DrawTranslators(wiRenderer::getCamera(), threadID); - wiRenderer::GetDevice()->EventEnd(threadID); + wiRenderer::DrawDebugWorld(wiRenderer::getCamera(), threadID); } if (getEmittedParticlesEnabled()) @@ -497,7 +479,7 @@ void Renderable3DComponent::RenderComposition(wiRenderTarget& shadedSceneRT, wiR int current = wiRenderer::GetDevice()->GetFrameCount() % 2 == 0 ? 0 : 1; int history = 1 - current; rtTemporalAA[current].Set(threadID); { - wiRenderer::UpdateGBuffer(mainRT.GetTextureResolvedMSAA(threadID, 0), mainRT.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); + wiRenderer::BindGBufferTextures(mainRT.GetTextureResolvedMSAA(threadID, 0), mainRT.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); fx.presentFullScreen = false; fx.process.setTemporalAAResolve(true); fx.setMaskMap(rtTemporalAA[history].GetTexture()); @@ -683,9 +665,9 @@ void Renderable3DComponent::RenderColorGradedComposition() if (getColorGradingEnabled()) { wiRenderer::GetDevice()->EventBegin("Color Graded Composition", GRAPHICSTHREAD_IMMEDIATE); - if (wiRenderer::GetColorGrading() != nullptr){ + if (colorGradingTex != nullptr){ fx.process.setColorGrade(true); - fx.setMaskMap(wiRenderer::GetColorGrading()); + fx.setMaskMap(colorGradingTex); } else { @@ -709,14 +691,3 @@ void Renderable3DComponent::RenderColorGradedComposition() } wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); } - - -void Renderable3DComponent::setPreferredThreadingCount(unsigned short value) -{ - for (auto& wt : workerThreads) - { - delete wt; - } - - workerThreads.clear(); -} \ No newline at end of file diff --git a/WickedEngine/Renderable3DComponent.h b/WickedEngine/Renderable3DComponent.h index 436f1d4e2..1e641b377 100644 --- a/WickedEngine/Renderable3DComponent.h +++ b/WickedEngine/Renderable3DComponent.h @@ -1,10 +1,8 @@ #pragma once #include "Renderable2DComponent.h" -#include "wiTaskThread.h" #include "wiRenderer.h" #include "wiWaterPlane.h" #include "wiGraphicsDevice.h" -#include class Renderable3DComponent : public Renderable2DComponent @@ -44,6 +42,8 @@ private: bool tessellationEnabled; bool sharpenFilterEnabled; + wiGraphicsTypes::Texture2D* colorGradingTex = nullptr; + UINT msaaSampleCount; protected: @@ -66,8 +66,6 @@ protected: virtual void ResizeBuffers() override; - std::vector workerThreads; - virtual void RenderFrameSetUp(GRAPHICSTHREAD threadID); virtual void RenderReflections(GRAPHICSTHREAD threadID); virtual void RenderShadows(GRAPHICSTHREAD threadID); @@ -113,9 +111,9 @@ public: inline bool getTessellationEnabled() { return tessellationEnabled && wiRenderer::GetDevice()->CheckCapability(wiGraphicsTypes::GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION); } inline bool getSharpenFilterEnabled() { return sharpenFilterEnabled && getSharpenFilterAmount() > 0; } - inline UINT getMSAASampleCount() { return msaaSampleCount; } + inline wiGraphicsTypes::Texture2D* getColorGradingTexture() { return colorGradingTex; } - inline unsigned int getThreadingCount(){ return (unsigned int)workerThreads.size(); } + inline UINT getMSAASampleCount() { return msaaSampleCount; } inline void setLightShaftQuality(float value){ lightShaftQuality = value; } inline void setBloomDownSample(float value){ bloomDownSample = value; } @@ -151,11 +149,10 @@ public: inline void setTessellationEnabled(bool value) { tessellationEnabled = value; } inline void setSharpenFilterEnabled(bool value) { sharpenFilterEnabled = value; } + inline void setColorGradingTexture(wiGraphicsTypes::Texture2D* tex) { colorGradingTex = tex; } + inline void setMSAASampleCount(UINT value) { msaaSampleCount = value; ResizeBuffers(); } - - virtual void setPreferredThreadingCount(unsigned short value); - void setProperties(); Renderable3DComponent(); diff --git a/WickedEngine/Renderable3DComponent_BindLua.cpp b/WickedEngine/Renderable3DComponent_BindLua.cpp index 5fea6439a..7356e216a 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.cpp +++ b/WickedEngine/Renderable3DComponent_BindLua.cpp @@ -1,5 +1,6 @@ #include "Renderable3DComponent_BindLua.h" #include "wiResourceManager_BindLua.h" +#include "Texture_BindLua.h" const char Renderable3DComponent_BindLua::className[] = "Renderable3DComponent"; @@ -41,6 +42,7 @@ Luna::FunctionType Renderable3DComponent_BindLua: lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingTexture), lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesReflectionEnabled), @@ -59,8 +61,6 @@ Luna::FunctionType Renderable3DComponent_BindLua: lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus), lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength), - - lunamethod(Renderable3DComponent_BindLua, SetPreferredThreadingCount), { NULL, NULL } }; Luna::PropertyType Renderable3DComponent_BindLua::properties[] = { @@ -173,6 +173,24 @@ int Renderable3DComponent_BindLua::SetColorGradingEnabled(lua_State* L) wiLua::SError(L, "SetColorGradingEnabled(bool value) not enough arguments!"); return 0; } +int Renderable3DComponent_BindLua::SetColorGradingTexture(lua_State* L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + Texture_BindLua* tex = Luna::lightcheck(L, 1); + if (tex != nullptr) + { + ((Renderable3DComponent*)component)->setColorGradingTexture(tex->texture); + } + else + wiLua::SError(L, "SetColorGradingTexture(Texture texture2D) argument is not a texture!"); + } + else + wiLua::SError(L, "SetColorGradingTexture(Texture texture2D) not enough arguments!"); + + return 0; +} int Renderable3DComponent_BindLua::SetEmitterParticlesEnabled(lua_State* L) { if (component == nullptr) @@ -415,22 +433,6 @@ int Renderable3DComponent_BindLua::SetDepthOfFieldStrength(lua_State* L) return 0; } -int Renderable3DComponent_BindLua::SetPreferredThreadingCount(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "SetPreferredThreadingCount(int value) component is null!"); - return 0; - } - if (wiLua::SGetArgCount(L) > 0) - { - ((Renderable3DComponent*)component)->setPreferredThreadingCount((unsigned short)wiLua::SGetInt(L, 1)); - } - else - wiLua::SError(L, "SetPreferredThreadingCount(int value) not enough arguments!"); - return 0; -} - void Renderable3DComponent_BindLua::Bind() { static bool initialized = false; diff --git a/WickedEngine/Renderable3DComponent_BindLua.h b/WickedEngine/Renderable3DComponent_BindLua.h index cedaca4a2..5a7b53b5a 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.h +++ b/WickedEngine/Renderable3DComponent_BindLua.h @@ -22,6 +22,7 @@ public: int SetFXAAEnabled(lua_State* L); int SetBloomEnabled(lua_State* L); int SetColorGradingEnabled(lua_State* L); + int SetColorGradingTexture(lua_State* L); int SetEmitterParticlesEnabled(lua_State* L); int SetHairParticlesEnabled(lua_State* L); int SetHairParticlesReflectionEnabled(lua_State* L); @@ -41,8 +42,6 @@ public: int SetDepthOfFieldFocus(lua_State* L); int SetDepthOfFieldStrength(lua_State* L); - int SetPreferredThreadingCount(lua_State* L); - static void Bind(); }; diff --git a/WickedEngine/TiledDeferredRenderableComponent.cpp b/WickedEngine/TiledDeferredRenderableComponent.cpp index ab8902679..0ffe0ffa8 100644 --- a/WickedEngine/TiledDeferredRenderableComponent.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent.cpp @@ -59,7 +59,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); + wiRenderer::BindDepthTextures(dtDepthCopy.GetTexture(), rtLinearDepth.GetTexture(), threadID); if (getStereogramEnabled()) { @@ -73,7 +73,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } rtGBuffer.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), rtGBuffer.GetTexture(3), nullptr, threadID); + wiRenderer::BindGBufferTextures(rtGBuffer.GetTexture(0), rtGBuffer.GetTexture(1), rtGBuffer.GetTexture(2), rtGBuffer.GetTexture(3), nullptr, threadID); wiRenderer::GetDevice()->BindResource(CS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID); diff --git a/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp b/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp index 4592cb048..b82c248a5 100644 --- a/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp +++ b/WickedEngine/TiledDeferredRenderableComponent_BindLua.cpp @@ -40,6 +40,7 @@ Luna::FunctionType TiledDeferredRender lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingTexture), lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesReflectionEnabled), @@ -58,8 +59,7 @@ Luna::FunctionType TiledDeferredRender lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus), lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength), - lunamethod(Renderable3DComponent_BindLua, SetPreferredThreadingCount), -{ NULL, NULL } + { NULL, NULL } }; Luna::PropertyType TiledDeferredRenderableComponent_BindLua::properties[] = { { NULL, NULL } diff --git a/WickedEngine/TiledForwardRenderableComponent.cpp b/WickedEngine/TiledForwardRenderableComponent.cpp index 6d440d6d1..1a0e9b85b 100644 --- a/WickedEngine/TiledForwardRenderableComponent.cpp +++ b/WickedEngine/TiledForwardRenderableComponent.cpp @@ -48,7 +48,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) } rtLinearDepth.Deactivate(threadID); - wiRenderer::UpdateDepthBuffer(dtDepthCopy.GetTextureResolvedMSAA(threadID), rtLinearDepth.GetTexture(), threadID); + wiRenderer::BindDepthTextures(dtDepthCopy.GetTextureResolvedMSAA(threadID), rtLinearDepth.GetTexture(), threadID); wiRenderer::ComputeTiledLightCulling(false, threadID); @@ -64,7 +64,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID) wiRenderer::DrawSky(threadID); } rtMain.Deactivate(threadID); - wiRenderer::UpdateGBuffer(rtMain.GetTextureResolvedMSAA(threadID, 0), rtMain.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); + wiRenderer::BindGBufferTextures(rtMain.GetTextureResolvedMSAA(threadID, 0), rtMain.GetTextureResolvedMSAA(threadID, 1), nullptr, nullptr, nullptr, threadID); diff --git a/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp b/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp index e6baa6987..e406f26ae 100644 --- a/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp +++ b/WickedEngine/TiledForwardRenderableComponent_BindLua.cpp @@ -40,6 +40,7 @@ Luna::FunctionType TiledForwardRenderab lunamethod(Renderable3DComponent_BindLua, SetFXAAEnabled), lunamethod(Renderable3DComponent_BindLua, SetBloomEnabled), lunamethod(Renderable3DComponent_BindLua, SetColorGradingEnabled), + lunamethod(Renderable3DComponent_BindLua, SetColorGradingTexture), lunamethod(Renderable3DComponent_BindLua, SetEmitterParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesEnabled), lunamethod(Renderable3DComponent_BindLua, SetHairParticlesReflectionEnabled), @@ -58,7 +59,6 @@ Luna::FunctionType TiledForwardRenderab lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus), lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength), - lunamethod(Renderable3DComponent_BindLua, SetPreferredThreadingCount), { NULL, NULL } }; Luna::PropertyType TiledForwardRenderableComponent_BindLua::properties[] = { diff --git a/WickedEngine/WickedEngine.h b/WickedEngine/WickedEngine.h index 16b3c9bc8..2e19e4c2a 100644 --- a/WickedEngine/WickedEngine.h +++ b/WickedEngine/WickedEngine.h @@ -26,7 +26,6 @@ #include "wiDirectInput.h" #include "wiXInput.h" #include "wiRawInput.h" -#include "wiTaskThread.h" #include "wiMath.h" #include "wiLensFlare.h" #include "wiSound.h" diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems index ebc83445c..2f437b5c5 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems +++ b/WickedEngine/WickedEngine_SHARED.vcxitems @@ -338,7 +338,6 @@ - @@ -366,7 +365,6 @@ - @@ -683,7 +681,6 @@ - diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters index 89041f40b..e8c37e73b 100644 --- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters +++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters @@ -924,9 +924,6 @@ ENGINE\Helpers - - ENGINE\Helpers - ENGINE\Helpers @@ -960,9 +957,6 @@ ENGINE\Graphics - - ENGINE\Graphics - ENGINE\Scripting @@ -1832,9 +1826,6 @@ ENGINE\Graphics - - ENGINE\Graphics - ENGINE\Scripting diff --git a/WickedEngine/wiBULLET.cpp b/WickedEngine/wiBULLET.cpp index 354b2c6aa..03b22808c 100644 --- a/WickedEngine/wiBULLET.cpp +++ b/WickedEngine/wiBULLET.cpp @@ -2,6 +2,7 @@ #include "wiSceneComponents.h" +#include "btBulletDynamicsCommon.h" #include "LinearMath/btHashMap.h" #include "BulletSoftBody/btSoftRigidDynamicsWorld.h" @@ -16,48 +17,63 @@ using namespace wiSceneComponents; int PHYSICS::softBodyIterationCount=5; bool PHYSICS::rigidBodyPhysicsEnabled = true, PHYSICS::softBodyPhysicsEnabled = true; -bool wiBULLET::grab=false; -RAY wiBULLET::grabRay=RAY(); + +struct BulletPhysicsWorld +{ + btCollisionConfiguration* collisionConfiguration; + btCollisionDispatcher* dispatcher; + btBroadphaseInterface* overlappingPairCache; + btSequentialImpulseConstraintSolver* solver; + btDynamicsWorld* dynamicsWorld; + btAlignedObjectArray collisionShapes; + + btSoftBodySolver* softBodySolver; + btSoftBodySolverOutput* softBodySolverOutput; + + btVector3 wind; +}; wiBULLET::wiBULLET() { + bulletPhysics = new BulletPhysicsWorld; + registeredObjects=-1; ///-----initialization_start----- //softBodySolver = new btDefaultSoftBodySolver(); - softBodySolver=NULL; + bulletPhysics->softBodySolver = nullptr; ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. //collisionConfiguration = new btDefaultCollisionConfiguration(); - collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); + bulletPhysics->collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) - dispatcher = new btCollisionDispatcher(collisionConfiguration); + bulletPhysics->dispatcher = new btCollisionDispatcher(bulletPhysics->collisionConfiguration); ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. - overlappingPairCache = new btDbvtBroadphase(); + bulletPhysics->overlappingPairCache = new btDbvtBroadphase(); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) - solver = new btSequentialImpulseConstraintSolver; + bulletPhysics->solver = new btSequentialImpulseConstraintSolver; //dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration); - dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration,softBodySolver); + bulletPhysics->dynamicsWorld = new btSoftRigidDynamicsWorld(bulletPhysics->dispatcher, bulletPhysics->overlappingPairCache, bulletPhysics->solver, bulletPhysics->collisionConfiguration, bulletPhysics->softBodySolver); - dynamicsWorld->getSolverInfo().m_solverMode|=SOLVER_RANDMIZE_ORDER; - dynamicsWorld->getDispatchInfo().m_enableSatConvex = true; - dynamicsWorld->getSolverInfo().m_splitImpulse=true; + bulletPhysics->dynamicsWorld->getSolverInfo().m_solverMode|=SOLVER_RANDMIZE_ORDER; + bulletPhysics->dynamicsWorld->getDispatchInfo().m_enableSatConvex = true; + bulletPhysics->dynamicsWorld->getSolverInfo().m_splitImpulse=true; - dynamicsWorld->setGravity(btVector3(0,-11,0)); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().air_density = (btScalar)1.0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_density = 0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_offset = 0; - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().water_normal = btVector3(0,0,0); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().m_gravity.setValue(0,-11,0); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo().m_sparsesdf.Initialize(); //??? + bulletPhysics->dynamicsWorld->setGravity(btVector3(0,-11,0)); + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().air_density = (btScalar)1.0; + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().water_density = 0; + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().water_offset = 0; + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().water_normal = btVector3(0,0,0); + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().m_gravity.setValue(0,-11,0); + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo().m_sparsesdf.Initialize(); //??? - dynamicsWorld->setInternalTickCallback(soundTickCallback,this,true); - dynamicsWorld->setInternalTickCallback(pickingPreTickCallback,this,true); + //dynamicsWorld->setInternalTickCallback(soundTickCallback,this,true); + //dynamicsWorld->setInternalTickCallback(pickingPreTickCallback,this,true); #ifdef BACKLOG @@ -76,29 +92,31 @@ wiBULLET::~wiBULLET() ClearWorld(); //delete dynamics world - delete dynamicsWorld; + delete bulletPhysics->dynamicsWorld; //delete solver - delete solver; + delete bulletPhysics->solver; //delete broadphase - delete overlappingPairCache; + delete bulletPhysics->overlappingPairCache; //delete dispatcher - delete dispatcher; + delete bulletPhysics->dispatcher; - delete collisionConfiguration; + delete bulletPhysics->collisionConfiguration; //next line is optional: it will be cleared by the destructor when the array goes out of scope - collisionShapes.clear(); + bulletPhysics->collisionShapes.clear(); ///-----cleanup_end----- CleanUp(); + + delete bulletPhysics; } void wiBULLET::addWind(const XMFLOAT3& wind){ - this->wind = btVector3(btScalar(wind.x),btScalar(wind.y),btScalar(wind.z)); + this->bulletPhysics->wind = btVector3(btScalar(wind.x),btScalar(wind.y),btScalar(wind.z)); } @@ -107,7 +125,7 @@ void wiBULLET::addBox(const XMFLOAT3& sca, const XMFLOAT4& rot, const XMFLOAT3& btCollisionShape* shape = new btBoxShape(btVector3(sca.x,sca.y,sca.z)); shape->setMargin(btScalar(0.05)); - collisionShapes.push_back(shape); + bulletPhysics->collisionShapes.push_back(shape); btTransform shapeTransform; shapeTransform.setIdentity(); @@ -137,7 +155,7 @@ void wiBULLET::addBox(const XMFLOAT3& sca, const XMFLOAT4& rot, const XMFLOAT3& body->setActivationState(DISABLE_DEACTIVATION); //add the body to the dynamics world - dynamicsWorld->addRigidBody(body); + bulletPhysics->dynamicsWorld->addRigidBody(body); if (body->getMotionState()) @@ -218,7 +236,7 @@ void wiBULLET::addSphere(float rad, const XMFLOAT3& pos btCollisionShape* shape = new btSphereShape(btScalar(rad)); shape->setMargin(btScalar(0.05)); - collisionShapes.push_back(shape); + bulletPhysics->collisionShapes.push_back(shape); btTransform shapeTransform; shapeTransform.setIdentity(); @@ -247,7 +265,7 @@ void wiBULLET::addSphere(float rad, const XMFLOAT3& pos body->setActivationState(DISABLE_DEACTIVATION); //add the body to the dynamics world - dynamicsWorld->addRigidBody(body); + bulletPhysics->dynamicsWorld->addRigidBody(body); if (body->getMotionState()) @@ -270,7 +288,7 @@ void wiBULLET::addCapsule(float rad, float hei, const XMFLOAT4& rot, const XMFLO btCollisionShape* shape = new btCapsuleShape(btScalar(rad),btScalar(hei)); shape->setMargin(btScalar(0.05)); - collisionShapes.push_back(shape); + bulletPhysics->collisionShapes.push_back(shape); btTransform shapeTransform; shapeTransform.setIdentity(); @@ -300,7 +318,7 @@ void wiBULLET::addCapsule(float rad, float hei, const XMFLOAT4& rot, const XMFLO body->setActivationState(DISABLE_DEACTIVATION); //add the body to the dynamics world - dynamicsWorld->addRigidBody(body); + bulletPhysics->dynamicsWorld->addRigidBody(body); if (body->getMotionState()) @@ -326,7 +344,7 @@ void wiBULLET::addConvexHull(const std::vector& vertices, const XMFLOA shape->setLocalScaling(btVector3(sca.x,sca.y,sca.z)); shape->setMargin(btScalar(0.05)); - collisionShapes.push_back(shape); + bulletPhysics->collisionShapes.push_back(shape); btTransform shapeTransform; shapeTransform.setIdentity(); @@ -358,7 +376,7 @@ void wiBULLET::addConvexHull(const std::vector& vertices, const XMFLOA body->setActivationState(DISABLE_DEACTIVATION); //add the body to the dynamics world - dynamicsWorld->addRigidBody(body); + bulletPhysics->dynamicsWorld->addRigidBody(body); if (body->getMotionState()) @@ -408,7 +426,7 @@ void wiBULLET::addTriangleMesh(const std::vector& vertices, const std: shape->setMargin(btScalar(0.05)); shape->setLocalScaling(btVector3(sca.x,sca.y,sca.z)); - collisionShapes.push_back(shape); + bulletPhysics->collisionShapes.push_back(shape); btTransform shapeTransform; shapeTransform.setIdentity(); @@ -438,7 +456,7 @@ void wiBULLET::addTriangleMesh(const std::vector& vertices, const std: body->setActivationState( DISABLE_DEACTIVATION ); //add the body to the dynamics world - dynamicsWorld->addRigidBody(body); + bulletPhysics->dynamicsWorld->addRigidBody(body); if (body->getMotionState()) @@ -477,7 +495,7 @@ void wiBULLET::addSoftBodyTriangleMesh(const Mesh* mesh, const XMFLOAT3& sca, co btSoftBody* softBody = btSoftBodyHelpers::CreateFromTriMesh( - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo() + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo() ,&btVerts[0] ,&btInd[0] ,tCount @@ -556,13 +574,13 @@ void wiBULLET::addSoftBodyTriangleMesh(const Mesh* mesh, const XMFLOAT3& sca, co softBody->getCollisionShape()->setMargin(btScalar(0.2)); - softBody->setWindVelocity(wind); + softBody->setWindVelocity(bulletPhysics->wind); softBody->setPose(true,true); softBody->setActivationState(DISABLE_DEACTIVATION); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->addSoftBody(softBody); + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->addSoftBody(softBody); transforms.push_back(new PhysicsTransform); } @@ -574,7 +592,7 @@ void wiBULLET::connectVerticesToSoftBody(Mesh* const mesh, int objectI){ if (!softBodyPhysicsEnabled) return; - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[objectI]; + btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[objectI]; btSoftBody* softBody = btSoftBody::upcast(obj); @@ -583,7 +601,7 @@ void wiBULLET::connectVerticesToSoftBody(Mesh* const mesh, int objectI){ softBody->getAabb(min, max); mesh->aabb.create(XMFLOAT3(min.x(), min.y(), min.z()), XMFLOAT3(max.x(), max.y(), max.z())); - softBody->setWindVelocity(wind); + softBody->setWindVelocity(bulletPhysics->wind); btSoftBody::tNodeArray& nodes(softBody->m_nodes); @@ -608,7 +626,7 @@ void wiBULLET::connectSoftBodyToVertices(const Mesh* const mesh, int objectI){ return; if(!firstRunWorld){ - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[objectI]; + btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[objectI]; btSoftBody* softBody = btSoftBody::upcast(obj); if(softBody){ @@ -634,7 +652,7 @@ void wiBULLET::transformBody(const XMFLOAT4& rot, const XMFLOAT3& pos, int objec return; } - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[objectI]; + btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[objectI]; btRigidBody* rigidBody = btRigidBody::upcast(obj); if(rigidBody){ btTransform transform; @@ -647,7 +665,7 @@ void wiBULLET::transformBody(const XMFLOAT4& rot, const XMFLOAT3& pos, int objec PHYSICS::PhysicsTransform* wiBULLET::getObject(int index){ - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[index]; + btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[index]; btTransform trans; btRigidBody* body = btRigidBody::upcast(obj); @@ -776,7 +794,7 @@ void wiBULLET::removeObject(Object* object) void wiBULLET::Update(float dt){ if (rigidBodyPhysicsEnabled || softBodyPhysicsEnabled) - dynamicsWorld->stepSimulation(dt, 6); + bulletPhysics->dynamicsWorld->stepSimulation(dt, 6); } void wiBULLET::MarkForRead(){ @@ -791,16 +809,16 @@ void wiBULLET::UnMarkForWrite(){ } void wiBULLET::ClearWorld(){ - for(int i=dynamicsWorld->getNumCollisionObjects()-1;i>=0;i--) + for(int i= bulletPhysics->dynamicsWorld->getNumCollisionObjects()-1;i>=0;i--) { deleteObject(i); } //delete collision shapes - for (int j=0;jcollisionShapes.size();j++) { - btCollisionShape* shape = collisionShapes[j]; - collisionShapes[j] = 0; + btCollisionShape* shape = bulletPhysics->collisionShapes[j]; + bulletPhysics->collisionShapes[j] = 0; delete shape; } @@ -818,101 +836,101 @@ void wiBULLET::CleanUp(){ void wiBULLET::deleteObject(int id) { - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[id]; + btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[id]; btRigidBody* body = btRigidBody::upcast(obj); if (body && body->getMotionState()) { delete body->getMotionState(); } - while (dynamicsWorld->getNumConstraints()) + while (bulletPhysics->dynamicsWorld->getNumConstraints()) { - btTypedConstraint* pc = dynamicsWorld->getConstraint(0); - dynamicsWorld->removeConstraint(pc); + btTypedConstraint* pc = bulletPhysics->dynamicsWorld->getConstraint(0); + bulletPhysics->dynamicsWorld->removeConstraint(pc); delete pc; } btSoftBody* softBody = btSoftBody::upcast(obj); if (softBody) { - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->removeSoftBody(softBody); + ((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->removeSoftBody(softBody); } else { btRigidBody* body = btRigidBody::upcast(obj); if (body) - dynamicsWorld->removeRigidBody(body); + bulletPhysics->dynamicsWorld->removeRigidBody(body); else - dynamicsWorld->removeCollisionObject(obj); + bulletPhysics->dynamicsWorld->removeCollisionObject(obj); } delete obj; registeredObjects--; } - -void wiBULLET::soundTickCallback(btDynamicsWorld *world, btScalar timeStep) { - int numManifolds = world->getDispatcher()->getNumManifolds(); - for (int i=0;igetDispatcher()->getManifoldByIndexInternal(i); - btCollisionObject* obA = (btCollisionObject*)(contactManifold->getBody0()); - btCollisionObject* obB = (btCollisionObject*)(contactManifold->getBody1()); - - int numContacts = contactManifold->getNumContacts(); - for (int j=0;jgetContactPoint(j); - if (pt.getDistance()<0.f) - { - if(pt.getAppliedImpulse()>10.f){ - //TODO: play some sound - } - const btVector3& ptA = pt.getPositionWorldOnA(); - const btVector3& ptB = pt.getPositionWorldOnB(); - const btVector3& normalOnB = pt.m_normalWorldOnB; - } - } - } -} - -void wiBULLET::pickingPreTickCallback (btDynamicsWorld *world, btScalar timeStep) -{ -// world->getWorldUserInfo(); // -// if(grab) -// { -// /*const int x=softDemo->m_lastmousepos[0]; -// const int y=softDemo->m_lastmousepos[1]; -// const btVector3 rayFrom=softDemo->getCameraPosition(); -// const btVector3 rayTo=softDemo->getRayTo(x,y); -// const btVector3 rayDir=(rayTo-rayFrom).normalized(); -// const btVector3 N=(softDemo->getCameraTargetPosition()-softDemo->getCameraPosition()).normalized(); -// const btScalar O=btDot(softDemo->m_impact,N);*/ -// const btVector3 rayFrom=btVector3(grabRay.origin.x,grabRay.origin.y,grabRay.origin.z); -// const btVector3 rayDir=btVector3(grabRay.direction.x,grabRay.direction.y,grabRay.direction.z); -// //const btScalar den=btDot(N,rayDir); -// //if((den*den)>0) -///* { -// const btScalar num=O-btDot(N,rayFrom); -// const btScalar hit=num/den; -// if((hit>0)&&(hit<1500)) -// { -// softDemo->m_goal=rayFrom+rayDir*hit; -// } -// }*/ -// btVector3 delta=softDemo->m_goal-softDemo->m_node->m_x; -// static const btScalar maxdrag=10; -// if(delta.length2()>(maxdrag*maxdrag)) -// { -// delta=delta.normalized()*maxdrag; -// } -// softDemo->m_node->m_v+=delta/timeStep; -// } +//void wiBULLET::soundTickCallback(btDynamicsWorld *world, btScalar timeStep) { +// int numManifolds = world->getDispatcher()->getNumManifolds(); +// for (int i=0;igetDispatcher()->getManifoldByIndexInternal(i); +// btCollisionObject* obA = (btCollisionObject*)(contactManifold->getBody0()); +// btCollisionObject* obB = (btCollisionObject*)(contactManifold->getBody1()); +// +// int numContacts = contactManifold->getNumContacts(); +// for (int j=0;jgetContactPoint(j); +// if (pt.getDistance()<0.f) +// { +// if(pt.getAppliedImpulse()>10.f){ +// //TODO: play some sound +// } +// const btVector3& ptA = pt.getPositionWorldOnA(); +// const btVector3& ptB = pt.getPositionWorldOnB(); +// const btVector3& normalOnB = pt.m_normalWorldOnB; +// } +// } +// } +//} +// +//void wiBULLET::pickingPreTickCallback (btDynamicsWorld *world, btScalar timeStep) +//{ +//// world->getWorldUserInfo(); +//// +//// if(grab) +//// { +//// /*const int x=softDemo->m_lastmousepos[0]; +//// const int y=softDemo->m_lastmousepos[1]; +//// const btVector3 rayFrom=softDemo->getCameraPosition(); +//// const btVector3 rayTo=softDemo->getRayTo(x,y); +//// const btVector3 rayDir=(rayTo-rayFrom).normalized(); +//// const btVector3 N=(softDemo->getCameraTargetPosition()-softDemo->getCameraPosition()).normalized(); +//// const btScalar O=btDot(softDemo->m_impact,N);*/ +//// const btVector3 rayFrom=btVector3(grabRay.origin.x,grabRay.origin.y,grabRay.origin.z); +//// const btVector3 rayDir=btVector3(grabRay.direction.x,grabRay.direction.y,grabRay.direction.z); +//// //const btScalar den=btDot(N,rayDir); +//// //if((den*den)>0) +/////* { +//// const btScalar num=O-btDot(N,rayFrom); +//// const btScalar hit=num/den; +//// if((hit>0)&&(hit<1500)) +//// { +//// softDemo->m_goal=rayFrom+rayDir*hit; +//// } +//// }*/ +//// btVector3 delta=softDemo->m_goal-softDemo->m_node->m_x; +//// static const btScalar maxdrag=10; +//// if(delta.length2()>(maxdrag*maxdrag)) +//// { +//// delta=delta.normalized()*maxdrag; +//// } +//// softDemo->m_node->m_v+=delta/timeStep; +//// } +//// +//} +//void wiBULLET::setGrab(bool value, const RAY& ray){ +// grab=value; +// grabRay=ray; +//} diff --git a/WickedEngine/wiBULLET.h b/WickedEngine/wiBULLET.h index 836d4689d..142a3d78d 100644 --- a/WickedEngine/wiBULLET.h +++ b/WickedEngine/wiBULLET.h @@ -1,36 +1,14 @@ #pragma once #include "wiPHYSICS.h" -#include "BULLET/btBulletDynamicsCommon.h" - -class btCollisionConfiguration; -class btCollisionDispatcher; -class btBroadphaseInterface; -class btSequentialImpulseConstraintSolver; -class btDynamicsWorld; -class btCollisionShape; -class btSoftBodySolver; -class btSoftBodySolverOutput; +struct BulletPhysicsWorld; struct RAY; class wiBULLET:public PHYSICS { private: - btCollisionConfiguration* collisionConfiguration; - btCollisionDispatcher* dispatcher; - btBroadphaseInterface* overlappingPairCache; - btSequentialImpulseConstraintSolver* solver; - btDynamicsWorld* dynamicsWorld; - btAlignedObjectArray collisionShapes; - - btSoftBodySolver* softBodySolver; - btSoftBodySolverOutput* softBodySolverOutput; - - btVector3 wind; - - static bool grab; - static RAY grabRay; + BulletPhysicsWorld * bulletPhysics = nullptr; void deleteObject(int id); public: @@ -72,10 +50,5 @@ public: void ClearWorld(); void CleanUp(); - void setGrab(bool val, const RAY& ray); - static void pickingPreTickCallback (btDynamicsWorld *world, btScalar timeStep); - static void soundTickCallback(btDynamicsWorld *world, btScalar timeStep); - - ALIGN_16 }; diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index 775d12958..24da765da 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -19,27 +19,6 @@ enum RENDERTYPE RENDERTYPE_OPAQUE = 1, RENDERTYPE_TRANSPARENT = 2, RENDERTYPE_WATER = 4, - RENDERTYPE_LIGHT = 8, - RENDERTYPE_DECAL = 16, - RENDERTYPE_ENVPROBE = 32, - RENDERTYPE_FORCEFIELD = 64, - RENDERTYPE_EMITTER = 128, - RENDERTYPE_CAMERA = 256, - RENDERTYPE_ARMATURE = 512, -}; -enum PICKTYPE -{ - PICK_VOID = RENDERTYPE_VOID, - PICK_OPAQUE = RENDERTYPE_OPAQUE, - PICK_TRANSPARENT = RENDERTYPE_TRANSPARENT, - PICK_WATER = RENDERTYPE_WATER, - PICK_LIGHT = RENDERTYPE_LIGHT, - PICK_DECAL = RENDERTYPE_DECAL, - PICK_ENVPROBE = RENDERTYPE_ENVPROBE, - PICK_FORCEFIELD = RENDERTYPE_FORCEFIELD, - PICK_EMITTER = RENDERTYPE_EMITTER, - PICK_CAMERA = RENDERTYPE_CAMERA, - PICK_ARMATURE = RENDERTYPE_ARMATURE, }; enum SHADERTYPE diff --git a/WickedEngine/wiFrustum.cpp b/WickedEngine/wiFrustum.cpp index a81b55f39..7cbda15fb 100644 --- a/WickedEngine/wiFrustum.cpp +++ b/WickedEngine/wiFrustum.cpp @@ -69,12 +69,12 @@ void Frustum::ConstructFrustum(float screenDepth, XMFLOAT4X4 projectionMatrix, c } -bool Frustum::CheckPoint(const XMFLOAT3& point) +bool Frustum::CheckPoint(const XMFLOAT3& point) const { XMVECTOR p = XMLoadFloat3(&point); - for(short i=0; i<6; i++) + for (short i = 0; i < 6; i++) { - if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), p) ) < 0.0f) + if (XMVectorGetX(XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), p)) < 0.0f) { return false; } @@ -82,13 +82,13 @@ bool Frustum::CheckPoint(const XMFLOAT3& point) return true; } -bool Frustum::CheckSphere(const XMFLOAT3& center, float radius) +bool Frustum::CheckSphere(const XMFLOAT3& center, float radius) const { int i; XMVECTOR c = XMLoadFloat3(¢er); - for(i=0; i<6; i++) + for (i = 0; i < 6; i++) { - if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), c) ) < -radius) + if (XMVectorGetX(XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), c)) < -radius) { return false; } @@ -96,37 +96,38 @@ bool Frustum::CheckSphere(const XMFLOAT3& center, float radius) return true; } -int Frustum::CheckBox(const AABB& box) +int Frustum::CheckBox(const AABB& box) const { int iTotalIn = 0; - for(int p = 0; p < 6; ++p) + for (int p = 0; p < 6; ++p) { - + int iInCount = 8; int iPtIn = 1; - for(int i = 0; i < 8; ++i) { - if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[p]), XMLoadFloat3(&box.corners[i])) ) < 0.0f) + for (int i = 0; i < 8; ++i) { + if (XMVectorGetX(XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[p]), XMLoadFloat3(&box.corners[i]))) < 0.0f) { - iPtIn=0; + iPtIn = 0; --iInCount; } } - if(iInCount == 0) + if (iInCount == 0) return(false); iTotalIn += iPtIn; } - if(iTotalIn == 6) + if (iTotalIn == 6) return(BOX_FRUSTUM_INSIDE); return(BOX_FRUSTUM_INTERSECTS); } -const XMFLOAT4& Frustum::getLeftPlane() { return m_planesNorm[2]; } -const XMFLOAT4& Frustum::getRightPlane() { return m_planesNorm[3]; } -const XMFLOAT4& Frustum::getTopPlane() { return m_planesNorm[4]; } -const XMFLOAT4& Frustum::getBottomPlane() { return m_planesNorm[5]; } -const XMFLOAT4& Frustum::getFarPlane(){return m_planesNorm[1];} -const XMFLOAT4& Frustum::getNearPlane(){return m_planesNorm[0];} -XMFLOAT3 Frustum::getCamPos(){ - return XMFLOAT3(-view._41,-view._42,-view._43); +const XMFLOAT4& Frustum::getLeftPlane() const { return m_planesNorm[2]; } +const XMFLOAT4& Frustum::getRightPlane() const { return m_planesNorm[3]; } +const XMFLOAT4& Frustum::getTopPlane() const { return m_planesNorm[4]; } +const XMFLOAT4& Frustum::getBottomPlane() const { return m_planesNorm[5]; } +const XMFLOAT4& Frustum::getFarPlane() const { return m_planesNorm[1]; } +const XMFLOAT4& Frustum::getNearPlane() const { return m_planesNorm[0]; } +XMFLOAT3 Frustum::getCamPos() const +{ + return XMFLOAT3(-view._41, -view._42, -view._43); } diff --git a/WickedEngine/wiFrustum.h b/WickedEngine/wiFrustum.h index 6c1aae3c4..22b94eed5 100644 --- a/WickedEngine/wiFrustum.h +++ b/WickedEngine/wiFrustum.h @@ -15,19 +15,19 @@ public: void ConstructFrustum(float screenDepth, XMFLOAT4X4 projectionMatrix, const XMFLOAT4X4& viewMatrix, const XMMATRIX& world = XMMatrixIdentity()); - bool CheckPoint(const XMFLOAT3&); - bool CheckSphere(const XMFLOAT3&, float); + bool CheckPoint(const XMFLOAT3&) const; + bool CheckSphere(const XMFLOAT3&, float) const; #define BOX_FRUSTUM_INTERSECTS 1 #define BOX_FRUSTUM_INSIDE 2 - int CheckBox(const AABB& box); + int CheckBox(const AABB& box) const; - const XMFLOAT4& getLeftPlane(); - const XMFLOAT4& getRightPlane(); - const XMFLOAT4& getTopPlane(); - const XMFLOAT4& getBottomPlane(); - const XMFLOAT4& getFarPlane(); - const XMFLOAT4& getNearPlane(); - XMFLOAT3 getCamPos(); + const XMFLOAT4& getLeftPlane() const; + const XMFLOAT4& getRightPlane() const; + const XMFLOAT4& getTopPlane() const; + const XMFLOAT4& getBottomPlane() const; + const XMFLOAT4& getFarPlane() const; + const XMFLOAT4& getNearPlane() const; + XMFLOAT3 getCamPos() const; }; diff --git a/WickedEngine/wiLines.cpp b/WickedEngine/wiLines.cpp deleted file mode 100644 index b72b3d758..000000000 --- a/WickedEngine/wiLines.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "wiLines.h" -#include "wiRenderer.h" - -using namespace wiGraphicsTypes; - -Lines::Lines() -{ - desc = Description(); - desc.length=1; - parentArmature=0; - parentBone=0; - SetUpVertices(); -} - -Lines::Lines(float newLen, const XMFLOAT4& newColor, int newParentArmature, int newParentBone) -{ - desc = Description(); - desc.length = newLen; - desc.color = newColor; - parentArmature = newParentArmature; - parentBone = newParentBone; - SetUpVertices(); -} - -Lines::Lines(const XMFLOAT3& a, const XMFLOAT3& b, const XMFLOAT4& c) -{ - desc = Description(); - desc.length = 0; - desc.color = c; - parentArmature = 0; - parentBone = 0; - - //Vertex* verts = new Vertex[2]; - - //verts[0].pos = XMFLOAT3(a.x,a.y,a.z); - //verts[1].pos = XMFLOAT3(b.x,b.y,b.z); - - XMFLOAT4 verts[] = { - XMFLOAT4(a.x,a.y,a.z,1), XMFLOAT4(1,1,1,1), - XMFLOAT4(b.x,b.y,b.z,1), XMFLOAT4(1,1,1,1), - }; - - GPUBufferDesc bd; - ZeroMemory( &bd, sizeof(bd) ); - bd.Usage = USAGE_DEFAULT; - bd.ByteWidth = sizeof(verts); - bd.BindFlags = BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = 0; - SubresourceData InitData; - ZeroMemory( &InitData, sizeof(InitData) ); - InitData.pSysMem = verts; - wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); - - //if(verts){ - // delete[](verts); - // verts=NULL; - //} -} -Lines::~Lines() -{ - CleanUp(); -} - -void Lines::CleanUp() -{ - -} - -void Lines::SetUpVertices() -{ - //Vertex* verts = new Vertex[2]; - - //verts[0].pos = XMFLOAT3(0,0,0); - //verts[1].pos = XMFLOAT3(0,0,desc.length); - - //GPUBufferDesc bd; - //ZeroMemory( &bd, sizeof(bd) ); - //bd.Usage = USAGE_DEFAULT; - //bd.ByteWidth = sizeof( Vertex ) * 2; - //bd.BindFlags = BIND_VERTEX_BUFFER; - //bd.CPUAccessFlags = 0; - //SubresourceData InitData; - //ZeroMemory( &InitData, sizeof(InitData) ); - //InitData.pSysMem = verts; - //wiRenderer::GetDevice()->CreateBuffer( &bd, &InitData, &vertexBuffer ); - - //if(verts){ - // delete[](verts); - // verts=NULL; - //} - - - - - - //Vertex* verts = new Vertex[2]; - - //verts[0].pos = XMFLOAT3(a.x,a.y,a.z); - //verts[1].pos = XMFLOAT3(b.x,b.y,b.z); - - XMFLOAT4 verts[] = { - XMFLOAT4(0,0,0,1), XMFLOAT4(1,1,1,1), - XMFLOAT4(0,0,desc.length,1), XMFLOAT4(1,1,1,1), - }; - - GPUBufferDesc bd; - ZeroMemory(&bd, sizeof(bd)); - bd.Usage = USAGE_DEFAULT; - bd.ByteWidth = sizeof(verts); - bd.BindFlags = BIND_VERTEX_BUFFER; - bd.CPUAccessFlags = 0; - SubresourceData InitData; - ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = verts; - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer); - - //if(verts){ - // delete[](verts); - // verts=NULL; - //} -} - -void Lines::Transform(const XMFLOAT4X4& mat) -{ - desc.transform=mat; -} \ No newline at end of file diff --git a/WickedEngine/wiLines.h b/WickedEngine/wiLines.h deleted file mode 100644 index dc1e18832..000000000 --- a/WickedEngine/wiLines.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include "CommonInclude.h" -#include "wiGraphicsAPI.h" - -class Lines -{ -private: - struct Description{ - XMFLOAT4X4 transform; - float length; - XMFLOAT4 color; - - Description(){ - length=0; - color=XMFLOAT4(1,1,1,1); - transform=XMFLOAT4X4( - 1,0,0,0, - 0,1,0,0, - 0,0,1,0, - 0,0,0,1 - ); - }; - }; - void SetUpVertices(); -public: - Lines(); - Lines(float newLen, const XMFLOAT4& newColor, int newParentArmature, int newParentBone); - Lines(const XMFLOAT3& a, const XMFLOAT3& b, const XMFLOAT4& c); - ~Lines(); - void CleanUp(); - void Transform(const XMFLOAT4X4& mat); - - Description desc; - int parentArmature,parentBone; - - wiGraphicsTypes::GPUBuffer vertexBuffer; - - ALIGN_16 -}; - diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 77ff5b79d..369315153 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -13,7 +13,6 @@ #include "wiLensFlare.h" #include "wiTextureHelper.h" #include "wiPHYSICS.h" -#include "wiLines.h" #include "wiCube.h" #include "wiWaterPlane.h" #include "wiEnums.h" @@ -79,14 +78,12 @@ UINT wiRenderer::entityArrayOffset_Decals = 0, wiRenderer::entityArrayCount_Deca UINT wiRenderer::entityArrayOffset_ForceFields = 0, wiRenderer::entityArrayCount_ForceFields = 0; UINT wiRenderer::entityArrayOffset_EnvProbes = 0, wiRenderer::entityArrayCount_EnvProbes = 0; -Texture2D* wiRenderer::enviroMap,*wiRenderer::colorGrading; -float wiRenderer::GameSpeed=1,wiRenderer::overrideGameSpeed=1; +Texture2D* wiRenderer::enviroMap = nullptr; +float wiRenderer::GameSpeed=1; bool wiRenderer::debugLightCulling = false; bool wiRenderer::occlusionCulling = false; bool wiRenderer::temporalAA = false, wiRenderer::temporalAADEBUG = false; wiRenderer::VoxelizedSceneData wiRenderer::voxelSceneData = VoxelizedSceneData(); -int wiRenderer::visibleCount; -wiRenderTarget wiRenderer::normalMapRT, wiRenderer::imagesRT, wiRenderer::imagesRTAdd; Camera *wiRenderer::cam = nullptr, *wiRenderer::refCam = nullptr, *wiRenderer::prevFrameCam = nullptr; PHYSICS* wiRenderer::physicsEngine = nullptr; wiOcean* wiRenderer::ocean = nullptr; @@ -96,8 +93,6 @@ string wiRenderer::SHADERPATH = "shaders/"; #pragma region STATIC TEMP -int wiRenderer::vertexCount; -deque wiRenderer::images; deque wiRenderer::waterRipples; wiSPTree* wiRenderer::spTree = nullptr; @@ -108,12 +103,9 @@ Scene* wiRenderer::scene = nullptr; unordered_set wiRenderer::objectsWithTrails; unordered_set wiRenderer::emitterSystems; -std::vector wiRenderer::boneLines; -std::vector wiRenderer::linesTemp; -std::vector wiRenderer::cubes; - std::vector wiRenderer::renderableTranslators; std::vector> wiRenderer::renderableBoxes; +std::vector wiRenderer::renderableLines; std::unordered_map wiRenderer::frameCullings; @@ -125,10 +117,6 @@ unordered_set deferredMIPGens; #pragma endregion -wiRenderer::wiRenderer() -{ -} - void wiRenderer::Present(function drawToScreen1,function drawToScreen2,function drawToScreen3) { GetDevice()->PresentBegin(); @@ -151,10 +139,6 @@ void wiRenderer::Present(function drawToScreen1,function drawToS } -void wiRenderer::CleanUp() -{ -} - void wiRenderer::SetUpStaticComponents() { for (int i = 0; i < VSTYPE_LAST; ++i) @@ -231,37 +215,8 @@ void wiRenderer::SetUpStaticComponents() wiHairParticle::SetUpStatic(); wiEmittedParticle::SetUpStatic(); - GameSpeed=1; - - resetVertexCount(); - resetVisibleObjectCount(); - - GetScene().wind=Wind(); - Cube::LoadStatic(); - spTree_lights=nullptr; - - - waterRipples.resize(0); - - - normalMapRT.Initialize( - GetInternalResolution().x - , GetInternalResolution().y - ,false, RTFormat_normalmaps - ); - imagesRTAdd.Initialize( - GetInternalResolution().x - , GetInternalResolution().y - ,false - ); - imagesRT.Initialize( - GetInternalResolution().x - , GetInternalResolution().y - ,false - ); - SetShadowProps2D(SHADOWRES_2D, SHADOWCOUNT_2D, SOFTSHADOWQUALITY_2D); SetShadowPropsCube(SHADOWRES_CUBE, SHADOWCOUNT_CUBE); @@ -352,13 +307,7 @@ void wiRenderer::ClearWorld() physicsEngine->ClearWorld(); enviroMap = nullptr; - colorGrading = nullptr; - wiRenderer::resetVertexCount(); - - for (wiSprite* x : images) - x->CleanUp(); - images.clear(); for (wiSprite* x : waterRipples) x->CleanUp(); waterRipples.clear(); @@ -410,119 +359,119 @@ int wiRenderer::GetSunArrayIndex() } return -1; } -float wiRenderer::GetGameSpeed() { return GameSpeed*overrideGameSpeed; } +float wiRenderer::GetGameSpeed() { return GameSpeed; } -void wiRenderer::SetUpBoneLines() -{ - boneLines.clear(); - for (Model* model : GetScene().models) - { - //for (unsigned int i = 0; i < model->armatures.size(); i++) { - // for (unsigned int j = 0; j < model->armatures[i]->boneCollection.size(); j++) { - // boneLines.push_back(new Lines(model->armatures[i]->boneCollection[j]->length, XMFLOAT4A(1, 1, 1, 1), i, j)); - // } - //} - int i = 0; - for (auto& a : model->armatures) - { - int j = 0; - for (auto& b : a->boneCollection) - { - boneLines.push_back(new Lines(b->length, XMFLOAT4A(1, 1, 1, 1), i, j)); - j++; - } - i++; - } - } -} -void wiRenderer::UpdateBoneLines() -{ - if (debugBoneLines) - { - for (unsigned int i = 0; i < boneLines.size(); i++) { - int armatureI = boneLines[i]->parentArmature; - int boneI = boneLines[i]->parentBone; - - int arm = 0; - for (Model* model : GetScene().models) - { - for (Armature* armature : model->armatures) - { - if (arm == armatureI) - { - int bonI = 0; - for (Bone* b : armature->boneCollection) - { - if (boneI == bonI) - { - boneLines[i]->Transform(b->world); - } - bonI++; - } - } - arm++; - } - } - } - } -} -void iterateSPTree2(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col); -void iterateSPTree(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col){ - if(!n) return; - if(n->count){ - for (unsigned int i = 0; ichildren.size(); ++i) - iterateSPTree(n->children[i],cubes,col); - } - if(!n->objects.empty()){ - cubes.push_back(Cube(n->box.getCenter(),n->box.getHalfWidth(),col)); - for(Cullable* object:n->objects){ - cubes.push_back(Cube(object->bounds.getCenter(),object->bounds.getHalfWidth(),XMFLOAT4A(1,0,0,1))); - //Object* o = (Object*)object; - //for(wiHairParticle& hps : o->hParticleSystems) - // iterateSPTree2(hps.spTree->root,cubes,XMFLOAT4A(0,1,0,1)); - } - } -} -void iterateSPTree2(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col){ - if(!n) return; - if(n->count){ - for (unsigned int i = 0; ichildren.size(); ++i) - iterateSPTree2(n->children[i],cubes,col); - } - if(!n->objects.empty()){ - cubes.push_back(Cube(n->box.getCenter(),n->box.getHalfWidth(),col)); - } -} -void wiRenderer::SetUpCubes(){ - /*if(debugBoxes){ - cubes.resize(0); - iterateSPTree(spTree->root,cubes); - for(Object* object:objects) - cubes.push_back(Cube(XMFLOAT3(0,0,0),XMFLOAT3(1,1,1),XMFLOAT4A(1,0,0,1))); - }*/ - cubes.clear(); -} -void wiRenderer::UpdateCubes(){ - if(debugPartitionTree && spTree && spTree->root){ - /*int num=0; - iterateSPTreeUpdate(spTree->root,cubes,num); - for(Object* object:objects){ - AABB b=object->frameBB; - XMFLOAT3 c = b.getCenter(); - XMFLOAT3 hw = b.getHalfWidth(); - cubes[num].Transform( XMMatrixScaling(hw.x,hw.y,hw.z) * XMMatrixTranslation(c.x,c.y,c.z) ); - num+=1; - }*/ - cubes.clear(); - if(spTree) iterateSPTree(spTree->root,cubes,XMFLOAT4A(1,1,0,1)); - if(spTree_lights) iterateSPTree(spTree_lights->root,cubes,XMFLOAT4A(1,1,1,1)); - } - //if(debugBoxes){ - // for(Decal* decal : decals){ - // cubes.push_back(Cube(decal->bounds.getCenter(),decal->bounds.getHalfWidth(),XMFLOAT4A(1,0,1,1))); - // } - //} -} +//void wiRenderer::SetUpBoneLines() +//{ +// boneLines.clear(); +// for (Model* model : GetScene().models) +// { +// //for (unsigned int i = 0; i < model->armatures.size(); i++) { +// // for (unsigned int j = 0; j < model->armatures[i]->boneCollection.size(); j++) { +// // boneLines.push_back(new Lines(model->armatures[i]->boneCollection[j]->length, XMFLOAT4A(1, 1, 1, 1), i, j)); +// // } +// //} +// int i = 0; +// for (auto& a : model->armatures) +// { +// int j = 0; +// for (auto& b : a->boneCollection) +// { +// boneLines.push_back(new Lines(b->length, XMFLOAT4A(1, 1, 1, 1), i, j)); +// j++; +// } +// i++; +// } +// } +//} +//void wiRenderer::UpdateBoneLines() +//{ +// if (debugBoneLines) +// { +// for (unsigned int i = 0; i < boneLines.size(); i++) { +// int armatureI = boneLines[i]->parentArmature; +// int boneI = boneLines[i]->parentBone; +// +// int arm = 0; +// for (Model* model : GetScene().models) +// { +// for (Armature* armature : model->armatures) +// { +// if (arm == armatureI) +// { +// int bonI = 0; +// for (Bone* b : armature->boneCollection) +// { +// if (boneI == bonI) +// { +// boneLines[i]->Transform(b->world); +// } +// bonI++; +// } +// } +// arm++; +// } +// } +// } +// } +//} +//void iterateSPTree2(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col); +//void iterateSPTree(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col){ +// if(!n) return; +// if(n->count){ +// for (unsigned int i = 0; ichildren.size(); ++i) +// iterateSPTree(n->children[i],cubes,col); +// } +// if(!n->objects.empty()){ +// cubes.push_back(Cube(n->box.getCenter(),n->box.getHalfWidth(),col)); +// for(Cullable* object:n->objects){ +// cubes.push_back(Cube(object->bounds.getCenter(),object->bounds.getHalfWidth(),XMFLOAT4A(1,0,0,1))); +// //Object* o = (Object*)object; +// //for(wiHairParticle& hps : o->hParticleSystems) +// // iterateSPTree2(hps.spTree->root,cubes,XMFLOAT4A(0,1,0,1)); +// } +// } +//} +//void iterateSPTree2(wiSPTree::Node* n, std::vector& cubes, const XMFLOAT4A& col){ +// if(!n) return; +// if(n->count){ +// for (unsigned int i = 0; ichildren.size(); ++i) +// iterateSPTree2(n->children[i],cubes,col); +// } +// if(!n->objects.empty()){ +// cubes.push_back(Cube(n->box.getCenter(),n->box.getHalfWidth(),col)); +// } +//} +//void wiRenderer::SetUpCubes(){ +// /*if(debugBoxes){ +// cubes.resize(0); +// iterateSPTree(spTree->root,cubes); +// for(Object* object:objects) +// cubes.push_back(Cube(XMFLOAT3(0,0,0),XMFLOAT3(1,1,1),XMFLOAT4A(1,0,0,1))); +// }*/ +// cubes.clear(); +//} +//void wiRenderer::UpdateCubes(){ +// if(debugPartitionTree && spTree && spTree->root){ +// /*int num=0; +// iterateSPTreeUpdate(spTree->root,cubes,num); +// for(Object* object:objects){ +// AABB b=object->frameBB; +// XMFLOAT3 c = b.getCenter(); +// XMFLOAT3 hw = b.getHalfWidth(); +// cubes[num].Transform( XMMatrixScaling(hw.x,hw.y,hw.z) * XMMatrixTranslation(c.x,c.y,c.z) ); +// num+=1; +// }*/ +// cubes.clear(); +// if(spTree) iterateSPTree(spTree->root,cubes,XMFLOAT4A(1,1,0,1)); +// if(spTree_lights) iterateSPTree(spTree_lights->root,cubes,XMFLOAT4A(1,1,1,1)); +// } +// //if(debugBoxes){ +// // for(Decal* decal : decals){ +// // cubes.push_back(Cube(decal->bounds.getCenter(),decal->bounds.getHalfWidth(),XMFLOAT4A(1,0,1,1))); +// // } +// //} +//} bool wiRenderer::ResolutionChanged() { @@ -1207,7 +1156,6 @@ enum DEBUGRENDERING DEBUGRENDERING_GRID, DEBUGRENDERING_CUBE, DEBUGRENDERING_LINES, - DEBUGRENDERING_BONELINES, DEBUGRENDERING_EMITTER, DEBUGRENDERING_VOXEL, DEBUGRENDERING_FORCEFIELD_POINT, @@ -2152,15 +2100,6 @@ void wiRenderer::LoadShaders() desc.bs = blendStates[BSTYPE_TRANSPARENT]; desc.pt = LINELIST; break; - case DEBUGRENDERING_BONELINES: - desc.vs = vertexShaders[VSTYPE_LINE]; - desc.ps = pixelShaders[PSTYPE_LINE]; - desc.il = vertexLayouts[VLTYPE_LINE]; - desc.dss = depthStencils[DSSTYPE_XRAY]; - desc.rs = rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH]; - desc.bs = blendStates[BSTYPE_TRANSPARENT]; - desc.pt = LINELIST; - break; case DEBUGRENDERING_EMITTER: desc.vs = vertexShaders[VSTYPE_OBJECT_DEBUG]; desc.ps = pixelShaders[PSTYPE_OBJECT_DEBUG]; @@ -3154,8 +3093,10 @@ void wiRenderer::UpdatePerFrameData(float dt) refCam->Reflect(cam, waterPlane.getXMFLOAT4()); - UpdateBoneLines(); - UpdateCubes(); + for (auto& x : waterRipples) + { + x->Update(dt * 60 * GameSpeed); + } renderTime_Prev = renderTime; renderTime += dt * GameSpeed; @@ -3679,24 +3620,6 @@ void wiRenderer::OcclusionCulling_Read() wiProfiler::GetInstance().EndRange(); // Occlusion Culling Read } -void wiRenderer::UpdateImages() -{ - for (wiSprite* x : images) - x->Update(GameSpeed); - for (wiSprite* x : waterRipples) - x->Update(GameSpeed); - - ManageImages(); - ManageWaterRipples(); -} -void wiRenderer::ManageImages() -{ - while (!images.empty() && - (images.front()->effects.opacity <= 0 + FLT_EPSILON || images.front()->effects.fade == 1)) - { - images.pop_front(); - } -} void wiRenderer::PutDecal(Decal* decal) { GetScene().GetWorldNode()->decals.insert(decal); @@ -3733,115 +3656,134 @@ void wiRenderer::DrawWaterRipples(GRAPHICSTHREAD threadID) GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawDebugSpheres(Camera* camera, GRAPHICSTHREAD threadID) +void wiRenderer::DrawDebugWorld(Camera* camera, GRAPHICSTHREAD threadID) { - //if(debugSpheres){ - // BindPrimitiveTopology(TRIANGLESTRIP,threadID); - // BindVertexLayout(vertexLayouts[VLTYPE_EFFECT] : vertexLayouts[VLTYPE_LINE],threadID); - // - // BindRasterizerState(rasterizers[RSTYPE_FRONT],threadID); - // BindDepthStencilState(depthStencils[DSSTYPE_XRAY],STENCILREF_EMPTY,threadID); - // BindBlendState(blendStates[BSTYPE_TRANSPARENT],threadID); + GraphicsDevice* device = GetDevice(); + device->EventBegin("DrawDebugWorld", threadID); - // BindPS(linePS,threadID); - // BindVS(lineVS,threadID); - - // BindVertexBuffer(HitSphere::vertexBuffer,0,sizeof(XMFLOAT3A),threadID); - - // for (unsigned int i = 0; irotation))* - // XMMatrixScaling( spheres[i]->radius,spheres[i]->radius,spheres[i]->radius ) * - // XMMatrixTranslationFromVector( XMLoadFloat3(&spheres[i]->translation) ) - // *camera->GetViewProjection() - // ); - - // XMFLOAT4A propColor; - // if(spheres[i]->TYPE==HitSphere::HitSphereType::HITTYPE) propColor = XMFLOAT4A(0.1098f,0.4196f,1,1); - // else if(spheres[i]->TYPE==HitSphere::HitSphereType::INVTYPE) propColor=XMFLOAT4A(0,0,0,1); - // else if(spheres[i]->TYPE==HitSphere::HitSphereType::ATKTYPE) propColor=XMFLOAT4A(0.96f,0,0,1); - // sb.color=propColor; - - // UpdateBuffer(lineBuffer,&sb,threadID); - - - // //threadID->Draw((HitSphere::RESOLUTION+1)*2,0); - // Draw((HitSphere::RESOLUTION+1)*2,threadID); - - // } - //} - -} -void wiRenderer::DrawDebugBoneLines(Camera* camera, GRAPHICSTHREAD threadID) -{ - if(debugBoneLines) + if (debugBoneLines) { - GetDevice()->EventBegin("DebugBoneLines", threadID); - - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_BONELINES], threadID); + device->EventBegin("DebugBoneLines", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); MiscCB sb; - for (unsigned int i = 0; idesc.transform)*camera->GetViewProjection()); - sb.mColor = boneLines[i]->desc.color; + sb.mTransform = XMMatrixTranspose(camera->GetViewProjection()); + sb.mColor = XMFLOAT4(1, 1, 1, 1); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + for (auto& model : GetScene().models) + { + for (auto& armature : model->armatures) + { + if (armature->boneCollection.empty()) + { + continue; + } - GPUBuffer* vbs[] = { - &boneLines[i]->vertexBuffer, - }; - const UINT strides[] = { - sizeof(XMFLOAT4) + sizeof(XMFLOAT4), - }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->Draw(2, 0, threadID); + struct LineSegment + { + XMFLOAT4 a, colorA, b, colorB; + }; + UINT offset; + void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * armature->boneCollection.size(), offset, threadID); + + int i = 0; + for (auto& bone : armature->boneCollection) + { + XMMATRIX world = XMLoadFloat4x4(&bone->world); + XMVECTOR a = XMVectorSet(0, 0, 0, 1); + XMVECTOR b = XMVectorSet(0, 0, bone->length, 1); + + a = XMVector4Transform(a, world); + b = XMVector4Transform(b, world); + + + LineSegment segment; + XMStoreFloat4(&segment.a, a); + XMStoreFloat4(&segment.b, b); + + memcpy((void*)((size_t)mem + i * sizeof(LineSegment)), &segment, sizeof(LineSegment)); + i++; + } + + device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); + + GPUBuffer* vbs[] = { + dynamicVertexBufferPool, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + const UINT offsets[] = { + offset, + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); + + device->Draw(2 * i, 0, threadID); + + } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugLines(Camera* camera, GRAPHICSTHREAD threadID) -{ - if (linesTemp.empty()) - return; + + if (!renderableLines.empty()) + { + device->EventBegin("DebugLines", threadID); - GetDevice()->EventBegin("DebugLines", threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_LINES], threadID); + MiscCB sb; + sb.mTransform = XMMatrixTranspose(camera->GetViewProjection()); + sb.mColor = XMFLOAT4(1, 1, 1, 1); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - MiscCB sb; - for (unsigned int i = 0; idesc.transform)*camera->GetViewProjection()); - sb.mColor = linesTemp[i]->desc.color; + struct LineSegment + { + XMFLOAT4 a, colorA, b, colorB; + }; + UINT offset; + void* mem = device->AllocateFromRingBuffer(dynamicVertexBufferPool, sizeof(LineSegment) * renderableLines.size(), offset, threadID); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + int i = 0; + for (auto& line : renderableLines) + { + LineSegment segment; + segment.a = XMFLOAT4(line.start.x, line.start.y, line.start.z, 1); + segment.b = XMFLOAT4(line.end.x, line.end.y, line.end.z, 1); + segment.colorA = segment.colorB = line.color; + + memcpy((void*)((size_t)mem + i * sizeof(LineSegment)), &segment, sizeof(LineSegment)); + i++; + } + + device->InvalidateBufferAccess(dynamicVertexBufferPool, threadID); GPUBuffer* vbs[] = { - &linesTemp[i]->vertexBuffer, + dynamicVertexBufferPool, }; const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->Draw(2, 0, threadID); + const UINT offsets[] = { + offset, + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID); + + device->Draw(2 * i, 0, threadID); + + renderableLines.clear(); + + device->EventEnd(threadID); } - for (Lines* x : linesTemp) - delete x; - linesTemp.clear(); - - GetDevice()->EventEnd(threadID); -} -void wiRenderer::DrawDebugBoxes(Camera* camera, GRAPHICSTHREAD threadID) -{ - if(debugPartitionTree || !renderableBoxes.empty()) + if (debugPartitionTree && spTree != nullptr) { - GetDevice()->EventBegin("DebugBoxes", threadID); - - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->EventBegin("DebugPartitionTree", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { &Cube::vertexBuffer, @@ -3849,41 +3791,74 @@ void wiRenderer::DrawDebugBoxes(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); MiscCB sb; - for (auto& x : cubes) + + + wiSPTree::Node* nodes[100]; + UINT stackpos = 0; + + nodes[stackpos++] = spTree->root; + + do { - sb.mTransform =XMMatrixTranspose(XMLoadFloat4x4(&x.desc.transform)*camera->GetViewProjection()); - sb.mColor=x.desc.color; + wiSPTree::Node* node = nodes[--stackpos]; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + for (auto& child : node->children) + { + nodes[stackpos++] = child; + } + + sb.mTransform = XMMatrixTranspose(node->box.getAsBoxMatrix() * camera->GetViewProjection()); + sb.mColor = XMFLOAT4(1, 1, 0, 1); - GetDevice()->DrawIndexed(24, 0, 0, threadID); - } - cubes.clear(); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + + device->DrawIndexed(24, 0, 0, threadID); + + } while (stackpos > 0); + + device->EventEnd(threadID); + } + + if (!renderableBoxes.empty()) + { + device->EventBegin("DebugBoxes", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + + GPUBuffer* vbs[] = { + &Cube::vertexBuffer, + }; + const UINT strides[] = { + sizeof(XMFLOAT4) + sizeof(XMFLOAT4), + }; + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + + MiscCB sb; for (auto& x : renderableBoxes) { sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&x.first)*camera->GetViewProjection()); sb.mColor = x.second; - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->DrawIndexed(24, 0, 0, threadID); + device->DrawIndexed(24, 0, 0, threadID); } renderableBoxes.clear(); - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawTranslators(Camera* camera, GRAPHICSTHREAD threadID) -{ - if(!renderableTranslators.empty()) + + + if (!renderableTranslators.empty()) { - GetDevice()->EventBegin("Translators", threadID); - + device->EventBegin("Translators", threadID); + XMMATRIX VP = camera->GetViewProjection(); MiscCB sb; @@ -3905,27 +3880,27 @@ void wiRenderer::DrawTranslators(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_SOLIDPART], threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_SOLIDPART], threadID); } // xy sb.mTransform = matX; sb.mColor = x->state == wiTranslator::TRANSLATOR_XY ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Plane, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Plane, 0, threadID); // xz sb.mTransform = matZ; sb.mColor = x->state == wiTranslator::TRANSLATOR_XZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Plane, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Plane, 0, threadID); // yz sb.mTransform = matY; sb.mColor = x->state == wiTranslator::TRANSLATOR_YZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.2f, 0.2f, 0, 0.2f); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Plane, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Plane, 0, threadID); // Lines: { @@ -3935,27 +3910,27 @@ void wiRenderer::DrawTranslators(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_WIREPART], threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_WIREPART], threadID); } // x sb.mTransform = matX; sb.mColor = x->state == wiTranslator::TRANSLATOR_X ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(1, 0, 0, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Axis, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Axis, 0, threadID); // y sb.mTransform = matY; sb.mColor = x->state == wiTranslator::TRANSLATOR_Y ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 1, 0, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Axis, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Axis, 0, threadID); // z sb.mTransform = matZ; sb.mColor = x->state == wiTranslator::TRANSLATOR_Z ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0, 0, 1, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Axis, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->Draw(wiTranslator::vertexCount_Axis, 0, threadID); // Origin: { @@ -3965,30 +3940,27 @@ void wiRenderer::DrawTranslators(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); sb.mTransform = XMMatrixTranspose(mat); sb.mColor = x->state == wiTranslator::TRANSLATOR_XYZ ? XMFLOAT4(1, 1, 1, 1) : XMFLOAT4(0.5f, 0.5f, 0.5f, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_SOLIDPART], threadID); - GetDevice()->Draw(wiTranslator::vertexCount_Origin, 0, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_TRANSLATOR_SOLIDPART], threadID); + device->Draw(wiTranslator::vertexCount_Origin, 0, threadID); } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); renderableTranslators.clear(); } -} -void wiRenderer::DrawDebugEnvProbes(Camera* camera, GRAPHICSTHREAD threadID) -{ - if (debugEnvProbes) + + + if (debugEnvProbes) { - GetDevice()->EventBegin("Debug EnvProbes", threadID); - - + device->EventBegin("Debug EnvProbes", threadID); // Envmap spheres: - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_ENVPROBE], threadID); MiscCB sb; for (Model* model : GetScene().models) @@ -4001,18 +3973,18 @@ void wiRenderer::DrawDebugEnvProbes(Camera* camera, GRAPHICSTHREAD threadID) } sb.mTransform = XMMatrixTranspose(XMMatrixTranslation(x->translation.x, x->translation.y, x->translation.z)); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->BindResource(PS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ONDEMAND0, threadID, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->GetDesc().MipLevels + x->textureIndex); + device->BindResource(PS, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], TEXSLOT_ONDEMAND0, threadID, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]->GetDesc().MipLevels + x->textureIndex); - GetDevice()->Draw(2880, 0, threadID); // uv-sphere + device->Draw(2880, 0, threadID); // uv-sphere } } // Local proxy boxes: - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { &Cube::vertexBuffer, @@ -4020,8 +3992,8 @@ void wiRenderer::DrawDebugEnvProbes(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); for (Model* model : GetScene().models) { @@ -4030,22 +4002,21 @@ void wiRenderer::DrawDebugEnvProbes(Camera* camera, GRAPHICSTHREAD threadID) sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&x->world)*camera->GetViewProjection()); sb.mColor = XMFLOAT4(0, 1, 1, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->DrawIndexed(24, 0, 0, threadID); + device->DrawIndexed(24, 0, 0, threadID); } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugGridHelper(Camera* camera, GRAPHICSTHREAD threadID) -{ - if(gridHelper) - { - GetDevice()->EventBegin("GridHelper", threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_GRID], threadID); + + if (gridHelper) + { + device->EventBegin("GridHelper", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_GRID], threadID); static float col = 0.7f; static int gridVertexCount = 0; @@ -4054,23 +4025,23 @@ void wiRenderer::DrawDebugGridHelper(Camera* camera, GRAPHICSTHREAD threadID) { const float h = 0.01f; // avoid z-fight with zero plane const int a = 20; - XMFLOAT4 verts[((a+1) * 2 + (a+1) * 2) * 2]; + XMFLOAT4 verts[((a + 1) * 2 + (a + 1) * 2) * 2]; int count = 0; for (int i = 0; i <= a; ++i) { - verts[count++] = XMFLOAT4(i - a*0.5f, h, -a*0.5f, 1); + verts[count++] = XMFLOAT4(i - a * 0.5f, h, -a * 0.5f, 1); verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); - verts[count++] = XMFLOAT4(i - a*0.5f, h, +a*0.5f, 1); + verts[count++] = XMFLOAT4(i - a * 0.5f, h, +a * 0.5f, 1); verts[count++] = (i == a / 2 ? XMFLOAT4(0, 0, 1, 1) : XMFLOAT4(col, col, col, 1)); } for (int j = 0; j <= a; ++j) { - verts[count++] = XMFLOAT4(-a*0.5f, h, j - a*0.5f, 1); + verts[count++] = XMFLOAT4(-a * 0.5f, h, j - a * 0.5f, 1); verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); - verts[count++] = XMFLOAT4(+a*0.5f, h, j - a*0.5f, 1); + verts[count++] = XMFLOAT4(+a * 0.5f, h, j - a * 0.5f, 1); verts[count++] = (j == a / 2 ? XMFLOAT4(1, 0, 0, 1) : XMFLOAT4(col, col, col, 1)); } @@ -4086,14 +4057,14 @@ void wiRenderer::DrawDebugGridHelper(Camera* camera, GRAPHICSTHREAD threadID) ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = verts; grid = new GPUBuffer; - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, grid); + device->CreateBuffer(&bd, &InitData, grid); } MiscCB sb; sb.mTransform = XMMatrixTranspose(camera->GetViewProjection()); sb.mColor = XMFLOAT4(1, 1, 1, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); GPUBuffer* vbs[] = { grid, @@ -4101,39 +4072,35 @@ void wiRenderer::DrawDebugGridHelper(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->Draw(gridVertexCount, 0, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->Draw(gridVertexCount, 0, threadID); - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugVoxels(Camera* camera, GRAPHICSTHREAD threadID) -{ - if (voxelHelper && textures[TEXTYPE_3D_VOXELRADIANCE] != nullptr) - { - GetDevice()->EventBegin("Debug Voxels", threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_VOXEL], threadID); + if (voxelHelper && textures[TEXTYPE_3D_VOXELRADIANCE] != nullptr) + { + device->EventBegin("Debug Voxels", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_VOXEL], threadID); MiscCB sb; sb.mTransform = XMMatrixTranspose(XMMatrixTranslationFromVector(XMLoadFloat3(&voxelSceneData.center)) * camera->GetViewProjection()); sb.mColor = XMFLOAT4(1, 1, 1, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); + device->Draw(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res, 0, threadID); - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugEmitters(Camera* camera, GRAPHICSTHREAD threadID) -{ - if (debugEmitters || !renderableBoxes.empty()) + + if (debugEmitters || !renderableBoxes.empty()) { - GetDevice()->EventBegin("DebugEmitters", threadID); - - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_EMITTER], threadID); + device->EventBegin("DebugEmitters", threadID); + + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_EMITTER], threadID); MiscCB sb; for (auto& x : emitterSystems) @@ -4142,7 +4109,7 @@ void wiRenderer::DrawDebugEmitters(Camera* camera, GRAPHICSTHREAD threadID) { sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&x->object->world)*camera->GetViewProjection()); sb.mColor = XMFLOAT4(0, 1, 0, 1); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); GPUBuffer* vbs[] = { x->object->mesh->vertexBuffer_POS, @@ -4150,21 +4117,20 @@ void wiRenderer::DrawDebugEmitters(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(Mesh::Vertex_POS), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindIndexBuffer(x->object->mesh->indexBuffer, x->object->mesh->GetIndexFormat(), 0, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(x->object->mesh->indexBuffer, x->object->mesh->GetIndexFormat(), 0, threadID); - GetDevice()->DrawIndexed((int)x->object->mesh->indices.size(), 0, 0, threadID); + device->DrawIndexed((int)x->object->mesh->indices.size(), 0, 0, threadID); } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugForceFields(Camera* camera, GRAPHICSTHREAD threadID) -{ - if (debugForceFields) + + + if (debugForceFields) { - GetDevice()->EventBegin("DebugForceFields", threadID); + device->EventBegin("DebugForceFields", threadID); MiscCB sb; uint32_t i = 0; @@ -4174,17 +4140,17 @@ void wiRenderer::DrawDebugForceFields(Camera* camera, GRAPHICSTHREAD threadID) { sb.mTransform = XMMatrixTranspose(camera->GetViewProjection()); sb.mColor = XMFLOAT4(camera->translation.x, camera->translation.y, camera->translation.z, (float)i); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); switch (force->type) { case ENTITY_TYPE_FORCEFIELD_POINT: - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); - GetDevice()->Draw(2880, 0, threadID); // uv-sphere + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_POINT], threadID); + device->Draw(2880, 0, threadID); // uv-sphere break; case ENTITY_TYPE_FORCEFIELD_PLANE: - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); - GetDevice()->Draw(14, 0, threadID); // box + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_FORCEFIELD_PLANE], threadID); + device->Draw(14, 0, threadID); // box break; } @@ -4192,16 +4158,15 @@ void wiRenderer::DrawDebugForceFields(Camera* camera, GRAPHICSTHREAD threadID) } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } -} -void wiRenderer::DrawDebugCameras(Camera* camera, GRAPHICSTHREAD threadID) -{ + + if (debugCameras) { - GetDevice()->EventBegin("DebugCameras", threadID); + device->EventBegin("DebugCameras", threadID); - GetDevice()->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); + device->BindGraphicsPSO(PSO_debug[DEBUGRENDERING_CUBE], threadID); GPUBuffer* vbs[] = { &Cube::vertexBuffer, @@ -4209,8 +4174,8 @@ void wiRenderer::DrawDebugCameras(Camera* camera, GRAPHICSTHREAD threadID) const UINT strides[] = { sizeof(XMFLOAT4) + sizeof(XMFLOAT4), }; - GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); - GetDevice()->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); + device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, nullptr, threadID); + device->BindIndexBuffer(&Cube::indexBuffer, INDEXFORMAT_16BIT, 0, threadID); MiscCB sb; sb.mColor = XMFLOAT4(1, 1, 1, 1); @@ -4221,14 +4186,16 @@ void wiRenderer::DrawDebugCameras(Camera* camera, GRAPHICSTHREAD threadID) { sb.mTransform = XMMatrixTranspose(XMLoadFloat4x4(&x->world)*camera->GetViewProjection()); - GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); + device->UpdateBuffer(constantBuffers[CBTYPE_MISC], &sb, threadID); - GetDevice()->DrawIndexed(24, 0, 0, threadID); + device->DrawIndexed(24, 0, 0, threadID); } } - GetDevice()->EventEnd(threadID); + device->EventEnd(threadID); } + + device->EventEnd(threadID); } void wiRenderer::DrawSoftParticles(Camera* camera, bool distortion, GRAPHICSTHREAD threadID) @@ -4345,51 +4312,6 @@ void wiRenderer::DrawTrails(GRAPHICSTHREAD threadID, Texture2D* refracRes) //GetDevice()->EventEnd(threadID); } -void wiRenderer::DrawImagesAdd(GRAPHICSTHREAD threadID, Texture2D* refracRes){ - imagesRTAdd.Activate(threadID,0,0,0,1); - //wiImage::BatchBegin(threadID); - for(wiSprite* x : images){ - if(x->effects.blendFlag==BLENDMODE_ADDITIVE){ - /*Texture2D* nor = x->effects.normalMap; - x->effects.setNormalMap(nullptr); - bool changedBlend=false; - if(x->effects.blendFlag==BLENDMODE_OPAQUE && nor){ - x->effects.blendFlag=BLENDMODE_ADDITIVE; - changedBlend=true; - }*/ - x->Draw(refracRes, threadID); - /*if(changedBlend) - x->effects.blendFlag=BLENDMODE_OPAQUE; - x->effects.setNormalMap(nor);*/ - } - } -} -void wiRenderer::DrawImages(GRAPHICSTHREAD threadID, Texture2D* refracRes){ - imagesRT.Activate(threadID,0,0,0,0); - //wiImage::BatchBegin(threadID); - for(wiSprite* x : images){ - if(x->effects.blendFlag==BLENDMODE_ALPHA || x->effects.blendFlag==BLENDMODE_OPAQUE){ - /*Texture2D* nor = x->effects.normalMap; - x->effects.setNormalMap(nullptr); - bool changedBlend=false; - if(x->effects.blendFlag==BLENDMODE_OPAQUE && nor){ - x->effects.blendFlag=BLENDMODE_ADDITIVE; - changedBlend=true; - }*/ - x->Draw(refracRes, threadID); - /*if(changedBlend) - x->effects.blendFlag=BLENDMODE_OPAQUE; - x->effects.setNormalMap(nor);*/ - } - } -} -void wiRenderer::DrawImagesNormals(GRAPHICSTHREAD threadID, Texture2D* refracRes){ - normalMapRT.Activate(threadID,0,0,0,0); - //wiImage::BatchBegin(threadID); - for(wiSprite* x : images){ - x->DrawNormal(threadID); - } -} void wiRenderer::DrawLights(Camera* camera, GRAPHICSTHREAD threadID) { const FrameCulling& culling = frameCullings[camera]; @@ -7649,10 +7571,9 @@ void wiRenderer::UpdateFrameCB(GRAPHICSTHREAD threadID) cb.mEnvProbeArrayOffset = entityArrayOffset_EnvProbes; cb.mEnvProbeArrayCount = entityArrayCount_EnvProbes; cb.mVoxelRadianceRetargetted = voxelSceneData.centerChangedThisFrame ? 1 : 0; - auto& wind = GetScene().wind; - cb.mWindRandomness = wind.randomness; - cb.mWindWaveSize = wind.waveSize; - cb.mWindDirection = wind.direction; + cb.mWindRandomness = GetScene().worldInfo.windRandomness; + cb.mWindWaveSize = GetScene().worldInfo.windWaveSize; + cb.mWindDirection = GetScene().worldInfo.windDirection; cb.mFrameCount = (UINT)GetDevice()->GetFrameCount(); cb.mSunEntityArrayIndex = GetSunArrayIndex(); cb.mTemporalAASampleRotation = 0; @@ -7758,7 +7679,7 @@ void wiRenderer::SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID) GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_API], &apiCB[threadID], threadID); } } -void wiRenderer::UpdateGBuffer(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) +void wiRenderer::BindGBufferTextures(Texture2D* slot0, Texture2D* slot1, Texture2D* slot2, Texture2D* slot3, Texture2D* slot4, GRAPHICSTHREAD threadID) { GetDevice()->BindResource(PS, slot0, TEXSLOT_GBUFFER0, threadID); GetDevice()->BindResource(PS, slot1, TEXSLOT_GBUFFER1, threadID); @@ -7772,7 +7693,7 @@ void wiRenderer::UpdateGBuffer(Texture2D* slot0, Texture2D* slot1, Texture2D* sl GetDevice()->BindResource(CS, slot3, TEXSLOT_GBUFFER3, threadID); GetDevice()->BindResource(CS, slot4, TEXSLOT_GBUFFER4, threadID); } -void wiRenderer::UpdateDepthBuffer(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) +void wiRenderer::BindDepthTextures(Texture2D* depth, Texture2D* linearDepth, GRAPHICSTHREAD threadID) { GetDevice()->BindResource(PS, depth, TEXSLOT_DEPTH, threadID); GetDevice()->BindResource(VS, depth, TEXSLOT_DEPTH, threadID); @@ -7872,193 +7793,8 @@ wiWaterPlane wiRenderer::GetWaterPlane() return waterPlane; } -wiRenderer::Picked wiRenderer::Pick(RAY& ray, int pickType, uint32_t layerMask) -{ - std::vector pickPoints; - // pick meshes... - CulledCollection culledRenderer; - CulledList culledObjects; - wiSPTree* searchTree = spTree; - if (searchTree != nullptr) - { - searchTree->getVisible(ray, culledObjects); - - RayIntersectMeshes(ray, culledObjects, pickPoints, pickType, true, true, layerMask); - } - - // pick other... - for (auto& model : GetScene().models) - { - if (pickType & PICK_LIGHT) - { - for (auto& light : model->lights) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&light->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(light->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = light; - pick.light = light; - pick.distance = wiMath::Distance(light->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - //if (light->bounds.intersects(ray)) - //{ - // Picked pick = Picked(); - // pick.transform = light; - // pick.light = light; - // if (light->type == Light::DIRECTIONAL) - // { - // pick.distance = FLT_MAX; - // } - // else - // { - // pick.distance = wiMath::Distance(light->translation, ray.origin); - // } - // pickPoints.push_back(pick); - //} - } - } - if (pickType & PICK_DECAL) - { - for (auto& decal : model->decals) - { - //XMVECTOR localOrigin = XMLoadFloat3(&ray.origin), localDirection = XMLoadFloat3(&ray.direction); - //XMMATRIX localTransform = XMLoadFloat4x4(&decal->world); - //localTransform = XMMatrixInverse(nullptr, localTransform); - //localOrigin = XMVector3Transform(localOrigin, localTransform); - //localDirection = XMVector3TransformNormal(localDirection, localTransform); - //RAY localRay = RAY(localOrigin, localDirection); - //if (AABB(XMFLOAT3(-1, -1, -1), XMFLOAT3(1, 1, 1)).intersects(localRay)) - //{ - // Picked pick = Picked(); - // pick.transform = decal; - // pick.decal = decal; - // pick.distance = wiMath::Distance(decal->translation, ray.origin); - // pickPoints.push_back(pick); - //} - - // decals are now picked like lights instead (user experience reasons) - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&decal->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(decal->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = decal; - pick.decal = decal; - pick.distance = wiMath::Distance(decal->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - } - } - if (pickType & PICK_FORCEFIELD) - { - for (auto& force : model->forces) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&force->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(force->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = force; - pick.forceField = force; - pick.distance = wiMath::Distance(force->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - } - } - if (pickType & PICK_EMITTER) - { - for (auto& object : model->objects) - { - if (object->eParticleSystems.empty()) - { - continue; - } - - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&object->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(object->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = object; - pick.object = object; - pick.distance = wiMath::Distance(object->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - } - } - - if (pickType & PICK_ENVPROBE) - { - for (auto& x : model->environmentProbes) - { - if (SPHERE(x->translation, 1).intersects(ray)) - { - Picked pick = Picked(); - pick.transform = x; - pick.envProbe = x; - pick.distance = wiMath::Distance(x->translation, ray.origin); - pickPoints.push_back(pick); - } - } - } - if (pickType & PICK_CAMERA) - { - for (auto& camera : model->cameras) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&camera->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(camera->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = camera; - pick.camera = camera; - pick.distance = wiMath::Distance(camera->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - } - } - if (pickType & PICK_ARMATURE) - { - for (auto& armature : model->armatures) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&ray.origin), XMLoadFloat3(&ray.origin) + XMLoadFloat3(&ray.direction), XMLoadFloat3(&armature->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(armature->translation, cam->translation) * 0.05f) - { - Picked pick = Picked(); - pick.transform = armature; - pick.armature = armature; - pick.distance = wiMath::Distance(armature->translation, ray.origin) * 0.95f; - pickPoints.push_back(pick); - } - } - } - } - - if (!pickPoints.empty()) { - Picked min = pickPoints.front(); - for (unsigned int i = 1; i < pickPoints.size(); ++i) { - if (pickPoints[i].distance < min.distance) { - min = pickPoints[i]; - } - } - return min; - } - - return Picked(); -} -wiRenderer::Picked wiRenderer::Pick(long cursorX, long cursorY, int pickType, uint32_t layerMask) -{ - RAY ray = getPickRay(cursorX, cursorY); - - return Pick(ray, pickType, layerMask); -} - -RAY wiRenderer::getPickRay(long cursorX, long cursorY){ +RAY wiRenderer::getPickRay(long cursorX, long cursorY) { Camera* cam = getCamera(); XMMATRIX V = cam->GetView(); XMMATRIX P = cam->GetRealProjection(); @@ -8069,174 +7805,116 @@ RAY wiRenderer::getPickRay(long cursorX, long cursorY){ return RAY(lineStart, rayDirection); } -void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObjects, std::vector& points, - int pickType, bool dynamicObjects, bool onlyVisible, uint32_t layerMask) +wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask, bool dynamicObjects, bool onlyVisible) { - if (culledObjects.empty()) + RayIntersectWorldResult result; + + if (spTree != nullptr) { - return; - } + CulledList culledObjects; + spTree->getVisible(ray, culledObjects); - const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); - const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); - - // pre allocate helper vector array: - static size_t _arraySize = 10000; - static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); - - for (Cullable* culled : culledObjects) - { - Object* object = (Object*)culled; - - const uint32_t objectLayerMask = object->GetLayerMask(); - if (objectLayerMask & layerMask) + if (culledObjects.empty()) { + return result; + } - if (!(pickType & object->GetRenderTypes())) + const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin); + const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction)); + + // pre allocate helper vector array: + static size_t _arraySize = 10000; + static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); + + for (Cullable* culled : culledObjects) + { + Object* object = (Object*)culled; + + const uint32_t objectLayerMask = object->GetLayerMask(); + if (objectLayerMask & layerMask) { - continue; - } - if (!dynamicObjects && object->isDynamic()) - { - continue; - } - if (onlyVisible && object->IsOccluded() && GetOcclusionCullingEnabled()) - { - continue; - } - Mesh* mesh = object->mesh; - if (mesh->vertices_POS.size() >= _arraySize) - { - // grow preallocated vector helper array - _mm_free(_vertices); - _arraySize = (mesh->vertices_POS.size() + 1) * 2; - _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); - } - - const XMMATRIX objectMat = object->getMatrix(); - const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); - - const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); - const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); - - Mesh::Vertex_FULL _tmpvert; - - if (object->isArmatureDeformed() && !object->mesh->armature->boneCollection.empty()) - { - for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) + if (!(renderTypeMask & object->GetRenderTypes())) { - _tmpvert = mesh->TransformVertex((int)i); - _vertices[i] = XMLoadFloat4(&_tmpvert.pos); + continue; } - } - else if (mesh->hasDynamicVB()) - { - for (size_t i = 0; i < mesh->vertices_Transformed_POS.size(); ++i) + if (!dynamicObjects && object->isDynamic()) { - _vertices[i] = mesh->vertices_Transformed_POS[i].LoadPOS(); + continue; } - } - else - { - for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) + if (onlyVisible && object->IsOccluded() && GetOcclusionCullingEnabled()) { - _vertices[i] = mesh->vertices_POS[i].LoadPOS(); + continue; } - } - for (size_t i = 0; i < mesh->indices.size(); i += 3) - { - int i0 = mesh->indices[i], i1 = mesh->indices[i + 1], i2 = mesh->indices[i + 2]; - float distance; - if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance)) + Mesh* mesh = object->mesh; + if (mesh->vertices_POS.size() >= _arraySize) { - XMVECTOR& pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); - XMVECTOR& nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat)); - Picked picked = Picked(); - picked.transform = object; - picked.object = object; - XMStoreFloat3(&picked.position, pos); - XMStoreFloat3(&picked.normal, nor); - picked.distance = wiMath::Distance(pos, rayOrigin); - picked.subsetIndex = (int)mesh->vertices_POS[i0].GetMaterialIndex(); - points.push_back(picked); + // grow preallocated vector helper array + _mm_free(_vertices); + _arraySize = (mesh->vertices_POS.size() + 1) * 2; + _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); } + + const XMMATRIX objectMat = object->getMatrix(); + const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat); + + const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); + const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); + + Mesh::Vertex_FULL _tmpvert; + + if (object->isArmatureDeformed() && !object->mesh->armature->boneCollection.empty()) + { + for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) + { + _tmpvert = mesh->TransformVertex((int)i); + _vertices[i] = XMLoadFloat4(&_tmpvert.pos); + } + } + else if (mesh->hasDynamicVB()) + { + for (size_t i = 0; i < mesh->vertices_Transformed_POS.size(); ++i) + { + _vertices[i] = mesh->vertices_Transformed_POS[i].LoadPOS(); + } + } + else + { + for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) + { + _vertices[i] = mesh->vertices_POS[i].LoadPOS(); + } + } + + for (size_t i = 0; i < mesh->indices.size(); i += 3) + { + int i0 = mesh->indices[i], i1 = mesh->indices[i + 1], i2 = mesh->indices[i + 2]; + float distance; + if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance)) + { + XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat); + distance = wiMath::Distance(pos, rayOrigin); + + if (distance < result.distance) + { + XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat)); + + result.object = object; + XMStoreFloat3(&result.position, pos); + XMStoreFloat3(&result.normal, nor); + result.distance = distance; + result.subsetIndex = (int)mesh->vertices_POS[i0].GetMaterialIndex(); + } + } + } + } } - } -} -void wiRenderer::CalculateVertexAO(Object* object) -{ - ////TODO - - //static const float minAmbient = 0.05f; - //static const float falloff = 0.1f; - - //Mesh* mesh = object->mesh; - - //XMMATRIX& objectMat = object->getMatrix(); - - //CulledCollection culledRenderer; - //CulledList culledObjects; - //wiSPTree* searchTree = spTree; - - //int ind = 0; - //for (SkinnedVertex& vert : mesh->vertices) - //{ - // float ambientShadow = 0.0f; - - // XMFLOAT3 vPos, vNor; - - // //XMVECTOR p = XMVector4Transform(XMVectorSet(vert.pos.x, vert.pos.y, vert.pos.z, 1), XMLoadFloat4x4(&object->world)); - // //XMVECTOR n = XMVector3Transform(XMVectorSet(vert.nor.x, vert.nor.y, vert.nor.z, 0), XMLoadFloat4x4(&object->world)); - - // //XMStoreFloat3(&vPos, p); - // //XMStoreFloat3(&vNor, n); - - // Vertex v = TransformVertex(mesh, vert, objectMat); - // vPos.x = v.pos.x; - // vPos.y = v.pos.y; - // vPos.z = v.pos.z; - // vNor.x = v.nor.x; - // vNor.y = v.nor.y; - // vNor.z = v.nor.z; - - // RAY ray = RAY(vPos, vNor); - // XMVECTOR& rayOrigin = XMLoadFloat3(&ray.origin); - // XMVECTOR& rayDirection = XMLoadFloat3(&ray.direction); - - // searchTree->getVisible(ray, culledObjects); - - // std::vector points; - - // RayIntersectMeshes(ray, culledObjects, points, PICK_OPAQUE, false); - - - // if (!points.empty()){ - // Picked min = points.front(); - // float mini = wiMath::DistanceSquared(min.position, ray.origin); - // for (unsigned int i = 1; ivertices[ind].nor.w = ambientLightIntensity; - // } - - // ++ind; - //} - - //mesh->calculatedAO = true; + return result; } Model* wiRenderer::LoadModel(const std::string& fileName, const XMMATRIX& transform) @@ -8266,7 +7944,6 @@ void wiRenderer::LoadWorldInfo(const std::string& fileName) //LoadWiWorldInfo(fileName, GetScene().worldInfo, GetScene().wind); WorldInfo& worldInfo = GetScene().worldInfo; - Wind& wind = GetScene().wind; string extension = wiHelper::GetExtensionFromFileName(fileName); @@ -8321,7 +7998,7 @@ void wiRenderer::LoadWorldInfo(const std::string& fileName) XMFLOAT4 r; float s; file >> r.x >> r.y >> r.z >> r.w >> s; - XMStoreFloat3(&wind.direction, XMVector3Transform(XMVectorSet(0, s, 0, 0), XMMatrixRotationQuaternion(XMLoadFloat4(&r)))); + XMStoreFloat3(&worldInfo.windDirection, XMVector3Transform(XMVectorSet(0, s, 0, 0), XMMatrixRotationQuaternion(XMLoadFloat4(&r)))); } break; case 'm': @@ -8376,7 +8053,7 @@ void wiRenderer::SynchronizeWithPhysicsEngine(float dt) { if (physicsEngine && GetGameSpeed()) { - physicsEngine->addWind(GetScene().wind.direction); + physicsEngine->addWind(GetScene().worldInfo.windDirection); // Update physics world data for (Model* model : GetScene().models) @@ -8617,11 +8294,14 @@ void wiRenderer::AddRenderableTranslator(wiTranslator* translator) { renderableTranslators.push_back(translator); } - void wiRenderer::AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color) { renderableBoxes.push_back(pair(boxMatrix,color)); } +void wiRenderer::AddRenderableLine(const RenderableLine& line) +{ + renderableLines.push_back(line); +} void wiRenderer::AddDeferredMIPGen(Texture2D* tex) { @@ -8662,9 +8342,6 @@ void wiRenderer::AddModel(Model* model) spTree_lights = new Octree(collection); } } - - SetUpCubes(); - SetUpBoneLines(); } void wiRenderer::Add(Object* value) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index bae7765c1..5cd112859 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -253,30 +253,18 @@ public: protected: - static void SetUpBoneLines(); - static void UpdateBoneLines(); - static void SetUpCubes(); - static void UpdateCubes(); - - - static bool wireRender, debugSpheres, debugBoneLines, debugPartitionTree, debugEnvProbes, debugEmitters, debugForceFields, debugCameras, gridHelper, voxelHelper, advancedLightCulling, advancedRefractions; static bool ldsSkinningEnabled; static bool requestReflectionRendering; - static wiGraphicsTypes::Texture2D* enviroMap,*colorGrading; + static wiGraphicsTypes::Texture2D* enviroMap; static void LoadBuffers(); static void LoadShaders(); static void SetUpStates(); - static int vertexCount; - static int visibleCount; - static void addVertexCount(const int& toadd){vertexCount+=toadd;} - - - static float GameSpeed, overrideGameSpeed; + static float GameSpeed; static wiSceneComponents::Scene* scene; @@ -316,8 +304,6 @@ protected: public: static std::string SHADERPATH; - wiRenderer(); - void CleanUp(); static void SetUpStaticComponents(); static void CleanUpStatic(); @@ -327,8 +313,6 @@ public: static void UpdateRenderData(GRAPHICSTHREAD threadID); static void OcclusionCulling_Render(GRAPHICSTHREAD threadID); static void OcclusionCulling_Read(); - static void UpdateImages(); - static void ManageImages(); static void PutDecal(wiSceneComponents::Decal* decal); static void PutWaterRipple(const std::string& image, const XMFLOAT3& pos); static void ManageWaterRipples(); @@ -399,8 +383,6 @@ public: static void SetAdvancedRefractionsEnabled(bool value) { advancedRefractions = value; } static bool GetAdvancedRefractionsEnabled(); // also needs additional driver support for now... static bool IsRequestedReflectionRendering() { return requestReflectionRendering; } - static wiGraphicsTypes::Texture2D* GetColorGrading(){return colorGrading;}; - static void SetColorGrading(wiGraphicsTypes::Texture2D* tex){colorGrading=tex;}; static void SetEnviromentMap(wiGraphicsTypes::Texture2D* tex){ enviroMap = tex; } static wiGraphicsTypes::Texture2D* GetEnviromentMap(){ return enviroMap; } static wiGraphicsTypes::Texture2D* GetLuminance(wiGraphicsTypes::Texture2D* sourceImage, GRAPHICSTHREAD threadID); @@ -460,8 +442,8 @@ public: static void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID); static void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID); static void ResetAlphaRef(GRAPHICSTHREAD threadID) { SetAlphaRef(0.75f, threadID); } - static void UpdateGBuffer(wiGraphicsTypes::Texture2D* slot0, wiGraphicsTypes::Texture2D* slot1, wiGraphicsTypes::Texture2D* slot2, wiGraphicsTypes::Texture2D* slot3, wiGraphicsTypes::Texture2D* slot4, GRAPHICSTHREAD threadID); - static void UpdateDepthBuffer(wiGraphicsTypes::Texture2D* depth, wiGraphicsTypes::Texture2D* linearDepth, GRAPHICSTHREAD threadID); + static void BindGBufferTextures(wiGraphicsTypes::Texture2D* slot0, wiGraphicsTypes::Texture2D* slot1, wiGraphicsTypes::Texture2D* slot2, wiGraphicsTypes::Texture2D* slot3, wiGraphicsTypes::Texture2D* slot4, GRAPHICSTHREAD threadID); + static void BindDepthTextures(wiGraphicsTypes::Texture2D* depth, wiGraphicsTypes::Texture2D* linearDepth, GRAPHICSTHREAD threadID); static void RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culledRenderer, SHADERTYPE shaderType, UINT renderTypeFlags, GRAPHICSTHREAD threadID, bool tessellation = false, bool occlusionCulling = false, uint32_t layerMask = 0xFFFFFFFF); @@ -470,23 +452,9 @@ public: static void DrawWorld(wiSceneComponents::Camera* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); static void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask = 0xFFFFFFFF); static void DrawWorldTransparent(wiSceneComponents::Camera* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF); - void DrawDebugSpheres(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugBoneLines(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugLines(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugBoxes(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawTranslators(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugEnvProbes(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugGridHelper(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugVoxels(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugEmitters(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugForceFields(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); - static void DrawDebugCameras(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); + static void DrawDebugWorld(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); static void DrawSoftParticles(wiSceneComponents::Camera* camera, bool distortion, GRAPHICSTHREAD threadID); static void DrawTrails(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); - static void DrawImagesAdd(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); - //alpha-opaque - static void DrawImages(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); - static void DrawImagesNormals(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes); static void DrawLights(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); static void DrawLightVisualizers(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); static void DrawVolumeLights(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); @@ -533,95 +501,35 @@ public: static XMVECTOR GetSunPosition(); static XMFLOAT4 GetSunColor(); static int GetSunArrayIndex(); - static int getVertexCount(){return vertexCount;} - static void resetVertexCount(){vertexCount=0;} - static int getVisibleObjectCount(){return visibleCount;} - static void resetVisibleObjectCount(){visibleCount=0;} static wiSPTree* spTree; static wiSPTree* spTree_lights; - // The scene holds all models, world information and wind information + // The scene holds all models, and world information static wiSceneComponents::Scene& GetScene(); - static std::vector boneLines; - static std::vector linesTemp; - static std::vector cubes; - static std::unordered_set objectsWithTrails; static std::unordered_set emitterSystems; - static std::deque images; static std::deque waterRipples; static void ClearWorld(); - - - static wiRenderTarget normalMapRT, imagesRT, imagesRTAdd; static wiSceneComponents::Camera* cam, *refCam, *prevFrameCam; static wiSceneComponents::Camera* getCamera(){ return cam; } static wiSceneComponents::Camera* getRefCamera(){ return refCam; } - std::string DIRECTORY; - - struct Picked - { - wiSceneComponents::Transform* transform; - wiSceneComponents::Object* object; - wiSceneComponents::Light* light; - wiSceneComponents::Decal* decal; - wiSceneComponents::EnvironmentProbe* envProbe; - wiSceneComponents::ForceField* forceField; - wiSceneComponents::Camera* camera; - wiSceneComponents::Armature* armature; - XMFLOAT3 position,normal; - float distance; - int subsetIndex; - - Picked() - { - Clear(); - } - - // Subset index, position, normal, distance don't distinguish between pickeds! - bool operator==(const Picked& other) - { - return - transform == other.transform && - object == other.object && - light == other.light && - decal == other.decal && - envProbe == other.envProbe && - forceField == other.forceField && - camera == other.camera && - armature == other.armature - ; - } - void Clear() - { - distance = 0; - subsetIndex = -1; - SAFE_INIT(transform); - SAFE_INIT(object); - SAFE_INIT(light); - SAFE_INIT(decal); - SAFE_INIT(envProbe); - SAFE_INIT(forceField); - SAFE_INIT(camera); - SAFE_INIT(armature); - } - }; - - // Pick closest object in the world - // pickType: PICKTYPE enum values concatenated with | operator - // layer : concatenated string of layers to check against, empty string : all layers will be checked - // layerDisable : concatenated string of layers to NOT check against - static Picked Pick(long cursorX, long cursorY, int pickType = PICK_OPAQUE, uint32_t layerMask = 0xFFFFFFFF); - static Picked Pick(RAY& ray, int pickType = PICK_OPAQUE, uint32_t layerMask = 0xFFFFFFFF); static RAY getPickRay(long cursorX, long cursorY); - static void RayIntersectMeshes(const RAY& ray, const CulledList& culledObjects, std::vector& points, - int pickType = PICK_OPAQUE, bool dynamicObjects = true, bool onlyVisible = false, uint32_t layerMask = 0xFFFFFFFF); - static void CalculateVertexAO(wiSceneComponents::Object* object); + + struct RayIntersectWorldResult + { + wiSceneComponents::Object* object = nullptr; + XMFLOAT3 position = XMFLOAT3(0, 0, 0); + XMFLOAT3 normal = XMFLOAT3(0, 0, 0); + float distance = FLT_MAX; + int subsetIndex = -1; + }; + static RayIntersectWorldResult RayIntersectWorld(const RAY& ray, UINT renderTypeMask = RENDERTYPE_OPAQUE, uint32_t layerMask = 0xFFFFFFFF, bool dynamicObjects = true, bool onlyVisible = false); + static PHYSICS* physicsEngine; static void SynchronizeWithPhysicsEngine(float dt = 1.0f / 60.0f); @@ -646,17 +554,22 @@ public: // Add box to render in next frame static void AddRenderableBox(const XMFLOAT4X4& boxMatrix, const XMFLOAT4& color = XMFLOAT4(1,1,1,1)); + struct RenderableLine + { + XMFLOAT3 start = XMFLOAT3(0, 0, 0); + XMFLOAT3 end = XMFLOAT3(0, 0, 0); + XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1); + }; + static std::vector renderableLines; + static void AddRenderableLine(const RenderableLine& line); + static void AddDeferredMIPGen(wiGraphicsTypes::Texture2D* tex); - // Add model to the scene + static void AddModel(wiSceneComponents::Model* value); - // Add Object Instance static void Add(wiSceneComponents::Object* value); - // Add Light Instance static void Add(wiSceneComponents::Light* value); - // Add Force Field Instance static void Add(wiSceneComponents::ForceField* value); - // Add Camera Instance static void Add(wiSceneComponents::Camera* value); // Remove from the scene diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp index 54baead8e..7d0a18c8b 100644 --- a/WickedEngine/wiRenderer_BindLua.cpp +++ b/WickedEngine/wiRenderer_BindLua.cpp @@ -1,6 +1,5 @@ #include "wiRenderer_BindLua.h" #include "wiRenderer.h" -#include "wiLines.h" #include "wiSceneComponents.h" #include "wiHelper.h" #include "wiSceneComponents_BindLua.h" @@ -405,23 +404,6 @@ namespace wiRenderer_BindLua wiLua::SError(L, "SetEnvironmentMap(Texture cubemap) not enough arguments!"); return 0; } - int SetColorGrading(lua_State* L) - { - int argc = wiLua::SGetArgCount(L); - if (argc > 0) - { - Texture_BindLua* tex = Luna::lightcheck(L, 1); - if (tex != nullptr) - { - wiRenderer::SetColorGrading(tex->texture); - } - else - wiLua::SError(L, "SetColorGrading(Texture texture2D) argument is not a texture!"); - } - else - wiLua::SError(L, "SetColorGrading(Texture texture2D) not enough arguments!"); - return 0; - } int HairParticleSettings(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -587,18 +569,18 @@ namespace wiRenderer_BindLua Ray_BindLua* ray = Luna::lightcheck(L, 1); if (ray != nullptr) { - int pickType = PICKTYPE::PICK_OPAQUE; + UINT renderTypeMask = RENDERTYPE_OPAQUE; uint32_t layerMask = 0xFFFFFFFF; if (argc > 1) { - pickType = wiLua::SGetInt(L, 2); + renderTypeMask = (UINT)wiLua::SGetInt(L, 2); if (argc > 2) { int mask = wiLua::SGetInt(L, 3); layerMask = *reinterpret_cast(&mask); } } - wiRenderer::Picked pick = wiRenderer::Pick(ray->ray, pickType, layerMask); + auto& pick = wiRenderer::RayIntersectWorld(ray->ray, renderTypeMask, layerMask); Luna::push(L, new Object_BindLua(pick.object)); Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.position))); Luna::push(L, new Vector_BindLua(XMLoadFloat3(&pick.normal))); @@ -609,35 +591,35 @@ namespace wiRenderer_BindLua return 0; } int DrawLine(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 1) { - int argc = wiLua::SGetArgCount(L); - if (argc > 1) + Vector_BindLua* a = Luna::lightcheck(L, 1); + Vector_BindLua* b = Luna::lightcheck(L, 2); + if (a && b) { - Vector_BindLua* a = Luna::lightcheck(L, 1); - Vector_BindLua* b = Luna::lightcheck(L, 2); - if (a && b) + wiRenderer::RenderableLine line; + XMStoreFloat3(&line.start, a->vector); + XMStoreFloat3(&line.end, b->vector); + if (argc > 2) { - XMFLOAT3 xa, xb; - XMFLOAT4 xc = XMFLOAT4(1, 1, 1, 1); - XMStoreFloat3(&xa, a->vector); - XMStoreFloat3(&xb, b->vector); - if (argc > 2) - { - Vector_BindLua* c = Luna::lightcheck(L, 3); - if (c) - XMStoreFloat4(&xc, c->vector); - else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); - } - wiRenderer::linesTemp.push_back(new Lines(xa, xb, xc)); + Vector_BindLua* c = Luna::lightcheck(L, 3); + if (c) + XMStoreFloat4(&line.color, c->vector); + else + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); } - else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); + wiRenderer::AddRenderableLine(line); } else - wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) not enough arguments!"); - return 0; + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) one or more arguments are not vectors!"); } + else + wiLua::SError(L, "DrawLine(Vector origin,end, opt Vector color) not enough arguments!"); + + return 0; + } int PutWaterRipple(lua_State* L) { int argc = wiLua::SGetArgCount(L); @@ -756,7 +738,6 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RegisterFunc("LoadWorldInfo", LoadWorldInfo); wiLua::GetGlobal()->RegisterFunc("DuplicateInstance", DuplicateInstance); wiLua::GetGlobal()->RegisterFunc("SetEnvironmentMap", SetEnvironmentMap); - wiLua::GetGlobal()->RegisterFunc("SetColorGrading", SetColorGrading); wiLua::GetGlobal()->RegisterFunc("HairParticleSettings", HairParticleSettings); wiLua::GetGlobal()->RegisterFunc("SetAlphaCompositionEnabled", SetAlphaCompositionEnabled); wiLua::GetGlobal()->RegisterFunc("SetShadowProps2D", SetShadowProps2D); @@ -783,13 +764,6 @@ namespace wiRenderer_BindLua wiLua::GetGlobal()->RunText("PICK_OPAQUE = 1"); wiLua::GetGlobal()->RunText("PICK_TRANSPARENT = 2"); wiLua::GetGlobal()->RunText("PICK_WATER = 4"); - wiLua::GetGlobal()->RunText("PICK_LIGHT = 8"); - wiLua::GetGlobal()->RunText("PICK_DECAL = 16"); - wiLua::GetGlobal()->RunText("PICK_ENVPROBE = 32"); - wiLua::GetGlobal()->RunText("PICK_FORCEFIELD = 64"); - wiLua::GetGlobal()->RunText("PICK_EMITTER = 128"); - wiLua::GetGlobal()->RunText("PICK_CAMERA = 256"); - wiLua::GetGlobal()->RunText("PICK_ARMATURE = 512"); wiLua::GetGlobal()->RegisterFunc("ClearWorld", ClearWorld); diff --git a/WickedEngine/wiSPTree.cpp b/WickedEngine/wiSPTree.cpp index 19db4dd4d..bf04e684e 100644 --- a/WickedEngine/wiSPTree.cpp +++ b/WickedEngine/wiSPTree.cpp @@ -128,7 +128,7 @@ void wiSPTree::Sort(const XMFLOAT3& origin, CulledList& objects, SortType sortTy } } -void wiSPTree::getVisible(Frustum& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) +void wiSPTree::getVisible(const Frustum& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) { if (node == nullptr) { @@ -170,7 +170,7 @@ void wiSPTree::getVisible(Frustum& frustum, CulledList& objects, SortType sortTy Sort(frustum.getCamPos(), objects, sortType); } } -void wiSPTree::getVisible(AABB& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) +void wiSPTree::getVisible(const AABB& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) { if (node == nullptr) { @@ -211,7 +211,7 @@ void wiSPTree::getVisible(AABB& frustum, CulledList& objects, SortType sortType, Sort(frustum.getCenter(), objects, sortType); } } -void wiSPTree::getVisible(SPHERE& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) +void wiSPTree::getVisible(const SPHERE& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) { if (node == nullptr) { @@ -247,7 +247,7 @@ void wiSPTree::getVisible(SPHERE& frustum, CulledList& objects, SortType sortTyp Sort(frustum.center, objects, sortType); } } -void wiSPTree::getVisible(RAY& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) +void wiSPTree::getVisible(const RAY& frustum, CulledList& objects, SortType sortType, CullStrictness type, Node* node) { if (node == nullptr) { diff --git a/WickedEngine/wiSPTree.h b/WickedEngine/wiSPTree.h index c27ae9f9a..9e4f5adfa 100644 --- a/WickedEngine/wiSPTree.h +++ b/WickedEngine/wiSPTree.h @@ -71,10 +71,10 @@ public: static void Sort(const XMFLOAT3& origin, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE); void AddObjects(Node* node, const std::vector& newObjects); - void getVisible(Frustum& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); - void getVisible(AABB& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); - void getVisible(SPHERE& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); - void getVisible(RAY& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); + void getVisible(const Frustum& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); + void getVisible(const AABB& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); + void getVisible(const SPHERE& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); + void getVisible(const RAY& frustum, CulledList& objects, SortType sortType = SP_TREE_SORT_UNIQUE, CullStrictness type = SP_TREE_STRICT_CULL, Node* node = nullptr); void getAll(CulledList& objects, Node* node = nullptr); // Updates the tree. Returns null if successful, returns a new tree if the tree is resized. The old tree can be thrown away then. wiSPTree* updateTree(Node* node = nullptr); diff --git a/WickedEngine/wiSceneComponents.cpp b/WickedEngine/wiSceneComponents.cpp index 4ea3552fa..85764ec2b 100644 --- a/WickedEngine/wiSceneComponents.cpp +++ b/WickedEngine/wiSceneComponents.cpp @@ -1458,35 +1458,42 @@ void Model::FinishLoading() { if (x->parent == nullptr) { - for (Transform* y : transforms) + if (x->boneParent.empty()) { - if (x != y && !x->parentName.empty() && !x->parentName.compare(y->name)) + // Normal parenting: + if (!x->parentName.empty()) { - Transform* parent = y; - string parentName = parent->name; - if (!x->boneParent.empty()) + for (Transform* y : transforms) { - Armature* armature = dynamic_cast(y); - if (armature != nullptr) + if (x != y && !x->parentName.compare(y->name)) { - for (Bone* bone : armature->boneCollection) - { - if (!bone->name.compare(x->boneParent)) - { - parent = bone; - break; - } - } + XMFLOAT4X4 saved_parent_rest_inv = x->parent_inv_rest; + x->attachTo(y); + x->parent_inv_rest = saved_parent_rest_inv; + break; } } - // Match parent - XMFLOAT4X4 saved_parent_rest_inv = x->parent_inv_rest; - x->attachTo(parent); - x->parent_inv_rest = saved_parent_rest_inv; - x->parentName = parentName; // this will ensure that the bone parenting is always resolved as armature->bone - break; } } + else + { + // Bone parenting: + for (Armature* armature : armatures) + { + if (armature != x) + { + Bone* y = armature->GetBone(x->boneParent); + if (y != nullptr) + { + XMFLOAT4X4 saved_parent_rest_inv = x->parent_inv_rest; + x->attachTo(y); + x->parent_inv_rest = saved_parent_rest_inv; + break; + } + } + } + } + } // If it has still no parent, then attach to this model! @@ -1861,11 +1868,6 @@ void Model::Serialize(wiArchive& archive) #pragma endregion #pragma region BONE -XMMATRIX Bone::getMatrix(int getTranslation, int getRotation, int getScale) -{ - - return XMMatrixTranslation(0,0,length)*XMLoadFloat4x4(&world); -} void Bone::UpdateTransform() { //Transform::UpdateTransform(); @@ -2105,24 +2107,40 @@ void Armature::UpdateTransform() { Transform::UpdateTransform(); - XMMATRIX worldMatrix = getMatrix(); XMMATRIX remapMat = XMLoadFloat4x4(&skinningRemap); - - // Update bone tree from root: for (Bone* root : rootbones) { // Update tree for skinning: // Note that skinning is not using the armature transform, it will be calculated in armature local space // This is needed because we want to skin meshes, then reuse the meshes for multiple objects without additional deform RecursiveBoneTransform(this, root, remapMat); + } - // Update tree for bone attaching: + XMMATRIX worldMatrix = getMatrix(); + for (Bone* bone : boneCollection) + { + // Update each bone for attaching: // The Skinning (RecursiveBoneTrasform) was operating in armature local space, but for bone attachments without deform, // we need the matrices in world space - XMMATRIX boneMatrix = XMLoadFloat4x4(&root->world); + XMMATRIX boneMatrix = XMLoadFloat4x4(&bone->world); boneMatrix = boneMatrix * worldMatrix; - XMStoreFloat4x4(&root->world, boneMatrix); - root->UpdateTransform(); + + // Save individual components for prev-frame: + bone->worldPrev = bone->world; + bone->translationPrev = bone->translation; + bone->rotationPrev = bone->rotation; + bone->scalePrev = bone->scale; + + // Update individual components: + XMVECTOR v[3]; + XMMatrixDecompose(&v[0], &v[1], &v[2], boneMatrix); + XMStoreFloat3(&bone->scale, v[0]); + XMStoreFloat4(&bone->rotation, v[1]); + XMStoreFloat3(&bone->translation, v[2]); + XMStoreFloat4x4(&bone->world, boneMatrix); + + // Any attachments should be updated too: + bone->UpdateTransform(); } } void Armature::UpdateArmature() @@ -2225,14 +2243,6 @@ void Armature::RecursiveBoneTransform(Armature* armature, Bone* bone, const XMMA } } - bone->worldPrev = bone->world; - bone->translationPrev = bone->translation; - bone->rotationPrev = bone->rotation; - bone->scalePrev = bone->scale; - XMStoreFloat3(&bone->translation, finalTrans); - XMStoreFloat4(&bone->rotation, finalRotat); - XMStoreFloat3(&bone->scale, finalScala); - // Bone local T-pose matrix (relative to PARENT): XMMATRIX rest = XMLoadFloat4x4(&bone->world_rest); diff --git a/WickedEngine/wiSceneComponents.h b/WickedEngine/wiSceneComponents.h index 71f220902..d62bda090 100644 --- a/WickedEngine/wiSceneComponents.h +++ b/WickedEngine/wiSceneComponents.h @@ -661,8 +661,7 @@ struct Bone : public Transform connected = false; } - XMMATRIX getMatrix(int getTranslation = 1, int getRotation = 1, int getScale = 1); - virtual void UpdateTransform(); + virtual void UpdateTransform() override; void Serialize(wiArchive& archive); }; struct AnimationLayer @@ -950,6 +949,9 @@ struct WorldInfo{ float cloudiness; float cloudScale; float cloudSpeed; + XMFLOAT3 windDirection; + float windRandomness; + float windWaveSize; WorldInfo(){ horizon = XMFLOAT3(0.0f, 0.0f, 0.0f); @@ -960,14 +962,11 @@ struct WorldInfo{ cloudiness = 0.0f; cloudScale = 0.0003f; cloudSpeed = 0.1f; + windDirection = XMFLOAT3(0, 0, 0); + windRandomness = 5; + windWaveSize = 1; } }; -struct Wind{ - XMFLOAT3 direction; - float randomness; - float waveSize; - Wind():direction(XMFLOAT3(0,0,0)),randomness(5),waveSize(1){} -}; struct Camera : public Transform, public ModelChild { XMFLOAT4X4 View, Projection, VP; @@ -1222,7 +1221,6 @@ struct Scene // First is always the world node std::vector models; WorldInfo worldInfo; - Wind wind; Scene(); ~Scene(); diff --git a/WickedEngine/wiTaskThread.h b/WickedEngine/wiTaskThread.h deleted file mode 100644 index 418ea6779..000000000 --- a/WickedEngine/wiTaskThread.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include "CommonInclude.h" - -class wiTaskThread { -public: - wiTaskThread(std::function task) - : m_task(std::move(task)), - m_wakeup(false), - m_stop(false), - m_thread(&wiTaskThread::taskFunc, this) - {} - ~wiTaskThread() { stop(); join(); } - - void wakeup() { - auto lock = std::unique_lock(m_wakemutex); - m_wakeup = true; - m_wakecond.notify_one(); - } - void wait() { - auto lock = std::unique_lock(m_waitmutex); - while (m_wakeup) - m_waitcond.wait(lock); - } - - void stop() { - auto lock = std::unique_lock(m_wakemutex); - m_stop = true; - m_wakecond.notify_one(); - } - void join() { - m_thread.join(); - } - -private: - std::function m_task; - - bool m_wakeup; - bool m_stop; - std::mutex m_wakemutex; - std::condition_variable m_wakecond; - - std::mutex m_waitmutex; - std::condition_variable m_waitcond; - - std::thread m_thread; - - void taskFunc() { - while (true) { - { - auto lock = std::unique_lock(m_wakemutex); - while (!m_wakeup && !m_stop) - m_wakecond.wait(lock); - if (m_stop) { - return; - } - } - - try { m_task(); } catch (...) {} - - { - auto lock = std::unique_lock(m_waitmutex); - m_wakeup = false; - m_waitcond.notify_all(); - } - } - } - -}; \ No newline at end of file diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 669248bd6..3c734cb41 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 20; // minor bug fixes, alterations, refactors, updates - const int revision = 0; + const int revision = 1; long GetVersion() diff --git a/models/Sample/scene.wimf b/models/Sample/scene.wimf index 89aeed991..19f046dc2 100644 Binary files a/models/Sample/scene.wimf and b/models/Sample/scene.wimf differ diff --git a/scripts/character_controller_tps.lua b/scripts/character_controller_tps.lua index e15b17e30..41e76beb7 100644 --- a/scripts/character_controller_tps.lua +++ b/scripts/character_controller_tps.lua @@ -308,6 +308,13 @@ runProcess(function() --intersection DrawAxis(player.p,0.5) + -- Head bone + DrawAxis(player.skeleton.GetBone("testa").GetPosition(),1.0) + -- Left hand bone + DrawAxis(player.skeleton.GetBone("mano_L").GetPosition(),1.0) + -- Right hand bone + DrawAxis(player.skeleton.GetBone("mano_R").GetPosition(),1.0) + -- Wait for the engine to render the scene render()