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