Skip to content

Commit

Permalink
Checkerboard fixes and prep
Browse files Browse the repository at this point in the history
This code was written on stream but was not committed; this will allow
easier experimentation with actual temporal reprojection.
  • Loading branch information
zeux committed Dec 27, 2024
1 parent 17d800b commit e1bfa3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/niagara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ int main(int argc, const char** argv)

// checkerboard rendering: we dispatch half as many columns and xform them to fill the screen
int shadowWidthCB = shadowCheckerboard ? (swapchain.width + 1) / 2 : swapchain.width;
int shadowCheckerboardF = shadowCheckerboard ? 1 + (frameIndex % 2) : 0;

vkCmdWriteTimestamp(commandBuffer, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, queryPoolTimestamp, timestamp + 0);

Expand All @@ -1500,7 +1501,7 @@ int main(int argc, const char** argv)
shadowData.sunJitter = shadowblurEnabled ? 1e-2f : 0;
shadowData.inverseViewProjection = inverse(projection * view);
shadowData.imageSize = vec2(float(swapchain.width), float(swapchain.height));
shadowData.checkerboard = shadowCheckerboard;
shadowData.checkerboard = shadowCheckerboardF;

dispatch(commandBuffer, shadowProgram, shadowWidthCB, swapchain.height, shadowData, descriptors);
}
Expand All @@ -1520,8 +1521,9 @@ int main(int argc, const char** argv)
DescriptorInfo descriptors[] = { { shadowTarget.imageView, VK_IMAGE_LAYOUT_GENERAL }, { readSampler, depthTarget.imageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL } };

vec4 fillData = vec4(float(swapchain.width), float(swapchain.height), 0, 0);
memcpy(&fillData.z, &shadowCheckerboardF, sizeof(shadowCheckerboardF));

dispatch(commandBuffer, shadowProgram, shadowWidthCB, swapchain.height, fillData, descriptors);
dispatch(commandBuffer, shadowfillProgram, shadowWidthCB, swapchain.height, fillData, descriptors);
}

for (int pass = 0; pass < (shadowblurEnabled ? 2 : 0); ++pass)
Expand Down
8 changes: 4 additions & 4 deletions src/shaders/shadow.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ShadowData
mat4 inverseViewProjection;

vec2 imageSize;
uint checkerboard;
int checkerboard;
};

layout(push_constant) uniform block
Expand Down Expand Up @@ -115,11 +115,11 @@ bool shadowTraceTransparent(vec3 wpos, vec3 dir, uint rayflags)

void main()
{
uvec2 pos = gl_GlobalInvocationID.xy;
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);

if (shadowData.checkerboard > 0)
{
// checkerboard even
// checkerboard
pos.x *= 2;
pos.x += (pos.y ^ shadowData.checkerboard) & 1;
}
Expand Down Expand Up @@ -156,5 +156,5 @@ void main()

float shadow = shadowhit ? 0.0 : 1.0;

imageStore(outImage, ivec2(pos), vec4(shadow, 0, 0, 0));
imageStore(outImage, pos, vec4(shadow, 0, 0, 0));
}
5 changes: 3 additions & 2 deletions src/shaders/shadowfill.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(push_constant) uniform block
{
vec2 imageSize;
int checkerboard;
};

layout(binding = 0, r8) uniform image2D shadowImage;
Expand All @@ -16,9 +17,9 @@ void main()
{
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);

// checkerboard odd
// checkerboard (opposite)
pos.x *= 2;
pos.x += pos.y & 1;
pos.x += ~(pos.y ^ checkerboard) & 1;

float depth = texelFetch(depthImage, pos, 0).r;

Expand Down

0 comments on commit e1bfa3c

Please sign in to comment.