Skip to content

Commit

Permalink
feat(shader_graph): add base scene graph shader and node implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Nov 23, 2024
1 parent d2a07eb commit be03e96
Show file tree
Hide file tree
Showing 23 changed files with 950 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build_scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def download_addon(name,addonName,url,commitId=None):
if not skip_repository_updates:
if with_pfm:
download_addon("PFM","filmmaker","https://github.com/Silverlan/pfm.git","b0cc0afcdb96aab8a5fe778fb20aef7eb5329115")
download_addon("model editor","tool_model_editor","https://github.com/Silverlan/pragma_model_editor.git","bd4844c06b9a42bacd17bb7e52d3381c3fd119e4")
download_addon("model editor","tool_model_editor","https://github.com/Silverlan/pragma_model_editor.git","a9ea4820f03be250bdf1e6951dad313561b75b17")

if with_vr:
download_addon("VR","virtual_reality","https://github.com/Silverlan/PragmaVR.git","93fe4f849493651c14133ddf1963b0a8b719f836")
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 @@ -32,7 +32,7 @@
get_submodule("util_versioned_archive","https://github.com/Silverlan/util_versioned_archive.git","e8db74a6ad9ed44d7e8a4492eb8fe44eae3452f6")
get_submodule("util_vmf","https://github.com/Silverlan/util_vmf.git","4e477b1425e1a7b9898975effaf527f661e792da")
get_submodule("util_zip","https://github.com/Silverlan/util_zip.git","d9bf05a5cbf71bf53f9fbea82c7352f870989ed1")
get_submodule("util_shadergraph","https://github.com/Silverlan/util_shadergraph.git","33b89dfa095b64414703de5bcf9a7f9cd87bcbf6")
get_submodule("util_shadergraph","https://github.com/Silverlan/util_shadergraph.git","610d417e369a7a7408ad29949e72f81aab74456e")
get_submodule("vfilesystem","https://github.com/Silverlan/vfilesystem.git","3d6001b2202ac4eecb8d68de1909f72c22060a31")
get_submodule("wgui","https://github.com/Silverlan/wgui.git","66d3758336d6e58046813a30298a6a3d9af74318")
get_submodule("util_unicode","https://github.com/Silverlan/util_unicode.git","5a0ac6c02f199e42d7d38d99231503cf42e26f8a")
Expand Down
6 changes: 6 additions & 0 deletions core/client/include/pragma/c_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ namespace pragma::debug {
namespace pragma::string {
class Utf8String;
};
namespace pragma::rendering {
class ShaderGraphManager;
};
struct InputBindingLayer;
struct CoreInputBindingLayer;
struct FontSet;
Expand Down Expand Up @@ -203,6 +206,8 @@ class DLLCLIENT CEngine : public Engine, public pragma::RenderContext {
// Shaders
::util::WeakHandle<prosper::Shader> ReloadShader(const std::string &name);
void ReloadShaderPipelines();
pragma::rendering::ShaderGraphManager &GetShaderGraphManager() { return *m_shaderGraphManager; }
const pragma::rendering::ShaderGraphManager &GetShaderGraphManager() const { return const_cast<CEngine *>(this)->GetShaderGraphManager(); }
//

Double GetDeltaFrameTime() const;
Expand Down Expand Up @@ -272,6 +277,7 @@ class DLLCLIENT CEngine : public Engine, public pragma::RenderContext {
float m_nearZ, m_farZ;
std::unique_ptr<StateInstance> m_clInstance;
std::unique_ptr<ConVarInfoList> m_clConfig;
std::unique_ptr<pragma::rendering::ShaderGraphManager> m_shaderGraphManager;
std::optional<Vector2i> m_renderResolution = {};

std::shared_ptr<pragma::debug::GPUProfiler> m_gpuProfiler;
Expand Down
32 changes: 32 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/nodes/camera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 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_SHADER_GRAPH_NODES_CAMERA_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_CAMERA_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT CameraNode : public pragma::shadergraph::Node {
public:
static constexpr const char *OUT_POSITION = "position";
static constexpr const char *OUT_FOV = "fov";
static constexpr const char *OUT_NEARZ = "nearZ";
static constexpr const char *OUT_FARZ = "farZ";
static constexpr const char *OUT_VIEW_MATRIX = "viewMatrix";
static constexpr const char *OUT_PROJECTION_MATRIX = "projectionMatrix";
static constexpr const char *OUT_VIEW_PROJECTION_MATRIX = "viewProjectionMatrix";

CameraNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
29 changes: 29 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/nodes/fog.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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_SHADER_GRAPH_NODES_FOG_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_FOG_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT FogNode : public pragma::shadergraph::Node {
public:
static constexpr const char *OUT_COLOR = "color";
static constexpr const char *OUT_START_DISTANCE = "startDistance";
static constexpr const char *OUT_END_DISTANCE = "endDistance";
static constexpr const char *OUT_DENSITY = "density";

FogNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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_SHADER_GRAPH_NODES_LIGHTMAP_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_LIGHTMAP_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT LightmapNode : public pragma::shadergraph::Node {
public:
static constexpr const char *OUT_LIGHT_MAP = "lightMap";
static constexpr const char *OUT_LIGHT_MAP_INDIRECT = "lightMapIndirect";
static constexpr const char *OUT_LIGHT_MAP_DOMINANT = "lightMapDominant";

LightmapNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
27 changes: 27 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/nodes/object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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_SHADER_GRAPH_NODES_OBJECT_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_OBJECT_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT ObjectNode : public pragma::shadergraph::Node {
public:
static constexpr const char *OUT_MODEL_MATRIX = "modelMatrix";
static constexpr const char *OUT_COLOR = "color";

ObjectNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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_SHADER_GRAPH_NODES_SCENE_OUTPUT_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_SCENE_OUTPUT_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT SceneOutputNode : public pragma::shadergraph::Node {
public:
static constexpr const char *IN_COLOR = "color";
static constexpr const char *IN_ALPHA = "alpha";
static constexpr const char *IN_BLOOM_COLOR = "bloomColor";
// TODO: Only allow one of these!
SceneOutputNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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_SHADER_GRAPH_NODES_SHADER_MATERIAL_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_SHADER_MATERIAL_HPP__

#include "pragma/clientdefinitions.h"
#include "pragma/rendering/shader_material/shader_material.hpp"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT ShaderMaterialNode : public pragma::shadergraph::Node {
public:
ShaderMaterialNode(const std::string_view &type, const pragma::rendering::shader_material::ShaderMaterial &shaderMaterial);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
private:
const pragma::rendering::shader_material::ShaderMaterial &m_shaderMaterial;
};
};

#endif
29 changes: 29 additions & 0 deletions core/client/include/pragma/rendering/shader_graph/nodes/time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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_SHADER_GRAPH_NODES_TIME_HPP__
#define __PRAGMA_SHADER_GRAPH_NODES_TIME_HPP__

#include "pragma/clientdefinitions.h"

import pragma.shadergraph;

namespace pragma::rendering::shader_graph {
class DLLCLIENT TimeNode : public pragma::shadergraph::Node {
public:
static constexpr const char *OUT_TIME = "time";
static constexpr const char *OUT_DELTA_TIME = "deltaTime";
static constexpr const char *OUT_REAL_TIME = "realTime";
static constexpr const char *OUT_DELTA_REAL_TIME = "deltaRealTime";

TimeNode(const std::string_view &type);

virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override;
};
};

#endif
68 changes: 68 additions & 0 deletions core/client/include/pragma/rendering/shader_graph_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* 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) 2021 Silverlan
*/

#ifndef __SHADER_GRAPH_MANAGER_HPP__
#define __SHADER_GRAPH_MANAGER_HPP__

#include <pragma/clientdefinitions.h>
#include <string>
#include <unordered_map>
#include <memory>

import pragma.shadergraph;

namespace pragma::rendering {
class DLLCLIENT ShaderGraphData {
public:
ShaderGraphData(const std::string &typeName, const std::string &identifier, const std::shared_ptr<pragma::shadergraph::Graph> &graph) : m_typeName {typeName}, m_identifier {identifier}, m_graph {graph} {}
const std::string &GetIdentifier() const { return m_identifier; }
void GenerateGlsl();
private:
std::string m_typeName;
std::string m_identifier;
std::shared_ptr<pragma::shadergraph::Graph> m_graph;
};

class ShaderGraphManager;
class DLLCLIENT ShaderGraphTypeManager {
public:
ShaderGraphTypeManager(const std::string &typeName, std::shared_ptr<pragma::shadergraph::NodeRegistry> nodeRegistry) : m_typeName {typeName}, m_nodeRegistry {nodeRegistry} {}
void ReloadShader(const std::string &identifier);
std::shared_ptr<ShaderGraphData> GetGraph(const std::string &identifier) const;
const std::shared_ptr<pragma::shadergraph::NodeRegistry> &GetNodeRegistry() const { return m_nodeRegistry; }
private:
friend ShaderGraphManager;
void RegisterGraph(const std::string &identifier, std::shared_ptr<pragma::shadergraph::Graph> graph);
std::shared_ptr<pragma::shadergraph::Graph> RegisterGraph(const std::string &identifier);
std::shared_ptr<pragma::shadergraph::Graph> CreateGraph() const;
std::string m_typeName;
std::unordered_map<std::string, std::shared_ptr<ShaderGraphData>> m_graphs;
std::shared_ptr<pragma::shadergraph::NodeRegistry> m_nodeRegistry;
};

class DLLCLIENT ShaderGraphManager {
public:
static constexpr const char *ROOT_GRAPH_PATH = "scripts/shader_data/graphs/";
static std::string GetShaderFilePath(const std::string &type, const std::string &identifier);
static std::string GetShaderGraphFilePath(const std::string &type, const std::string &identifier);

ShaderGraphManager() {}
~ShaderGraphManager() {}
const std::unordered_map<std::string, std::shared_ptr<ShaderGraphTypeManager>> &GetShaderGraphTypeManagers() const { return m_shaderGraphTypeManagers; }
void RegisterGraphTypeManager(const std::string &type, std::shared_ptr<pragma::shadergraph::NodeRegistry> nodeRegistry);
std::shared_ptr<pragma::shadergraph::Graph> RegisterGraph(const std::string &type, const std::string &identifier);
std::shared_ptr<pragma::shadergraph::Graph> CreateGraph(const std::string &type) const;
void ReloadShader(const std::string &identifier);
std::shared_ptr<ShaderGraphData> GetGraph(const std::string &identifier) const;
std::shared_ptr<pragma::shadergraph::NodeRegistry> GetNodeRegistry(const std::string &type) const;
private:
std::unordered_map<std::string, std::shared_ptr<ShaderGraphTypeManager>> m_shaderGraphTypeManagers;
std::unordered_map<std::string, std::string> m_shaderNameToType;
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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 __C_SHADER_GRAPH_HPP__
#define __C_SHADER_GRAPH_HPP__

#include "pragma/rendering/shaders/world/c_shader_textured.hpp"

class Texture;
namespace pragma {
class DLLCLIENT ShaderGraph : public ShaderGameWorldLightingPass {
public:
ShaderGraph(prosper::IPrContext &context, const std::string &identifier, const std::string &fsShader);

virtual void RecordBindScene(rendering::ShaderProcessor &shaderProcessor, const pragma::CSceneComponent &scene, const pragma::CRasterizationRendererComponent &renderer, prosper::IDescriptorSet &dsScene, prosper::IDescriptorSet &dsRenderer, prosper::IDescriptorSet &dsRenderSettings,
prosper::IDescriptorSet &dsLights, prosper::IDescriptorSet &dsShadows, const Vector4 &drawOrigin, ShaderGameWorld::SceneFlags &inOutSceneFlags) const override;
protected:
using ShaderGameWorldLightingPass::RecordDraw;
void RecordBindSceneDescriptorSets(rendering::ShaderProcessor &shaderProcessor, const pragma::CSceneComponent &scene, const pragma::CRasterizationRendererComponent &renderer, prosper::IDescriptorSet &dsScene, prosper::IDescriptorSet &dsRenderer,
prosper::IDescriptorSet &dsRenderSettings, prosper::IDescriptorSet &dsLights, prosper::IDescriptorSet &dsShadows, ShaderGameWorld::SceneFlags &inOutSceneFlags, float &outIblStrength) const;
virtual void OnPipelinesInitialized() override;
virtual void InitializeGfxPipeline(prosper::GraphicsPipelineCreateInfo &pipelineInfo, uint32_t pipelineIdx) override;
virtual void InitializeMaterialData(const CMaterial &mat, const rendering::shader_material::ShaderMaterial &shaderMat, pragma::rendering::shader_material::ShaderMaterialData &inOutMatData) override;
virtual void UpdateRenderFlags(CModelSubMesh &mesh, SceneFlags &inOutFlags) override;
virtual void InitializeGfxPipelineDescriptorSets() override;
std::shared_ptr<prosper::IDescriptorSetGroup> InitializeMaterialDescriptorSet(CMaterial &mat, const prosper::DescriptorSetInfo &descSetInfo);

SceneFlags m_extRenderFlags = SceneFlags::None;
std::shared_ptr<prosper::IDescriptorSetGroup> m_defaultPbrDsg = nullptr;
};
};

#endif
Loading

0 comments on commit be03e96

Please sign in to comment.