From c47565226461f74bb537adfb1b6cd21c397e2a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20J=C3=B6nsson?= Date: Sun, 24 Mar 2024 12:36:25 +0100 Subject: [PATCH] Fixes --- .../Shaders/Source/HLSL/2D/Billboard_gs.hlsl | 8 +- .../Source/HLSL/Deferred/Decal_ps.hlsl | 2 +- .../Source/HLSL/Environment/Skybox_ps.hlsl | 2 +- Volt/Sandbox/src/Sandbox/Sandbox.cpp | 46 +++++++++++ Volt/Volt/src/Volt/Asset/Asset.h | 64 +++++++-------- Volt/Volt/src/Volt/Asset/AssetFactory.cpp | 78 +++++++++++++++++++ Volt/Volt/src/Volt/Asset/AssetFactory.h | 25 ++++++ Volt/Volt/src/Volt/Asset/AssetManager.cpp | 58 +++++++++----- Volt/Volt/src/Volt/Asset/AssetManager.h | 5 ++ .../Volt/src/Volt/Rendering/SceneRenderer.cpp | 2 +- Volt/Volt/src/Volt/Scene/Entity.cpp | 7 +- Volt/Volt/src/Volt/Scene/Entity.h | 2 - 12 files changed, 236 insertions(+), 63 deletions(-) create mode 100644 Volt/Volt/src/Volt/Asset/AssetFactory.cpp create mode 100644 Volt/Volt/src/Volt/Asset/AssetFactory.h diff --git a/Engine/Engine/Shaders/Source/HLSL/2D/Billboard_gs.hlsl b/Engine/Engine/Shaders/Source/HLSL/2D/Billboard_gs.hlsl index 5826a3de7..961aec7fc 100644 --- a/Engine/Engine/Shaders/Source/HLSL/2D/Billboard_gs.hlsl +++ b/Engine/Engine/Shaders/Source/HLSL/2D/Billboard_gs.hlsl @@ -16,10 +16,10 @@ void main(point DefaultBillboardVertex input[1], inout TriangleStream ou { const float2 offsets[4] = { - { -100.f, 100.f }, - { 100.f, 100.f }, - { -100.f, -100.f }, - { 100.f, -100.f } + { -1.f, 1.f }, + { 1.f, 1.f }, + { -1.f, -1.f }, + { 1.f, -1.f } }; const float2 uvs[4] = diff --git a/Engine/Engine/Shaders/Source/HLSL/Deferred/Decal_ps.hlsl b/Engine/Engine/Shaders/Source/HLSL/Deferred/Decal_ps.hlsl index ca6420c8e..96ec5880d 100644 --- a/Engine/Engine/Shaders/Source/HLSL/Deferred/Decal_ps.hlsl +++ b/Engine/Engine/Shaders/Source/HLSL/Deferred/Decal_ps.hlsl @@ -22,7 +22,7 @@ Output main(DecalOutput input) const float3 pixelNormal = normalize(cross(ddy(pixelWorldPosition), ddx(pixelWorldPosition))); float decalCull = saturate(dot(rotVec.xyz, pixelNormal)); - const float2 sampleCoords = -(objectSpacePosition.xy / 100.f) + 0.5f; + const float2 sampleCoords = -objectSpacePosition.xy + 0.5f; const Material material = GetMaterial(u_materialData.materialIndex); diff --git a/Engine/Engine/Shaders/Source/HLSL/Environment/Skybox_ps.hlsl b/Engine/Engine/Shaders/Source/HLSL/Environment/Skybox_ps.hlsl index 0356e66f0..66ab02956 100644 --- a/Engine/Engine/Shaders/Source/HLSL/Environment/Skybox_ps.hlsl +++ b/Engine/Engine/Shaders/Source/HLSL/Environment/Skybox_ps.hlsl @@ -32,7 +32,7 @@ float3 CalculateInscatteredLight(in float3 accumulatedLight, float2 position) float4 main(Input input) : SV_Target0 { float4 result = 0.f; - result = u_environmentMap.SampleLevel(u_linearSampler, input.samplePosition / 100.f, u_pushConstants.lod) * u_pushConstants.intensity; + result = u_environmentMap.SampleLevel(u_linearSampler, input.samplePosition, u_pushConstants.lod) * u_pushConstants.intensity; result.a = 1.f; result.rgb += CalculateInscatteredLight(result.rgb, input.position.xy); diff --git a/Volt/Sandbox/src/Sandbox/Sandbox.cpp b/Volt/Sandbox/src/Sandbox/Sandbox.cpp index 3f68f9a1b..14a07872e 100644 --- a/Volt/Sandbox/src/Sandbox/Sandbox.cpp +++ b/Volt/Sandbox/src/Sandbox/Sandbox.cpp @@ -882,6 +882,52 @@ bool Sandbox::OnImGuiUpdateEvent(Volt::AppImGuiUpdateEvent& e) RenderProgressBar(buildProgess); } + if (ImGui::Begin("Conversion Window")) + { + if (ImGui::Button("Convert Scene to M")) + { + Volt::Entity mainMenuEntity = myRuntimeScene->GetEntityWithName("PF_MainMenu"); + + myRuntimeScene->ForEachWithComponents([&](const entt::entity id, Volt::TransformComponent& transComp, const Volt::MeshComponent& meshComp) + { + Volt::Entity entity{ id, myRuntimeScene }; + entity.SetScale(entity.GetScale() * 0.01f); + }); + + myRuntimeScene->ForEachWithComponents([&](const entt::entity id, Volt::TransformComponent& transComp) + { + Volt::Entity entity{ id, myRuntimeScene }; + + if (mainMenuEntity) + { + if (myRuntimeScene->IsRelatedTo(mainMenuEntity, entity)) + { + return; + } + } + + if (entity == mainMenuEntity) + { + return; + } + + entity.SetLocalPosition(entity.GetLocalPosition() * 0.01f); + }); + + myRuntimeScene->ForEachWithComponents([&](const entt::entity id, Volt::PointLightComponent& comp) + { + comp.radius *= 0.01f; + }); + + myRuntimeScene->ForEachWithComponents([&](const entt::entity id, Volt::SpotLightComponent& comp) + { + comp.range *= 0.01f; + }); + } + + ImGui::End(); + } + return false; } diff --git a/Volt/Volt/src/Volt/Asset/Asset.h b/Volt/Volt/src/Volt/Asset/Asset.h index 02c36637f..b498fdb90 100644 --- a/Volt/Volt/src/Volt/Asset/Asset.h +++ b/Volt/Volt/src/Volt/Asset/Asset.h @@ -22,38 +22,40 @@ namespace Volt Queued = BIT(2) }; - enum class AssetType : uint64_t + enum class AssetType : uint32_t { None = 0, - Mesh = BIT(0), - MeshSource = BIT(1), - Animation = BIT(2), - Skeleton = BIT(3), - Texture = BIT(4), - Material = BIT(5), - Shader = BIT(6), - ShaderSource = BIT(7), - Scene = BIT(8), - AnimatedCharacter = BIT(9), - ParticlePreset = BIT(10), - Prefab = BIT(11), - Font = BIT(12), - PhysicsMaterial = BIT(13), - Video = BIT(14), - BlendSpace = BIT(15), - NavMesh = BIT(16), - AnimationGraph = BIT(17), - GraphKey = BIT(18), - MonoScript = BIT(19), - BehaviorGraph = BIT(20), - MaterialGraph = BIT(21), - RenderPipeline = BIT(22), - Timeline = BIT(23), - NetContract = BIT(24), - PostProcessingMaterial = BIT(25), - PostProcessingStack = BIT(26), - MotionWeave = BIT(27), - TextureSource = BIT(28) + Mesh, + MeshSource, + Animation, + Skeleton, + Texture, + Material, + Shader, + ShaderSource, + Scene, + AnimatedCharacter, + ParticlePreset, + Prefab, + Font, + PhysicsMaterial, + Video, + BlendSpace, + NavMesh, + AnimationGraph, + GraphKey, + MonoScript, + BehaviorGraph, + RenderPipeline, + Timeline, + NetContract, + PostProcessingMaterial, + PostProcessingStack, + MotionWeave, + TextureSource, + + // Add new assets above this line + Count }; inline AssetType operator|(AssetType aLhs, AssetType aRhs) @@ -97,7 +99,6 @@ namespace Volt { ".hlslh", AssetType::ShaderSource }, { ".hlsli", AssetType::ShaderSource }, - { ".vtmgraph", AssetType::MaterialGraph }, { ".vtmat", AssetType::Material }, { ".vtpostmat", AssetType::PostProcessingMaterial }, { ".vtpoststack", AssetType::PostProcessingStack }, @@ -135,7 +136,6 @@ namespace Volt { "Shader", AssetType::Shader }, { "Shader Source", AssetType::ShaderSource }, - { "Material Graph", AssetType::MaterialGraph }, { "Material", AssetType::Material }, { "Post Processing Material", AssetType::PostProcessingMaterial }, { "Post Processing Stack", AssetType::PostProcessingStack }, diff --git a/Volt/Volt/src/Volt/Asset/AssetFactory.cpp b/Volt/Volt/src/Volt/Asset/AssetFactory.cpp new file mode 100644 index 000000000..6e4208b61 --- /dev/null +++ b/Volt/Volt/src/Volt/Asset/AssetFactory.cpp @@ -0,0 +1,78 @@ +#include "vtpch.h" +#include "AssetFactory.h" + +#include "Volt/Asset/Mesh/Mesh.h" +#include "Volt/Asset/Mesh/Material.h" +#include "Volt/Asset/Animation/Animation.h" +#include "Volt/Asset/Animation/Skeleton.h" +#include "Volt/Asset/Animation/AnimatedCharacter.h" +#include "Volt/Asset/Animation/AnimationGraphAsset.h" +#include "Volt/Asset/ParticlePreset.h" +#include "Volt/Asset/Text/Font.h" +#include "Volt/Asset/Prefab.h" +#include "Volt/Asset/Video/Video.h" +#include "Volt/Asset/TimelinePreset.h" +#include "Volt/Asset/Rendering/PostProcessingMaterial.h" +#include "Volt/Asset/Rendering/PostProcessingStack.h" + +#include "Volt/Scene/Scene.h" +#include "Volt/Animation/BlendSpace.h" + +#include "Volt/Physics/PhysicsMaterial.h" + +#include "Volt/Rendering/Shader/Shader.h" +#include "Volt/Rendering/Texture/Texture2D.h" + +#include "Volt/BehaviorTree/BehaviorTree.hpp" +#include "Volt/Rendering/RenderPipeline/RenderPipeline.h" +#include "Volt/Net/SceneInteraction/NetContract.h" + +#include + +namespace Volt +{ + template + void RegisterCreateFunction(AssetType type, std::unordered_map& out) + { + out[type] = []() { return CreateRef(); } + } + + void AssetFactory::Initialize() + { + RegisterCreateFunction(AssetType::Mesh, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::MeshSource, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Animation, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Skeleton, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Texture, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Material, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Shader, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::ShaderSource, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Scene, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::AnimatedCharacter, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::ParticlePreset, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Prefab, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::Font, m_assetFactoryFunctions); + RegisterCreateFunction(AssetType::PhysicsMaterial, m_assetFactoryFunctions); + RegisterCreateFunction