Skip to content

Commit

Permalink
volumetric cloud shadow improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 5, 2025
1 parent 1d48390 commit a9e1058
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 109 deletions.
1 change: 0 additions & 1 deletion WickedEngine/offlineshadercompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ wi::vector<ShaderEntry> shaders = {
{"volumetricCloud_renderCS_capture", wi::graphics::ShaderStage::CS },
{"volumetricCloud_renderCS_capture_MSAA", wi::graphics::ShaderStage::CS },
{"volumetricCloud_reprojectCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_shadow_filterCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_shadow_renderCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_shapenoiseCS", wi::graphics::ShaderStage::CS },
{"volumetricCloud_upsamplePS", wi::graphics::ShaderStage::PS },
Expand Down
4 changes: 0 additions & 4 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)volumetricCloud_shadow_filterCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)volumetricCloud_shadow_renderCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
Expand Down
3 changes: 0 additions & 3 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -968,9 +968,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)volumetricCloud_shadow_renderCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)volumetricCloud_shadow_filterCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)volumetricCloud_renderCS_capture_MSAA.hlsl">
<Filter>CS</Filter>
</FxCompile>
Expand Down
6 changes: 3 additions & 3 deletions WickedEngine/shaders/shadowHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ inline half3 shadow_cube(in ShaderEntity light, in float3 Lunnormalized, in min1
inline half shadow_2D_volumetricclouds(float3 P)
{
// Project into shadow map space (no need to divide by .w because ortho projection!):
half3 shadow_pos = mul(GetFrame().cloudShadowLightSpaceMatrix, float4(P, 1)).xyz;
half3 shadow_uv = clipspace_to_uv(shadow_pos);
float3 shadow_pos = mul(GetFrame().cloudShadowLightSpaceMatrix, float4(P, 1)).xyz;
float3 shadow_uv = clipspace_to_uv(shadow_pos);

[branch]
if (shadow_uv.z < 0.5)
Expand All @@ -166,7 +166,7 @@ inline half shadow_2D_volumetricclouds(float3 P)
[branch]
if (is_saturated(shadow_uv))
{
half cloudShadowSampleZ = shadow_pos.z;
float cloudShadowSampleZ = shadow_pos.z;

Texture2D<half4> texture_volumetricclouds_shadow = bindless_textures_half4[GetFrame().texture_volumetricclouds_shadow_index];
half3 cloudShadowData = texture_volumetricclouds_shadow.SampleLevel(sampler_linear_clamp, shadow_uv.xy, 0.0).rgb;
Expand Down
44 changes: 0 additions & 44 deletions WickedEngine/shaders/volumetricCloud_shadow_filterCS.hlsl

This file was deleted.

4 changes: 2 additions & 2 deletions WickedEngine/shaders/volumetricCloud_shadow_renderCS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Texture2D<float4> texture_curlNoise : register(t2);
Texture2D<float4> texture_weatherMapFirst : register(t3);
Texture2D<float4> texture_weatherMapSecond : register(t4);

RWTexture2D<float3> texture_render : register(u0);
RWTexture2D<float4> texture_render : register(u0);

static const float2 sampleCountMinMax = float2(16.0, 32.0); // Based on sun angle, more angle more samples

Expand Down Expand Up @@ -139,5 +139,5 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID, uint3
}

// Output
texture_render[DTid.xy] = result;
texture_render[DTid.xy] = float4(result, 1);
}
3 changes: 1 addition & 2 deletions WickedEngine/wiEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace wi::enums
enum TEXTYPES
{
TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW,
TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED,
TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_GAUSSIAN_TEMP,
TEXTYPE_2D_SKYATMOSPHERE_TRANSMITTANCELUT,
TEXTYPE_2D_SKYATMOSPHERE_MULTISCATTEREDLUMINANCELUT,
TEXTYPE_2D_SKYATMOSPHERE_SKYVIEWLUT,
Expand Down Expand Up @@ -342,7 +342,6 @@ namespace wi::enums
CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_RENDER_CAPTURE_MSAA,
CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_REPROJECT,
CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_SHADOW_RENDER,
CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_SHADOW_FILTER,
CSTYPE_POSTPROCESS_FXAA,
CSTYPE_POSTPROCESS_TEMPORALAA,
CSTYPE_POSTPROCESS_SHARPEN,
Expand Down
61 changes: 12 additions & 49 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,6 @@ void LoadShaders()
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_RENDER_CAPTURE_MSAA], "volumetricCloud_renderCS_capture_MSAA.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_REPROJECT], "volumetricCloud_reprojectCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_SHADOW_RENDER], "volumetricCloud_shadow_renderCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_SHADOW_FILTER], "volumetricCloud_shadow_filterCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_FXAA], "fxaaCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_TEMPORALAA], "temporalaaCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_POSTPROCESS_SHARPEN], "sharpenCS.cso"); });
Expand Down Expand Up @@ -3854,12 +3853,12 @@ void UpdatePerFrameData(
desc.layout = ResourceState::SHADER_RESOURCE_COMPUTE;
device->CreateTexture(&desc, nullptr, &textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW]);
device->SetName(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW], "textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW]");
device->CreateTexture(&desc, nullptr, &textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED]);
device->SetName(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED], "textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED]");
device->CreateTexture(&desc, nullptr, &textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_GAUSSIAN_TEMP]);
device->SetName(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_GAUSSIAN_TEMP], "textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_GAUSSIAN_TEMP]");
}

