-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shader_graph): add geometry, texture_coordinate and vector_trans…
…form nodes
- Loading branch information
Showing
14 changed files
with
288 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "/common/inputs/entity.glsl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "/common/inputs/textures/parallax_map.glsl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "/common/vertex_outputs/vertex_data.glsl" |
29 changes: 29 additions & 0 deletions
29
core/client/include/pragma/rendering/shader_graph/nodes/geometry.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_GEOMETRY_HPP__ | ||
#define __PRAGMA_SHADER_GRAPH_NODES_GEOMETRY_HPP__ | ||
|
||
#include "pragma/clientdefinitions.h" | ||
|
||
import pragma.shadergraph; | ||
|
||
namespace pragma::rendering::shader_graph { | ||
class DLLCLIENT GeometryNode : public pragma::shadergraph::Node { | ||
public: | ||
static constexpr const char *OUT_POSITION_WS = "position_ws"; | ||
static constexpr const char *OUT_NORMAL_WS = "normal_ws"; | ||
static constexpr const char *OUT_NORMAL_CS = "normal_cs"; | ||
static constexpr const char *OUT_TANGENT_WS = "tangent_ws"; | ||
|
||
GeometryNode(const std::string_view &type); | ||
|
||
virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override; | ||
}; | ||
}; | ||
|
||
#endif |
26 changes: 26 additions & 0 deletions
26
core/client/include/pragma/rendering/shader_graph/nodes/texture_coordinate.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* 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_TEXTURE_COORDINATE_HPP__ | ||
#define __PRAGMA_SHADER_GRAPH_NODES_TEXTURE_COORDINATE_HPP__ | ||
|
||
#include "pragma/clientdefinitions.h" | ||
|
||
import pragma.shadergraph; | ||
|
||
namespace pragma::rendering::shader_graph { | ||
class DLLCLIENT TextureCoordinateNode : public pragma::shadergraph::Node { | ||
public: | ||
static constexpr const char *OUT_UV = "uv"; | ||
|
||
TextureCoordinateNode(const std::string_view &type); | ||
|
||
virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override; | ||
}; | ||
}; | ||
|
||
#endif |
43 changes: 43 additions & 0 deletions
43
core/client/include/pragma/rendering/shader_graph/nodes/vector_transform.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* 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_VECTOR_TRANSFORM_HPP__ | ||
#define __PRAGMA_SHADER_GRAPH_NODES_VECTOR_TRANSFORM_HPP__ | ||
|
||
#include "pragma/clientdefinitions.h" | ||
|
||
import pragma.shadergraph; | ||
|
||
namespace pragma::rendering::shader_graph { | ||
class DLLCLIENT VectorTransformNode : public pragma::shadergraph::Node { | ||
public: | ||
enum class Type : uint8_t { | ||
Vector = 0, | ||
Point, | ||
Normal, | ||
}; | ||
|
||
enum class Space : uint8_t { | ||
World = 0, | ||
Object, | ||
Camera, | ||
}; | ||
|
||
static constexpr const char *IN_TRANSFORM_TYPE = "transformType"; | ||
static constexpr const char *IN_CONVERT_FROM = "convertForm"; | ||
static constexpr const char *IN_CONVERT_TO = "convertTo"; | ||
static constexpr const char *IN_VECTOR = "vector"; | ||
|
||
static constexpr const char *OUT_VECTOR = "vector"; | ||
|
||
VectorTransformNode(const std::string_view &type); | ||
|
||
virtual std::string DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const override; | ||
}; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* 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 | ||
*/ | ||
|
||
#include "stdafx_client.h" | ||
#include "pragma/rendering/shader_graph/nodes/geometry.hpp" | ||
|
||
using namespace pragma::rendering::shader_graph; | ||
|
||
GeometryNode::GeometryNode(const std::string_view &type) : Node {type} | ||
{ | ||
AddOutput(OUT_POSITION_WS, pragma::shadergraph::SocketType::Vector); | ||
AddOutput(OUT_NORMAL_WS, pragma::shadergraph::SocketType::Vector); | ||
AddOutput(OUT_NORMAL_CS, pragma::shadergraph::SocketType::Vector); | ||
AddOutput(OUT_TANGENT_WS, pragma::shadergraph::SocketType::Vector); | ||
|
||
AddModuleDependency("vertex_data"); | ||
} | ||
|
||
std::string GeometryNode::DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &gn) const | ||
{ | ||
std::ostringstream code; | ||
code << gn.GetGlslOutputDeclaration(OUT_POSITION_WS) << " = get_vertex_position_ws();\n"; | ||
code << gn.GetGlslOutputDeclaration(OUT_NORMAL_WS) << " = get_vertex_normal();\n"; | ||
code << gn.GetGlslOutputDeclaration(OUT_NORMAL_CS) << " = get_vertex_normal_cs();\n"; | ||
|
||
auto prefix = gn.GetBaseVarName() + "_"; | ||
std::string tbn = prefix + "tbn"; | ||
code << "mat3 " << tbn << " = get_tbn_matrix();\n"; | ||
code << gn.GetGlslOutputDeclaration(OUT_TANGENT_WS) << " = normalize(" << tbn << "[0]);\n"; | ||
return code.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
core/client/src/rendering/shader_graph/nodes/texture_coordinate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* 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 | ||
*/ | ||
|
||
#include "stdafx_client.h" | ||
#include "pragma/rendering/shader_graph/nodes/texture_coordinate.hpp" | ||
|
||
using namespace pragma::rendering::shader_graph; | ||
|
||
TextureCoordinateNode::TextureCoordinateNode(const std::string_view &type) : Node {type} | ||
{ | ||
AddOutput(OUT_UV, pragma::shadergraph::SocketType::Vector); | ||
|
||
AddModuleDependency("uv_data"); | ||
} | ||
|
||
std::string TextureCoordinateNode::DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &instance) const | ||
{ | ||
std::ostringstream code; | ||
code << instance.GetGlslOutputDeclaration(OUT_UV) << " = vec3(get_uv_coordinates(), 0.0);\n"; | ||
return code.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
core/client/src/rendering/shader_graph/nodes/vector_transform.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* 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 | ||
*/ | ||
|
||
#include "stdafx_client.h" | ||
#include "pragma/rendering/shader_graph/nodes/vector_transform.hpp" | ||
|
||
using namespace pragma::rendering::shader_graph; | ||
|
||
VectorTransformNode::VectorTransformNode(const std::string_view &type) : Node {type} | ||
{ | ||
AddSocketEnum<Type>(IN_TRANSFORM_TYPE, Type::Vector); | ||
AddSocketEnum<Space>(IN_CONVERT_FROM, Space::World); | ||
AddSocketEnum<Space>(IN_CONVERT_TO, Space::Object); | ||
AddInput(IN_VECTOR, pragma::shadergraph::SocketType::Vector, Vector3 {0.f, 0.f, 0.f}); | ||
AddOutput(OUT_VECTOR, pragma::shadergraph::SocketType::Vector); | ||
|
||
AddModuleDependency("camera"); | ||
AddModuleDependency("entity"); | ||
} | ||
|
||
std::string VectorTransformNode::DoEvaluate(const pragma::shadergraph::Graph &graph, const pragma::shadergraph::GraphNode &gn) const | ||
{ | ||
std::ostringstream code; | ||
|
||
auto vector = gn.GetInputNameOrValue(IN_VECTOR); | ||
|
||
auto type = *gn.GetConstantInputValue<Type>(IN_TRANSFORM_TYPE); | ||
auto convertFrom = *gn.GetConstantInputValue<Space>(IN_CONVERT_FROM); | ||
auto convertTo = *gn.GetConstantInputValue<Space>(IN_CONVERT_TO); | ||
|
||
if(convertFrom == convertTo) { | ||
code << gn.GetGlslOutputDeclaration(OUT_VECTOR) << " = " << vector << ";\n"; | ||
return code.str(); | ||
} | ||
|
||
auto prefix = gn.GetBaseVarName() + "_"; | ||
std::string matName = prefix + "mat"; | ||
code << "mat4 " << matName << " = "; | ||
switch(convertFrom) { | ||
case Space::Object: | ||
switch(convertTo) { | ||
case Space::World: | ||
code << "get_model_matrix()"; | ||
break; | ||
case Space::Camera: | ||
code << "get_view_matrix() *get_model_matrix()"; | ||
break; | ||
} | ||
break; | ||
case Space::Camera: | ||
switch(convertTo) { | ||
case Space::World: | ||
code << "inverse(get_view_matrix())"; | ||
break; | ||
case Space::Object: | ||
code << "inverse(get_model_matrix()) *inverse(get_view_matrix())"; | ||
break; | ||
} | ||
break; | ||
case Space::World: | ||
switch(convertTo) { | ||
case Space::Object: | ||
code << "inverse(get_model_matrix())"; | ||
break; | ||
case Space::Camera: | ||
code << "get_view_matrix()"; | ||
break; | ||
} | ||
break; | ||
} | ||
code << ";\n"; | ||
|
||
code << gn.GetGlslOutputDeclaration(OUT_VECTOR) << " = "; | ||
switch(type) { | ||
case Type::Vector: | ||
// Vectors are transformed with the matrix, ignoring translation. | ||
code << "(" << matName << " * vec4(" << vector << ", 0.0)).xyz"; | ||
break; | ||
|
||
case Type::Normal: | ||
// Normals require the inverse transpose of the matrix. | ||
code << "(transpose(inverse(mat3(" << matName << "))) * " << vector << ")"; | ||
break; | ||
|
||
case Type::Point: | ||
// Points are fully transformed, including translation. | ||
code << "(" << matName << " * vec4(" << vector << ", 1.0)).xyz"; | ||
break; | ||
} | ||
code << ";\n"; | ||
return code.str(); | ||
} |