Shader生成准备增加WorldPosition

This commit is contained in:
2025-07-07 01:27:25 +08:00
parent 79d86686e8
commit e021f30877
5 changed files with 85 additions and 53 deletions

View File

@@ -81,6 +81,7 @@ namespace hgl::graph
bool SetMaterialInstance(const AnsiString &mi_glsl_codes,const uint32_t mi_struct_bytes,const uint32_t shader_stage_flag_bits); bool SetMaterialInstance(const AnsiString &mi_glsl_codes,const uint32_t mi_struct_bytes,const uint32_t shader_stage_flag_bits);
bool SetLocalToWorld(const uint32_t shader_stage_flag_bits); bool SetLocalToWorld(const uint32_t shader_stage_flag_bits);
//bool SetWorldPosition(const uint32_t shader_stage_flag_bits);
bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes); bool AddStruct(const AnsiString &ubo_typename,const AnsiString &codes);

View File

@@ -3,7 +3,8 @@
#include<hgl/shadergen/ShaderCreateInfo.h> #include<hgl/shadergen/ShaderCreateInfo.h>
#include<hgl/shadergen/ShaderDescriptorInfo.h> #include<hgl/shadergen/ShaderDescriptorInfo.h>
namespace hgl{namespace graph{ namespace hgl::graph
{
class ShaderCreateInfoGeometry:public ShaderCreateInfo class ShaderCreateInfoGeometry:public ShaderCreateInfo
{ {
GeometryShaderDescriptorInfo gsdi; GeometryShaderDescriptorInfo gsdi;
@@ -32,4 +33,4 @@ public:
bool ProcLayout() override; bool ProcLayout() override;
}; };
}}//namespace hgl::graph }//namespace hgl::graph

View File

@@ -3,9 +3,7 @@
#include<hgl/shadergen/ShaderCreateInfo.h> #include<hgl/shadergen/ShaderCreateInfo.h>
#include<hgl/shadergen/ShaderDescriptorInfo.h> #include<hgl/shadergen/ShaderDescriptorInfo.h>
namespace hgl namespace hgl::graph
{
namespace graph
{ {
class ShaderCreateInfoVertex:public ShaderCreateInfo class ShaderCreateInfoVertex:public ShaderCreateInfo
{ {
@@ -42,5 +40,4 @@ namespace hgl
void AddJoint(); void AddJoint();
};//class ShaderCreateInfoVertex:public ShaderCreateInfo };//class ShaderCreateInfoVertex:public ShaderCreateInfo
}//namespace graph
}//namespace hgl::graph }//namespace hgl::graph

View File

@@ -3,6 +3,7 @@
#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"common/MFGetPosition.h"
#include"ShaderLibrary.h" #include"ShaderLibrary.h"
using namespace hgl; using namespace hgl;
@@ -217,22 +218,50 @@ bool MaterialCreateInfo::SetLocalToWorld(const uint32_t shader_stage_flag_bits)
const AnsiString L2W_MAX_COUNT_STRING=AnsiString::numberOf(l2w_max_count); const AnsiString L2W_MAX_COUNT_STRING=AnsiString::numberOf(l2w_max_count);
auto *it=shader_map.GetDataList(); for(auto it:shader_map)
for(int i=0;i<shader_map.GetCount();i++)
{ {
if((*it)->key&shader_stage_flag_bits) if(it->key&shader_stage_flag_bits)
{ {
(*it)->value->AddDefine("L2W_MAX_COUNT",L2W_MAX_COUNT_STRING); it->value->AddDefine("L2W_MAX_COUNT",L2W_MAX_COUNT_STRING);
} }
++it;
} }
l2w_shader_stage=shader_stage_flag_bits; l2w_shader_stage=shader_stage_flag_bits;
return(true); return(true);
} }
//
//bool MaterialCreateInfo::SetWorldPosition(const uint32_t shader_stage_flag_bits)
//{
// if(shader_stage_flag_bits==0)return(false);
//
// {
// vert->AddOutput(SVT_VEC4,"WorldPosition");
//
// if(l2w_shader_stage)
// {
// vert->AddFunction(func::GetWorldPosition3DL2W_VS);
// }
// else
// {
// vert->AddFunction(func::GetWorldPosition3D_VS);
// }
// }
//
// if(shader_stage_flag_bits&VK_SHADER_STAGE_GEOMETRY_BIT)
// {
// geom->AddOutput(SVT_VEC4,"WorldPosition");
//
// geom->AddFunction(func::GetWorldPosition3D_Other);
// }
//
// if(shader_stage_flag_bits&VK_SHADER_STAGE_FRAGMENT_BIT)
// {
// geom->AddFunction(func::GetWorldPosition3D_Other);
// }
//
// return(true);
//}
void MaterialCreateInfo::SetDevice(const VulkanDevAttr *dev_attr) void MaterialCreateInfo::SetDevice(const VulkanDevAttr *dev_attr)
{ {

View File

@@ -19,6 +19,10 @@ namespace func
"vec4 GetPosition2D(){return GetLocalToWorld()*viewport.ortho_matrix*vec4(Position,0,1);}" //Ortho "vec4 GetPosition2D(){return GetLocalToWorld()*viewport.ortho_matrix*vec4(Position,0,1);}" //Ortho
}; };
constexpr const char *GetWorldPosition3D_VS ="vec4 GetWorldPosition3D(){return vec4(Position,1);}";
constexpr const char *GetWorldPosition3DL2W_VS ="vec4 GetWorldPosition3D(){return GetLocalToWorld()*vec4(Position,1);}";
constexpr const char *GetWorldPosition3D_Other ="vec4 GetWorldPosition3D(){return WorldPosition;}";
constexpr const char *GetPosition3D ="vec4 GetPosition3D(){return vec4(Position,1);}"; constexpr const char *GetPosition3D ="vec4 GetPosition3D(){return vec4(Position,1);}";
constexpr const char *GetPosition3DL2W ="vec4 GetPosition3D(){return GetLocalToWorld()*vec4(Position,1);}"; constexpr const char *GetPosition3DL2W ="vec4 GetPosition3D(){return GetLocalToWorld()*vec4(Position,1);}";
constexpr const char *GetPosition3DCamera ="vec4 GetPosition3D(){return camera.vp*vec4(Position,1);}"; constexpr const char *GetPosition3DCamera ="vec4 GetPosition3D(){return camera.vp*vec4(Position,1);}";