Skip to content

Commit

Permalink
[lighting] fixed broken shadows in the living room world, improved/fi…
Browse files Browse the repository at this point in the history
…xed screen space shadows which were too hard
  • Loading branch information
PanosK92 committed Jan 3, 2025
1 parent 7fd4ce5 commit e6e6a52
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 171 deletions.
24 changes: 12 additions & 12 deletions data/shaders/screen_space_shadows/bend_sss.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//=======================

#define WAVE_SIZE 64
#define SAMPLE_COUNT 256
#define HARD_SHADOW_SAMPLES 16
#define FADE_OUT_SAMPLES 8
#define SAMPLE_COUNT 256 // shadow samples per-pixel, determines overall cost, default: 60
#define HARD_SHADOW_SAMPLES 1 // initial shadow samples that will produce a hard shadow, and not perform sample-averaging, defauult: 4
#define FADE_OUT_SAMPLES 64 // samples that will fade out at the end of the shadow (for a minor cost), default : 8

#include "bend_sss_gpu.hlsl"

Expand All @@ -41,18 +41,18 @@ void main_cs
{
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_f2_value(); // 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.LightCoordinate = pass_get_f4_value(); // values stored in DispatchList::LightCoordinate_Shader by BuildDispatchList()
in_parameters.WaveOffset = pass_get_f2_value(); // 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.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_uav_sss;
in_parameters.PointBorderSampler = samplers[sampler_point_clamp_border]; // 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.
in_parameters.PointBorderSampler = samplers[sampler_point_clamp_border]; // 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);
}
42 changes: 0 additions & 42 deletions data/shaders/screen_space_shadows/sss.hlsl

This file was deleted.

90 changes: 43 additions & 47 deletions runtime/Rendering/Font/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,8 @@ namespace Spartan
Vector2 cursor = position;
float starting_pos_x = cursor.x;

// allocate ahead of time
{
// calculate the required size for vertices and indices
size_t required_vertices_count = text.length() * 6; // 6 vertices per character
size_t required_indices_count = required_vertices_count; // 1 index per vertex

// reserve memory for class members
m_vertices.reserve(required_vertices_count);
m_indices.reserve(required_indices_count);

// clear existing data (reuse preallocated memory)
m_vertices.clear();
m_indices.clear();
}
m_vertices.clear();
m_indices.clear();

// generate vertices - draw each latter onto a quad
for (char character : text)
Expand Down Expand Up @@ -189,78 +177,86 @@ namespace Spartan
if (m_font_data.empty())
return;

// combine all vertices/indices into one
vector<RHI_Vertex_PosTex> vertices;
vector<uint32_t> indices;
uint32_t vertex_offset = 0;

for (const FontData& text_data : m_font_data)
// merge all vertices and indices
{
vertices.insert(vertices.end(), text_data.vertices.begin(), text_data.vertices.end());
for (uint32_t index : text_data.indices)
m_vertices.clear();
m_indices.clear();

uint32_t vertex_offset = 0;
for (const FontData& text_data : m_font_data)
{
indices.push_back(index + vertex_offset);
m_vertices.insert(m_vertices.end(), text_data.vertices.begin(), text_data.vertices.end());
for (uint32_t index : text_data.indices)
{
m_indices.push_back(index + vertex_offset);
}
vertex_offset += static_cast<uint32_t>(text_data.vertices.size());
}
vertex_offset += static_cast<uint32_t>(text_data.vertices.size());
}

// grow buffers if needed
{
if (vertices.size() > m_buffer_vertex->GetElementCount())
if (m_vertices.size() > m_buffer_vertex->GetElementCount())
{
m_buffer_vertex = make_shared<RHI_Buffer>(RHI_Buffer_Type::Vertex,
sizeof(vertices[0]),
static_cast<uint32_t>(vertices.size()),
static_cast<void*>(&vertices[0]),
true,
m_buffer_vertex = make_shared<RHI_Buffer>(
RHI_Buffer_Type::Vertex, // type
sizeof(m_vertices[0]), // stride
static_cast<uint32_t>(m_vertices.size()), // element count
static_cast<void*>(&m_vertices[0]), // data
true, // mappable
"font_vertex"
);
}

if (indices.size() > m_buffer_index->GetElementCount())
if (m_indices.size() > m_buffer_index->GetElementCount())
{
m_buffer_index = make_shared<RHI_Buffer>(RHI_Buffer_Type::Index,
sizeof(indices[0]),
static_cast<uint32_t>(indices.size()),
static_cast<void*>(&indices[0]),
true,
m_buffer_index = make_shared<RHI_Buffer>(
RHI_Buffer_Type::Index, // type
sizeof(m_indices[0]), // stride
static_cast<uint32_t>(m_indices.size()), // element count
static_cast<void*>(&m_indices[0]), // data
true, // mappable
"font_index"
);
}
}

// update vertex buffer in chunks
{
const size_t vertex_size = sizeof(vertices[0]);
size_t vertices_size = vertices.size() * vertex_size;
const size_t vertex_size = sizeof(m_vertices[0]);
size_t size = m_vertices.size() * vertex_size;
size_t offset = 0;

// zero out
memset(m_buffer_vertex->GetMappedData(), 0, m_buffer_vertex->GetObjectSize());

// update
while (offset < vertices_size)
while (offset < size)
{
size_t current_chunk_size = min(static_cast<size_t>(rhi_max_buffer_update_size), vertices_size - offset);
cmd_list->UpdateBuffer(m_buffer_vertex.get(), offset, current_chunk_size, &vertices[offset / vertex_size]);
size_t current_chunk_size = min(static_cast<size_t>(rhi_max_buffer_update_size), size - offset);

cmd_list->UpdateBuffer(m_buffer_vertex.get(), offset, current_chunk_size, &m_vertices[offset / vertex_size]);

offset += current_chunk_size;
}
}

// update index buffer in chunks
{
const size_t index_size = sizeof(indices[0]);
const size_t index_size = sizeof(m_indices[0]);
size_t size = m_indices.size() * index_size;
size_t offset = 0;
size_t indices_size = indices.size() * index_size;

// zero out
memset(m_buffer_index->GetMappedData(), 0, m_buffer_index->GetObjectSize());

// update
while (offset < indices_size)
while (offset < size)
{
size_t current_chunk_size = min(static_cast<size_t>(rhi_max_buffer_update_size), indices_size - offset);
cmd_list->UpdateBuffer(m_buffer_index.get(), offset, current_chunk_size, &indices[offset / index_size]);
size_t current_chunk_size = min(static_cast<size_t>(rhi_max_buffer_update_size), size - offset);

cmd_list->UpdateBuffer(m_buffer_index.get(), offset, current_chunk_size, &m_indices[offset / index_size]);

offset += current_chunk_size;
}
}
Expand Down
Loading

0 comments on commit e6e6a52

Please sign in to comment.