Skip to content

Commit

Permalink
Merge pull request #113 from Nickelium/screenspaceshadow
Browse files Browse the repository at this point in the history
Screenspaceshadow
  • Loading branch information
PanosK92 authored Oct 21, 2023
2 parents 912a728 + bfe8379 commit b5b211a
Show file tree
Hide file tree
Showing 18 changed files with 1,186 additions and 66 deletions.
2 changes: 2 additions & 0 deletions data/shaders/common_textures.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ Texture2D tex : register(t35);
Texture2D tex2 : register(t36);
Texture2D tex_font_atlas : register(t37);
TextureCube tex_reflection_probe : register(t38);
Texture2DArray tex_sss : register(t39);

// Storage
RWTexture2D<float4> tex_uav : register(u0);
RWTexture2D<float4> tex_uav2 : register(u1);
RWTexture2D<float4> tex_uav3 : register(u2);
globallycoherent RWStructuredBuffer<uint> g_atomic_counter : register(u3);
globallycoherent RWTexture2D<float4> tex_uav_mips[12] : register(u4);
RWTexture2DArray<float4> tex_uav4 : register(u5);
5 changes: 3 additions & 2 deletions data/shaders/light.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ void mainCS(uint3 thread_id : SV_DispatchThreadID)
}

// screen space shadows
if (is_screen_space_shadows_enabled())
int array_slice_index = pass_get_f3_value2().x;
if (light_has_shadows() && is_screen_space_shadows_enabled() && array_slice_index != -1)
{
shadow.a = min(shadow.a, ScreenSpaceShadows(surface, light));
shadow.a = min(shadow.a, tex_sss[int3(thread_id.xy, array_slice_index)].x);
}

// ensure that the shadow is as transparent as the material
Expand Down
67 changes: 67 additions & 0 deletions data/shaders/screen_space_shadows/bend_sss.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright(c) 2016-2023 Panos Karabelas
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

//= INCLUDES =======================
#include "../common.hlsl"
#include "screen_space_shadows.hlsl"
//==================================

#define WAVE_SIZE 64
#define SAMPLE_COUNT 60
#define HARD_SHADOW_SAMPLES 4
#define FADE_OUT_SAMPLES 8

#include "bend_sss_gpu.hlsl"

[numthreads(WAVE_SIZE, 1, 1)]
void mainCS
(
uint3 DTid : SV_DispatchThreadID,
uint3 Gid : SV_GroupID,
uint3 GTid : SV_GroupThreadID,
uint groupIndex : SV_GroupIndex
)
{
// create surface
Surface surface;
surface.Build(DTid.xy, true, true, true);

// create light
Light light;
light.Build(surface);

DispatchParameters in_parameters;
in_parameters.SetDefaults();
in_parameters.LightCoordinate = pass_get_f4_value(); // Values stored in DispatchList::LightCoordinate_Shader by BuildDispatchList()
in_parameters.WaveOffset = pass_get_resolution_in(); // Values stored in DispatchData::WaveOffset_Shader by BuildDispatchList()
in_parameters.NearDepthValue = pass_get_f3_value().x; // Set to the Depth Buffer Value for the near clip plane, as determined by renderer projection matrix setup (typically 1).
in_parameters.FarDepthValue = pass_get_f3_value().y; // Set to the Depth Buffer Value for the far clip plane, as determined by renderer projection matrix setup (typically 0).
in_parameters.ArraySliceIndex = pass_get_f3_value().z;
in_parameters.InvDepthTextureSize = pass_get_f3_value2().xy; // Inverse of the texture dimensions for 'DepthTexture' (used to convert from pixel coordinates to UVs)
in_parameters.DepthTexture = tex;
in_parameters.OutputTexture = tex_uav4;
in_parameters.PointBorderSampler = samplers[sampler_point_wrap]; // A point sampler, with Wrap Mode set to Clamp-To-Border-Color (D3D12_TEXTURE_ADDRESS_MODE_BORDER), and Border Color set to "FarDepthValue" (typically zero), or some other far-depth value out of DepthBounds.
in_parameters.DebugOutputEdgeMask = false; // Use this to visualize edges, for tuning the 'BilinearThreshold' value.
in_parameters.DebugOutputThreadIndex = false; // Debug output to visualize layout of compute threads
in_parameters.DebugOutputWaveIndex = false; // Debug output to visualize layout of compute wavefronts, useful to sanity check the Light Coordinate is being computed correctly.

WriteScreenSpaceShadow(in_parameters, Gid, GTid.x);
}
Loading

0 comments on commit b5b211a

Please sign in to comment.