Skip to content

Commit

Permalink
[renderer] removed skysphere to skybox conversion since it takes 1 ms…
Browse files Browse the repository at this point in the history
… and fidelityfx doesn't need when ibl factor is set to 0
  • Loading branch information
PanosK92 committed Jan 4, 2025
1 parent 8e53821 commit 386b054
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 138 deletions.
57 changes: 0 additions & 57 deletions data/shaders/skysphere_to_skybox.hlsl

This file was deleted.

2 changes: 0 additions & 2 deletions runtime/RHI/D3D12/D3D12_FidelityFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ namespace Spartan
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_brdf,
RHI_Texture* tex_skybox,
RHI_Texture* tex_output
)
{
Expand Down Expand Up @@ -123,7 +122,6 @@ namespace Spartan
RHI_Texture* tex_velocity,
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_skybox,
array<RHI_Texture*, 8>& tex_noise,
RHI_Texture* tex_diffuse_gi,
RHI_Texture* tex_specular_gi,
Expand Down
2 changes: 0 additions & 2 deletions runtime/RHI/RHI_FidelityFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ namespace Spartan
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_brdf,
RHI_Texture* tex_skybox,
RHI_Texture* tex_output
);

Expand All @@ -95,7 +94,6 @@ namespace Spartan
RHI_Texture* tex_velocity,
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_skybox,
std::array< RHI_Texture*, 8>& tex_noise,
RHI_Texture* tex_diffuse_gi,
RHI_Texture* tex_specular_gi,
Expand Down
62 changes: 35 additions & 27 deletions runtime/RHI/Vulkan/Vulkan_FidelityFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ namespace Spartan
namespace
{
// shared among all contexts
FfxInterface ffx_interface = {};
Matrix view = Matrix::Identity;
Matrix view_previous = Matrix::Identity;
Matrix projection = Matrix::Identity;
Matrix projection_previous = Matrix::Identity;
Matrix view_projection = Matrix::Identity;
Matrix view_inverted = Matrix::Identity;
Matrix projection_inverted = Matrix::Identity;
Matrix view_projection_previous = Matrix::Identity;
Matrix view_projection_inverted = Matrix::Identity;
uint32_t resolution_render_width = 0;
uint32_t resolution_render_height = 0;
uint32_t resolution_output_width = 0;
uint32_t resolution_output_height = 0;
FfxInterface ffx_interface = {};
Matrix view = Matrix::Identity;
Matrix view_previous = Matrix::Identity;
Matrix projection = Matrix::Identity;
Matrix projection_previous = Matrix::Identity;
Matrix view_projection = Matrix::Identity;
Matrix view_inverted = Matrix::Identity;
Matrix projection_inverted = Matrix::Identity;
Matrix view_projection_previous = Matrix::Identity;
Matrix view_projection_inverted = Matrix::Identity;
uint32_t resolution_render_width = 0;
uint32_t resolution_render_height = 0;
uint32_t resolution_output_width = 0;
uint32_t resolution_output_height = 0;
shared_ptr<RHI_Texture> texture_skybox = nullptr;

void ffx_message_callback(FfxMsgType type, const wchar_t* message)
{
Expand Down Expand Up @@ -830,6 +831,12 @@ namespace Spartan

// assets
{
// shared
{
// empty skybox (the engine uses a skysphere)
texture_skybox = make_shared<RHI_Texture>(RHI_Texture_Type::TypeCube, 1, 1, 6, 1, RHI_Format::R16G16B16A16_Float, RHI_Texture_Srv | RHI_Texture_Uav, "skybox");
}

// brixelizer gi
{
// sdf atlas texture
Expand Down Expand Up @@ -918,6 +925,9 @@ namespace Spartan
brixelizer_gi::texture_normal_previous = nullptr;
brixelizer_gi::buffer_cascade_aabb_tree.fill(nullptr);
brixelizer_gi::buffer_cascade_brick_map.fill(nullptr);

// shared
texture_skybox = nullptr;
#endif
}

Expand Down Expand Up @@ -1103,7 +1113,6 @@ namespace Spartan
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_brdf,
RHI_Texture* tex_skybox,
RHI_Texture* tex_output
)
{
Expand All @@ -1114,14 +1123,14 @@ namespace Spartan

// set resources
sssr::description_dispatch.commandList = to_ffx_cmd_list(cmd_list);
sssr::description_dispatch.color = to_ffx_resource(tex_color, L"sssr_color");
sssr::description_dispatch.depth = to_ffx_resource(tex_depth, L"sssr_depth");
sssr::description_dispatch.motionVectors = to_ffx_resource(tex_velocity, L"sssr_velocity");
sssr::description_dispatch.normal = to_ffx_resource(tex_normal, L"sssr_normal");
sssr::description_dispatch.materialParameters = to_ffx_resource(tex_material, L"sssr_roughness");
sssr::description_dispatch.environmentMap = to_ffx_resource(tex_skybox, L"sssr_environment");
sssr::description_dispatch.brdfTexture = to_ffx_resource(tex_brdf, L"sssr_brdf");
sssr::description_dispatch.output = to_ffx_resource(tex_output, L"sssr_output");
sssr::description_dispatch.color = to_ffx_resource(tex_color, L"sssr_color");
sssr::description_dispatch.depth = to_ffx_resource(tex_depth, L"sssr_depth");
sssr::description_dispatch.motionVectors = to_ffx_resource(tex_velocity, L"sssr_velocity");
sssr::description_dispatch.normal = to_ffx_resource(tex_normal, L"sssr_normal");
sssr::description_dispatch.materialParameters = to_ffx_resource(tex_material, L"sssr_roughness");
sssr::description_dispatch.environmentMap = to_ffx_resource(texture_skybox.get(), L"sssr_environment");
sssr::description_dispatch.brdfTexture = to_ffx_resource(tex_brdf, L"sssr_brdf");
sssr::description_dispatch.output = to_ffx_resource(tex_output, L"sssr_output");

// set render size
sssr::description_dispatch.renderSize.width = static_cast<uint32_t>(tex_color->GetWidth() * resolution_scale);
Expand All @@ -1140,7 +1149,7 @@ namespace Spartan
sssr::description_dispatch.temporalStabilityFactor = 0.8f; // the accumulation of history values, higher values reduce noise, but are more likely to exhibit ghosting artifacts
sssr::description_dispatch.temporalVarianceGuidedTracingEnabled = true; // whether a ray should be spawned on pixels where a temporal variance is detected or not
sssr::description_dispatch.samplesPerQuad = 1; // the minimum number of rays per quad, variance guided tracing can increase this up to a maximum of 4
sssr::description_dispatch.iblFactor = 1.0f;
sssr::description_dispatch.iblFactor = 0.0f;
sssr::description_dispatch.roughnessChannel = 0;
sssr::description_dispatch.isRoughnessPerceptual = true;
sssr::description_dispatch.roughnessThreshold = 1.0f; // regions with a roughness value greater than this threshold won't spawn rays
Expand Down Expand Up @@ -1345,7 +1354,6 @@ namespace Spartan
RHI_Texture* tex_velocity,
RHI_Texture* tex_normal,
RHI_Texture* tex_material,
RHI_Texture* tex_skybox,
array<RHI_Texture*, 8>& tex_noise,
RHI_Texture* tex_diffuse_gi,
RHI_Texture* tex_specular_gi,
Expand All @@ -1368,7 +1376,7 @@ namespace Spartan
set_ffx_float16(brixelizer_gi::description_dispatch_gi.prevProjection, projection_previous);

// set resources
brixelizer_gi::description_dispatch_gi.environmentMap = to_ffx_resource(tex_skybox, L"brixelizer_gi_environment");
brixelizer_gi::description_dispatch_gi.environmentMap = to_ffx_resource(texture_skybox.get(), L"brixelizer_gi__environment");
brixelizer_gi::description_dispatch_gi.prevLitOutput = to_ffx_resource(tex_frame, L"brixelizer_gi_lit_output_previous");
brixelizer_gi::description_dispatch_gi.depth = to_ffx_resource(tex_depth, L"brixelizer_gi_depth");
brixelizer_gi::description_dispatch_gi.historyDepth = to_ffx_resource(brixelizer_gi::texture_depth_previous.get(), L"brixelizer_gi_depth_previous");
Expand Down Expand Up @@ -1401,7 +1409,7 @@ namespace Spartan
brixelizer_gi::description_dispatch_gi.isRoughnessPerceptual = true; // if false, we assume roughness squared was stored in the Gbuffer
brixelizer_gi::description_dispatch_gi.roughnessChannel = 0; // the channel to read the roughness from the roughness texture
brixelizer_gi::description_dispatch_gi.roughnessThreshold = 1.0f; // regions with a roughness value greater than this threshold won't spawn specular rays
brixelizer_gi::description_dispatch_gi.environmentMapIntensity = 1.0f; // value to scale the contribution from the environment map
brixelizer_gi::description_dispatch_gi.environmentMapIntensity = 0.0f; // value to scale the contribution from the environment map
brixelizer_gi::description_dispatch_gi.motionVectorScale.x = -1.0f;
brixelizer_gi::description_dispatch_gi.motionVectorScale.y = -1.0f;
set_ffx_float3(brixelizer_gi::description_dispatch_gi.cameraPosition, cb_frame->camera_position);
Expand Down
2 changes: 0 additions & 2 deletions runtime/Rendering/Renderer_Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ namespace Spartan
ssao_c,
sss_c_bend,
skysphere_c,
skysphere_to_skybox_c,
blur_gaussian_c,
blur_gaussian_bilaterial_c,
variable_rate_shading_c,
Expand Down Expand Up @@ -230,7 +229,6 @@ namespace Spartan
ssr,
sss,
skysphere,
skybox,
bloom,
blur,
outline,
Expand Down
53 changes: 13 additions & 40 deletions runtime/Rendering/Renderer_Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ namespace Spartan
GetRenderTarget(Renderer_RenderTarget::gbuffer_normal),
GetRenderTarget(Renderer_RenderTarget::gbuffer_material),
GetRenderTarget(Renderer_RenderTarget::brdf_specular_lut),
GetRenderTarget(Renderer_RenderTarget::skybox),
GetRenderTarget(Renderer_RenderTarget::ssr)
);

Expand Down Expand Up @@ -1054,11 +1053,9 @@ namespace Spartan
void Renderer::Pass_Skysphere(RHI_CommandList* cmd_list)
{
// acquire resources
RHI_Shader* shader_skysphere = GetShader(Renderer_Shader::skysphere_c);
RHI_Shader* shader_skysphere_to_skybox = GetShader(Renderer_Shader::skysphere_to_skybox_c);
RHI_Texture* tex_skysphere = GetRenderTarget(Renderer_RenderTarget::skysphere);
RHI_Texture* tex_skybox = GetRenderTarget(Renderer_RenderTarget::skybox);
if (!shader_skysphere->IsCompiled() || !shader_skysphere_to_skybox->IsCompiled())
RHI_Shader* shader_skysphere = GetShader(Renderer_Shader::skysphere_c);
RHI_Texture* tex_skysphere = GetRenderTarget(Renderer_RenderTarget::skysphere);
if (!shader_skysphere->IsCompiled())
return;

// get directional light
Expand All @@ -1083,41 +1080,18 @@ namespace Spartan

cmd_list->BeginTimeblock("skysphere");
{
// atmospheric scattering
{
// set pipeline state
static RHI_PipelineState pso_skysphere;
pso_skysphere.name = "skysphere";
pso_skysphere.shaders[Compute] = shader_skysphere;
cmd_list->SetPipelineState(pso_skysphere);

// set pass constants
m_pcb_pass_cpu.set_f3_value2(static_cast<float>(light->GetIndex()), 0.0f, 0.0f);
cmd_list->PushConstants(m_pcb_pass_cpu);
// set pipeline state
static RHI_PipelineState pso_skysphere;
pso_skysphere.name = "skysphere";
pso_skysphere.shaders[Compute] = shader_skysphere;
cmd_list->SetPipelineState(pso_skysphere);

cmd_list->SetTexture(Renderer_BindingsUav::tex, tex_skysphere);
cmd_list->Dispatch(tex_skysphere);
}
// set pass constants
m_pcb_pass_cpu.set_f3_value2(static_cast<float>(light->GetIndex()), 0.0f, 0.0f);
cmd_list->PushConstants(m_pcb_pass_cpu);

// write the skysphere to a small cubemap because fidelityfx requires it
{
// pipeline
static RHI_PipelineState pso_skysphere_to_skybox;
pso_skysphere_to_skybox.name = "skysphere_to_skybox";
pso_skysphere_to_skybox.shaders[Compute] = shader_skysphere_to_skybox;
cmd_list->SetPipelineState(pso_skysphere_to_skybox);

// textures
cmd_list->SetTexture(Renderer_BindingsUav::tex_sss, tex_skybox);
cmd_list->SetTexture(Renderer_BindingsSrv::tex, tex_skysphere);
cmd_list->SetTexture(Renderer_BindingsSrv::tex2, GetStandardTexture(Renderer_StandardTexture::Noise_blue_0));

// dispatch
const uint32_t thread_group_count = 8;
const uint32_t thread_group_count_x = (tex_skysphere->GetWidth() + thread_group_count - 1) / thread_group_count;
const uint32_t thread_group_count_y = (tex_skysphere->GetHeight() + thread_group_count - 1) / thread_group_count;
cmd_list->Dispatch(thread_group_count_x, thread_group_count_y, 6);
}
cmd_list->SetTexture(Renderer_BindingsUav::tex, tex_skysphere);
cmd_list->Dispatch(tex_skysphere);
}
cmd_list->EndTimeblock();
}
Expand Down Expand Up @@ -1240,7 +1214,6 @@ namespace Spartan
GetRenderTarget(Renderer_RenderTarget::gbuffer_velocity),
GetRenderTarget(Renderer_RenderTarget::gbuffer_normal),
GetRenderTarget(Renderer_RenderTarget::gbuffer_material),
GetRenderTarget(Renderer_RenderTarget::skybox),
noise_textures,
GetRenderTarget(Renderer_RenderTarget::light_diffuse_gi),
GetRenderTarget(Renderer_RenderTarget::light_specular_gi),
Expand Down
10 changes: 2 additions & 8 deletions runtime/Rendering/Renderer_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ namespace Spartan

// sky
render_target(Renderer_RenderTarget::skysphere) = make_shared<RHI_Texture>(RHI_Texture_Type::Type2D, 4096, 4096, 1, mip_count, RHI_Format::R11G11B10_Float, flags | RHI_Texture_PerMipViews, "skysphere");
render_target(Renderer_RenderTarget::skybox) = make_shared<RHI_Texture>(RHI_Texture_Type::TypeCube, 256, 256, 6, 1, RHI_Format::R16G16B16A16_Float, RHI_Texture_Srv | RHI_Texture_Uav, "skybox"); // for fidelityfx
}

RHI_Device::QueueWaitAll();
Expand Down Expand Up @@ -421,13 +420,8 @@ namespace Spartan
}

// sky
{
shader(Renderer_Shader::skysphere_c) = make_shared<RHI_Shader>();
shader(Renderer_Shader::skysphere_c)->Compile(RHI_Shader_Type::Compute, shader_dir + "skysphere.hlsl", async);

shader(Renderer_Shader::skysphere_to_skybox_c) = make_shared<RHI_Shader>();
shader(Renderer_Shader::skysphere_to_skybox_c)->Compile(RHI_Shader_Type::Compute, shader_dir + "skysphere_to_skybox.hlsl", async);
}
shader(Renderer_Shader::skysphere_c) = make_shared<RHI_Shader>();
shader(Renderer_Shader::skysphere_c)->Compile(RHI_Shader_Type::Compute, shader_dir + "skysphere.hlsl", async);

// fxaa
shader(Renderer_Shader::fxaa_c) = make_shared<RHI_Shader>();
Expand Down

0 comments on commit 386b054

Please sign in to comment.