Skip to content
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
11 changes: 0 additions & 11 deletions assets/shaders/ssao.vert

This file was deleted.

13 changes: 6 additions & 7 deletions assets/shaders/ssao_blur.frag
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#version 410 core
#version 450 core

out float g_occlusion;
layout(location = 0) in vec2 v_texcoord;
layout(location = 0) out float g_occlusion;

in vec2 v_texcoord;

uniform sampler2D u_ssao_input;
layout(set = 0, binding = 0) uniform sampler2D u_ssao_input;

void main() {
float result = 0.0;
vec2 texel_size = 1.0 / vec2(textureSize(u_ssao_input, 0));

// 4x4 Box Blur
// 4x4 Box Blur (Simple)
for (int x = -2; x < 2; ++x) {
for (int y = -2; y < 2; ++y) {
vec2 offset = vec2(float(x), float(y)) * texel_size;
result += texture(u_ssao_input, v_texcoord + offset).r;
}
}

g_occlusion = result / (4.0 * 4.0);
g_occlusion = result / 16.0;
}
34 changes: 29 additions & 5 deletions engine/assets/shader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,35 @@
#include <fstream>
#include <sstream>

#ifdef _WIN32
#include <windows.h>

Check warning on line 9 in engine/assets/shader_compiler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk

See more on https://sonarcloud.io/project/issues?id=jackthepunished_horizon-engine&issues=AZ0OSRksXPeeTARt7DtW&open=AZ0OSRksXPeeTARt7DtW&pullRequest=2
#endif

#ifdef HZ_VULKAN_BACKEND
#include <shaderc/shaderc.hpp>
#endif

