Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path tracing updates #800

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Editor/AnimationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void AnimationWindow::Create(EditorComponent* _editor)
{
editor = _editor;
wi::gui::Window::Create(ICON_ANIMATION " Animation", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE);
SetSize(XMFLOAT2(520, 500));
SetSize(XMFLOAT2(520, 540));

closeButton.SetTooltip("Delete AnimationComponent");
OnClose([=](wi::gui::EventArgs args) {
Expand Down Expand Up @@ -975,10 +975,10 @@ void AnimationWindow::Create(EditorComponent* _editor)

}
// Example function to check if an entity already exists in the list
static bool EntityExistsInList(Entity entity, std::vector<Entity> entityList)
static bool EntityExistsInList(Entity entity, const wi::vector<Entity>& entityList)
{
// Iterate through the list of entities
for (Entity& e : entityList)
for (Entity e : entityList)
{
if (e == entity)
{
Expand Down Expand Up @@ -1007,7 +1007,7 @@ void AnimationWindow::SetEntity(Entity entity)
if (animation != nullptr)
{
// Define a list of entities
std::vector<Entity> bone_list;
wi::vector<Entity> bone_list;
// Add items to root bone name combo box.
for (const AnimationComponent::AnimationChannel& channel : animation->channels)
{
Expand Down Expand Up @@ -1299,7 +1299,9 @@ void AnimationWindow::ResizeLayout()
add(endInput);
add(recordCombo);
add(retargetCombo);
add(rootMotionCheckBox);
rootMotionCheckBox.SetPos(XMFLOAT2(margin_left, y));
y += rootMotionCheckBox.GetSize().y;
y += padding;
add(rootBoneComboBox);
add_fullwidth(keyframesList);
}
1 change: 1 addition & 0 deletions WickedEngine/offlineshadercompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ wi::vector<ShaderEntry> shaders = {
{"emittedparticle_emitCS_volume", wi::graphics::ShaderStage::CS},
{"emittedparticle_finishUpdateCS", wi::graphics::ShaderStage::CS},
{"downsample4xCS", wi::graphics::ShaderStage::CS},
{"lineardepthCS", wi::graphics::ShaderStage::CS},
{"depthoffield_prepassCS_earlyexit", wi::graphics::ShaderStage::CS},
{"depthoffield_mainCS_cheap", wi::graphics::ShaderStage::CS},
{"depthoffield_mainCS_earlyexit", wi::graphics::ShaderStage::CS },
Expand Down
4 changes: 4 additions & 0 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)lineardepthCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectGS_primitiveID_emulation.hlsl" />
<FxCompile Include="$(MSBuildThisFileDirectory)objectGS_primitiveID_emulation_alphatest.hlsl" />
<FxCompile Include="$(MSBuildThisFileDirectory)screenVS.hlsl">
Expand Down
3 changes: 3 additions & 0 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,9 @@
<FxCompile Include="$(MSBuildThisFileDirectory)copyStencilBitPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)lineardepthCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop.h">
Expand Down
35 changes: 35 additions & 0 deletions WickedEngine/shaders/lineardepthCS.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "globals.hlsli"
#include "ShaderInterop_Postprocess.h"

Texture2D<float> input : register(t0);

RWTexture2D<float> output_lineardepth_mip0 : register(u0);
RWTexture2D<float> output_lineardepth_mip1 : register(u1);
RWTexture2D<float> output_lineardepth_mip2 : register(u2);
RWTexture2D<float> output_lineardepth_mip3 : register(u3);
RWTexture2D<float> output_lineardepth_mip4 : register(u4);

[numthreads(POSTPROCESS_BLOCKSIZE, POSTPROCESS_BLOCKSIZE, 1)]
void main(uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID)
{
const uint2 pixel = DTid.xy;
const float depth = input[pixel];
float lineardepth = compute_lineardepth(depth) * GetCamera().z_far_rcp;
output_lineardepth_mip0[pixel] = lineardepth;
if (GTid.x % 2 == 0 && GTid.y % 2 == 0)
{
output_lineardepth_mip1[pixel / 2] = lineardepth;
}
if (GTid.x % 4 == 0 && GTid.y % 4 == 0)
{
output_lineardepth_mip2[pixel / 4] = lineardepth;
}
if (GTid.x % 8 == 0 && GTid.y % 8 == 0)
{
output_lineardepth_mip3[pixel / 8] = lineardepth;
}
if (GTid.x % 16 == 0 && GTid.y % 16 == 0)
{
output_lineardepth_mip4[pixel / 16] = lineardepth;
}
}
1 change: 1 addition & 0 deletions WickedEngine/wiEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ namespace wi::enums
CSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL_UNORM4,
CSTYPE_POSTPROCESS_UPSAMPLE_BILATERAL_UINT4,
CSTYPE_POSTPROCESS_DOWNSAMPLE4X,
CSTYPE_POSTPROCESS_LINEARDEPTH,
CSTYPE_POSTPROCESS_NORMALSFROMDEPTH,
CSTYPE_POSTPROCESS_SCREENSPACESHADOW,
CSTYPE_POSTPROCESS_RTSHADOW,
Expand Down
48 changes: 24 additions & 24 deletions WickedEngine/wiRenderPath3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,31 @@ namespace wi

scene->camera = *camera;
scene->Update(dt * wi::renderer::GetGameSpeed());
}

// Frustum culling for main camera:
visibility_main.layerMask = getLayerMask();
visibility_main.scene = scene;
visibility_main.camera = camera;
visibility_main.flags = wi::renderer::Visibility::ALLOW_EVERYTHING;
wi::renderer::UpdateVisibility(visibility_main);

if (visibility_main.planar_reflection_visible)
{
// Frustum culling for planar reflections:
camera_reflection = *camera;
camera_reflection.jitter = XMFLOAT2(0, 0);
camera_reflection.Reflect(visibility_main.reflectionPlane);
visibility_reflection.layerMask = getLayerMask();
visibility_reflection.scene = scene;
visibility_reflection.camera = &camera_reflection;
visibility_reflection.flags =
wi::renderer::Visibility::ALLOW_OBJECTS |
wi::renderer::Visibility::ALLOW_EMITTERS |
wi::renderer::Visibility::ALLOW_HAIRS |
wi::renderer::Visibility::ALLOW_LIGHTS
;
wi::renderer::UpdateVisibility(visibility_reflection);
// Frustum culling for main camera:
visibility_main.layerMask = getLayerMask();
visibility_main.scene = scene;
visibility_main.camera = camera;
visibility_main.flags = wi::renderer::Visibility::ALLOW_EVERYTHING;
wi::renderer::UpdateVisibility(visibility_main);

if (visibility_main.planar_reflection_visible)
{
// Frustum culling for planar reflections:
camera_reflection = *camera;
camera_reflection.jitter = XMFLOAT2(0, 0);
camera_reflection.Reflect(visibility_main.reflectionPlane);
visibility_reflection.layerMask = getLayerMask();
visibility_reflection.scene = scene;
visibility_reflection.camera = &camera_reflection;
visibility_reflection.flags =
wi::renderer::Visibility::ALLOW_OBJECTS |
wi::renderer::Visibility::ALLOW_EMITTERS |
wi::renderer::Visibility::ALLOW_HAIRS |
wi::renderer::Visibility::ALLOW_LIGHTS
;
wi::renderer::UpdateVisibility(visibility_reflection);
}
}

XMUINT2 internalResolution = GetInternalResolution();
Expand Down
148 changes: 88 additions & 60 deletions WickedEngine/wiRenderPath3D_PathTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace wi

void RenderPath3D_PathTracing::ResizeBuffers()
{
DeleteGPUResources();

GraphicsDevice* device = wi::graphics::GetDevice();

Expand Down Expand Up @@ -78,17 +79,42 @@ namespace wi
desc.format = Format::R32_FLOAT;
device->CreateTexture(&desc, nullptr, &traceDepth);
device->SetName(&traceDepth, "traceDepth");
device->CreateTexture(&desc, nullptr, &traceDepth);
device->SetName(&traceDepth, "traceDepth");
desc.format = Format::R8_UINT;
device->CreateTexture(&desc, nullptr, &traceStencil);
device->SetName(&traceStencil, "traceStencil");

depthBuffer_Copy = traceDepth;
depthBuffer_Copy1 = traceDepth;

desc.layout = ResourceState::DEPTHSTENCIL;
desc.bind_flags = BindFlag::DEPTH_STENCIL;
desc.format = wi::renderer::format_depthbuffer_main;
device->CreateTexture(&desc, nullptr, &depthBuffer_Main);
device->SetName(&depthBuffer_Main, "depthBuffer_Main");
}
}
{
TextureDesc desc;
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::UNORDERED_ACCESS;
desc.format = Format::R32_FLOAT;
desc.width = internalResolution.x;
desc.height = internalResolution.y;
desc.mip_levels = 5;
desc.layout = ResourceState::SHADER_RESOURCE_COMPUTE;
device->CreateTexture(&desc, nullptr, &rtLinearDepth);
device->SetName(&rtLinearDepth, "rtLinearDepth");

for (uint32_t i = 0; i < desc.mip_levels; ++i)
{
int subresource_index;
subresource_index = device->CreateSubresource(&rtLinearDepth, SubresourceType::SRV, 0, 1, i, 1);
assert(subresource_index == i);
subresource_index = device->CreateSubresource(&rtLinearDepth, SubresourceType::UAV, 0, 1, i, 1);
assert(subresource_index == i);
}
}
{
TextureDesc desc;
desc.bind_flags = BindFlag::SHADER_RESOURCE | BindFlag::UNORDERED_ACCESS;
Expand Down Expand Up @@ -174,7 +200,6 @@ namespace wi

RenderPath3D::Update(dt);


#ifdef OPEN_IMAGE_DENOISE
if (sam == target)
{
Expand Down Expand Up @@ -332,8 +357,8 @@ namespace wi

wi::renderer::BindCameraCB(
*camera,
*camera,
*camera,
camera_previous,
camera_reflection,
cmd
);
wi::renderer::BindCommonResources(cmd);
Expand Down Expand Up @@ -412,70 +437,45 @@ namespace wi

wi::renderer::BindCameraCB(
*camera,
*camera,
*camera,
camera_previous,
camera_reflection,
cmd
);
wi::renderer::BindCommonResources(cmd);

// Lightshafts:
bool lightshafts = false;
if (depthBuffer_Main.IsValid())
{
XMVECTOR sunDirection = XMLoadFloat3(&scene->weather.sunDirection);
if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, camera->GetAt())) > 0)
{
device->EventBegin("Light Shafts", cmd);
lightshafts = true;
wi::renderer::Postprocess_Lineardepth(traceDepth, rtLinearDepth, cmd);

// Render sun stencil cutout:
{
RenderPassImage rp[] = {
RenderPassImage::DepthStencil(
&depthBuffer_Main,
RenderPassImage::LoadOp::LOAD,
RenderPassImage::StoreOp::STORE,
ResourceState::DEPTHSTENCIL,
ResourceState::DEPTHSTENCIL,
ResourceState::DEPTHSTENCIL
),
RenderPassImage::RenderTarget(&rtSun[0], RenderPassImage::LoadOp::CLEAR),
};
device->RenderPassBegin(rp, arraysize(rp), cmd);

Viewport vp;
vp.width = (float)depthBuffer_Main.GetDesc().width;
vp.height = (float)depthBuffer_Main.GetDesc().height;
device->BindViewports(1, &vp, cmd);

Rect scissor = GetScissorInternalResolution();
device->BindScissorRects(1, &scissor, cmd);

wi::renderer::DrawSun(cmd);

device->RenderPassEnd(cmd);
}
if (scene->weather.IsRealisticSky())
{
wi::renderer::ComputeSkyAtmosphereSkyViewLut(cmd);

// Radial blur on the sun:
{
XMVECTOR sunPos = XMVector3Project(camera->GetEye() + sunDirection * camera->zFarP, 0, 0,
1.0f, 1.0f, 0.1f, 1.0f,
camera->GetProjection(), camera->GetView(), XMMatrixIdentity());
{
XMFLOAT2 sun;
XMStoreFloat2(&sun, sunPos);
wi::renderer::Postprocess_LightShafts(
getMSAASampleCount() > 1 ? rtSun_resolved : rtSun[0],
rtSun[1],
cmd,
sun,
getLightShaftsStrength()
);
}
}
device->EventEnd(cmd);
if (scene->weather.IsRealisticSkyAerialPerspective())
{
wi::renderer::ComputeSkyAtmosphereCameraVolumeLut(cmd);
}
}
if (scene->weather.IsRealisticSky() && scene->weather.IsRealisticSkyAerialPerspective())
{
wi::renderer::Postprocess_AerialPerspective(
aerialperspectiveResources,
cmd
);
}
if (scene->weather.IsVolumetricClouds())
{
wi::renderer::Postprocess_VolumetricClouds(
volumetriccloudResources,
cmd,
*camera,
camera_previous,
camera_reflection,
false,
scene->weather.volumetricCloudsWeatherMapFirst.IsValid() ? &scene->weather.volumetricCloudsWeatherMapFirst.GetTexture() : nullptr,
scene->weather.volumetricCloudsWeatherMapSecond.IsValid() ? &scene->weather.volumetricCloudsWeatherMapSecond.GetTexture() : nullptr
);
}

RenderLightShafts(cmd);

// Composite other effects on top:
{
Expand Down Expand Up @@ -517,9 +517,29 @@ namespace wi
device->EventEnd(cmd);
}

// Blend Aerial Perspective on top:
if (scene->weather.IsRealisticSky() && scene->weather.IsRealisticSkyAerialPerspective())
{
device->EventBegin("Aerial Perspective Blend", cmd);
wi::image::Params fx;
fx.enableFullScreen();
fx.blendFlag = wi::enums::BLENDMODE_PREMULTIPLIED;
wi::image::Draw(&aerialperspectiveResources.texture_output, fx, cmd);
device->EventEnd(cmd);
}

// Blend the volumetric clouds on top:
if (scene->weather.IsVolumetricClouds())
{
wi::renderer::Postprocess_VolumetricClouds_Upsample(volumetriccloudResources, cmd);
}

wi::renderer::DrawDebugWorld(*scene, *camera, *this, cmd);
wi::renderer::DrawLightVisualizers(visibility_main, cmd);
wi::renderer::DrawSpritesAndFonts(*scene, *camera, false, cmd);

if (lightshafts)
XMVECTOR sunDirection = XMLoadFloat3(&scene->weather.sunDirection);
if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, camera->GetAt())) > 0)
{
device->EventBegin("Contribute LightShafts", cmd);
wi::image::Params fx;
Expand All @@ -528,6 +548,14 @@ namespace wi
wi::image::Draw(&rtSun[1], fx, cmd);
device->EventEnd(cmd);
}
if (getLensFlareEnabled())
{
wi::renderer::DrawLensFlares(
visibility_main,
cmd,
scene->weather.IsVolumetricClouds() ? &volumetriccloudResources.texture_cloudMask : nullptr
);
}

device->RenderPassEnd(cmd);
}
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiRenderPath3D_PathTracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace wi
float getDenoiserProgress() const { return denoiserProgress; }
bool isDenoiserAvailable() const;

void resetProgress() { sam = -1; denoiserProgress = 0; }
void resetProgress() { sam = -1; denoiserProgress = 0; volumetriccloudResources.frame = 0; }

uint8_t instanceInclusionMask_PathTrace = 0xFF;
};
Expand Down
Loading
Loading