Implemented shadows. Light components can enable shadows through editor. #406

Merged
Xenosas1337 merged 7 commits from SP3-1-Rendering into main 2023-03-08 14:17:15 +08:00
3 changed files with 15 additions and 7 deletions
Showing only changes of commit 2bba48b09f - Show all commits

View File

@ -30,5 +30,5 @@ constexpr SHEventIdentifier SH_BUTTON_RELEASE_EVENT { 21 };
constexpr SHEventIdentifier SH_BUTTON_HOVER_ENTER_EVENT { 22 };
constexpr SHEventIdentifier SH_BUTTON_HOVER_EXIT_EVENT { 23 };
constexpr SHEventIdentifier SH_ASSET_COMPILE_EVENT { 24 };
constexpr SHEventIdentifier SH_LIGHT_DELETE_EVENT { 25 };
constexpr SHEventIdentifier SH_GRAPHICS_LIGHT_DELETE_EVENT { 25 };

View File

@ -542,7 +542,7 @@ namespace SHADE
std::make_shared<SHEventReceiverSpec<SHGraphicsSystem>>(this, &SHGraphicsSystem::ReceiveLightDeleteEvent)
};
ReceiverPtr lightDeleteReceivePtr = std::dynamic_pointer_cast<SHEventReceiver>(lightDeleteEvent);
SHEventManager::SubscribeTo(SH_ASSET_COMPILE_EVENT, lightDeleteReceivePtr);
SHEventManager::SubscribeTo(SH_GRAPHICS_LIGHT_DELETE_EVENT, lightDeleteReceivePtr);
std::shared_ptr<SHEventReceiverSpec<SHGraphicsSystem>> compileAssetReceiever
@ -951,19 +951,19 @@ namespace SHADE
auto const& EVENT_DATA = reinterpret_cast<const SHEventSpec<SHLightShadowEvent>*>(eventPtr.get())->data;
auto* lightComp = SHComponentManager::GetComponent<SHLightComponent>(EVENT_DATA->lightEntity);
if (lightComp && lightComp->GetShadowMapIndex())
if (lightComp && lightComp->GetShadowMapIndex() != SHLightData::INVALID_SHADOW_MAP_INDEX)
{
std::string depthResourceName = "ShadowMap_Depth " + std::to_string(EVENT_DATA->lightEntity);
std::string shadowMapResourceName = "ShadowMap " + std::to_string(EVENT_DATA->lightEntity);
std::string shadowMapBlurredResourceName = "ShadowMap Blurred" + std::to_string(EVENT_DATA->lightEntity);
// Remove render graph node
renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName);
//renderGraph->RemoveNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName);
// Remove render graph resource
renderGraph->RemoveResource(depthResourceName);
renderGraph->RemoveResource(shadowMapResourceName);
renderGraph->RemoveResource(shadowMapBlurredResourceName);
//renderGraph->RemoveResource(depthResourceName);
//renderGraph->RemoveResource(shadowMapResourceName);
//renderGraph->RemoveResource(shadowMapBlurredResourceName);
// Register light component shadow map index into light system as recyclable
lightingSubSystem->RemoveShadowMap (EVENT_DATA->lightEntity);

View File

@ -21,6 +21,14 @@ namespace SHADE
void SHLightComponent::OnDestroy(void)
{
if (lightData.shadowMapIndex != SHLightData::INVALID_SHADOW_MAP_INDEX)
{
// Create new event and broadcast it
SHDeleteLightEvent newEvent;
newEvent.lightEntity = GetEID();
SHEventManager::BroadcastEvent<SHDeleteLightEvent>(newEvent, SH_GRAPHICS_LIGHT_DELETE_EVENT);
}
}