From c2b80eb2f94b85ac9f11b41583689ab48f2998de Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 4 Jul 2023 12:41:35 -0400 Subject: [PATCH] Fixed rendering error when disabling volumetric --- .../resources/Shaders/atmospheric_sky.shader | 2 +- Editor/resources/Shaders/volumetric.shader | 4 ++-- Nuake/src/Audio/AudioManager.cpp | 2 +- Nuake/src/Core/Physics/DynamicWorld.cpp | 24 ++++++++++++++----- Nuake/src/Core/Physics/PhysicsShapes.h | 4 ++-- Nuake/src/Rendering/SceneRenderer.cpp | 12 ++++++++++ Nuake/src/Scene/Scene.cpp | 2 ++ Nuake/src/Scene/Systems/PhysicsSystem.cpp | 1 + Nuake/src/Scripting/WrenScript.cpp | 2 +- 9 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Editor/resources/Shaders/atmospheric_sky.shader b/Editor/resources/Shaders/atmospheric_sky.shader index 86aea015..9ee94f63 100644 --- a/Editor/resources/Shaders/atmospheric_sky.shader +++ b/Editor/resources/Shaders/atmospheric_sky.shader @@ -155,5 +155,5 @@ void main() float L = escape(O, D, AtmosphereRadius); col = scatter(O, D, L, col); - FragColor = vec4(sqrt(col), 1.); + FragColor = vec4(sqrt(col * 4.0), 1.); } \ No newline at end of file diff --git a/Editor/resources/Shaders/volumetric.shader b/Editor/resources/Shaders/volumetric.shader index a711c536..941bd7bf 100644 --- a/Editor/resources/Shaders/volumetric.shader +++ b/Editor/resources/Shaders/volumetric.shader @@ -63,8 +63,8 @@ vec3 ComputeVolumetric(vec3 FragPos, Light light) vec3 rayVector = FragPos - startPosition; // Ray Direction float rayLength = length(rayVector); // Length of the raymarched - if(rayLength > 1000.0) - return vec3(1.0, 1.0, 1.0); + //if(rayLength > 1000.0) + // return vec3(0.0, 0.0, 0.0); float stepLength = rayLength / u_StepCount; // Step length vec3 rayDirection = rayVector / rayLength; vec3 step = rayDirection * stepLength; // Normalized to step length direction diff --git a/Nuake/src/Audio/AudioManager.cpp b/Nuake/src/Audio/AudioManager.cpp index d29ada24..d8672ea6 100644 --- a/Nuake/src/Audio/AudioManager.cpp +++ b/Nuake/src/Audio/AudioManager.cpp @@ -11,7 +11,7 @@ namespace Nuake _soloud = CreateRef(); _soloud->init(); - _audioThreadRunning = true; + _audioThreadRunning = false; _audioThread = std::thread(&AudioManager::AudioThreadLoop, this); } diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index 7c32c9c1..8553ab46 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -158,7 +158,7 @@ namespace Nuake // See: ContactListener virtual JPH::ValidateResult OnContactValidate(const JPH::Body& inBody1, const JPH::Body& inBody2, const JPH::CollideShapeResult& inCollisionResult) override { - std::cout << "Contact validate callback" << std::endl; + //std::cout << "Contact validate callback" << std::endl; // Allows you to ignore a contact before it is created (using layers to not make objects collide is cheaper!) return JPH::ValidateResult::AcceptAllContactsForThisBodyPair; @@ -166,17 +166,17 @@ namespace Nuake virtual void OnContactAdded(const JPH::Body& inBody1, const JPH::Body& inBody2, const JPH::ContactManifold& inManifold, JPH::ContactSettings& ioSettings) override { - std::cout << "A contact was added" << std::endl; + //std::cout << "A contact was added" << std::endl; } virtual void OnContactPersisted(const JPH::Body& inBody1, const JPH::Body& inBody2, const JPH::ContactManifold& inManifold, JPH::ContactSettings& ioSettings) override { - std::cout << "A contact was persisted" << std::endl; + //std::cout << "A contact was persisted" << std::endl; } virtual void OnContactRemoved(const JPH::SubShapeIDPair& inSubShapePair) override { - std::cout << "A contact was removed" << std::endl; + //std::cout << "A contact was removed" << std::endl; } }; @@ -282,10 +282,11 @@ namespace Nuake void DynamicWorld::AddCharacterController(Ref cc) { JPH::Ref settings = new JPH::CharacterSettings(); - settings->mMaxSlopeAngle = JPH::DegreesToRadians(45.0f); + settings->mMaxSlopeAngle = JPH::DegreesToRadians(cc->MaxSlopeAngle); settings->mLayer = Layers::MOVING; - settings->mFriction = 0.5f; + settings->mFriction = cc->Friction; settings->mShape = GetJoltShape(cc->Shape); + settings->mGravityFactor = 0.0f; auto& joltPos = JPH::Vec3(cc->Position.x, cc->Position.y, cc->Position.z); JPH::Character* character = new JPH::Character(settings, joltPos, JPH::Quat::sIdentity(), cc->GetEntity().GetID() , _JoltPhysicsSystem.get()); @@ -419,6 +420,17 @@ namespace Nuake _JoltBodyInterface->RemoveBodies(reinterpret_cast(_registeredBodies.data()), _registeredBodies.size()); _registeredBodies.clear(); + + if (_registeredCharacters.empty()) + { + return; + } + + for (auto& character : _registeredCharacters) + { + character.second->RemoveFromPhysicsSystem(); + } + _registeredCharacters.clear(); } void DynamicWorld::MoveAndSlideCharacterController(const Entity& entity, const Vector3 velocity) diff --git a/Nuake/src/Core/Physics/PhysicsShapes.h b/Nuake/src/Core/Physics/PhysicsShapes.h index 91570d1e..f21c28b3 100644 --- a/Nuake/src/Core/Physics/PhysicsShapes.h +++ b/Nuake/src/Core/Physics/PhysicsShapes.h @@ -23,13 +23,13 @@ namespace Nuake class Box : public PhysicShape { private: - glm::vec3 Size; + Vector3 Size; public: Box(); Box(glm::vec3 size); Box(float x, float y, float z); - glm::vec3 GetSize() const { return Size; } + Vector3 GetSize() const { return Size; } }; class Sphere : public PhysicShape diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 7cbcb5c3..14f4ad78 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -93,6 +93,18 @@ namespace Nuake { } framebuffer.Unbind(); } + else + { + framebuffer.Bind(); + { + RenderCommand::Clear(); + Shader* shader = ShaderManager::GetShader("resources/Shaders/copy.shader"); + shader->Bind(); + + shader->SetUniformTex("u_Source", finalOutput.get(), 0); + Renderer::DrawQuad(); + } + } finalOutput = framebuffer.GetTexture(); diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 460db10f..21d1062b 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -91,8 +91,10 @@ namespace Nuake { { for (auto& system : m_Systems) { + Logger::Log("Init system"); if (!system->Init()) { + return false; } } diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 29d80313..3b1a4382 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -211,6 +211,7 @@ namespace Nuake auto [transform, rigidBodyComponent] = view.get(e); Entity ent = Entity({ e, m_Scene }); Ref rigidBody; + if (ent.HasComponent()) { float mass = rigidBodyComponent.Mass; diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index 1d5bfec1..687f8937 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -120,7 +120,7 @@ namespace Nuake { void WrenScript::CallExit() { - if (!CompiledSuccesfully) + if (!CompiledSuccesfully || !m_Instance) return; WrenVM* vm = ScriptingEngine::GetWrenVM();