namespace hz {

// Safe path-to-string conversion that avoids MinGW's broken narrow locale
// conversion (which throws "Illegal byte sequence" on Turkish Windows etc.)
static std::string path_to_string(const std::filesystem::path& p) {
#ifdef _WIN32
// On Windows, go through wide string -> narrow via WideCharToMultiByte CP_UTF8
const auto& ws = p.native(); // returns const wstring& on Windows
if (ws.empty())
return {};
int size_needed = WideCharToMultiByte(CP_UTF8, 0, ws.data(), static_cast<int>(ws.size()),
nullptr, 0, nullptr, nullptr);
std::string result(static_cast<size_t>(size_needed), '\0');
WideCharToMultiByte(CP_UTF8, 0, ws.data(), static_cast<int>(ws.size()), result.data(),
size_needed, nullptr, nullptr);
return result;
#else
return p.string();
#endif
}

namespace {

#ifdef HZ_VULKAN_BACKEND
Expand Down Expand Up @@ -65,7 +88,7 @@
// Read the file
std::ifstream file(resolved_path, std::ios::binary | std::ios::ate);
if (!file) {
std::string error_msg = "Could not open include file: " + resolved_path.string();
std::string error_msg = "Could not open include file: " + path_to_string(resolved_path);
auto* error_data = new std::string(std::move(error_msg));
result->source_name = "";
result->source_name_length = 0;
Expand All @@ -82,7 +105,7 @@
content->resize(static_cast<size_t>(size));
file.read(content->data(), size);

auto* name = new std::string(resolved_path.string());
auto* name = new std::string(path_to_string(resolved_path));

Check failure on line 108 in engine/assets/shader_compiler.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=jackthepunished_horizon-engine&issues=AZ0OSRksXPeeTARt7DtX&open=AZ0OSRksXPeeTARt7DtX&pullRequest=2

result->source_name = name->c_str();
result->source_name_length = name->size();
Expand Down Expand Up @@ -232,7 +255,7 @@
// Read the file
std::ifstream file(path, std::ios::binary | std::ios::ate);
if (!file) {
result.error_message = "Could not open shader file: " + path.string();
result.error_message = "Could not open shader file: " + path_to_string(path);
HZ_LOG_ERROR("{}", result.error_message);
return result;
}
Expand All @@ -248,7 +271,8 @@
if (stage == rhi::ShaderStage::None) {
stage = infer_stage_from_extension(path);
if (stage == rhi::ShaderStage::None) {
result.error_message = "Could not infer shader stage from extension: " + path.string();
result.error_message =
"Could not infer shader stage from extension: " + path_to_string(path);
HZ_LOG_ERROR("{}", result.error_message);
return result;
}
Expand All @@ -257,7 +281,7 @@
// Set up compilation options
ShaderCompileOptions options;
options.source = source;
options.filename = path.string();
options.filename = path_to_string(path);
options.stage = stage;

// Add common include paths
Expand Down
4 changes: 2 additions & 2 deletions engine/assets/shader_compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace hz {
* @brief Options for shader compilation
*/
struct ShaderCompileOptions {
std::string_view source; ///< GLSL source code
std::string_view filename; ///< Filename for error messages (can be empty)
std::string_view source; ///< GLSL source code
std::string filename; ///< Filename for error messages (can be empty)
rhi::ShaderStage stage{rhi::ShaderStage::None};

/// Macro definitions: {name, value} pairs
Expand Down
27 changes: 13 additions & 14 deletions engine/renderer/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,9 @@
pl_desc.set_layouts = {&camera_layout, &gbuffer_layout, descriptor_layout.get()};
pipeline_layout = device.create_pipeline_layout(pl_desc);

// Create Pipeline (using temp RenderPass for compatibility)
auto rp_desc = rhi::RenderPassDesc::simple(rhi::Format::R8_UNORM);
auto temp_rp = device.create_render_pass(rp_desc);

rhi::GraphicsPipelineDesc pipe_desc{};
pipe_desc.layout = pipeline_layout.get();
pipe_desc.render_pass = temp_rp.get();
pipe_desc.color_attachment_formats = {rhi::Format::R8_UNORM};

rhi::VertexInputLayout item_layout;
item_layout.bindings.push_back({0, 5 * sizeof(float), rhi::VertexInputRate::Vertex});
Expand Down Expand Up @@ -406,13 +402,9 @@
pl_desc.set_layouts = {blur_descriptor_layout.get()};
blur_layout = device.create_pipeline_layout(pl_desc);

// Pipeline
auto rp_desc = rhi::RenderPassDesc::simple(rhi::Format::R8_UNORM);
auto temp_rp = device.create_render_pass(rp_desc);

rhi::GraphicsPipelineDesc pipe_desc{};
pipe_desc.layout = blur_layout.get();
pipe_desc.render_pass = temp_rp.get();
pipe_desc.color_attachment_formats = {rhi::Format::R8_UNORM};

auto vs = device.create_shader_from_file("assets/shaders/deferred/vk_fullscreen.vert",
rhi::ShaderStage::Vertex, "FullscreenVert");
Expand Down Expand Up @@ -1292,7 +1284,7 @@
// =========================================================================
// Geometry Pipeline
// =========================================================================
{

Check warning on line 1287 in engine/renderer/deferred_renderer.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce verbosity with "using enum" for "hz::rhi::Format".

See more on https://sonarcloud.io/project/issues?id=jackthepunished_horizon-engine&issues=AZ0OSRm5XPeeTARt7DtY&open=AZ0OSRm5XPeeTARt7DtY&pullRequest=2
rhi::GraphicsPipelineDesc desc;
desc.vertex_shader = vk_geometry_vert.get();
desc.fragment_shader = vk_geometry_frag.get();
Expand All @@ -1303,7 +1295,10 @@
desc.blend = rhi::BlendState::disabled(4);
desc.multisample = {};
desc.layout = m_geometry_layout.get();
desc.render_pass = m_geometry_pass.get();
desc.color_attachment_formats = {
rhi::Format::RGBA16_FLOAT, rhi::Format::RGBA16_FLOAT,
rhi::Format::RGBA16_FLOAT, rhi::Format::RG16_FLOAT};
desc.depth_attachment_format = rhi::Format::D32_FLOAT;
m_geometry_pipeline = m_device.create_graphics_pipeline(desc);
}

Expand All @@ -1321,7 +1316,7 @@
desc.blend = rhi::BlendState::disabled(1);
desc.multisample = {};
desc.layout = m_lighting_layout.get();
desc.render_pass = m_lighting_pass.get();
desc.color_attachment_formats = {rhi::Format::RGBA16_FLOAT};
m_lighting_pipeline = m_device.create_graphics_pipeline(desc);
}

Expand All @@ -1339,7 +1334,7 @@
desc.blend = rhi::BlendState::disabled(1);
desc.multisample = {};
desc.layout = m_composite_layout.get();
desc.render_pass = m_composite_pass.get();
desc.color_attachment_formats = {m_swapchain.format()};
m_composite_pipeline = m_device.create_graphics_pipeline(desc);
}

Expand All @@ -1356,7 +1351,7 @@
desc.blend = rhi::BlendState::disabled(0);
desc.multisample = {};
desc.layout = m_shadow_layout.get();
desc.render_pass = m_shadow_pass.get();
desc.depth_attachment_format = rhi::Format::D32_FLOAT;
m_shadow_pipeline = m_device.create_graphics_pipeline(desc);
}

Expand Down Expand Up @@ -1387,6 +1382,10 @@
m_device.create_uniform_buffer(sizeof(glm::vec4) * 2 + sizeof(glm::uvec4), "LightUBO");
m_shadow_ubo = m_device.create_uniform_buffer(sizeof(DeferredShadowUBO), "ShadowUBO");

if (m_camera_set && m_camera_ubo) {
m_camera_set->write_buffer(0, *m_camera_ubo);
}

// Create samplers
{
rhi::SamplerDesc desc;
Expand Down
Loading
Loading