Implemented Shadows (f0kin finally)

This commit is contained in:
Brandon Mak 2023-03-07 17:39:51 +08:00
parent 826df94c96
commit b6b2c75fc3
7 changed files with 38 additions and 25 deletions

View File

@ -32,10 +32,11 @@ layout(location = 0) in struct
vec2 uv; // location = 1
vec4 normal; // location = 2
vec4 worldPos; // location = 3
vec3 worldNormal; // location = 4
} In;
// material stuff
layout(location = 4) flat in struct
layout(location = 5) flat in struct
{
int materialIndex;
uint eid;
@ -72,10 +73,11 @@ void main()
{
position = In.vertPos;
normals = In.normal;
albedo = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv);
albedo = vec4 (texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv).xyz, 1.0f);
worldSpacePosition = In.worldPos;
outEntityID = In2.eid;
lightLayerIndices = uvec4 (In2.lightLayerIndex, 0, 0, 1);
// float vpHeight = float (In2.screenSpacePos.y) - MatProp.data[In2.materialIndex].highlightPosition;
// bring the frame of reference to the object's screen space pos
@ -100,4 +102,6 @@ void main()
}
else
objectVFX = vec4(0.0f, 0.0f, 0.0f, 1.0f);
objectVFX.a = 1.0f;
}

View File

@ -17,6 +17,7 @@ layout(location = 0) out struct
vec2 uv; // location = 1
vec4 normal; // location = 2
vec4 worldPos; // location = 3
vec3 worldNormal; // location = 4
} Out;
@ -36,7 +37,7 @@ struct GenericData
};
// material stuff
layout(location = 4) out struct
layout(location = 5) out struct
{
int materialIndex;
uint eid;
@ -76,11 +77,13 @@ void main()
// uvs for texturing in fragment shader
Out.uv = aUV;
mat3 transposeInv = mat3 (transpose(inverse(modelViewMat)));
mat3 mvTransInv = mat3 (transpose(inverse(modelViewMat)));
mat3 modelTransInv = mat3 (transpose(inverse(worldTransform)));
// normals are also in view space
Out.normal.rgb = transposeInv * aNormal.rgb;
Out.normal.rgb = mvTransInv * aNormal.rgb;
Out.normal.rgb = normalize (Out.normal.rgb);
Out.worldNormal = normalize (modelTransInv * aNormal);
// Get center of object in world position
vec4 worldPos = vec4(worldTransform[3][0], worldTransform[3][1], worldTransform[3][2], 1.0f);

View File

@ -128,7 +128,7 @@ namespace SHADE
SHFreetypeInstance::Init();
//SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false);
@ -870,7 +870,8 @@ 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> companionSubpass = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data())->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_WRITE_SUBPASS);
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);
if (EVENT_DATA->generateRenderer)
{
@ -929,7 +930,8 @@ namespace SHADE
);
shadowMapPipeline = tempLibrary.GetGraphicsPipeline({ shadowMapVS, shadowMapFS, shadowMapDrawSubpass });
}
shadowMapDrawSubpass->SetCompanionSubpass(companionSubpass, shadowMapPipeline); // set companion subpass and pipeline
shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteSubpass, shadowMapPipeline); // set companion subpass and pipeline
shadowMapDrawSubpass->AddCompanionSubpass(gBufferWriteVfxSubpass, shadowMapPipeline); // set companion subpass and pipeline
// 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);

View File

@ -77,7 +77,7 @@ namespace SHADE
, name { rhs.name }
, viewport {rhs.viewport}
, renderer {rhs.renderer}
, companionSubpass {rhs.companionSubpass}
, companionSubpasses {std::move (rhs.companionSubpasses)}
, dummyPipelineLayout{rhs.dummyPipelineLayout}
{
@ -115,7 +115,7 @@ namespace SHADE
name = std::move(rhs.name);
renderer = rhs.renderer;
viewport = rhs.viewport;
companionSubpass = rhs.companionSubpass;
companionSubpasses = rhs.companionSubpasses;
dummyPipelineLayout = rhs.dummyPipelineLayout;
@ -237,17 +237,19 @@ namespace SHADE
BindInputDescriptorSets (commandBuffer, descMappings.at(SHPredefinedDescriptorTypes::RENDER_GRAPH_RESOURCE), frameIndex);
// If companion subpass is not a valid handle, render super batch normally
if (!companionSubpass.companion)
if (companionSubpasses.empty())
{
// Draw all the batches
superBatch->Draw(commandBuffer, frameIndex);
}
else
{
for (auto& companion : companionSubpasses)
{
// if not bind pipeline for companion and and execute draw command
commandBuffer->BindPipeline(companionSubpass.pipeline);
companionSubpass.companion->superBatch->Draw(commandBuffer, frameIndex, false);
commandBuffer->BindPipeline(companion.pipeline);
companion.subpass->superBatch->Draw(commandBuffer, frameIndex, false);
}
}
}
@ -493,10 +495,11 @@ namespace SHADE
subpassIndex = index;
}
void SHSubpass::SetCompanionSubpass(Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept
void SHSubpass::AddCompanionSubpass(Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept
{
companionSubpass.companion = companion;
companionSubpass.pipeline = pipeline;
companionSubpasses.push_back(CompanionSubpass{companion, pipeline});
//companionSubpass.companion = companion;
//companionSubpass.pipeline = pipeline;
}
/***************************************************************************/

View File

@ -33,7 +33,7 @@ namespace SHADE
struct CompanionSubpass
{
// subpass whose data will be borrowed to draw
Handle<SHSubpass> companion;
Handle<SHSubpass> subpass;
// Pipeline that will be used for all the draw calls from all batches of the companion subpass
Handle<SHVkPipeline> pipeline;
@ -114,7 +114,8 @@ namespace SHADE
//! Optional component to a companion subpass. If the subpass handle of this object
//! is valid, the subpass will be drawn using this companion's data.
CompanionSubpass companionSubpass;
//CompanionSubpass companionSubpass;
std::vector<CompanionSubpass> companionSubpasses;
private:
/*-----------------------------------------------------------------------*/
@ -165,7 +166,7 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* PUBLIC SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/
void SetCompanionSubpass (Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept;
void AddCompanionSubpass (Handle<SHSubpass> companion, Handle<SHVkPipeline> pipeline) noexcept;
Handle<SHRenderGraphNode> GetParentNode(void) const noexcept;
SHSubPassIndex GetIndex() const noexcept;