Skip to content

Commit

Permalink
Merge pull request #136 from Silverlan/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan authored Dec 12, 2024
2 parents 09bda57 + e89a0e9 commit a0200c5
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 21 deletions.
80 changes: 80 additions & 0 deletions assets/shaders/debug/debug_print.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef F_SH_DEBUG_PRINT_GLS
#define F_SH_DEBUG_PRINT_GLS

// These have to match the enums in pragma/rendering/global_render_settings_buffer_data.hpp
#define GLSL_TYPE_INT32 0
#define GLSL_TYPE_UINT32 1
#define GLSL_TYPE_FLOAT 2
#define GLSL_TYPE_BOOLEAN 3
#define GLSL_TYPE_VECTOR2 4
#define GLSL_TYPE_VECTOR3 5
#define GLSL_TYPE_VECTOR4 6
#define GLSL_TYPE_MAT4 7
#define GLSL_TYPE_VECTOR2I 8
#define GLSL_TYPE_VECTOR3I 9
#define GLSL_TYPE_VECTOR4I 10
#define GLSL_TYPE_NOT_SET 11
#define GLSL_TYPE_COUNT 12
#define GLSL_TYPE_LAST 11

layout(std140, LAYOUT_ID(RENDER_SETTINGS, DEBUG_PRINT)) buffer DebugPrintData {
mat4 value;
uint type;
} u_debugPrintData;

void print(int value) {
u_debugPrintData.value[0][0] = value;
u_debugPrintData.type = GLSL_TYPE_INT32;
}

void print(uint value) {
u_debugPrintData.value[0][0] = value;
u_debugPrintData.type = GLSL_TYPE_UINT32;
}

void print(float value) {
u_debugPrintData.value[0][0] = value;
u_debugPrintData.type = GLSL_TYPE_FLOAT;
}

void print(bool value) {
u_debugPrintData.value[0][0] = value ? 1.0 : 0.0;
u_debugPrintData.type = GLSL_TYPE_BOOLEAN;
}

void print(vec2 value) {
u_debugPrintData.value[0] = vec4(value, 0.0, 0.0);
u_debugPrintData.type = GLSL_TYPE_VECTOR2;
}

void print(vec3 value) {
u_debugPrintData.value[0] = vec4(value, 0.0);
u_debugPrintData.type = GLSL_TYPE_VECTOR3;
}

void print(vec4 value) {
u_debugPrintData.value[0] = value;
u_debugPrintData.type = GLSL_TYPE_VECTOR4;
}

void print(mat4 value) {
u_debugPrintData.value = value;
u_debugPrintData.type = GLSL_TYPE_MAT4;
}

void print(ivec2 value) {
u_debugPrintData.value[0] = vec4(value, 0.0, 0.0);
u_debugPrintData.type = GLSL_TYPE_VECTOR2I;
}

void print(ivec3 value) {
u_debugPrintData.value[0] = vec4(value, 0.0);
u_debugPrintData.type = GLSL_TYPE_VECTOR3I;
}

void print(ivec4 value) {
u_debugPrintData.value[0] = vec4(value);
u_debugPrintData.type = GLSL_TYPE_VECTOR4I;
}