const float cloudShadowSnapLength = 5000.0f;
const float cloudShadowExtent = 35000.0f; // The cloud shadow bounding box size
const float cloudShadowExtent = 10000.0f; // The cloud shadow bounding box size
const float cloudShadowNearPlane = 0.0f;
const float cloudShadowFarPlane = cloudShadowExtent * 2.0;

Expand Down Expand Up @@ -3891,7 +3890,7 @@ void UpdatePerFrameData(
XMStoreFloat4x4(&frameCB.cloudShadowLightSpaceMatrix, cloudShadowLightSpaceMatrix);
XMStoreFloat4x4(&frameCB.cloudShadowLightSpaceMatrixInverse, cloudShadowLightSpaceMatrixInverse);
frameCB.cloudShadowFarPlaneKm = cloudShadowFarPlane * metersToSkyUnit;
frameCB.texture_volumetricclouds_shadow_index = device->GetDescriptorIndex(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED], SubresourceType::SRV);
frameCB.texture_volumetricclouds_shadow_index = device->GetDescriptorIndex(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW], SubresourceType::SRV);
}

if (scene.weather.IsRealisticSky() && !textures[TEXTYPE_2D_SKYATMOSPHERE_TRANSMITTANCELUT].IsValid())
Expand Down Expand Up @@ -8113,7 +8112,6 @@ void ComputeVolumetricCloudShadows(

{
GPUBarrier barriers[] = {
GPUBarrier::Memory(),
GPUBarrier::Image(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW], ResourceState::UNORDERED_ACCESS, textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW].desc.layout),
};
device->Barrier(barriers, arraysize(barriers), cmd);
Expand All @@ -8122,49 +8120,14 @@ void ComputeVolumetricCloudShadows(
device->EventEnd(cmd);
}

auto CloudShadowFilter = [&](PostProcess& postprocess, CommandList cmd)
{
// Cloud shadow filter pass:
{
device->EventBegin("Volumetric Cloud Filter Shadow", cmd);
device->BindComputeShader(&shaders[CSTYPE_POSTPROCESS_VOLUMETRICCLOUDS_SHADOW_FILTER], cmd);
device->PushConstants(&postprocess, sizeof(postprocess), cmd);

device->BindResource(&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW], 0, cmd);

const GPUResource* uavs[] = {
&textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED],
};
device->BindUAVs(uavs, 0, arraysize(uavs), cmd);

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

device->Dispatch(
(textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED].GetDesc().width + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE,
(textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_FILTERED].GetDesc().height + POSTPROCESS_BLOCKSIZE - 1) / POSTPROCESS_BLOCKSIZE,
1,
cmd
);

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

device->EventEnd(cmd);
}
};

// We filter twice for to avoid rapid changing pixels and to mimic penumbra
CloudShadowFilter(postprocess, cmd);
CloudShadowFilter(postprocess, cmd);
Postprocess_Blur_Gaussian(
textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW],
textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW_GAUSSIAN_TEMP],
textures[TEXTYPE_2D_VOLUMETRICCLOUDS_SHADOW],
cmd,
-1, -1,
false // wide
);

wi::profiler::EndRange(range);
device->EventEnd(cmd);
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 = 646;
const int revision = 647;

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

Expand Down

0 comments on commit a9e1058

Please sign in to comment.