Skip to content

Commit

Permalink
raytraced shadow changed to full resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 31, 2024
1 parent 2055856 commit 1bec956
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 46 deletions.
4 changes: 2 additions & 2 deletions WickedEngine/shaders/rtshadow_denoise_filterCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ float FFX_DNSR_Shadows_GetDepthSimilaritySigma()

float FFX_DNSR_Shadows_ReadDepth(uint2 did)
{
return texture_depth[did * 2];
return texture_depth[did];
}
float16_t3 FFX_DNSR_Shadows_ReadNormals(uint2 did)
{
return normalize((float16_t3)normals[did] * 2 - 1);
return normalize((float16_t3)normals[did] - 0.5);
}

bool FFX_DNSR_Shadows_IsShadowReciever(uint2 did)
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/shaders/rtshadow_denoise_temporalCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ inline void ResolverAABB(in uint shadow_index, float sharpness, float exposureSc
[numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)]
void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3 Gid : SV_GroupID, uint groupIndex : SV_GroupIndex)
{
if (texture_depth.Load(uint3(DTid.xy, 1)) == 0)
if (texture_depth[DTid.xy] == 0)
return;

// first 4 lights are denoised
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ float4x4 FFX_DNSR_Shadows_GetReprojectionMatrix()

float FFX_DNSR_Shadows_ReadDepth(uint2 did)
{
return texture_depth[did * 2];
return texture_depth[did];
}
float FFX_DNSR_Shadows_ReadPreviousDepth(int2 idx)
{
return texture_depth_history[idx * 2];
return texture_depth_history[idx];
}
float3 FFX_DNSR_Shadows_ReadNormals(uint2 did)
{
return normalize(normals[did] * 2 - 1);
return normalize(normals[did] - 0.5);
}
uint FFX_DNSR_Shadows_ReadRaytracedShadowMask(uint linear_tile_index)
{
Expand All @@ -70,7 +70,7 @@ float FFX_DNSR_Shadows_ReadHistory(float2 history_uv)
}
float2 FFX_DNSR_Shadows_ReadVelocity(uint2 did)
{
return -texture_velocity[did * 2].xy;
return -texture_velocity[did].xy;
}

void FFX_DNSR_Shadows_WriteReprojectionResults(uint2 did, float2 value)
Expand Down
4 changes: 2 additions & 2 deletions WickedEngine/shaders/screenspaceshadowCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint3 GTid :
#endif // RTSHADOW

float3 P = reconstruct_position(uv, depth);
float3 N = decode_oct(texture_normal[DTid.xy * 2]);
float3 N = decode_oct(texture_normal[DTid.xy]);

Surface surface;
surface.init();
Expand All @@ -45,7 +45,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint3 GTid :

const float4 bluenoise = blue_noise(DTid.xy);

const uint2 tileIndex = uint2(floor(DTid.xy * 2 / TILED_CULLING_BLOCKSIZE));
const uint2 tileIndex = uint2(floor(DTid.xy / TILED_CULLING_BLOCKSIZE));
const uint flatTileIndex = flatten2D(tileIndex, GetCamera().entity_culling_tilecount.xy) * SHADER_ENTITY_TILE_BUCKET_COUNT;

uint shadow_mask[4] = {0,0,0,0}; // FXC issue: can't dynamically index into uint4, unless unrolling all loops
Expand Down
53 changes: 19 additions & 34 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13281,14 +13281,12 @@ void CreateRTShadowResources(RTShadowResources& res, XMUINT2 resolution)
res.frame = 0;

TextureDesc desc;
desc.width = resolution.x / 2;
desc.height = resolution.y / 2;
desc.width = resolution.x;
desc.height = resolution.y;
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::UNORDERED_ACCESS;
desc.layout = ResourceState::SHADER_RESOURCE_COMPUTE;

desc.format = Format::R32G32B32A32_UINT;
device->CreateTexture(&desc, nullptr, &res.temp);
device->SetName(&res.temp, "rtshadow_temp");
device->CreateTexture(&desc, nullptr, &res.temporal[0]);
device->SetName(&res.temporal[0], "rtshadow_temporal[0]");
device->CreateTexture(&desc, nullptr, &res.temporal[1]);
Expand Down Expand Up @@ -13351,6 +13349,7 @@ void Postprocess_RTShadow(
{
// Maybe we don't need to clear them all, but it's safer this way:
GPUBarrier barriers[] = {
GPUBarrier::Image(&output, output.desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&res.temporal[0], res.temporal[0].desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&res.temporal[1], res.temporal[1].desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&res.denoised, res.denoised.desc.layout, ResourceState::UNORDERED_ACCESS),
Expand All @@ -13373,6 +13372,7 @@ void Postprocess_RTShadow(
GPUBarrier::Image(&res.moments[3][1], res.moments[3][1].desc.layout, ResourceState::UNORDERED_ACCESS),
};
device->Barrier(barriers, arraysize(barriers), cmd);
device->ClearUAV(&output, 0, cmd);
device->ClearUAV(&res.temporal[0], 0, cmd);
device->ClearUAV(&res.temporal[1], 0, cmd);
device->ClearUAV(&res.denoised, 0, cmd);
Expand Down Expand Up @@ -13400,7 +13400,7 @@ void Postprocess_RTShadow(
device->Barrier(barriers, arraysize(barriers), cmd);
}

const TextureDesc& desc = res.temp.GetDesc();
const TextureDesc& desc = output.GetDesc();

BindCommonResources(cmd);

Expand All @@ -13419,15 +13419,15 @@ void Postprocess_RTShadow(
device->PushConstants(&postprocess, sizeof(postprocess), cmd);

const GPUResource* uavs[] = {
&res.temp,
&output,
&res.normals,
&res.tiles
};
device->BindUAVs(uavs, 0, arraysize(uavs), cmd);

{
GPUBarrier barriers[] = {
GPUBarrier::Image(&res.temp, res.temp.desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&output, output.desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&res.normals, res.normals.desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Buffer(&res.tiles, ResourceState::SHADER_RESOURCE_COMPUTE, ResourceState::UNORDERED_ACCESS),
};
Expand All @@ -13443,7 +13443,7 @@ void Postprocess_RTShadow(

{
GPUBarrier barriers[] = {
GPUBarrier::Image(&res.temp, ResourceState::UNORDERED_ACCESS, res.temp.desc.layout),
GPUBarrier::Image(&output, ResourceState::UNORDERED_ACCESS, output.desc.layout),
GPUBarrier::Image(&res.normals, ResourceState::UNORDERED_ACCESS, res.normals.desc.layout),
GPUBarrier::Buffer(&res.tiles, ResourceState::UNORDERED_ACCESS, ResourceState::SHADER_RESOURCE_COMPUTE),
};
Expand Down Expand Up @@ -13664,7 +13664,7 @@ void Postprocess_RTShadow(
device->BindComputeShader(&shaders[CSTYPE_POSTPROCESS_RTSHADOW_DENOISE_TEMPORAL], cmd);
device->PushConstants(&postprocess, sizeof(postprocess), cmd);

device->BindResource(&res.temp, 0, cmd);
device->BindResource(&output, 0, cmd);
device->BindResource(&res.temporal[temporal_history], 1, cmd);
device->BindResource(&res.denoised, 3, cmd);

Expand Down Expand Up @@ -13697,26 +13697,15 @@ void Postprocess_RTShadow(
device->EventEnd(cmd);
}

Postprocess_Upsample_Bilateral(
res.temporal[temporal_output],
lineardepth,
output,
cmd
);
device->Barrier(GPUBarrier::Image(&output, output.desc.layout, ResourceState::COPY_DST), cmd);
device->CopyResource(&output, &res.temporal[temporal_output], cmd);
device->Barrier(GPUBarrier::Image(&output, ResourceState::COPY_DST, output.desc.layout), cmd);

wi::profiler::EndRange(prof_range);
device->EventEnd(cmd);
}
void CreateScreenSpaceShadowResources(ScreenSpaceShadowResources& res, XMUINT2 resolution)
{
TextureDesc desc;
desc.width = resolution.x / 2;
desc.height = resolution.y / 2;
desc.format = Format::R32G32B32A32_UINT;
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::UNORDERED_ACCESS;
desc.layout = ResourceState::SHADER_RESOURCE_COMPUTE;
device->CreateTexture(&desc, nullptr, &res.lowres);
device->SetName(&res.lowres, "screenspaceshadow.lowres");
}
void Postprocess_ScreenSpaceShadow(
const ScreenSpaceShadowResources& res,
Expand All @@ -13731,7 +13720,7 @@ void Postprocess_ScreenSpaceShadow(
device->EventBegin("Postprocess_ScreenSpaceShadow", cmd);
auto prof_range = wi::profiler::BeginRangeGPU("ScreenSpaceShadow", cmd);

const TextureDesc& desc = res.lowres.GetDesc();
const TextureDesc& desc = output.GetDesc();

device->BindComputeShader(&shaders[CSTYPE_POSTPROCESS_SCREENSPACESHADOW], cmd);

Expand All @@ -13745,17 +13734,20 @@ void Postprocess_ScreenSpaceShadow(
device->PushConstants(&postprocess, sizeof(postprocess), cmd);

const GPUResource* uavs[] = {
&res.lowres,
&output,
};
device->BindUAVs(uavs, 0, arraysize(uavs), cmd);

{
GPUBarrier barriers[] = {
GPUBarrier::Image(&res.lowres, res.lowres.desc.layout, ResourceState::UNORDERED_ACCESS),
GPUBarrier::Image(&output, output.desc.layout, ResourceState::UNORDERED_ACCESS),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

device->ClearUAV(&output, 0, cmd);
device->Barrier(GPUBarrier::Memory(&output), cmd);

device->Dispatch(
(desc.width + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE,
(desc.height + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE,
Expand All @@ -13765,18 +13757,11 @@ void Postprocess_ScreenSpaceShadow(

{
GPUBarrier barriers[] = {
GPUBarrier::Image(&res.lowres, ResourceState::UNORDERED_ACCESS, res.lowres.desc.layout),
GPUBarrier::Image(&output, ResourceState::UNORDERED_ACCESS, output.desc.layout),
};
device->Barrier(barriers, arraysize(barriers), cmd);
}

Postprocess_Upsample_Bilateral(
res.lowres,
lineardepth,
output,
cmd
);

wi::profiler::EndRange(prof_range);
device->EventEnd(cmd);
}
Expand Down
3 changes: 1 addition & 2 deletions WickedEngine/wiRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ namespace wi::renderer
);
struct RTShadowResources
{
wi::graphics::Texture temp;
wi::graphics::Texture temporal[2];
wi::graphics::Texture normals;

Expand All @@ -617,7 +616,7 @@ namespace wi::renderer
);
struct ScreenSpaceShadowResources
{
wi::graphics::Texture lowres;
int placeholder = 0;
};
void CreateScreenSpaceShadowResources(ScreenSpaceShadowResources& res, XMUINT2 resolution);
void Postprocess_ScreenSpaceShadow(
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 365;
const int revision = 366;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 1bec956

Please sign in to comment.