diff --git a/Assets/Shaders/DeferredComposite_CS.glsl b/Assets/Shaders/DeferredComposite_CS.glsl index d28eaec0..50a269ac 100644 --- a/Assets/Shaders/DeferredComposite_CS.glsl +++ b/Assets/Shaders/DeferredComposite_CS.glsl @@ -60,7 +60,7 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV if (fragPosLightPOV.z > sampledDepth && fragPosLightPOV.w > 0.0f) { - return 0.0f; + return 0.7f; } else return 1.0f; diff --git a/Assets/Shaders/DeferredComposite_CS.shshaderb b/Assets/Shaders/DeferredComposite_CS.shshaderb index ceca4e13..7f06b471 100644 Binary files a/Assets/Shaders/DeferredComposite_CS.shshaderb and b/Assets/Shaders/DeferredComposite_CS.shshaderb differ diff --git a/Assets/Shaders/ShadowMap_FS.glsl b/Assets/Shaders/ShadowMap_FS.glsl new file mode 100644 index 00000000..f514c70b --- /dev/null +++ b/Assets/Shaders/ShadowMap_FS.glsl @@ -0,0 +1,10 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable +#extension GL_EXT_nonuniform_qualifier : require + + +void main() +{ + +} \ No newline at end of file diff --git a/Assets/Shaders/ShadowMap_FS.shshaderb b/Assets/Shaders/ShadowMap_FS.shshaderb new file mode 100644 index 00000000..45304832 Binary files /dev/null and b/Assets/Shaders/ShadowMap_FS.shshaderb differ diff --git a/Assets/Shaders/ShadowMap_FS.shshaderb.shmeta b/Assets/Shaders/ShadowMap_FS.shshaderb.shmeta new file mode 100644 index 00000000..902f7f6d --- /dev/null +++ b/Assets/Shaders/ShadowMap_FS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ShadowMap_FS +ID: 45925790 +Type: 2 diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index e97d9eb4..ffc4bacc 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -5,6 +5,7 @@ //#define SHEDITOR #ifdef SHEDITOR #include "Editor/SHEditor.h" +#include "Physics/System/SHPhysicsDebugDrawSystem.h" //#include "Scenes/SBEditorScene.h" #endif // SHEDITOR @@ -31,7 +32,6 @@ #include "Input/SHInputManager.h" #include "Math/Transform/SHTransformSystem.h" #include "Physics/System/SHPhysicsSystem.h" -#include "Physics/System/SHPhysicsDebugDrawSystem.h" #include "Scripting/SHScriptEngine.h" #include "UI/SHUISystem.h" #include "Animation/SHAnimationSystem.h" @@ -74,12 +74,15 @@ namespace Sandbox #endif window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow, wndData); + + SHAssetManager::Load(); + // Create Systems SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); -#ifndef _PUBLISH +#ifdef SHEDITOR SHSystemManager::CreateSystem(); #endif @@ -122,7 +125,7 @@ namespace Sandbox SHSystemManager::RegisterRoutine(); SHSystemManager::RegisterRoutine(); -#ifndef _PUBLISH +#ifdef SHEDITOR SHSystemManager::RegisterRoutine(); #endif @@ -155,7 +158,6 @@ namespace Sandbox SHComponentManager::CreateComponentSparseSet(); //SHComponentManager::CreateComponentSparseSet(); - SHAssetManager::Load(); //auto font = SHAssetManager::GetData(176667660); SHSystemManager::RegisterRoutine(); diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp index b4330979..a7245123 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.cpp @@ -200,7 +200,9 @@ namespace SHADE void SHAudioSystem::ErrorCheck() const { if (result != FMOD_OK) - std::cerr << "Audio system error: " << FMOD_ErrorString(result) << std::endl; + { + SHLOG_ERROR( "Audio system error: {}", FMOD_ErrorString(result)) + } } void SHAudioSystem::PlayEventOnce(const char* path, bool isSFX, EntityID eid, bool spatial) @@ -319,6 +321,15 @@ namespace SHADE if (channel->isPlaying(&isPlaying) == FMOD_OK && isPlaying) channel->stop(); } + auto [begin, end] = audioClipLibrary.GetDenseAccess(); + for (auto it = begin; it != end; ++it) + { + if (it->instance) + { + it->instance->stop(FMOD_STUDIO_STOP_MODE::FMOD_STUDIO_STOP_IMMEDIATE); + it->instance->release(); + } + } masterGroup->stop(); } @@ -349,6 +360,10 @@ namespace SHADE audioClipHandle = audioClipLibrary.Create(); it->second->createInstance(&audioClipHandle->instance); } + else + { + SHLOG_ERROR("FMOD: Failed to find event path: {}", path) + } return audioClipHandle; } @@ -487,10 +502,12 @@ namespace SHADE } void SHAudioSystem::SetBgmVolume(float const bgmvol) { + bgmVolume = bgmvol; bgmChannelGroup->setVolume(bgmvol); } void SHAudioSystem::SetSfxVolume(float const sfxvol) { + sfxVolume = sfxvol; sfxChannelGroup->setVolume(sfxvol); } void SHAudioSystem::SetMasterVolume(float const mastervol) @@ -506,15 +523,12 @@ namespace SHADE { channel->setPaused(paused); } - for (auto const& event : eventMap) + auto [begin, end] = audioClipLibrary.GetDenseAccess(); + for (auto it = begin; it != end; ++it) { - int instanceCount = 0; - event.second->getInstanceCount(&instanceCount); - std::vector instances(instanceCount); - event.second->getInstanceList(instances.data(), static_cast(instances.size()), &instanceCount); - for (auto const& instance : instances) + if (it->instance) { - instance->setPaused(pause); + it->SetPause(pause); } } } @@ -546,6 +560,7 @@ namespace SHADE bank->loadSampleData(); int numOfEvents; bank->getEventCount(&numOfEvents); + if (numOfEvents > 0) { std::vector events(numOfEvents); @@ -560,11 +575,71 @@ namespace SHADE } } + float SHAudioSystem::GetVCAVolume(const char* path) + { + FMOD::Studio::VCA* vca = nullptr; + result = fmodStudioSystem->getVCA(path, &vca); + float volume = 0.0f; + if (result != FMOD_OK) + { + ErrorCheck(); + return volume; + } + result = vca->getVolume(&volume); + if (result != FMOD_OK) + { + ErrorCheck(); + return volume; + } + return volume; + } + + void SHAudioSystem::SetVCAVolume(const char* path, float value) + { + FMOD::Studio::VCA* vca = nullptr; + result = fmodStudioSystem->getVCA(path, &vca); + if (result != FMOD_OK) + { + ErrorCheck(); + return; + } + result = vca->setVolume(std::clamp(value, 0.0f, 1.0f)); + if (result != FMOD_OK) + { + ErrorCheck(); + return; + } + } + + float SHAudioSystem::GetParameterValue(const char* path) + { + float value = {}; + result = fmodStudioSystem->getParameterByName(path, &value); + if(result != FMOD_OK) + { + ErrorCheck(); + } + return value; + } + + void SHAudioSystem::SetParameter(const char* path, float value) + { + result = fmodStudioSystem->setParameterByName(path, value); + if (result != FMOD_OK) + { + ErrorCheck(); + } + } + void AudioClip::Play() { if(!instance) return; - instance->start(); + FMOD_RESULT result = instance->start(); + if (result != FMOD_OK) + { + SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + } } //void AudioClip::Play(bool isSfx) @@ -598,7 +673,11 @@ namespace SHADE { if (!instance) return; - instance->stop(fadeOut ? FMOD_STUDIO_STOP_ALLOWFADEOUT : FMOD_STUDIO_STOP_IMMEDIATE); + FMOD_RESULT result = instance->stop(fadeOut ? FMOD_STUDIO_STOP_ALLOWFADEOUT : FMOD_STUDIO_STOP_IMMEDIATE); + if (result != FMOD_OK) + { + SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + } } void AudioClip::SetPause(bool pause) @@ -623,7 +702,11 @@ namespace SHADE { if (!instance) return; - instance->setParameterByName(paramName, value); + FMOD_RESULT result = instance->setParameterByName(paramName, value); + if (result != FMOD_OK) + { + SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + } } //void AudioClip::SetParameterLabel(const char* paramName, const char* label) @@ -635,13 +718,33 @@ namespace SHADE float AudioClip::GetParameterValue(const char* paramName) { - if (!instance) - return {}; float value{}; - instance->getParameterByName(paramName, &value); + if (!instance) + return value; + auto result = instance->getParameterByName(paramName, &value); + if (result != FMOD_OK) + { + SHLOG_ERROR("Audio system error: {}", FMOD_ErrorString(result)) + } return value; } + float AudioClip::GetVolume() + { + float volume{}; + if(!instance) + return volume; + instance->getVolume(&volume); + return volume; + } + + void AudioClip::SetVolume(float volume) + { + if(!instance) + return; + instance->setVolume(volume); + } + SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent) { StopAllSounds(); diff --git a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h index 0c12cef4..5714a618 100644 --- a/SHADE_Engine/src/AudioSystem/SHAudioSystem.h +++ b/SHADE_Engine/src/AudioSystem/SHAudioSystem.h @@ -35,6 +35,8 @@ namespace SHADE void SetParameter(const char* paramName, float value); //void SetParameterLabel(const char* paramName, const char* label); float GetParameterValue(const char* paramName); + float GetVolume(); + void SetVolume(float volume); friend class SHAudioSystem; private: FMOD::Studio::EventInstance* instance = nullptr; @@ -85,7 +87,13 @@ namespace SHADE void SetPaused(bool pause); bool GetPaused() const; SHVec3 GetListenerPosition(); + void LoadBank(const char* path); + float GetVCAVolume(const char* path); + void SetVCAVolume(const char* path, float value); + + float GetParameterValue(const char* path); + void SetParameter(const char* path, float value); private: FMOD::Studio::System* fmodStudioSystem; diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h index 995a1cf5..d02ba3d5 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHSystemManager.h @@ -94,7 +94,7 @@ namespace SHADE if (systemContainer.find(id) == systemContainer.end()) { - std::cout << "System Manager error: System Version " << version << " does not exit." << std::endl; + std::cout << "System Manager error: System Version " << typeid(T).name() << ", " << version << " does not exist." << std::endl; return nullptr; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6734a77e..99685585 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -128,6 +128,7 @@ namespace SHADE SHFreetypeInstance::Init(); //SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAOBlur_CS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/PureCopy_CS.glsl", false); @@ -137,6 +138,7 @@ namespace SHADE //SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/Text_VS.glsl", false); + // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); static constexpr AssetID VS_ANIM = 47911992; animtVertShader = SHResourceManager::LoadOrGet(VS_ANIM); @@ -151,7 +153,8 @@ namespace SHADE static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); - static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); + static constexpr AssetID SHADOW_MAP_VS = 44646107; shadowMapVS = SHResourceManager::LoadOrGet(SHADOW_MAP_VS); + static constexpr AssetID SHADOW_MAP_FS = 45925790; shadowMapFS = SHResourceManager::LoadOrGet(SHADOW_MAP_FS); } @@ -583,14 +586,21 @@ namespace SHADE #endif } - //if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::B)) - //{ - // auto& lightComps = SHComponentManager::GetDense(); - // for (auto& comp : lightComps) - // { - // comp.SetEnableShadow(true); - // } - //} + static bool shadowAdded = false; + + if (shadowAdded == false/* && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B)*/) + { + shadowAdded = true; + auto& lightComps = SHComponentManager::GetDense(); + if (lightComps.size() > 2) + { + lightComps[2].SetEnableShadow(true); + } + //for (auto& comp : lightComps) + //{ + // comp.SetEnableShadow(true); + //} + } renderGraph->Begin(frameIndex); auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); @@ -809,11 +819,11 @@ namespace SHADE tempLibrary.Init(device); tempLibrary.CreateGraphicsPipelines ( - { shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, + { shadowMapVS, shadowMapFS }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::SystemType::BATCHING, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState ); - shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} }); + shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS }); } newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index d72dfcbd..a35065bd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -469,6 +469,7 @@ namespace SHADE Handle renderToSwapchainVS; Handle renderToSwapchainFS; Handle shadowMapVS; + Handle shadowMapFS; // Fonts Handle testFont; diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h index 312c3625..c80e5d5c 100644 --- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h +++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.h @@ -169,11 +169,8 @@ namespace SHADE SHPhysicsObjectManager objectManager; SHCollisionListener collisionListener; SHRaycaster raycaster; - - // For the debug drawer to draw rays - #ifdef SHEDITOR + std::vector raycastHits; - #endif /*---------------------------------------------------------------------------------*/ /* Function Members */ diff --git a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp index 435cb6fb..2bdeaa5c 100644 --- a/SHADE_Engine/src/Scripting/SHScriptEngine.cpp +++ b/SHADE_Engine/src/Scripting/SHScriptEngine.cpp @@ -62,9 +62,9 @@ namespace SHADE loadFunctions(); // Generate script assembly if it hasn't been before -#ifndef _PUBLISH + #ifndef _PUBLISH BuildScriptAssembly(); -#endif + #endif // Initialise the CSharp Engine csEngineInit(); @@ -261,6 +261,7 @@ namespace SHADE net5.0\n\ x64\n\ Release;Debug\n\ + $(DefaultItemExcludes);**/*.shmeta\n\ \n\ \n\ .\\bin\\Release\n\ @@ -283,7 +284,6 @@ namespace SHADE \n\ \n\ \n\ - \n\ \n\ \n\ \n"; diff --git a/SHADE_Managed/src/Audio/Audio.cxx b/SHADE_Managed/src/Audio/Audio.cxx index 9432886f..c3994cd4 100644 --- a/SHADE_Managed/src/Audio/Audio.cxx +++ b/SHADE_Managed/src/Audio/Audio.cxx @@ -99,6 +99,31 @@ namespace SHADE audioSys->StopAllSounds(); } + float Audio::GetVCAVolume(System::String^ path) + { + auto audioSys = SHSystemManager::GetSystem(); + + return audioSys->GetVCAVolume(Convert::ToNative(path).data()); + } + + void Audio::SetVCAVolume(System::String^ path, float volume) + { + auto audioSys = SHSystemManager::GetSystem(); + audioSys->SetVCAVolume(Convert::ToNative(path).data(), volume); + } + + float Audio::GetParameterValue(System::String^ path) + { + auto audioSys = SHSystemManager::GetSystem(); + return audioSys->GetParameterValue(Convert::ToNative(path).data()); + } + + void Audio::SetParameter(System::String^ path, float value) + { + auto audioSys = SHSystemManager::GetSystem(); + audioSys->SetParameter(Convert::ToNative(path).data(), value); + } + AudioClipHandler Audio::CreateAudioClip(System::String^ path) { auto audioSys = SHSystemManager::GetSystem(); diff --git a/SHADE_Managed/src/Audio/Audio.hxx b/SHADE_Managed/src/Audio/Audio.hxx index a8c94156..179a3eb7 100644 --- a/SHADE_Managed/src/Audio/Audio.hxx +++ b/SHADE_Managed/src/Audio/Audio.hxx @@ -101,6 +101,10 @@ namespace SHADE /// static void StopAllSounds(); + static float GetVCAVolume(System::String^ path); + static void SetVCAVolume(System::String^ path, float volume); + static float GetParameterValue(System::String^ path); + static void SetParameter(System::String^ path, float value); //to comment ltr static AudioClipHandler CreateAudioClip(System::String^ path); diff --git a/SHADE_Managed/src/Audio/AudioClip.cxx b/SHADE_Managed/src/Audio/AudioClip.cxx index 021a3437..7ed58714 100644 --- a/SHADE_Managed/src/Audio/AudioClip.cxx +++ b/SHADE_Managed/src/Audio/AudioClip.cxx @@ -84,6 +84,14 @@ namespace SHADE return NativeObject->GetParameterValue(Convert::ToNative(paramName).data()); } + float AudioClipHandler::GetVolume() + { + return NativeObject->GetVolume(); + } + void AudioClipHandler::SetVolume(float volume) + { + NativeObject->SetVolume(volume); + } } \ No newline at end of file diff --git a/SHADE_Managed/src/Audio/AudioClip.hxx b/SHADE_Managed/src/Audio/AudioClip.hxx index 09f6a2d1..34e9b4a5 100644 --- a/SHADE_Managed/src/Audio/AudioClip.hxx +++ b/SHADE_Managed/src/Audio/AudioClip.hxx @@ -72,6 +72,8 @@ namespace SHADE bool IsPaused(); void SetParameter(System::String^ paramName, float value); float GetParameterValue(System::String^ paramName); + float GetVolume(); + void SetVolume(float volume); protected: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Engine/Application.cxx b/SHADE_Managed/src/Engine/Application.cxx index 06ad632f..5bde66d2 100644 --- a/SHADE_Managed/src/Engine/Application.cxx +++ b/SHADE_Managed/src/Engine/Application.cxx @@ -28,25 +28,32 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ bool Application::IsPlaying::get() { +#ifdef SHEDITOR auto editor = SHSystemManager::GetSystem(); if (editor) return editor->editorState == SHEditor::State::PLAY || editor->editorState == SHEditor::State::PAUSE; +#endif return true; } bool Application::IsPaused::get() { +#ifdef SHEDITOR auto editor = SHSystemManager::GetSystem(); if (editor) return editor->editorState == SHEditor::State::PAUSE; - +#endif return false; } bool Application::IsEditor::get() { +#ifdef SHEDITOR return SHSystemManager::GetSystem() != nullptr; +#else + return false; +#endif } int Application::WindowWidth::get() {