Skip to content

Commit

Permalink
[ScreenSpaceShadows] Removed my old screen space shadows since they a…
Browse files Browse the repository at this point in the history
…re vastly inferior
  • Loading branch information
PanosK92 committed Oct 23, 2023
1 parent 09f8634 commit 23d51ee
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 224 deletions.
4 changes: 2 additions & 2 deletions data/shaders/common_buffers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ bool has_texture_metalness() { return buffer_material.propertie
bool has_texture_alpha_mask() { return buffer_material.properties & uint(1U << 6); }
bool has_texture_emissive() { return buffer_material.properties & uint(1U << 7); }
bool has_texture_occlusion() { return buffer_material.properties & uint(1U << 8); }
bool material_is_terrain() { return buffer_material.properties & uint(1U << 9); }
bool material_is_water() { return buffer_material.properties & uint(1U << 10); }
bool material_slope_based() { return buffer_material.properties & uint(1U << 9); }
bool material_animate_uv() { return buffer_material.properties & uint(1U << 10); }

// lighting properties
bool light_is_directional() { return buffer_light.options & uint(1U << 0); }
Expand Down
10 changes: 4 additions & 6 deletions data/shaders/g_buffer.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ float4 sample_albedo(float2 uv, float slope)
{
float4 albedo = tex_material_albedo.Sample(samplers[sampler_anisotropic_wrap], uv);

if (material_is_terrain())
if (material_slope_based())
{
// blend based on slope
float4 tex_flat = albedo;
float4 tex_slope = tex_material_albedo_2.Sample(samplers[sampler_anisotropic_wrap], uv * 0.3f);
albedo = lerp(tex_slope, tex_flat, slope);
Expand All @@ -96,9 +95,8 @@ float3 smaple_normal(float2 uv, float slope)
{
float3 normal = tex_material_normal.Sample(samplers[sampler_anisotropic_wrap], uv).xyz;

if (material_is_terrain())
if (material_slope_based())
{
// blend based on slope
float3 tex_flat = normal;
float3 tex_slope = tex_material_normal2.Sample(samplers[sampler_anisotropic_wrap], uv * 0.3f).rgb;
normal = lerp(tex_slope, tex_flat, slope);
Expand All @@ -117,7 +115,7 @@ PixelOutputType mainPS(PixelInputType input)
// uv
float2 uv = input.uv;
uv = float2(uv.x * buffer_material.tiling.x + buffer_material.offset.x, uv.y * buffer_material.tiling.y + buffer_material.offset.y);
uv += float(buffer_frame.frame * 0.001f) * material_is_water();
uv += float(buffer_frame.frame * 0.001f) * material_animate_uv();

// parallax mapping
if (has_texture_height())
Expand All @@ -143,7 +141,7 @@ PixelOutputType mainPS(PixelInputType input)
float slope = compute_slope(normal);
if (has_texture_normal())
{
// get tangent space normal and apply the user defined intensity. Then transform it to world space.
// get tangent space normal and apply the user defined intensity, then transform it to world space
float3 tangent_normal = normalize(unpack(smaple_normal(uv, slope)));
float normal_intensity = clamp(buffer_material.normal, 0.012f, buffer_material.normal);
tangent_normal.xy *= saturate(normal_intensity);
Expand Down
2 changes: 1 addition & 1 deletion data/shaders/shadow_mapping.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ float4 Shadow_Map(Surface surface, Light light)
// sample primary cascade
auto_bias(surface, pos_ndc, light, cascade_index);
shadow.a = SampleShadowMap(surface, float3(pos_uv, cascade_index), pos_ndc.z);

return shadow;
if (light_has_shadows_transparent())
{
if (shadow.a > 0.0f && surface.is_opaque())
Expand Down
104 changes: 48 additions & 56 deletions editor/Widgets/RenderOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ void RenderOptions::OnTickVisible()
// Reflect options from engine
bool do_dof = Renderer::GetOption<bool>(Renderer_Option::DepthOfField);
bool do_volumetric_fog = Renderer::GetOption<bool>(Renderer_Option::FogVolumetric);
bool do_ssgi = Renderer::GetOption<bool>(Renderer_Option::Ssgi);
bool do_sss = Renderer::GetOption<bool>(Renderer_Option::ScreenSpaceShadows);
bool do_ssgi = Renderer::GetOption<bool>(Renderer_Option::ScreenSpaceGlobalIllumination);
bool do_ssr = Renderer::GetOption<bool>(Renderer_Option::ScreenSpaceReflections);
bool do_motion_blur = Renderer::GetOption<bool>(Renderer_Option::MotionBlur);
bool do_film_grain = Renderer::GetOption<bool>(Renderer_Option::FilmGrain);
Expand Down Expand Up @@ -285,27 +286,27 @@ void RenderOptions::OnTickVisible()

if (option("Screen space lighting"))
{
// SSR
// ssr
option_check_box("SSR - Screen space reflections", do_ssr);

// SSGI
// ssgi
option_check_box("SSGI - Screen space global illumination", do_ssgi, "SSAO with a diffuse light bounce");
}

if (option("Anti-Aliasing"))
{
// Reflect
// reflect
Renderer_Antialiasing antialiasing = Renderer::GetOption<Renderer_Antialiasing>(Renderer_Option::Antialiasing);

// TAA
// taa
bool taa_enabled = antialiasing == Renderer_Antialiasing::Taa || antialiasing == Renderer_Antialiasing::TaaFxaa;
option_check_box("TAA - Temporal anti-aliasing", taa_enabled, "Used to improve many stochastic effects, you want this to always be enabled");

// FXAA
// fxaa
bool fxaa_enabled = antialiasing == Renderer_Antialiasing::Fxaa || antialiasing == Renderer_Antialiasing::TaaFxaa;
option_check_box("FXAA - Fast approximate anti-aliasing", fxaa_enabled);

// Map
// map
if (taa_enabled && fxaa_enabled)
{
Renderer::SetOption(Renderer_Option::Antialiasing, static_cast<float>(Renderer_Antialiasing::TaaFxaa));
Expand All @@ -326,41 +327,31 @@ void RenderOptions::OnTickVisible()

if (option("Camera"))
{
// Bloom
// bloom
option_value("Bloom", Renderer_Option::Bloom, "Controls the blend factor. If zero, then bloom is disabled", 0.01f);

// Motion blur
// motion blur
option_check_box("Motion blur (controlled by the camera's shutter speed)", do_motion_blur);

// Depth of Field
// depth of field
option_check_box("Depth of field (controlled by the camera's aperture)", do_dof);

// Chromatic aberration
// chromatic aberration
option_check_box("Chromatic aberration (controlled by the camera's aperture)", do_chromatic_aberration, "Emulates the inability of old cameras to focus all colors in the same focal point");

// Film grain
// film grain
option_check_box("Film grain", do_film_grain);
}

if (option("Lights"))
{
// Volumetric fog
// volumetric fog
option_check_box("Volumetric fog", do_volumetric_fog, "Requires a light with shadows enabled");

static vector<string> screen_spaces_hadow_modes =
{
"Disabled",
"Normal",
"Bend"
};

uint32_t screen_space_shadow_mode = Renderer::GetOption<uint32_t>(Renderer_Option::ScreenSpaceShadows);
if (option_combo_box("Screenspace shadow", screen_spaces_hadow_modes, screen_space_shadow_mode))
{
Renderer::SetOption(Renderer_Option::ScreenSpaceShadows, static_cast<float>(screen_space_shadow_mode));
}
// screen space shadows
option_check_box("Screen space shadows", do_sss, "Requires a light with shadows enabled");

// Shadow resolution
// shadow resolution
option_int("Shadow resolution", resolution_shadow);
}

Expand All @@ -375,21 +366,21 @@ void RenderOptions::OnTickVisible()
option_value("Paper white (nits)", Renderer_Option::PaperWhite, nullptr, 1.0f);
ImGui::EndDisabled();

// Tonemapping
// tonemapping
static vector<string> tonemapping_options = { "AMD", "ACES", "Reinhard", "Uncharted 2", "Matrix", "Off" };
uint32_t selection_index = Renderer::GetOption<uint32_t>(Renderer_Option::Tonemapping);
if (option_combo_box("Tonemapping", tonemapping_options, selection_index))
{
Renderer::SetOption(Renderer_Option::Tonemapping, static_cast<float>(selection_index));
}

// Dithering
// dithering
option_check_box("Debanding", do_debanding, "Reduces color banding");

// VSync
// vsync
option_check_box("VSync", do_vsync, "Vertical Synchronization");

// FPS Limit
// fps Limit
{
option_first_column();
const FpsLimitType fps_limit_type = Timer::GetFpsLimitType();
Expand All @@ -406,15 +397,15 @@ void RenderOptions::OnTickVisible()
}
}

// Depth-PrePass
// depth pre pass
option_check_box("Depth PrePass", do_depth_prepass);

// Performance metrics
// performance metrics
{
bool performance_metrics_previous = performance_metrics;
option_check_box("Performance Metrics", performance_metrics);

// Reset metrics on activation
// reset metrics on activation
if (performance_metrics_previous == false && performance_metrics == true)
{
Profiler::ClearMetrics();
Expand All @@ -438,27 +429,28 @@ void RenderOptions::OnTickVisible()
ImGui::EndTable();
}

// Map options to engine
Renderer::SetOption(Renderer_Option::ShadowResolution, static_cast<float>(resolution_shadow));
Renderer::SetOption(Renderer_Option::DepthOfField, do_dof);
Renderer::SetOption(Renderer_Option::FogVolumetric, do_volumetric_fog);
Renderer::SetOption(Renderer_Option::Ssgi, do_ssgi);
Renderer::SetOption(Renderer_Option::ScreenSpaceReflections, do_ssr);
Renderer::SetOption(Renderer_Option::MotionBlur, do_motion_blur);
Renderer::SetOption(Renderer_Option::FilmGrain, do_film_grain);
Renderer::SetOption(Renderer_Option::ChromaticAberration, do_chromatic_aberration);
Renderer::SetOption(Renderer_Option::Debanding, do_debanding);
Renderer::SetOption(Renderer_Option::Hdr, do_hdr);
Renderer::SetOption(Renderer_Option::Vsync, do_vsync);
Renderer::SetOption(Renderer_Option::Debug_TransformHandle, debug_transform);
Renderer::SetOption(Renderer_Option::Debug_SelectionOutline, debug_selection_outline);
Renderer::SetOption(Renderer_Option::Debug_Physics, debug_physics);
Renderer::SetOption(Renderer_Option::Debug_Aabb, debug_aabb);
Renderer::SetOption(Renderer_Option::Debug_Lights, debug_light);
Renderer::SetOption(Renderer_Option::Debug_PickingRay, debug_picking_ray);
Renderer::SetOption(Renderer_Option::Debug_Grid, debug_grid);
Renderer::SetOption(Renderer_Option::Debug_ReflectionProbes, debug_reflection_probes);
Renderer::SetOption(Renderer_Option::Debug_PerformanceMetrics, performance_metrics);
Renderer::SetOption(Renderer_Option::Debug_Wireframe, debug_wireframe);
Renderer::SetOption(Renderer_Option::DepthPrepass, do_depth_prepass);
// map options to engine
Renderer::SetOption(Renderer_Option::ShadowResolution, static_cast<float>(resolution_shadow));
Renderer::SetOption(Renderer_Option::DepthOfField, do_dof);
Renderer::SetOption(Renderer_Option::FogVolumetric, do_volumetric_fog);
Renderer::SetOption(Renderer_Option::ScreenSpaceGlobalIllumination, do_ssgi);
Renderer::SetOption(Renderer_Option::ScreenSpaceReflections, do_ssr);
Renderer::SetOption(Renderer_Option::ScreenSpaceShadows, do_sss);
Renderer::SetOption(Renderer_Option::MotionBlur, do_motion_blur);
Renderer::SetOption(Renderer_Option::FilmGrain, do_film_grain);
Renderer::SetOption(Renderer_Option::ChromaticAberration, do_chromatic_aberration);
Renderer::SetOption(Renderer_Option::Debanding, do_debanding);
Renderer::SetOption(Renderer_Option::Hdr, do_hdr);
Renderer::SetOption(Renderer_Option::Vsync, do_vsync);
Renderer::SetOption(Renderer_Option::Debug_TransformHandle, debug_transform);
Renderer::SetOption(Renderer_Option::Debug_SelectionOutline, debug_selection_outline);
Renderer::SetOption(Renderer_Option::Debug_Physics, debug_physics);
Renderer::SetOption(Renderer_Option::Debug_Aabb, debug_aabb);
Renderer::SetOption(Renderer_Option::Debug_Lights, debug_light);
Renderer::SetOption(Renderer_Option::Debug_PickingRay, debug_picking_ray);
Renderer::SetOption(Renderer_Option::Debug_Grid, debug_grid);
Renderer::SetOption(Renderer_Option::Debug_ReflectionProbes, debug_reflection_probes);
Renderer::SetOption(Renderer_Option::Debug_PerformanceMetrics, performance_metrics);
Renderer::SetOption(Renderer_Option::Debug_Wireframe, debug_wireframe);
Renderer::SetOption(Renderer_Option::DepthPrepass, do_depth_prepass);
}
66 changes: 33 additions & 33 deletions runtime/Core/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,39 @@ namespace Spartan
{
switch (option)
{
case Renderer_Option::Debug_Aabb: return "Debug_Aabb";
case Renderer_Option::Debug_PickingRay: return "Debug_PickingRay";
case Renderer_Option::Debug_Grid: return "Debug_Grid";
case Renderer_Option::Debug_ReflectionProbes: return "Debug_ReflectionProbes";
case Renderer_Option::Debug_TransformHandle: return "Debug_TransformHandle";
case Renderer_Option::Debug_SelectionOutline: return "Debug_SelectionOutline";
case Renderer_Option::Debug_Lights: return "Debug_Lights";
case Renderer_Option::Debug_PerformanceMetrics: return "Debug_PerformanceMetrics";
case Renderer_Option::Debug_Physics: return "Debug_Physics";
case Renderer_Option::Debug_Wireframe: return "Debug_Wireframe";
case Renderer_Option::Bloom: return "Bloom";
case Renderer_Option::Fog: return "Fog";
case Renderer_Option::FogVolumetric: return "FogVolumetric";
case Renderer_Option::Ssgi: return "Ssgi";
case Renderer_Option::ScreenSpaceShadows: return "ScreenSpaceShadows";
case Renderer_Option::ScreenSpaceReflections: return "ScreenSpaceReflections";
case Renderer_Option::MotionBlur: return "MotionBlur";
case Renderer_Option::DepthOfField: return "DepthOfField";
case Renderer_Option::FilmGrain: return "FilmGrain";
case Renderer_Option::ChromaticAberration: return "ChromaticAberration";
case Renderer_Option::Debanding: return "Debanding";
case Renderer_Option::DepthPrepass: return "DepthPrepass";
case Renderer_Option::Anisotropy: return "Anisotropy";
case Renderer_Option::ShadowResolution: return "ShadowResolution";
case Renderer_Option::Gamma: return "Gamma";
case Renderer_Option::Exposure: return "Exposure";
case Renderer_Option::PaperWhite: return "PaperWhite";
case Renderer_Option::Antialiasing: return "Antialiasing";
case Renderer_Option::Tonemapping: return "Tonemapping";
case Renderer_Option::Upsampling: return "Upsampling";
case Renderer_Option::Sharpness: return "Sharpness";
case Renderer_Option::Hdr: return "Hdr";
case Renderer_Option::Vsync: return "Vsync";
case Renderer_Option::Debug_Aabb: return "Debug_Aabb";
case Renderer_Option::Debug_PickingRay: return "Debug_PickingRay";
case Renderer_Option::Debug_Grid: return "Debug_Grid";
case Renderer_Option::Debug_ReflectionProbes: return "Debug_ReflectionProbes";
case Renderer_Option::Debug_TransformHandle: return "Debug_TransformHandle";
case Renderer_Option::Debug_SelectionOutline: return "Debug_SelectionOutline";
case Renderer_Option::Debug_Lights: return "Debug_Lights";
case Renderer_Option::Debug_PerformanceMetrics: return "Debug_PerformanceMetrics";
case Renderer_Option::Debug_Physics: return "Debug_Physics";
case Renderer_Option::Debug_Wireframe: return "Debug_Wireframe";
case Renderer_Option::Bloom: return "Bloom";
case Renderer_Option::Fog: return "Fog";
case Renderer_Option::FogVolumetric: return "FogVolumetric";
case Renderer_Option::ScreenSpaceGlobalIllumination: return "ScreenSpaceGlobalIllumination";
case Renderer_Option::ScreenSpaceShadows: return "ScreenSpaceShadows";
case Renderer_Option::ScreenSpaceReflections: return "ScreenSpaceReflections";
case Renderer_Option::MotionBlur: return "MotionBlur";
case Renderer_Option::DepthOfField: return "DepthOfField";
case Renderer_Option::FilmGrain: return "FilmGrain";
case Renderer_Option::ChromaticAberration: return "ChromaticAberration";
case Renderer_Option::Debanding: return "Debanding";
case Renderer_Option::DepthPrepass: return "DepthPrepass";
case Renderer_Option::Anisotropy: return "Anisotropy";
case Renderer_Option::ShadowResolution: return "ShadowResolution";
case Renderer_Option::Gamma: return "Gamma";
case Renderer_Option::Exposure: return "Exposure";
case Renderer_Option::PaperWhite: return "PaperWhite";
case Renderer_Option::Antialiasing: return "Antialiasing";
case Renderer_Option::Tonemapping: return "Tonemapping";
case Renderer_Option::Upsampling: return "Upsampling";
case Renderer_Option::Sharpness: return "Sharpness";
case Renderer_Option::Hdr: return "Hdr";
case Renderer_Option::Vsync: return "Vsync";
default:
{
SP_ASSERT_MSG(false, "Renderer_Option not handled");
Expand Down
2 changes: 1 addition & 1 deletion runtime/RHI/RHI_Implemenation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Spartan
bool RHI_Context::validation = true;
bool RHI_Context::gpu_markers = true;
bool RHI_Context::gpu_profiling = true;
bool RHI_Context::renderdoc = false;
bool RHI_Context::renderdoc = true;
#else
bool RHI_Context::validation = false;
bool RHI_Context::gpu_markers = false;
Expand Down
Loading

0 comments on commit 23d51ee

Please sign in to comment.