moved glsl to standalone .glsl file.
This commit is contained in:
parent
19df201ab5
commit
86123827cb
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
11
ShaderLibrary/GetJointMatrix.glsl
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
mat4 GetJointMatrix()
|
||||||
|
{
|
||||||
|
// Joint数据分Joint ID和Joint Weight两部分
|
||||||
|
// Joint ID是一个uvec4,在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
|
||||||
|
// Joint Weight是权重,在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
|
||||||
|
|
||||||
|
return joint.mats[JointID.x]*JointWeight.x+
|
||||||
|
joint.mats[JointID.y]*JointWeight.y+
|
||||||
|
joint.mats[JointID.z]*JointWeight.z+
|
||||||
|
joint.mats[JointID.w]*JointWeight.w;
|
||||||
|
}
|
4
ShaderLibrary/GetLocalToWorld.glsl
Normal file
4
ShaderLibrary/GetLocalToWorld.glsl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
mat4 GetLocalToWorld()
|
||||||
|
{
|
||||||
|
return l2w.mats[Assign.x];
|
||||||
|
}
|
8
ShaderLibrary/GetMI.glsl
Normal file
8
ShaderLibrary/GetMI.glsl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
MaterialInstance GetMI()
|
||||||
|
{
|
||||||
|
#if ShaderStage == VertexShader
|
||||||
|
return mtl.mi[Assign.y];
|
||||||
|
#else
|
||||||
|
return mtl.mi[Input.MaterialInstanceID];
|
||||||
|
#endif
|
||||||
|
}
|
10
ShaderLibrary/HandoverMI.glsl
Normal file
10
ShaderLibrary/HandoverMI.glsl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
void HandoverMI()
|
||||||
|
{
|
||||||
|
#if ShaderStage == VertexShader
|
||||||
|
Output.MaterialInstanceID=Assign.y;
|
||||||
|
#elif ShaderStage == GeometryShader
|
||||||
|
Output.MaterialInstanceID=Input[0].MaterialInstanceID;
|
||||||
|
#else
|
||||||
|
Output.MaterialInstanceID=Input.MaterialInstanceID;
|
||||||
|
#endif
|
||||||
|
}
|
10
ShaderLibrary/ShaderHeader.glsl
Normal file
10
ShaderLibrary/ShaderHeader.glsl
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#version 460 core
|
||||||
|
|
||||||
|
#define VertexShader 0x01
|
||||||
|
#define TessControlShader 0x02
|
||||||
|
#define TeseEvalShader 0x04
|
||||||
|
#define GeometryShader 0x08
|
||||||
|
#define FragmentShader 0x10
|
||||||
|
#define ComputeShader 0x20
|
||||||
|
#define TaskShader 0x40
|
||||||
|
#define MeshShader 0x80
|
@ -80,6 +80,7 @@ public:
|
|||||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||||
|
|
||||||
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
||||||
|
void AddFunction(const AnsiString *str){function_list.Add(*str);}
|
||||||
|
|
||||||
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
|
void SetMaterialInstance(UBODescriptor *,const AnsiString &);
|
||||||
void SetLocalToWorld(UBODescriptor *);
|
void SetLocalToWorld(UBODescriptor *);
|
||||||
|
@ -13,7 +13,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_VERTEX_BIT,m){}
|
ShaderCreateInfoVertex(MaterialDescriptorInfo *);
|
||||||
~ShaderCreateInfoVertex()=default;
|
~ShaderCreateInfoVertex()=default;
|
||||||
|
|
||||||
int AddInput(const graph::VAT &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
int AddInput(const graph::VAT &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||||
|
@ -3,11 +3,18 @@
|
|||||||
#include<hgl/graph/mtl/UBOCommon.h>
|
#include<hgl/graph/mtl/UBOCommon.h>
|
||||||
#include<hgl/graph/VKDeviceAttribute.h>
|
#include<hgl/graph/VKDeviceAttribute.h>
|
||||||
#include"common/MFCommon.h"
|
#include"common/MFCommon.h"
|
||||||
|
#include"ShaderLibrary.h"
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
STD_MTL_NAMESPACE_BEGIN
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const AnsiString *MF_HandoverMI=nullptr;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
MaterialCreateInfo::MaterialCreateInfo(const MaterialCreateConfig *mc)
|
MaterialCreateInfo::MaterialCreateInfo(const MaterialCreateConfig *mc)
|
||||||
{
|
{
|
||||||
config=mc;
|
config=mc;
|
||||||
@ -32,6 +39,9 @@ MaterialCreateInfo::MaterialCreateInfo(const MaterialCreateConfig *mc)
|
|||||||
l2w_shader_stage=0;
|
l2w_shader_stage=0;
|
||||||
l2w_ubo=nullptr;
|
l2w_ubo=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!MF_HandoverMI)
|
||||||
|
MF_HandoverMI=LoadShader("HandoverMI");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MaterialCreateInfo::AddStruct(const AnsiString &struct_name,const AnsiString &codes)
|
bool MaterialCreateInfo::AddStruct(const AnsiString &struct_name,const AnsiString &codes)
|
||||||
@ -248,7 +258,7 @@ bool MaterialCreateInfo::CreateShader()
|
|||||||
{
|
{
|
||||||
sc->AddOutput(VAT_UINT,mtl::func::MaterialInstanceID,Interpolation::Flat);
|
sc->AddOutput(VAT_UINT,mtl::func::MaterialInstanceID,Interpolation::Flat);
|
||||||
|
|
||||||
sc->AddFunction(mtl::func::HandoverMI);
|
sc->AddFunction(MF_HandoverMI);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc->CreateShader(last);
|
sc->CreateShader(last);
|
||||||
|
@ -5,9 +5,16 @@
|
|||||||
|
|
||||||
#include"GLSLCompiler.h"
|
#include"GLSLCompiler.h"
|
||||||
#include"common/MFCommon.h"
|
#include"common/MFCommon.h"
|
||||||
|
#include"ShaderLibrary.h"
|
||||||
|
|
||||||
namespace hgl{namespace graph{
|
namespace hgl{namespace graph{
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const AnsiString *ShaderFileHeader=nullptr;
|
||||||
|
const AnsiString *MF_GetMI=nullptr;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
ShaderCreateInfo::ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorInfo *m)
|
ShaderCreateInfo::ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorInfo *m)
|
||||||
{
|
{
|
||||||
shader_stage=ss;
|
shader_stage=ss;
|
||||||
@ -18,6 +25,9 @@ ShaderCreateInfo::ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorIn
|
|||||||
|
|
||||||
define_macro_max_length=0;
|
define_macro_max_length=0;
|
||||||
define_value_max_length=0;
|
define_value_max_length=0;
|
||||||
|
|
||||||
|
if(!ShaderFileHeader)ShaderFileHeader =mtl::LoadShader("ShaderHeader");
|
||||||
|
if(!MF_GetMI )MF_GetMI =mtl::LoadShader("GetMI");
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderCreateInfo::~ShaderCreateInfo()
|
ShaderCreateInfo::~ShaderCreateInfo()
|
||||||
@ -159,7 +169,7 @@ void ShaderCreateInfo::SetMaterialInstance(UBODescriptor *ubo,const AnsiString &
|
|||||||
sdm->AddUBO(DescriptorSetType::PerMaterial,ubo);
|
sdm->AddUBO(DescriptorSetType::PerMaterial,ubo);
|
||||||
sdm->AddStruct(mtl::MaterialInstanceStruct);
|
sdm->AddStruct(mtl::MaterialInstanceStruct);
|
||||||
|
|
||||||
AddFunction(mtl::func::GetMI);
|
AddFunction(MF_GetMI);
|
||||||
|
|
||||||
mi_codes=mi;
|
mi_codes=mi;
|
||||||
}
|
}
|
||||||
@ -372,27 +382,18 @@ bool ShaderCreateInfo::ProcSampler()
|
|||||||
|
|
||||||
bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
|
bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
|
||||||
{
|
{
|
||||||
|
if(!ShaderFileHeader)
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(main_function.IsEmpty())
|
if(main_function.IsEmpty())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
//@see VKShaderStage.cpp
|
final_shader=ShaderFileHeader->c_str();
|
||||||
|
|
||||||
final_shader=R"(#version 460 core
|
|
||||||
|
|
||||||
#define VertexShader 0x01
|
|
||||||
#define TessControlShader 0x02
|
|
||||||
#define TeseEvalShader 0x04
|
|
||||||
#define GeometryShader 0x08
|
|
||||||
#define FragmentShader 0x10
|
|
||||||
#define ComputeShader 0x20
|
|
||||||
#define TaskShader 0x40
|
|
||||||
#define MeshShader 0x80
|
|
||||||
|
|
||||||
#define ShaderStage 0x)";
|
|
||||||
|
|
||||||
{
|
{
|
||||||
char ss_hex_str[9];
|
char ss_hex_str[9];
|
||||||
|
|
||||||
|
final_shader+="\n#define ShaderStage 0x";
|
||||||
final_shader+=utos(ss_hex_str,8,uint(shader_stage),16);
|
final_shader+=utos(ss_hex_str,8,uint(shader_stage),16);
|
||||||
final_shader+="\n";
|
final_shader+="\n";
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,19 @@
|
|||||||
#include<hgl/graph/VKRenderAssign.h>
|
#include<hgl/graph/VKRenderAssign.h>
|
||||||
#include"GLSLCompiler.h"
|
#include"GLSLCompiler.h"
|
||||||
#include"common/MFCommon.h"
|
#include"common/MFCommon.h"
|
||||||
|
#include"ShaderLibrary.h"
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const AnsiString *MF_GetLocalToWorld=nullptr;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
ShaderCreateInfoVertex::ShaderCreateInfoVertex(MaterialDescriptorInfo *m):ShaderCreateInfo(VK_SHADER_STAGE_VERTEX_BIT,m)
|
||||||
|
{
|
||||||
|
if(!MF_GetLocalToWorld)MF_GetLocalToWorld=mtl::LoadShader("GetLocalToWorld");
|
||||||
|
}
|
||||||
|
|
||||||
int ShaderCreateInfoVertex::AddInput(const VAT &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
int ShaderCreateInfoVertex::AddInput(const VAT &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
||||||
{
|
{
|
||||||
ShaderAttribute *ss=new ShaderAttribute;
|
ShaderAttribute *ss=new ShaderAttribute;
|
||||||
@ -45,7 +56,7 @@ void ShaderCreateInfoVertex::AddAssign()
|
|||||||
VK_VERTEX_INPUT_RATE_INSTANCE,
|
VK_VERTEX_INPUT_RATE_INSTANCE,
|
||||||
VertexInputGroup::Assign);
|
VertexInputGroup::Assign);
|
||||||
|
|
||||||
AddFunction(mtl::func::GetLocalToWorld);
|
AddFunction(MF_GetLocalToWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||||
|
49
src/ShaderGen/ShaderLibrary.cpp
Normal file
49
src/ShaderGen/ShaderLibrary.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include<hgl/type/String.h>
|
||||||
|
#include<hgl/type/Map.h>
|
||||||
|
#include<hgl/graph/mtl/StdMaterial.h>
|
||||||
|
#include<hgl/io/LoadString.h>
|
||||||
|
#include<hgl/filesystem/Filename.h>
|
||||||
|
#include<hgl/filesystem/Filesystem.h>
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
ObjectMap<AnsiString,UTF8String> shader_library;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 因为是Debug阶段,所以现在直接从文件系统加载
|
||||||
|
|
||||||
|
const AnsiString *LoadShader(const AnsiString &shader_name)
|
||||||
|
{
|
||||||
|
if(shader_name.IsEmpty())
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
UTF8String *shader;
|
||||||
|
|
||||||
|
if(shader_library.Get(shader_name,shader))
|
||||||
|
return shader;
|
||||||
|
|
||||||
|
const AnsiString filename=shader_name+".glsl";
|
||||||
|
|
||||||
|
const AnsiString fullname=filesystem::MergeFilename("ShaderLibrary",filename);
|
||||||
|
|
||||||
|
const OSString os_fn=ToOSString(fullname);
|
||||||
|
|
||||||
|
if(!filesystem::FileExist(os_fn))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
shader=new UTF8String;
|
||||||
|
|
||||||
|
if(LoadStringFromTextFile(*shader,os_fn)<=0)
|
||||||
|
{
|
||||||
|
delete shader;
|
||||||
|
shader=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
shader_library.Add(shader_name,shader);
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_END
|
12
src/ShaderGen/ShaderLibrary.h
Normal file
12
src/ShaderGen/ShaderLibrary.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<hgl/type/String.h>
|
||||||
|
#include<hgl/graph/mtl/StdMaterial.h>
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
//void SetGlobalDefine(const AnsiString &,const AnsiString &);
|
||||||
|
|
||||||
|
const AnsiString *LoadShader(const AnsiString &);
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_END
|
@ -7,51 +7,7 @@ namespace func
|
|||||||
{
|
{
|
||||||
//C++端使用一个RG8UI或RGB16UI格式的顶点输入流来传递Assign数据,其中x为LocalToWorld ID,y为MaterialInstance ID
|
//C++端使用一个RG8UI或RGB16UI格式的顶点输入流来传递Assign数据,其中x为LocalToWorld ID,y为MaterialInstance ID
|
||||||
|
|
||||||
constexpr const char GetLocalToWorld[]=R"(
|
|
||||||
mat4 GetLocalToWorld()
|
|
||||||
{
|
|
||||||
return l2w.mats[Assign.x];
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
constexpr const char MaterialInstanceID[]="MaterialInstanceID";
|
constexpr const char MaterialInstanceID[]="MaterialInstanceID";
|
||||||
|
|
||||||
constexpr const char HandoverMI[]=R"(
|
|
||||||
void HandoverMI()
|
|
||||||
{
|
|
||||||
#if ShaderStage == VertexShader
|
|
||||||
Output.MaterialInstanceID=Assign.y;
|
|
||||||
#elif ShaderStage == GeometryShader
|
|
||||||
Output.MaterialInstanceID=Input[0].MaterialInstanceID;
|
|
||||||
#else
|
|
||||||
Output.MaterialInstanceID=Input.MaterialInstanceID;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
constexpr const char GetMI[]=R"(
|
|
||||||
MaterialInstance GetMI()
|
|
||||||
{
|
|
||||||
#if ShaderStage == VertexShader
|
|
||||||
return mtl.mi[Assign.y];
|
|
||||||
#else
|
|
||||||
return mtl.mi[Input.MaterialInstanceID];
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
// Joint数据分Joint ID和Joint Weight两部分
|
|
||||||
// Joint ID是一个uvec4,在shader中为整数。在C++端可使用RGBA8UI或是RGBA16UI来传递。
|
|
||||||
// Joint Weight是权重,在shader中为浮点。在C++端使用RGBA8或RGBA4来传递。
|
|
||||||
|
|
||||||
constexpr const char GetJointMatrix[]=R"(
|
|
||||||
mat4 GetJointMatrix()
|
|
||||||
{
|
|
||||||
return joint.mats[JointID.x]*JointWeight.x+
|
|
||||||
joint.mats[JointID.y]*JointWeight.y+
|
|
||||||
joint.mats[JointID.z]*JointWeight.z+
|
|
||||||
joint.mats[JointID.w]*JointWeight.w;
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
}//namespace func
|
}//namespace func
|
||||||
STD_MTL_NAMESPACE_END
|
STD_MTL_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user