Changes to shadowpass
This commit is contained in:
@@ -46,12 +46,12 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
{
|
{
|
||||||
uint cascadeIndex = 0;
|
uint cascadeIndex = 0;
|
||||||
for (uint c = 0; c < NUM_CASCADES - 1; ++c) {
|
for (uint c = 0; c < NUM_CASCADES - 1; ++c) {
|
||||||
if (params.position_VS.z < pShadowMapping.cascadeSplits[c]) {
|
if (params.position_VS.z > pShadowMapping.cascadeSplits[c]) {
|
||||||
cascadeIndex = c + 1;
|
cascadeIndex = c + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float4 lightSpacePos = mul(pShadowMapping.lightSpaceMatrices[cascadeIndex][i], float4(params.position_WS, 1));
|
float4 lightSpacePos = mul(pShadowMapping.lightSpaceMatrices[cascadeIndex][i], float4(params.position_WS, 1));
|
||||||
lightSpacePos = mul(biasMat, lightSpacePos);
|
lightSpacePos = float4(lightSpacePos.xy * 0.5 + 0.5, lightSpacePos.zw);
|
||||||
float4 shadowCoord = lightSpacePos;
|
float4 shadowCoord = lightSpacePos;
|
||||||
int3 texDim;
|
int3 texDim;
|
||||||
pShadowMapping.shadowMaps[cascadeIndex].GetDimensions(texDim.x, texDim.y, texDim.z);
|
pShadowMapping.shadowMaps[cascadeIndex].GetDimensions(texDim.x, texDim.y, texDim.z);
|
||||||
@@ -62,12 +62,12 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
float shadowFactor = 0.0f;
|
float shadowFactor = 0.0f;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int range = 1;
|
int range = 1;
|
||||||
for (int x = -range; x <= range; ++x) {
|
//for (int x = -range; x <= range; ++x) {
|
||||||
for (int y = -range; y <= range; ++y) {
|
// for (int y = -range; y <= range; ++y) {
|
||||||
float shadow = 1.0f;
|
float shadow = 1.0f;
|
||||||
if (shadowCoord.z > 0.0 && shadowCoord.z < 1.0)
|
if (shadowCoord.z > 0.0 && shadowCoord.z < 1.0)
|
||||||
{
|
{
|
||||||
float dist = pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy + float2(dx * x, dy * y), i)).r;
|
float dist = pShadowMapping.shadowMaps[cascadeIndex].Sample(pShadowMapping.shadowSampler, float3(shadowCoord.xy, i)).r;
|
||||||
if (shadowCoord.w > 0 && dist < shadowCoord.z)
|
if (shadowCoord.w > 0 && dist < shadowCoord.z)
|
||||||
{
|
{
|
||||||
shadow = 0;
|
shadow = 0;
|
||||||
@@ -75,8 +75,8 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
|||||||
}
|
}
|
||||||
shadowFactor += shadow;
|
shadowFactor += shadow;
|
||||||
count++;
|
count++;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
result = (shadowFactor / count) * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
result = (shadowFactor / count) * pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ VertexShaderOutput vertexMain(
|
|||||||
float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
|
float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
|
||||||
//clip(dot(worldPos, clipPlane));
|
//clip(dot(worldPos, clipPlane));
|
||||||
output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
|
output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
|
||||||
|
output.clipPos.z = output.clipPos.w - 0.0001f; // Push to far plane
|
||||||
output.texCoords = normalize(vertices[vertexIndex]);
|
output.texCoords = normalize(vertices[vertexIndex]);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ int main() {
|
|||||||
// .filePath = sourcePath / "import" / "models" / "main1_sponza" / "sponza.gltf",
|
// .filePath = sourcePath / "import" / "models" / "main1_sponza" / "sponza.gltf",
|
||||||
// .importPath = "sponza",
|
// .importPath = "sponza",
|
||||||
//});
|
//});
|
||||||
|
AssetImporter::importMesh(MeshImportArgs{
|
||||||
|
.filePath = sourcePath / "import" / "models" / "cube.fbx",
|
||||||
|
.importPath = "",
|
||||||
|
});
|
||||||
AssetImporter::importMesh(MeshImportArgs{
|
AssetImporter::importMesh(MeshImportArgs{
|
||||||
.filePath = sourcePath / "import" / "models" / "rttest.gltf",
|
.filePath = sourcePath / "import" / "models" / "rttest.gltf",
|
||||||
.importPath = "rttest",
|
.importPath = "rttest",
|
||||||
|
|||||||
@@ -673,6 +673,10 @@ void BasePass::createRenderPass() {
|
|||||||
{
|
{
|
||||||
.polygonMode = Gfx::SE_POLYGON_MODE_FILL,
|
.polygonMode = Gfx::SE_POLYGON_MODE_FILL,
|
||||||
},
|
},
|
||||||
|
.depthStencilState = {
|
||||||
|
.depthTestEnable = true,
|
||||||
|
.depthCompareOp = Gfx::SE_COMPARE_OP_GREATER,
|
||||||
|
},
|
||||||
.colorBlend =
|
.colorBlend =
|
||||||
{
|
{
|
||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
|||||||
|
|
||||||
float nearClip = camera.nearPlane;
|
float nearClip = camera.nearPlane;
|
||||||
float farClip = camera.farPlane;
|
float farClip = camera.farPlane;
|
||||||
float clipRange = nearClip - farClip;
|
float clipRange = farClip - nearClip;
|
||||||
|
|
||||||
float minZ = farClip;
|
float minZ = nearClip;
|
||||||
float maxZ = nearClip;
|
float maxZ = farClip;
|
||||||
|
|
||||||
float range = maxZ - minZ;
|
float range = maxZ - minZ;
|
||||||
float ratio = maxZ / minZ;
|
float ratio = maxZ / minZ;
|
||||||
@@ -63,8 +63,8 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
|||||||
float log = minZ * std::pow(ratio, p);
|
float log = minZ * std::pow(ratio, p);
|
||||||
float uniform = minZ + range * p;
|
float uniform = minZ + range * p;
|
||||||
float d = cascadeSplitLambda * (log - uniform) + uniform;
|
float d = cascadeSplitLambda * (log - uniform) + uniform;
|
||||||
cascadeSplits[i] = (d - farClip) / clipRange;
|
cascadeSplits[i] = (d - nearClip) / clipRange;
|
||||||
splitDepths[i] = farClip + cascadeSplits[i] * clipRange;
|
splitDepths[i] = farClip - cascadeSplits[i] * clipRange;
|
||||||
cascades[i].viewParams.clear();
|
cascades[i].viewParams.clear();
|
||||||
}
|
}
|
||||||
cascadeSplitsBuffer->updateContents(0, sizeof(float) * NUM_CASCADES, splitDepths);
|
cascadeSplitsBuffer->updateContents(0, sizeof(float) * NUM_CASCADES, splitDepths);
|
||||||
@@ -111,7 +111,7 @@ void ShadowPass::beginFrame(const Component::Camera& camera, const Component::Tr
|
|||||||
Vector cameraPos = frustumCenter - lightDir * -minExtents.z;
|
Vector cameraPos = frustumCenter - lightDir * -minExtents.z;
|
||||||
Matrix4 viewMatrix = glm::lookAt(cameraPos, frustumCenter, Vector(0, 1, 0));
|
Matrix4 viewMatrix = glm::lookAt(cameraPos, frustumCenter, Vector(0, 1, 0));
|
||||||
Matrix4 projectionMatrix =
|
Matrix4 projectionMatrix =
|
||||||
orthographicProjection(minExtents.x, maxExtents.x, minExtents.y, maxExtents.y, 0.0f, maxExtents.z - minExtents.z);
|
orthographicProjection(minExtents.x, maxExtents.x, minExtents.y, maxExtents.y, maxExtents.z - minExtents.z, 0.0f);
|
||||||
Matrix4 viewProjectionMatrix = projectionMatrix * viewMatrix;
|
Matrix4 viewProjectionMatrix = projectionMatrix * viewMatrix;
|
||||||
viewParams = {
|
viewParams = {
|
||||||
.viewMatrix = viewMatrix,
|
.viewMatrix = viewMatrix,
|
||||||
|
|||||||
@@ -619,7 +619,7 @@ void VertexData::loadMeshlets(MeshId id, const Array<Vector>& loadedPositions, c
|
|||||||
// todo: use meshopt for bb generation
|
// todo: use meshopt for bb generation
|
||||||
m.bounding = AABB();
|
m.bounding = AABB();
|
||||||
for (size_t j = 0; j < m.vertexIndices.size; ++j) {
|
for (size_t j = 0; j < m.vertexIndices.size; ++j) {
|
||||||
m.bounding.adjust(loadedPositions[vertexIndices[meshoptMeshlets[i].vertex_offset + j]]);
|
m.bounding.adjust(loadedPositions[vertexIndices[meshoptMeshlets[i].vertex_offset + j + m.indicesOffset]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registeredMeshes[id].meshData = MeshData{
|
registeredMeshes[id].meshData = MeshData{
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public:
|
|||||||
DescriptorSetHandle(PGraphics graphics, const std::string& name);
|
DescriptorSetHandle(PGraphics graphics, const std::string& name);
|
||||||
virtual ~DescriptorSetHandle();
|
virtual ~DescriptorSetHandle();
|
||||||
constexpr VkDescriptorSet getHandle() const { return handle; }
|
constexpr VkDescriptorSet getHandle() const { return handle; }
|
||||||
PGraphics graphics;
|
|
||||||
VkDescriptorSet handle = VK_NULL_HANDLE;
|
VkDescriptorSet handle = VK_NULL_HANDLE;
|
||||||
OBufferAllocation constantsBuffer;
|
OBufferAllocation constantsBuffer;
|
||||||
bool isUsed = false;
|
bool isUsed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user