#endif
5 changes: 4 additions & 1 deletion assets/shaders/lighting/fs_lighting_spot.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
float get_spot_light_shadow_sample(uint lightIdx, bool dynamic, vec3 fragPosWs)
{
LightSourceData light = get_light_source(lightIdx);

if(light.shadowIndex == 0)
return 1.0;
vec4 depthCoord = get_light_vertex_position(lightIdx);
depthCoord.z *= light.position.w; // Undo transformation from get_light_vertex_position()
depthCoord = depthCoord / light.position.w;
Expand All @@ -22,6 +23,8 @@ float get_spot_light_shadow_sample(uint lightIdx, bool dynamic, vec3 fragPosWs)
float get_spot_light_shadow_factor(uint lightIdx, bool dynamic)
{
LightSourceData light = get_light_source(lightIdx);
if(light.shadowIndex == 0)
return 1.0;
vec4 depthCoord = get_light_vertex_position(lightIdx);
depthCoord.z *= light.position.w; // Undo transformation from get_light_vertex_position()
depthCoord = depthCoord / light.position.w;
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/scripts/external_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
get_submodule("mathutil","https://github.com/Silverlan/mathutil.git","e872f599805cf696ff6a84a4253fc44ae8e83a15")
get_submodule("networkmanager","https://github.com/Silverlan/networkmanager.git","981bc5809c1a768267ddace778205e1be0262730")
get_submodule("panima","https://github.com/Silverlan/panima.git","06916dd30cde319f31b1eee25cfed7dea8f14630")
get_submodule("prosper","https://github.com/Silverlan/prosper.git","d39a127688792194d8075ad85dd7b4312b49ff11")
get_submodule("prosper","https://github.com/Silverlan/prosper.git","a9b568c360fc06d8159215e3f0dd84f595d1fbce")
get_submodule("sharedutils","https://github.com/Silverlan/sharedutils.git","65031009e7f85722f243a493ad47e03ca10617fe")
get_submodule("util_bsp","https://github.com/Silverlan/util_bsp.git","2d912cceaaa59199a86431aa9d194e922b2ebea4")
get_submodule("util_formatted_text","https://github.com/Silverlan/util_formatted_text.git","c473a2bdc1ad84ef52d391226d6983ef3076958e")
Expand Down
13 changes: 3 additions & 10 deletions core/client/include/pragma/game/c_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace pragma {
class RenderQueueBuilder;
class RenderQueueWorkerManager;
struct GameWorldShaderSettings;
struct GlobalRenderSettingsBufferData;
};
class LuaShaderManager;
class LuaParticleModifierManager;
Expand Down Expand Up @@ -110,14 +111,6 @@ namespace pragma::string {
#pragma warning(push)
#pragma warning(disable : 4251)
class DLLCLIENT CGame : public Game {
public:
struct GlobalRenderSettingsBufferData {
GlobalRenderSettingsBufferData();
std::shared_ptr<prosper::IBuffer> debugBuffer = nullptr;
std::shared_ptr<prosper::IBuffer> timeBuffer = nullptr;
std::shared_ptr<prosper::IBuffer> csmBuffer = nullptr;
std::shared_ptr<prosper::IDescriptorSetGroup> descSetGroup = nullptr;
};
public:
CGame(NetworkState *state);
virtual ~CGame() override;
Expand Down Expand Up @@ -407,7 +400,7 @@ class DLLCLIENT CGame : public Game {
pragma::rendering::RenderQueueBuilder &GetRenderQueueBuilder();
pragma::rendering::RenderQueueWorkerManager &GetRenderQueueWorkerManager();
prosper::IDescriptorSet &GetGlobalRenderSettingsDescriptorSet();
GlobalRenderSettingsBufferData &GetGlobalRenderSettingsBufferData();
pragma::rendering::GlobalRenderSettingsBufferData &GetGlobalRenderSettingsBufferData();
void ReloadGameWorldShaderPipelines() const;
void ReloadPrepassShaderPipelines() const;
void OnGameWorldShaderSettingsChanged(const pragma::rendering::GameWorldShaderSettings &newSettings, const pragma::rendering::GameWorldShaderSettings &oldSettings);
Expand Down Expand Up @@ -504,7 +497,7 @@ class DLLCLIENT CGame : public Game {
StateFlags m_stateFlags = StateFlags::None;
void RenderScenePresent(std::shared_ptr<prosper::IPrimaryCommandBuffer> &drawCmd, prosper::Texture &texPostHdr, prosper::IImage *optOutImage, uint32_t layerId = 0u);

std::unique_ptr<GlobalRenderSettingsBufferData> m_globalRenderSettingsBufferData = nullptr;
std::unique_ptr<pragma::rendering::GlobalRenderSettingsBufferData> m_globalRenderSettingsBufferData;

// Scene
util::TWeakSharedHandle<pragma::CSceneComponent> m_scene = util::TWeakSharedHandle<pragma::CSceneComponent> {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2024 Silverlan
*/

#ifndef __PRAGMA_GLOBAL_RENDER_SETTINGS_BUFFER_DATA_HPP__
#define __PRAGMA_GLOBAL_RENDER_SETTINGS_BUFFER_DATA_HPP__

#include <memory>
#include <buffers/prosper_buffer.hpp>
#include <prosper_descriptor_set_group.hpp>
#include <udm_enums.hpp>

// #define PRAGMA_ENABLE_SHADER_DEBUG_PRINT

namespace pragma::rendering {
// These have to match the enums in shaders/debug/debug_print.glsl
enum class GlslType : uint32_t {
Int32 = 0,
UInt32,

Float,
Boolean,

Vector2,
Vector3,
Vector4,
Mat4,

Vector2i,
Vector3i,
Vector4i,

NotSet,

Count,
Last = Count - 1,
Invalid = std::numeric_limits<uint32_t>::max()
};
constexpr udm::Type glsl_type_to_udm(GlslType type)
{
switch(type) {
case GlslType::Int32:
return udm::Type::Int32;
case GlslType::UInt32:
return udm::Type::UInt32;
case GlslType::Float:
return udm::Type::Float;
case GlslType::Boolean:
return udm::Type::Boolean;
case GlslType::Vector2:
return udm::Type::Vector2;
case GlslType::Vector3:
return udm::Type::Vector3;
case GlslType::Vector4:
return udm::Type::Vector4;
case GlslType::Mat4:
return udm::Type::Mat4;
case GlslType::Vector2i:
return udm::Type::Vector2i;
case GlslType::Vector3i:
return udm::Type::Vector3i;
case GlslType::Vector4i:
return udm::Type::Vector4i;
default:
return udm::Type::Invalid;
}
}

template<typename T>
concept is_glsl_type = std::is_same_v<T, float> || std::is_same_v<T, bool> || std::is_same_v<T, int32_t> || std::is_same_v<T, uint32_t> || std::is_same_v<T, Mat4> || std::is_same_v<T, Vector4> || std::is_same_v<T, Vector3> || std::is_same_v<T, Vector2> || std::is_same_v<T, Vector4i>
|| std::is_same_v<T, Vector3i> || std::is_same_v<T, Vector2i>;
struct GlobalRenderSettingsBufferData {
#ifdef PRAGMA_ENABLE_SHADER_DEBUG_PRINT
#pragma pack(push, 1)
struct DebugPrintData {
uint8_t data[sizeof(Mat4)];
GlslType type = GlslType::NotSet;
};
#pragma pack(pop)
#endif

GlobalRenderSettingsBufferData();
std::shared_ptr<prosper::IBuffer> debugBuffer = nullptr;
std::shared_ptr<prosper::IBuffer> timeBuffer = nullptr;
std::shared_ptr<prosper::IBuffer> csmBuffer = nullptr;
#ifdef PRAGMA_ENABLE_SHADER_DEBUG_PRINT
std::shared_ptr<prosper::IBuffer> debugPrintBuffer = nullptr;
void EvaluateDebugPrint();
std::optional<std::string> GetDebugPrintString() const;
void ResetDebugPrintData();
#endif
std::shared_ptr<prosper::IDescriptorSetGroup> descSetGroup = nullptr;
};
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ namespace pragma {
Time,
CSMData,
GlobalInstance,
// #ifdef PRAGMA_ENABLE_SHADER_DEBUG_PRINT
DebugPrint,
// #endif
};

enum class DebugFlags : uint32_t {
Expand All @@ -89,6 +92,7 @@ namespace pragma {
virtual uint32_t GetRenderSettingsDescriptorSetIndex() const = 0;
virtual uint32_t GetCameraDescriptorSetIndex() const = 0;
virtual uint32_t GetRendererDescriptorSetIndex() const { return std::numeric_limits<uint32_t>::max(); }
virtual std::optional<std::string> GetGlslPrefixCode(prosper::ShaderStage stage) const override;
protected:
ShaderScene(prosper::IPrContext &context, const std::string &identifier, const std::string &vsShader, const std::string &fsShader, const std::string &gsShader = "");
prosper::SampleCountFlags GetSampleCount(uint32_t pipelineIdx) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pragma/rendering/shaders/world/c_shader_prepass.hpp"
#include "pragma/rendering/shaders/info/c_shader_velocity_buffer.hpp"
#include "pragma/rendering/c_renderflags.h"
#include "pragma/rendering/global_render_settings_buffer_data.hpp"
#include "pragma/entities/environment/effects/c_env_particle_system.h"
#include "pragma/entities/components/c_render_component.hpp"
#include "pragma/entities/components/c_animated_component.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "pragma/model/c_modelmesh.h"
#include "pragma/rendering/shaders/c_shader_shadow.hpp"
#include "pragma/rendering/shaders/world/c_shader_textured.hpp"
#include "pragma/rendering/global_render_settings_buffer_data.hpp"
#include "pragma/lua/c_lentity_handles.hpp"
#include <pragma/math/math_seb.h>
#include <pragma/math/e_frustum.h>
Expand Down
3 changes: 2 additions & 1 deletion core/client/src/game/c_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "pragma/rendering/renderers/rasterization_renderer.hpp"
#include "pragma/rendering/renderers/raytracing_renderer.hpp"
#include "pragma/rendering/render_queue_worker.hpp"
#include "pragma/rendering/global_render_settings_buffer_data.hpp"
#include "pragma/ai/c_navsystem.h"
#include <texturemanager/texturemanager.h>
#include <pragma/physics/environment.hpp>
Expand Down Expand Up @@ -660,7 +661,7 @@ void CGame::InitializeGame() // Called by NET_cl_resourcecomplete
c_engine->GetRenderContext().GetPipelineLoader().Flush();
c_engine->GetRenderContext().SavePipelineCache();

m_globalRenderSettingsBufferData = std::make_unique<GlobalRenderSettingsBufferData>();
m_globalRenderSettingsBufferData = std::make_unique<pragma::rendering::GlobalRenderSettingsBufferData>();
auto *scene = pragma::CSceneComponent::Create(pragma::CSceneComponent::CreateInfo {});
if(scene) {
scene->GetEntity().SetName("scene_game");
Expand Down
Loading

0 comments on commit a0200c5

Please sign in to comment.