Implemented Shadow maps (still needs improvement) #314
|
@ -1,4 +1,4 @@
|
||||||
Start in Fullscreen: false
|
Start in Fullscreen: false
|
||||||
Starting Scene ID: 87285316
|
Starting Scene ID: 86098106
|
||||||
Window Size: {x: 1920, y: 1080}
|
Window Size: {x: 1920, y: 1080}
|
||||||
Window Title: SHADE Engine
|
Window Title: SHADE Engine
|
|
@ -8440,10 +8440,15 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
|
Transform Component:
|
||||||
|
Translate: {x: 2.05652523, y: 1.65113854, z: -6.62914371}
|
||||||
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
|
IsActive: true
|
||||||
Light Component:
|
Light Component:
|
||||||
Position: {x: 0, y: 0, z: 0}
|
Position: {x: 0, y: 1.5, z: -6.71799994}
|
||||||
Type: Directional
|
Type: Directional
|
||||||
Direction: {x: 15, y: 90, z: 15}
|
Direction: {x: 0, y: 0, z: -1.11899996}
|
||||||
Color: {x: 1, y: 1, z: 1, w: 1}
|
Color: {x: 1, y: 1, z: 1, w: 1}
|
||||||
Layer: 4294967295
|
Layer: 4294967295
|
||||||
Strength: 1
|
Strength: 1
|
||||||
|
|
|
@ -52,7 +52,19 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV
|
||||||
{
|
{
|
||||||
vec4 fragPosLightPOV = lightPV * worldSpaceFragPos;
|
vec4 fragPosLightPOV = lightPV * worldSpaceFragPos;
|
||||||
vec3 converted = (fragPosLightPOV.xyz / fragPosLightPOV.w) * vec3(0.5f) + vec3(0.5f);
|
vec3 converted = (fragPosLightPOV.xyz / fragPosLightPOV.w) * vec3(0.5f) + vec3(0.5f);
|
||||||
return step (fragPosLightPOV.z, texture(shadowMap, converted.xy).r);
|
|
||||||
|
float sampledDepth = texture(shadowMap, converted.xy).r;
|
||||||
|
|
||||||
|
if (converted.x < 0.0f || converted.x > 1.0f || converted.y < 0.0f || converted.y > 1.0f)
|
||||||
|
return 1.0f;
|
||||||
|
|
||||||
|
if (fragPosLightPOV.z > sampledDepth && fragPosLightPOV.w > 0.0f)
|
||||||
|
{
|
||||||
|
return 0.3f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 1.0f;
|
||||||
|
// return step (fragPosLightPOV.z, );
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
Binary file not shown.
|
@ -315,7 +315,7 @@ namespace SHADE
|
||||||
|
|
||||||
//camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f);
|
//camera.perspProjMatrix = SHMatrix::OrthographicLH(9.0f, 9.0f, 0.1f, 20.0f);
|
||||||
camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
|
camera.orthoProjMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
|
||||||
//camera.perspProjMatrix = SHMatrix::OrthographicLH(4.0f, 4.0f, 0.1f, 200.0f);
|
//camera.perspProjMatrix = SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f);
|
||||||
//camera.projMatrix.Transpose();
|
//camera.projMatrix.Transpose();
|
||||||
|
|
||||||
camera.dirtyProj = false;
|
camera.dirtyProj = false;
|
||||||
|
|
|
@ -181,6 +181,8 @@ namespace SHADE
|
||||||
// Create Default Viewport
|
// Create Default Viewport
|
||||||
worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
|
worldViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(window->GetWindowSize().first), static_cast<float>(window->GetWindowSize().second), 0.0f, 1.0f));
|
||||||
|
|
||||||
|
shadowMapViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast<float>(SHLightingSubSystem::SHADOW_MAP_WIDTH), static_cast<float>(SHLightingSubSystem::SHADOW_MAP_HEIGHT), 0.0f, 1.0f));
|
||||||
|
|
||||||
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
std::vector<Handle<SHVkCommandPool>> renderContextCmdPools{ swapchain->GetNumImages() };
|
||||||
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -781,7 +783,7 @@ namespace SHADE
|
||||||
auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data());
|
auto shadowMapNode = renderGraph->AddNodeAfter(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data() + resourceName, {resourceName.c_str()}, SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data());
|
||||||
|
|
||||||
// Add a subpass to render to that shadow map
|
// Add a subpass to render to that shadow map
|
||||||
auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", worldViewport, lightComp->GetRenderer());
|
auto newSubpass = shadowMapNode->RuntimeAddSubpass(resourceName + " Subpass", shadowMapViewport, lightComp->GetRenderer());
|
||||||
newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH);
|
newSubpass->AddDepthOutput(resourceName, SH_RENDER_GRAPH_RESOURCE_FLAGS::DEPTH);
|
||||||
|
|
||||||
// regenerate the node
|
// regenerate the node
|
||||||
|
@ -793,8 +795,11 @@ namespace SHADE
|
||||||
SHPipelineLibrary tempLibrary{};
|
SHPipelineLibrary tempLibrary{};
|
||||||
Handle<SHRenderGraphNode> rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data());
|
Handle<SHRenderGraphNode> rgNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SHADOW_MAP_PASS.data());
|
||||||
|
|
||||||
|
SHRasterizationState rasterState{};
|
||||||
|
rasterState.cull_mode = vk::CullModeFlagBits::eBack;
|
||||||
|
|
||||||
tempLibrary.Init(device);
|
tempLibrary.Init(device);
|
||||||
tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState());
|
tempLibrary.CreateGraphicsPipelines({ shadowMapVS, {} }, shadowMapNode->GetRenderpass(), newSubpass, SHGraphicsPredefinedData::GetShadowMapViState(), rasterState);
|
||||||
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} });
|
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, {} });
|
||||||
}
|
}
|
||||||
newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline
|
newSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline
|
||||||
|
|
|
@ -441,6 +441,7 @@ namespace SHADE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Handle<SHViewport> worldViewport; // Whole screen
|
Handle<SHViewport> worldViewport; // Whole screen
|
||||||
|
Handle<SHViewport> shadowMapViewport;
|
||||||
std::vector<Handle<SHViewport>> viewports; // Additional viewports
|
std::vector<Handle<SHViewport>> viewports; // Additional viewports
|
||||||
|
|
||||||
// Renderers
|
// Renderers
|
||||||
|
|
|
@ -395,7 +395,7 @@ namespace SHADE
|
||||||
switch (lightComp->GetLightData().type)
|
switch (lightComp->GetLightData().type)
|
||||||
{
|
{
|
||||||
case SH_LIGHT_TYPE::DIRECTIONAL:
|
case SH_LIGHT_TYPE::DIRECTIONAL:
|
||||||
return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, lightComp->GetLightData().direction, SHVec3(0.0f, -1.0f, 0.0f)));
|
return SHMatrix::Transpose(SHMatrix::LookAtLH(lightComp->GetLightData().position, SHVec3::Normalise (lightComp->GetLightData().direction), SHVec3(0.0f, -1.0f, 0.0f)));
|
||||||
//return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f)));
|
//return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f)));
|
||||||
case SH_LIGHT_TYPE::POINT:
|
case SH_LIGHT_TYPE::POINT:
|
||||||
return {};
|
return {};
|
||||||
|
@ -518,7 +518,7 @@ namespace SHADE
|
||||||
if (auto renderer = light.GetRenderer())
|
if (auto renderer = light.GetRenderer())
|
||||||
{
|
{
|
||||||
//SHMatrix orthoMatrix = SHMatrix::OrthographicRH()
|
//SHMatrix orthoMatrix = SHMatrix::OrthographicRH()
|
||||||
renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(5.0f, 5.0f, 0.1f, 20.0f));
|
renderer->UpdateDataManual(frameIndex, GetViewMatrix(&light), SHMatrix::OrthographicLH(30.0f, 30.0f, 1.0f, 50.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type);
|
auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
||||||
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/) noexcept
|
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass, SHVertexInputState const& viState/* = SHGraphicsPredefinedData::GetDefaultViState()*/, SHRasterizationState const& rasterState) noexcept
|
||||||
{
|
{
|
||||||
std::vector<Handle<SHVkShaderModule>> modules{};
|
std::vector<Handle<SHVkShaderModule>> modules{};
|
||||||
if (vsFsPair.first)
|
if (vsFsPair.first)
|
||||||
|
@ -54,6 +54,8 @@ namespace SHADE
|
||||||
|
|
||||||
newPipeline->GetPipelineState().SetColorBlenState(colorBlendState);
|
newPipeline->GetPipelineState().SetColorBlenState(colorBlendState);
|
||||||
|
|
||||||
|
newPipeline->GetPipelineState().SetRasterizationState(rasterState);
|
||||||
|
|
||||||
// Actually construct the pipeline
|
// Actually construct the pipeline
|
||||||
newPipeline->ConstructPipeline();
|
newPipeline->ConstructPipeline();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ namespace SHADE
|
||||||
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
|
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
|
||||||
Handle<SHVkRenderpass> renderpass,
|
Handle<SHVkRenderpass> renderpass,
|
||||||
Handle<SHSubpass> subpass,
|
Handle<SHSubpass> subpass,
|
||||||
SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState()
|
SHVertexInputState const& viState = SHGraphicsPredefinedData::GetDefaultViState(),
|
||||||
|
SHRasterizationState const& rasterState = SHRasterizationState{}
|
||||||
) noexcept;
|
) noexcept;
|
||||||
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
|
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
|
||||||
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
|
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
|
||||||
|
|
Loading…
Reference in New Issue