Kindof works a little bit
This commit is contained in:
@@ -57,7 +57,6 @@ endif()
|
||||
|
||||
add_library(Engine SHARED "")
|
||||
|
||||
target_compile_definitions(Engine PRIVATE GLFW_WINDOWS)
|
||||
target_include_directories(Engine PRIVATE src/Engine)
|
||||
target_include_directories(Engine PRIVATE ${VCPKG_BASE_FOLDER}/include/)
|
||||
target_link_libraries(Engine PUBLIC Vulkan::Vulkan)
|
||||
|
||||
@@ -26,15 +26,16 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
float4 lightSpacePos = mul(pLightEnv.directionalLights[i].lightSpaceMatrix, float4(params.position_WS, 1));
|
||||
float3 projCoords = lightSpacePos.xyz / lightSpacePos.w;
|
||||
projCoords = projCoords * 0.5 + 0.5;
|
||||
projCoords.xy = projCoords.xy * 0.5 + 0.5;
|
||||
projCoords.z /= 2;
|
||||
float closestDepth = pLightEnv.shadowMap.Sample(pLightEnv.shadowSampler, projCoords.xy).r;
|
||||
float currentDepth = projCoords.z;
|
||||
float bias = max(0.05 * (1.0 - dot(brdf.getNormal(), pLightEnv.directionalLights[i].direction.xyz)), 0.005);
|
||||
float shadow = currentDepth > closestDepth - bias ? 1.0 : 0.0;
|
||||
float shadow = currentDepth + bias < closestDepth ? 1.0 : 0.0;
|
||||
|
||||
result += shadow * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
result += float3(currentDepth, 0, 0);//shadow * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for (uint i = 0; i < pLightEnv.numPo; ++i)
|
||||
for (uint i = 0; i < lightCount; ++i)
|
||||
{
|
||||
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||
|
||||
@@ -147,13 +147,13 @@ void BasePass::render() {
|
||||
query->beginQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "BaseBegin");
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Array<VertexData::TransparentDraw> transparentData;
|
||||
{
|
||||
graphics->beginDebugRegion("Opaque");
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
|
||||
permutation.setDepthCulling(true); // always use the culling info
|
||||
permutation.setPositionOnly(false);
|
||||
Array<VertexData::TransparentDraw> transparentData;
|
||||
{
|
||||
graphics->beginDebugRegion("Opaque");
|
||||
// Base Rendering
|
||||
for (VertexData* vertexData : VertexData::getList()) {
|
||||
transparentData.addAll(vertexData->getTransparentData());
|
||||
@@ -243,6 +243,7 @@ void BasePass::render() {
|
||||
commands.add(std::move(command));
|
||||
}
|
||||
}
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endDebugRegion();
|
||||
}
|
||||
|
||||
@@ -264,6 +265,8 @@ void BasePass::render() {
|
||||
// Transparent rendering
|
||||
{
|
||||
graphics->beginDebugRegion("Transparent");
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
|
||||
permutation.setPositionOnly(false);
|
||||
permutation.setDepthCulling(false); // ignore visibility infos for transparency
|
||||
Map<float, VertexData::TransparentDraw> sortedDraws;
|
||||
for (const auto& t : transparentData) {
|
||||
@@ -360,23 +363,25 @@ void BasePass::render() {
|
||||
// }
|
||||
}
|
||||
}
|
||||
commands.add(std::move(transparentCommand));
|
||||
graphics->executeCommands(std::move(transparentCommand));
|
||||
graphics->endDebugRegion();
|
||||
}
|
||||
// Debug vertices
|
||||
if (gDebugVertices.size() > 0) {
|
||||
graphics->beginDebugRegion("Debug");
|
||||
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
|
||||
permutation.setDepthCulling(true); // always use the culling info
|
||||
permutation.setPositionOnly(false);
|
||||
Gfx::ORenderCommand debugCommand = graphics->createRenderCommand("DebugRender");
|
||||
debugCommand->setViewport(viewport);
|
||||
debugCommand->bindPipeline(debugPipeline);
|
||||
debugCommand->bindDescriptor(viewParamsSet);
|
||||
debugCommand->bindVertexBuffer({debugVertices});
|
||||
debugCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
||||
commands.add(std::move(debugCommand));
|
||||
graphics->executeCommands(std::move(debugCommand));
|
||||
graphics->endDebugRegion();
|
||||
}
|
||||
|
||||
graphics->executeCommands(std::move(commands));
|
||||
graphics->endRenderPass();
|
||||
query->endQuery();
|
||||
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "BaseEnd");
|
||||
|
||||
@@ -81,8 +81,8 @@ void ShadowPass::render() {
|
||||
"Shadow");
|
||||
auto light = scene->getLightEnvironment()->getDirectionalLight(shadowIndex);
|
||||
Component::Camera lightCamera = Component::Camera{
|
||||
.nearPlane = -20.f,
|
||||
.farPlane = 10.0f,
|
||||
.nearPlane = -100.f,
|
||||
.farPlane = 100.0f,
|
||||
};
|
||||
Gfx::PDescriptorSet viewParamsSet = createViewParamsSet(lightCamera, scene->getLightEnvironment()->getDirectionalTransform(shadowIndex));
|
||||
graphics->beginRenderPass(renderPass);
|
||||
@@ -173,10 +173,10 @@ void ShadowPass::publishOutputs() {
|
||||
.offset = {0, 0},
|
||||
},
|
||||
.fieldOfView = 0,
|
||||
.left = -20,
|
||||
.right = 20,
|
||||
.top = -20,
|
||||
.bottom = 20});
|
||||
.left = -100,
|
||||
.right = 100,
|
||||
.top = 100,
|
||||
.bottom = -100});
|
||||
viewport = shadowViewport;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,6 @@ Matrix4 Viewport::getProjectionMatrix(float nearPlane, float farPlane) const {
|
||||
Matrix4 projectionMatrix = glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), nearPlane, farPlane);
|
||||
return correctionMatrix * projectionMatrix;
|
||||
} else {
|
||||
return correctionMatrix * glm::ortho(orthoLeft, orthoRight, orthoBottom, orthoTop, farPlane, nearPlane);
|
||||
return correctionMatrix * glm::ortho(orthoLeft, orthoRight, orthoBottom, orthoTop, nearPlane, farPlane);
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ void LightEnvironment::addDirectionalLight(const Component::DirectionalLight& di
|
||||
dirs.add(ShaderDirectionalLight{
|
||||
.color = Vector4(dirLight.color, dirLight.intensity),
|
||||
.direction = Vector4(transform.getForward(), 0),
|
||||
.lightSpaceMatrix = correctionMatrix * glm::ortho(-20.f, 20.f, 20.f, -20.f, 10.0f, -20.0f) * cameraMatrix,
|
||||
.lightSpaceMatrix = correctionMatrix * glm::ortho(-100.0f, 100.0f, -100.0f, 100.0f, -100.0f, 100.0f) * cameraMatrix,
|
||||
});
|
||||
directionalTransforms.add(transform);
|
||||
if (shadowMaps.size() < dirs.size()) {
|
||||
|
||||
Reference in New Issue
Block a user