Fixed Shadow bugs and implemented scripting for trajectory rendering #407
|
@ -45,14 +45,14 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0.242245644, y: 1.56757355, z: -6.07086945}
|
||||
Translate: {x: 0.236000001, y: 1.56757355, z: -6.07086945}
|
||||
Rotate: {x: -0, y: 0, z: -0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
Light Component:
|
||||
Position: {x: 2, y: 1.5, z: -5.5999999}
|
||||
Type: Directional
|
||||
Direction: {x: 0, y: 0, z: -1}
|
||||
Direction: {x: -0.0780000016, y: 0.159999996, z: -1}
|
||||
Color: {x: 0, y: 0, z: 0, w: 1}
|
||||
Layer: 4294967295
|
||||
Strength: 1
|
||||
|
|
|
@ -73,9 +73,12 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV
|
|||
|
||||
float worldNormalDotLight = dot (normalize (worldNormal), normalize(lightDir));
|
||||
|
||||
if (worldNormalDotLight < 0.0f)
|
||||
if (worldNormalDotLight <= 0.0f)
|
||||
return 0.7f;
|
||||
|
||||
// if (worldNormalDotLight <= 0.01f)
|
||||
// return 0.7f;
|
||||
|
||||
if (fragPosLightPOV.z > moments.x && fragPosLightPOV.w > 0.0f)
|
||||
{
|
||||
float p = step (fragPosLightPOV.z, moments.x);
|
||||
|
@ -94,6 +97,7 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
// return min (worldNormalDotLight + 0.7f, 1.0f);
|
||||
return 1.0f;
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -77,7 +77,7 @@ void main()
|
|||
worldSpacePosition = In.worldPos;
|
||||
|
||||
outEntityID = In2.eid;
|
||||
lightLayerIndices = uvec4 (In2.lightLayerIndex, 0, 0, 1);
|
||||
lightLayerIndices = uvec4 (In2.lightLayerIndex, packHalf2x16 (In.worldNormal.xy), packHalf2x16 (vec2 (In.worldNormal.z, 1.0f)), 1);
|
||||
|
||||
// float vpHeight = float (In2.screenSpacePos.y) - MatProp.data[In2.materialIndex].highlightPosition;
|
||||
// bring the frame of reference to the object's screen space pos
|
||||
|
|
Binary file not shown.
|
@ -865,32 +865,30 @@ namespace SHADE
|
|||
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);
|
||||
Handle<SHSubpass> gBufferWriteSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS);
|
||||
Handle<SHSubpass> gBufferWriteVfxSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_VFX_SUBPASS);
|
||||
|
||||
// we need to wait for the device to finish using the graph first
|
||||
device->WaitIdle();
|
||||
|
||||
|
||||
if (EVENT_DATA->enableShadow)
|
||||
{
|
||||
// When the light first enables shadow rendering, we need to prepare the relevant objects to render shadows; namely renderpasses and subpasses, pipelines and descriptor sets
|
||||
if (EVENT_DATA->firstEnable)
|
||||
{
|
||||
// we need to wait for the device to finish using the graph first
|
||||
device->WaitIdle();
|
||||
Handle<SHSubpass> gBufferWriteSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS);
|
||||
Handle<SHSubpass> gBufferWriteVfxSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_VFX_SUBPASS);
|
||||
|
||||
|
||||
// Create new renderer for the light component and give it to the light component
|
||||
Handle<SHRenderer> newRenderer = resourceManager.Create<SHRenderer>(device, swapchain->GetNumImages(), descPool, SHRenderer::PROJECTION_TYPE::ORTHOGRAPHIC);
|
||||
lightComp->SetRenderer(newRenderer);
|
||||
|
||||
// assign shadow map index to light component
|
||||
lightComp->SetShadowMapIndex(lightingSubSystem->GetNumShadowMaps());
|
||||
|
||||
|
||||
// Add the shadow map resource to the graph
|
||||
renderGraph->AddResource(depthResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eD32Sfloat);
|
||||
renderGraph->AddResource(shadowMapResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat);
|
||||
renderGraph->AddResource(shadowMapBlurredResourceName, { SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR, SH_RENDER_GRAPH_RESOURCE_FLAGS::INPUT, SH_RENDER_GRAPH_RESOURCE_FLAGS::STORAGE }, false, SHLightingSubSystem::SHADOW_MAP_WIDTH, SHLightingSubSystem::SHADOW_MAP_HEIGHT, vk::Format::eR32G32B32A32Sfloat);
|
||||
|
||||
|
||||
|
||||
// link resource to node. This means linking the resource and regenerating the node's renderpass and framebuffer.
|
||||
auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + shadowMapResourceName, { depthResourceName.c_str(), shadowMapResourceName.c_str(), shadowMapBlurredResourceName.c_str() }, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data());
|
||||
|
||||
|
@ -929,6 +927,10 @@ namespace SHADE
|
|||
// add the shadow map and the blurred version to the lighting system
|
||||
uint32_t const NEW_SHADOW_MAP_INDEX = lightingSubSystem->AddShadowMap(renderGraph->GetRenderGraphResource(shadowMapBlurredResourceName), EVENT_DATA->lightEntity);
|
||||
|
||||
// assign shadow map index to light component
|
||||
lightComp->SetShadowMapIndex(NEW_SHADOW_MAP_INDEX);
|
||||
|
||||
|
||||
// Get deferred composite node compute and modify descriptor set
|
||||
auto nodeCompute = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data())->GetNodeCompute(SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_COMPUTE.data());
|
||||
nodeCompute->ModifyWriteDescImageComputeResource(SHGraphicsConstants::DescriptorSetBindings::SHADOW_MAP_IMAGE_SAMPLER_DATA, lightingSubSystem->GetViewSamplerLayout(NEW_SHADOW_MAP_INDEX), NEW_SHADOW_MAP_INDEX);
|
||||
|
@ -964,12 +966,12 @@ namespace SHADE
|
|||
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);
|
||||
|
|
|
@ -62,7 +62,6 @@ namespace SHADE
|
|||
// write view projection matrix if renderer is available
|
||||
auto lightRenderer = lightComp->GetRenderer();
|
||||
if (lightRenderer)
|
||||
{
|
||||
lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix;
|
||||
|
||||
// Boolean to cast shadows in first 8 bits (1 byte)
|
||||
|
@ -70,7 +69,6 @@ namespace SHADE
|
|||
|
||||
// Next 24 bits for shadow map index
|
||||
lightPtr->shadowData |= (lightData.shadowMapIndex << 8);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SH_LIGHT_TYPE::POINT:
|
||||
|
|
|
@ -111,7 +111,6 @@ namespace SHADE
|
|||
renderGraphStorage->graphResources->at(resourceName).Free();
|
||||
renderGraphStorage->graphResources->erase (resourceName);
|
||||
|
||||
resourceHdl.Free ();
|
||||
/*
|
||||
* IMPORTANT NOTES
|
||||
*
|
||||
|
@ -134,8 +133,11 @@ namespace SHADE
|
|||
// Get handle to node since it exists
|
||||
auto nodeHdl = nodes[nodeIndexing[nodeName]];
|
||||
|
||||
nodes.erase(nodes.begin() + nodeIndexing[nodeName]);
|
||||
|
||||
nodeHdl.Free();
|
||||
nodeIndexing.erase(nodeName);
|
||||
|
||||
ReindexNodes();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue