From 5cb232227063c33af48dd3ddece7ac475380a5dc Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 10 Feb 2021 11:37:34 +0100 Subject: [PATCH] Add default Deformable material for splines --- Content/Editor/Particles/Particle Material Color.flax | 2 +- Content/Engine/DefaultDeformableMaterial.flax | 3 +++ Source/Editor/Cooker/Steps/DeployDataStep.cpp | 1 + Source/Engine/Graphics/GPUDevice.cpp | 9 +++++++++ Source/Engine/Graphics/GPUDevice.h | 5 +++++ Source/Engine/Level/Actors/SplineModel.cpp | 2 +- Source/Engine/Scripting/SoftObjectReference.h | 5 +++-- 7 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 Content/Engine/DefaultDeformableMaterial.flax diff --git a/Content/Editor/Particles/Particle Material Color.flax b/Content/Editor/Particles/Particle Material Color.flax index e2fdb046b..81fcbea72 100644 --- a/Content/Editor/Particles/Particle Material Color.flax +++ b/Content/Editor/Particles/Particle Material Color.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:14d75ef13449f9ed9a6e18ee82fe59fe4e83ac519b62b1e87aaadabd89673995 +oid sha256:e44da38b26f222f7081278dc64b7fa932c6f9bfd0b79694da784bd4d944e838a size 29232 diff --git a/Content/Engine/DefaultDeformableMaterial.flax b/Content/Engine/DefaultDeformableMaterial.flax new file mode 100644 index 000000000..3b2e45a87 --- /dev/null +++ b/Content/Engine/DefaultDeformableMaterial.flax @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dab7eb4f71a407eae7d6b051cbad701f234742b0d96646811c8a615de80e94eb +size 18800 diff --git a/Source/Editor/Cooker/Steps/DeployDataStep.cpp b/Source/Editor/Cooker/Steps/DeployDataStep.cpp index 9ce3a8a5d..96f8bfad2 100644 --- a/Source/Editor/Cooker/Steps/DeployDataStep.cpp +++ b/Source/Editor/Cooker/Steps/DeployDataStep.cpp @@ -74,6 +74,7 @@ bool DeployDataStep::Perform(CookingData& data) data.AddRootEngineAsset(TEXT("Shaders/SSR")); data.AddRootEngineAsset(TEXT("Shaders/VolumetricFog")); data.AddRootEngineAsset(TEXT("Engine/DefaultMaterial")); + data.AddRootEngineAsset(TEXT("Engine/DefaultDeformableMaterial")); data.AddRootEngineAsset(TEXT("Engine/DefaultTerrainMaterial")); if (!gameSettings->NoSplashScreen && !gameSettings->SplashScreen.IsValid()) data.AddRootEngineAsset(TEXT("Engine/Textures/Logo")); diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp index 821031454..51d92cd3f 100644 --- a/Source/Engine/Graphics/GPUDevice.cpp +++ b/Source/Engine/Graphics/GPUDevice.cpp @@ -18,6 +18,7 @@ #include "Engine/Profiler/Profiler.h" #include "Engine/Renderer/RenderList.h" #include "Engine/Core/Utilities.h" +#include "Engine/Scripting/SoftObjectReference.h" GPUPipelineState* GPUPipelineState::Spawn(const SpawnParams& params) { @@ -127,6 +128,7 @@ struct GPUDevice::PrivateData GPUPipelineState* PS_Clear = nullptr; GPUBuffer* FullscreenTriangleVB = nullptr; AssetReference DefaultMaterial; + SoftObjectReference DefaultDeformableMaterial; AssetReference DefaultNormalMap; AssetReference DefaultWhiteTexture; AssetReference DefaultBlackTexture; @@ -206,6 +208,7 @@ bool GPUDevice::LoadContent() _res->DefaultMaterial = Content::LoadAsyncInternal(TEXT("Engine/DefaultMaterial")); if (_res->DefaultMaterial == nullptr) return true; + _res->DefaultDeformableMaterial = Guid(0x639e12c0, 0x42d34bae, 0x89dd8b81, 0x7e1efc2d); // Load default normal map _res->DefaultNormalMap = Content::LoadAsyncInternal(TEXT("Engine/Textures/NormalTexture")); @@ -231,6 +234,7 @@ void GPUDevice::preDispose() // Release resources _res->DefaultMaterial = nullptr; + _res->DefaultDeformableMaterial = nullptr; _res->DefaultNormalMap = nullptr; _res->DefaultWhiteTexture = nullptr; _res->DefaultBlackTexture = nullptr; @@ -380,6 +384,11 @@ MaterialBase* GPUDevice::GetDefaultMaterial() const return _res->DefaultMaterial; } +MaterialBase* GPUDevice::GetDefaultDeformableMaterial() const +{ + return _res->DefaultDeformableMaterial.Get(); +} + GPUTexture* GPUDevice::GetDefaultNormalMap() const { return _res->DefaultNormalMap ? _res->DefaultNormalMap->GetTexture() : nullptr; diff --git a/Source/Engine/Graphics/GPUDevice.h b/Source/Engine/Graphics/GPUDevice.h index 0b5fb46b9..e1deb16cc 100644 --- a/Source/Engine/Graphics/GPUDevice.h +++ b/Source/Engine/Graphics/GPUDevice.h @@ -234,6 +234,11 @@ public: /// MaterialBase* GetDefaultMaterial() const; + /// + /// Gets the default material (Deformable domain). + /// + MaterialBase* GetDefaultDeformableMaterial() const; + /// /// Gets the default normal map texture. /// diff --git a/Source/Engine/Level/Actors/SplineModel.cpp b/Source/Engine/Level/Actors/SplineModel.cpp index 69fcf90bc..c8a7b7b1f 100644 --- a/Source/Engine/Level/Actors/SplineModel.cpp +++ b/Source/Engine/Level/Actors/SplineModel.cpp @@ -408,7 +408,7 @@ void SplineModel::Draw(RenderContext& renderContext) else if (slot.Material && slot.Material->IsLoaded()) material = slot.Material; else - material = nullptr; + material = GPUDevice::Instance->GetDefaultDeformableMaterial(); if (!material || !material->IsDeformable()) continue; diff --git a/Source/Engine/Scripting/SoftObjectReference.h b/Source/Engine/Scripting/SoftObjectReference.h index 1befaa0f7..b6f08db4a 100644 --- a/Source/Engine/Scripting/SoftObjectReference.h +++ b/Source/Engine/Scripting/SoftObjectReference.h @@ -311,9 +311,10 @@ public: /// Sets the object. /// /// The object ID. Uses Scripting to find the registered object of the given ID. - FORCE_INLINE void Set(const Guid& id) + void Set(const Guid& id) { - Set(static_cast(FindObject(id, T::GetStaticClass()))); + _id = id; + _object = nullptr; } ///