Compare commits
10 Commits
devel_31_V
...
devel_32_B
Author | SHA1 | Date | |
---|---|---|---|
90a4f1d49f | |||
3927b3c788 | |||
6b9ac3220b | |||
4251493415 | |||
686372b60f | |||
150b27c6e6 | |||
c61e4dfdb8 | |||
23197e147c | |||
f1f0843bee | |||
8d45c87cfd |
2
CMCore
2
CMCore
Submodule CMCore updated: ee2bf2b9b8...a82810d58a
Submodule CMSceneGraph updated: 1c8e479181...31a4223bd8
0
ShaderLibrary/Billboard/2DWay.vert
Normal file
0
ShaderLibrary/Billboard/2DWay.vert
Normal file
43
ShaderLibrary/Std3D/Billboard/2DWay.mtl
Normal file
43
ShaderLibrary/Std3D/Billboard/2DWay.mtl
Normal file
@@ -0,0 +1,43 @@
|
||||
#Material
|
||||
Name Billboard2DWay
|
||||
Base Std3D/Billboard
|
||||
|
||||
#VertexInput
|
||||
vec2 TexCoord
|
||||
|
||||
#Vertex
|
||||
Output
|
||||
{
|
||||
vec2 TexCoord
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
Output.TexCoord=TexCoord;
|
||||
|
||||
vec4 pos=GetPosition3D()
|
||||
+camera.camera_right*TexCoord.x*Billboard.Size.x
|
||||
+camera.camera_up *TexCoord.y*Billboard.Size.y;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
|
||||
#Fragment
|
||||
|
||||
sampler2D TextureBaseColor
|
||||
|
||||
Output
|
||||
{
|
||||
vec4 FragColor;
|
||||
}
|
||||
|
||||
Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
}
|
||||
}
|
207
example/Basic/BillboardTest.cpp
Normal file
207
example/Basic/BillboardTest.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
// Billboard
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
static float position_data[3]=
|
||||
{
|
||||
0,0,0
|
||||
};
|
||||
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
MaterialInstance * mi_billboard =nullptr;
|
||||
Pipeline * pipeline_billboard =nullptr;
|
||||
Renderable * ro_billboard =nullptr;
|
||||
|
||||
Texture2D * texture =nullptr;
|
||||
Sampler * sampler =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitPlaneGridMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
{
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
pipeline_plane_grid=CreatePipeline(mtl_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBillboardMP()
|
||||
{
|
||||
mtl::BillboardMaterialCreateConfig cfg(device->GetDeviceAttribute(),"Billboard2D",Prim::Billboard);
|
||||
|
||||
{
|
||||
cfg.fixed_size=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateBillboard2D(&cfg);
|
||||
|
||||
mi_billboard=db->CreateMaterialInstance(mci);
|
||||
if(!mi_billboard)return(false);
|
||||
|
||||
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D,Prim::Billboard);
|
||||
if(!pipeline_billboard)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitTexture()
|
||||
{
|
||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||
if(!texture)return(false);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!mi_billboard->GetMaterial()->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
|
||||
|
||||
mi_billboard->WriteMIData(texture_size);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mtl_plane_grid->GetDefaultVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_billboard->GetVIL());
|
||||
|
||||
pc.Init("Billboard",1);
|
||||
|
||||
if(!pc.WriteVAB(VAN::Position,VF_V3F,position_data))
|
||||
return(false);
|
||||
|
||||
ro_billboard=db->CreateRenderable(&pc,mi_billboard,pipeline_billboard);
|
||||
if(!ro_billboard)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
|
||||
render_root.CreateSubNode(ro_billboard);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitPlaneGridMP())
|
||||
return(false);
|
||||
|
||||
if(!InitBillboardMP())
|
||||
return(false);
|
||||
|
||||
if(!InitTexture())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
@@ -14,3 +14,5 @@ CreateProject(01_draw_triangle_in_NDC draw_triangle_in_NDC.cpp)
|
||||
CreateProject(02_draw_triangle_use_UBO draw_triangle_use_UBO.cpp)
|
||||
CreateProject(03_auto_instance auto_instance.cpp)
|
||||
CreateProject(04_auto_merge_material_instance auto_merge_material_instance.cpp)
|
||||
|
||||
CreateProject(05_Billboard BillboardTest.cpp)
|
@@ -44,7 +44,7 @@ private:
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
|
@@ -69,7 +69,7 @@ private:
|
||||
sampler=db->CreateSampler();
|
||||
|
||||
if(!material->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
mtl::SamplerName::BaseColor, ///<采样器名称
|
||||
texture, ///<纹理
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
@@ -78,7 +78,7 @@ class Semaphore;
|
||||
struct PipelineLayoutData;
|
||||
class DescriptorSet;
|
||||
|
||||
struct ShaderAttribute;
|
||||
struct VertexInputAttribute;
|
||||
|
||||
class ShaderResource;
|
||||
class ShaderModule;
|
||||
|
@@ -1,42 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
#include<hgl/graph/VKStruct.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class ShaderResource
|
||||
{
|
||||
VkShaderStageFlagBits stage_flag;
|
||||
|
||||
const uint32_t *spv_data;
|
||||
uint32 spv_size;
|
||||
|
||||
ShaderStageIO stage_io;
|
||||
|
||||
public:
|
||||
|
||||
ShaderResource(const VkShaderStageFlagBits &,const uint32_t *,const uint32);
|
||||
virtual ~ShaderResource();
|
||||
|
||||
const VkShaderStageFlagBits GetStage ()const {return stage_flag;}
|
||||
const char * GetStageName ()const {return GetShaderStageName(stage_flag);}
|
||||
|
||||
const uint32_t * GetSPVData ()const {return spv_data;}
|
||||
const uint32_t GetSPVSize ()const {return spv_size;}
|
||||
|
||||
ShaderAttributeArray & GetInputs () {return stage_io.input;}
|
||||
// ShaderAttributeArray & GetOutputs () {return stage_io.output;}
|
||||
|
||||
const uint GetInputCount ()const {return stage_io.input.count;}
|
||||
// const uint GetOutputCount ()const {return stage_io.output.count;}
|
||||
|
||||
const ShaderAttribute * GetInput (const AnsiString &)const;
|
||||
const int GetInputBinding (const AnsiString &)const;
|
||||
};//class ShaderResource
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_SHADER_RESOURCE_INCLUDE
|
@@ -12,7 +12,7 @@ struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
VAType position_format; ///<position格式
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -11,7 +11,7 @@ struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
VAType position_format; ///<position格式
|
||||
|
||||
// bool reverse_depth; ///<使用反向深度
|
||||
|
||||
@@ -54,6 +54,19 @@ public:
|
||||
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
||||
|
||||
struct BillboardMaterialCreateConfig:public Material3DCreateConfig
|
||||
{
|
||||
bool fixed_size; ///<固定大小(指像素尺寸)
|
||||
|
||||
Vector2u pixel_size; ///<像素尺寸
|
||||
|
||||
public:
|
||||
|
||||
using Material3DCreateConfig::Material3DCreateConfig;
|
||||
};
|
||||
|
||||
MaterialCreateInfo *CreateBillboard2D(mtl::BillboardMaterialCreateConfig *);
|
||||
|
||||
/**
|
||||
* 从文件加载材质
|
||||
* @param mtl_name 材质名称
|
||||
|
370
inc/hgl/graph/mtl/ShaderVariableType.h
Normal file
370
inc/hgl/graph/mtl/ShaderVariableType.h
Normal file
@@ -0,0 +1,370 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VKSamplerType.h>
|
||||
#include<hgl/graph/VKImageType.h>
|
||||
#include<hgl/CompOperator.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
enum class ShaderVariableBaseType:uint8
|
||||
{
|
||||
Scalar=0,
|
||||
Vector,
|
||||
Materix,
|
||||
Sampler,
|
||||
Image,
|
||||
AtomicCounter,
|
||||
ImplicitConversion,
|
||||
|
||||
ENUM_CLASS_RANGE(Scalar,Materix)
|
||||
};//enum class ShaderVariableBaseType
|
||||
|
||||
using SVBaseType=ShaderVariableBaseType;
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
struct ShaderVariableType
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
SVBaseType base_type;
|
||||
|
||||
union
|
||||
{
|
||||
struct Scalar
|
||||
{
|
||||
VABaseType type;
|
||||
}scalar;
|
||||
|
||||
struct Vector
|
||||
{
|
||||
VABaseType type;
|
||||
uint8 vec_size;
|
||||
}vector;
|
||||
|
||||
struct Matrix
|
||||
{
|
||||
VABaseType type;
|
||||
uint8 n;
|
||||
uint8 m;
|
||||
}matrix;
|
||||
|
||||
struct Sampler
|
||||
{
|
||||
SamplerType type;
|
||||
}sampler;
|
||||
|
||||
struct Image
|
||||
{
|
||||
ShaderImageType type;
|
||||
}image;
|
||||
};
|
||||
};
|
||||
|
||||
uint32 type_code;
|
||||
};
|
||||
|
||||
uint32 array_size;
|
||||
};
|
||||
|
||||
uint64 svt_code;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
ShaderVariableType()
|
||||
{
|
||||
svt_code=0;
|
||||
}
|
||||
|
||||
ShaderVariableType(const ShaderVariableType &svt)
|
||||
{
|
||||
svt_code=svt.svt_code;
|
||||
}
|
||||
|
||||
ShaderVariableType(const VAType &vat,const uint count)
|
||||
{
|
||||
From(vat,count);
|
||||
}
|
||||
|
||||
ShaderVariableType(const VABaseType &vabt,const uint32 count)
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Scalar;
|
||||
|
||||
scalar.type=vabt;
|
||||
|
||||
array_size=count;
|
||||
}
|
||||
|
||||
ShaderVariableType(const VABaseType &vabt,const uint8 size,const uint32 count)
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Vector;
|
||||
|
||||
vector.type=vabt;
|
||||
vector.vec_size=size;
|
||||
|
||||
array_size=count;
|
||||
}
|
||||
|
||||
ShaderVariableType(const VABaseType &vabt,const uint8 row,const uint8 col,const uint32 count)
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Materix;
|
||||
|
||||
matrix.type=vabt;
|
||||
matrix.n=col;
|
||||
matrix.m=row;
|
||||
|
||||
array_size=count;
|
||||
}
|
||||
|
||||
ShaderVariableType(const SamplerType &st,const uint32 count)
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Sampler;
|
||||
|
||||
sampler.type=st;
|
||||
|
||||
array_size=count;
|
||||
}
|
||||
|
||||
ShaderVariableType(const ShaderImageType &sit,const uint32 count)
|
||||
{
|
||||
svt_code=0;
|
||||
|
||||
base_type=SVBaseType::Image;
|
||||
|
||||
image.type=sit;
|
||||
|
||||
array_size=count;
|
||||
}
|
||||
|
||||
const bool Check()const
|
||||
{
|
||||
if(!RangeCheck(base_type))return(false);
|
||||
|
||||
RANGE_CHECK_RETURN_FALSE(base_type)
|
||||
|
||||
if(base_type==SVBaseType::Scalar)
|
||||
return(true);
|
||||
|
||||
if(base_type==SVBaseType::Vector)
|
||||
{
|
||||
if(vector.vec_size<2||vector.vec_size>4)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Materix)
|
||||
{
|
||||
if(matrix.m==0)
|
||||
{
|
||||
if(matrix.n<2||matrix.n>4)return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(matrix.n<2||matrix.n>4)return(false);
|
||||
if(matrix.m<2||matrix.m>4)return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Sampler)
|
||||
return RangeCheck(sampler.type);
|
||||
|
||||
if(base_type==SVBaseType::Image)
|
||||
return RangeCheck(image.type);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
int Comp(const ShaderVariableType &svt)const
|
||||
{
|
||||
int off=(int)base_type-(int)svt.base_type;
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
if(base_type==SVBaseType::Scalar)
|
||||
return int(scalar.type)-int(svt.scalar.type);
|
||||
|
||||
if(base_type==SVBaseType::Vector)
|
||||
{
|
||||
off=int(vector.type)-int(svt.vector.type);
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
off=vector.vec_size-svt.vector.vec_size;
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
return int(vector.type)-int(svt.vector.type);
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Materix)
|
||||
{
|
||||
off=int(matrix.type)-int(svt.matrix.type);
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
off=matrix.n-svt.matrix.n;
|
||||
|
||||
if(off)return(off);
|
||||
|
||||
return matrix.m-svt.matrix.m;
|
||||
}
|
||||
|
||||
if(base_type==SVBaseType::Sampler)
|
||||
return int(sampler.type)-int(svt.sampler.type);
|
||||
|
||||
if(base_type==SVBaseType::Image)
|
||||
return int(image.type)-int(svt.image.type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CompOperator(const ShaderVariableType &,Comp)
|
||||
|
||||
const uint64 ToCode()const{return svt_code;}
|
||||
const bool FromCode(const uint64 code)
|
||||
{
|
||||
svt_code=code;
|
||||
|
||||
return Check();
|
||||
}
|
||||
|
||||
const bool From(const VAType &vat,const uint16 count=1)
|
||||
{
|
||||
array_size=count;
|
||||
|
||||
if(vat.vec_size==1)
|
||||
{
|
||||
base_type=SVBaseType::Scalar;
|
||||
scalar.type=vat.basetype;
|
||||
|
||||
return(true);
|
||||
}
|
||||
else if(vat.vec_size<=4)
|
||||
{
|
||||
base_type=SVBaseType::Vector;
|
||||
|
||||
vector.type=vat.basetype;
|
||||
vector.vec_size=vat.vec_size;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1)
|
||||
{
|
||||
ShaderVariableType svt;
|
||||
|
||||
svt.base_type =SVBaseType::Scalar;
|
||||
svt.scalar.type =vabt;
|
||||
svt.array_size =count;
|
||||
|
||||
return svt;
|
||||
}
|
||||
};//struct ShaderVariableType
|
||||
#pragma pack(pop)
|
||||
|
||||
using SVType=ShaderVariableType;
|
||||
|
||||
const SVType SVT_BOOL (VABaseType::Bool, 1);
|
||||
const SVType SVT_INT (VABaseType::Int, 1);
|
||||
const SVType SVT_UINT (VABaseType::UInt, 1);
|
||||
const SVType SVT_FLOAT (VABaseType::Float, 1);
|
||||
const SVType SVT_DOUBLE(VABaseType::Double, 1);
|
||||
|
||||
const SVType SVT_BVEC2 (VABaseType::Bool, 2,1);
|
||||
const SVType SVT_BVEC3 (VABaseType::Bool, 3,1);
|
||||
const SVType SVT_BVEC4 (VABaseType::Bool, 4,1);
|
||||
|
||||
const SVType SVT_IVEC2 (VABaseType::Int, 2,1);
|
||||
const SVType SVT_IVEC3 (VABaseType::Int, 3,1);
|
||||
const SVType SVT_IVEC4 (VABaseType::Int, 4,1);
|
||||
|
||||
const SVType SVT_UVEC2 (VABaseType::UInt, 2,1);
|
||||
const SVType SVT_UVEC3 (VABaseType::UInt, 3,1);
|
||||
const SVType SVT_UVEC4 (VABaseType::UInt, 4,1);
|
||||
|
||||
const SVType SVT_VEC2 (VABaseType::Float, 2,1);
|
||||
const SVType SVT_VEC3 (VABaseType::Float, 3,1);
|
||||
const SVType SVT_VEC4 (VABaseType::Float, 4,1);
|
||||
|
||||
const SVType SVT_DVEC2 (VABaseType::Double, 2,1);
|
||||
const SVType SVT_DVEC3 (VABaseType::Double, 3,1);
|
||||
const SVType SVT_DVEC4 (VABaseType::Double, 4,1);
|
||||
|
||||
const SVType SVT_MAT2 (VABaseType::Float, 2,2,1);
|
||||
const SVType SVT_MAT3 (VABaseType::Float, 3,3,1);
|
||||
const SVType SVT_MAT4 (VABaseType::Float, 4,4,1);
|
||||
const SVType SVT_MAT2x3(VABaseType::Float, 2,3,1);
|
||||
const SVType SVT_MAT2x4(VABaseType::Float, 2,4,1);
|
||||
const SVType SVT_MAT3x2(VABaseType::Float, 3,2,1);
|
||||
const SVType SVT_MAT3x4(VABaseType::Float, 3,4,1);
|
||||
const SVType SVT_MAT4x2(VABaseType::Float, 4,2,1);
|
||||
const SVType SVT_MAT4x3(VABaseType::Float, 4,3,1);
|
||||
|
||||
const SVType SVT_Sampler1D(SamplerType::Sampler1D, 1);
|
||||
const SVType SVT_Sampler2D(SamplerType::Sampler2D, 1);
|
||||
const SVType SVT_Sampler3D(SamplerType::Sampler3D, 1);
|
||||
|
||||
const SVType SVT_SamplerCube(SamplerType::SamplerCube, 1);
|
||||
const SVType SVT_Sampler2DRect(SamplerType::Sampler2DRect, 1);
|
||||
|
||||
const SVType SVT_Sampler1DArray(SamplerType::Sampler1DArray,1);
|
||||
const SVType SVT_Sampler2DArray(SamplerType::Sampler2DArray,1);
|
||||
|
||||
const SVType SVT_SamplerCubeArray(SamplerType::SamplerCubeArray,1);
|
||||
|
||||
const SVType SVT_SamplerBuffer(SamplerType::SamplerBuffer,1);
|
||||
|
||||
const SVType SVT_Sampler2DMS(SamplerType::Sampler2DMS,1);
|
||||
const SVType SVT_Sampler2DMSArray(SamplerType::Sampler2DMSArray,1);
|
||||
|
||||
const SVType SVT_Sampler1DShadow(SamplerType::Sampler1DShadow,1);
|
||||
const SVType SVT_Sampler2DShadow(SamplerType::Sampler2DShadow,1);
|
||||
|
||||
const SVType SVT_SamplerCubeShadow(SamplerType::SamplerCubeShadow,1);
|
||||
const SVType SVT_Sampler2DRectShadow(SamplerType::Sampler2DRectShadow,1);
|
||||
|
||||
const SVType SVT_Sampler1DArrayShadow(SamplerType::Sampler1DArrayShadow,1);
|
||||
const SVType SVT_Sampler2DArrayShadow(SamplerType::Sampler2DArrayShadow,1);
|
||||
const SVType SVT_SamplerCubeArrayShadow(SamplerType::SamplerCubeArrayShadow,1);
|
||||
|
||||
const SVType SVT_Image1D(ShaderImageType::Image1D,1);
|
||||
const SVType SVT_Image2D(ShaderImageType::Image2D,1);
|
||||
const SVType SVT_Image3D(ShaderImageType::Image3D,1);
|
||||
|
||||
const SVType SVT_ImageCube(ShaderImageType::ImageCube,1);
|
||||
const SVType SVT_Image2DRect(ShaderImageType::Image2DRect,1);
|
||||
|
||||
const SVType SVT_Image1DArray(ShaderImageType::Image1DArray,1);
|
||||
const SVType SVT_Image2DArray(ShaderImageType::Image2DArray,1);
|
||||
|
||||
const SVType SVT_ImageCubeArray(ShaderImageType::ImageCubeArray,1);
|
||||
|
||||
const SVType SVT_ImageBuffer(ShaderImageType::ImageBuffer,1);
|
||||
|
||||
const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1);
|
||||
const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1);
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -39,6 +39,9 @@ constexpr const ShaderBufferSource SBS_CameraInfo=
|
||||
vec3 view_line; //pos-target
|
||||
vec3 world_up;
|
||||
|
||||
vec3 billboard_up;
|
||||
vec3 billboard_right;
|
||||
|
||||
float znear,zfar;)"
|
||||
};
|
||||
|
||||
|
@@ -1,9 +1,10 @@
|
||||
#ifndef HGL_SHADER_CREATE_INFO_INCLUDE
|
||||
#ifndef HGL_SHADER_CREATE_INFO_INCLUDE
|
||||
#define HGL_SHADER_CREATE_INFO_INCLUDE
|
||||
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKInterpolation.h>
|
||||
#include<hgl/graph/mtl/ShaderVariableType.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
@@ -65,9 +66,9 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
ShaderDescriptorInfo *sdm;
|
||||
ShaderDescriptorInfo *sdi;
|
||||
|
||||
VkShaderStageFlagBits GetShaderStage()const{return shader_stage;}
|
||||
const VkShaderStageFlagBits GetShaderStage()const{return shader_stage;}
|
||||
|
||||
public:
|
||||
|
||||
@@ -76,8 +77,9 @@ public:
|
||||
|
||||
bool AddDefine(const AnsiString &m,const AnsiString &v);
|
||||
|
||||
int AddOutput(const graph::VAT &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const graph::VAType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
//int AddOutput(const ShaderVariableType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth);
|
||||
|
||||
void AddFunction(const char *str){function_list.Add(str);}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ namespace hgl
|
||||
ShaderCreateInfoVertex(MaterialDescriptorInfo *);
|
||||
~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::VAType &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
int AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate=VK_VERTEX_INPUT_RATE_VERTEX,const VertexInputGroup &group=VertexInputGroup::Basic);
|
||||
|
||||
int hasInput(const char *);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
bool AddInput(ShaderAttribute *);
|
||||
bool AddOutput(ShaderAttribute *);
|
||||
bool AddInput(VertexInputAttribute *);
|
||||
bool AddOutput(VertexInputAttribute *);
|
||||
|
||||
bool hasInput(const char *)const; ///<是否有指定输入
|
||||
|
||||
|
@@ -98,11 +98,6 @@ SET(VK_RR_SOURCE ${SG_INCLUDE_PATH}/VKRenderResource.h
|
||||
|
||||
SOURCE_GROUP("Vulkan\\RenderResource" FILES ${VK_RR_SOURCE})
|
||||
|
||||
SET(VK_RR_SHADER_FILES ${SG_INCLUDE_PATH}/VKShaderResource.h
|
||||
Vulkan/VKShaderResource.cpp)
|
||||
|
||||
SOURCE_GROUP("Vulkan\\RenderResource\\Shader" FILES ${VK_RR_SHADER_FILES})
|
||||
|
||||
SET(VK_RR_MATERIAL_FILES ${SG_INCLUDE_PATH}/VKMaterialDescriptorManager.h
|
||||
Vulkan/VKMaterialDescriptorManager.cpp)
|
||||
|
||||
@@ -282,7 +277,6 @@ ENDIF(UNIX)
|
||||
SOURCE_GROUP("Vulkan\\Surface" FILES ${VULKAN_SURFACE_SOURCE})
|
||||
|
||||
SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
${VK_RR_SHADER_FILES}
|
||||
${VK_RR_MATERIAL_FILES}
|
||||
${VK_INST_SOURCE}
|
||||
${VK_DEBUG_SOURCE}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKShaderResource.h>
|
||||
#include<hgl/graph/VKMaterialDescriptorManager.h>
|
||||
#include<hgl/graph/VKVertexInput.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
@@ -124,7 +123,7 @@ Material *RenderResource::CreateMaterial(const mtl::MaterialCreateInfo *mci)
|
||||
ShaderCreateInfoVertex *vert=mci->GetVS();
|
||||
|
||||
if(vert)
|
||||
mtl->vertex_input=GetVertexInput(vert->sdm->GetShaderStageIO().input);
|
||||
mtl->vertex_input=GetVertexInput(vert->sdi->GetShaderStageIO().input);
|
||||
}
|
||||
|
||||
{
|
||||
|
@@ -1,55 +0,0 @@
|
||||
#include<hgl/graph/VKShaderResource.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/io/ConstBufferReader.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
ShaderResource::ShaderResource(const VkShaderStageFlagBits &flag,const uint32_t *sd,const uint32 size)
|
||||
{
|
||||
stage_flag=flag;
|
||||
spv_data=sd;
|
||||
spv_size=size;
|
||||
|
||||
Init(stage_io);
|
||||
}
|
||||
|
||||
ShaderResource::~ShaderResource()
|
||||
{
|
||||
Clear(stage_io);
|
||||
}
|
||||
|
||||
const ShaderAttribute *ShaderResource::GetInput(const AnsiString &name) const
|
||||
{
|
||||
if(stage_io.input.count<=0)return(nullptr);
|
||||
|
||||
const ShaderAttribute *ss=stage_io.input.items;
|
||||
|
||||
for(uint i=0;i<stage_io.input.count;i++)
|
||||
{
|
||||
if(name==ss->name)
|
||||
return ss;
|
||||
|
||||
++ss;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int ShaderResource::GetInputBinding(const AnsiString &name) const
|
||||
{
|
||||
if(stage_io.input.count<=0)return(-1);
|
||||
|
||||
const ShaderAttribute *ss=stage_io.input.items;
|
||||
|
||||
for(uint i=0;i<stage_io.input.count;i++)
|
||||
{
|
||||
if(name==ss->name)
|
||||
return i;
|
||||
|
||||
++ss;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
VK_NAMESPACE_END
|
@@ -20,7 +20,7 @@ void main()
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,Input.TexCoord);
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
})";
|
||||
|
||||
class MaterialPureTexture2D:public Std2DMaterial
|
||||
|
@@ -37,7 +37,7 @@ void main()
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureColor,Input.TexCoord);
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
})";
|
||||
|
||||
class MaterialRectTexture2D:public Std2DMaterial
|
||||
|
@@ -44,7 +44,7 @@ void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
FragColor=texture(TextureColor,vec3(Input.TexCoord,mi.id.x));
|
||||
FragColor=texture(TextureBaseColor,vec3(Input.TexCoord,mi.id.x));
|
||||
})";
|
||||
|
||||
class MaterialRectTexture2D:public Std2DMaterial
|
||||
|
16
src/ShaderGen/3d/M_Billboard.cpp
Normal file
16
src/ShaderGen/3d/M_Billboard.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include"Std3DMaterial.h"
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
|
||||
MaterialCreateInfo *CreateBillboard2DDynamic(mtl::BillboardMaterialCreateConfig *cfg);
|
||||
MaterialCreateInfo *CreateBillboard2DFixedSize(mtl::BillboardMaterialCreateConfig *cfg);
|
||||
|
||||
MaterialCreateInfo *CreateBillboard2D(mtl::BillboardMaterialCreateConfig *cfg)
|
||||
{
|
||||
if(cfg->fixed_size)
|
||||
return CreateBillboard2DFixedSize(cfg);
|
||||
else
|
||||
return CreateBillboard2DDynamic(cfg);
|
||||
}
|
||||
|
||||
STD_MTL_NAMESPACE_END
|
101
src/ShaderGen/3d/M_BillboardDynamicSize.cpp
Normal file
101
src/ShaderGen/3d/M_BillboardDynamicSize.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include"Std3DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
constexpr const char vs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
Output.l2w_id=Assign.x;
|
||||
gl_Position=vec4(Position,1);
|
||||
})";
|
||||
|
||||
constexpr const char gs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
const vec2 BillboardVertex[4]=vec2[]
|
||||
(
|
||||
vec2(-0.5,-0.5),
|
||||
vec2( 0.5,-0.5),
|
||||
vec2(-0.5, 0.5),
|
||||
vec2( 0.5, 0.5)
|
||||
);
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
gl_Position=camera.vp
|
||||
*l2w.mats[Input[0].l2w_id]
|
||||
*vec4( gl_in[0].gl_Position.xyz+
|
||||
BillboardVertex[i].x*camera.billboard_right+
|
||||
BillboardVertex[i].y*camera.billboard_up,
|
||||
1
|
||||
);
|
||||
|
||||
Output.TexCoord=vec2(BillboardVertex[i].x+0.5,BillboardVertex[i].y*-1.0+0.5);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
})";
|
||||
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
})";
|
||||
|
||||
class MaterialBillboard2DDynamicSize:public Std3DMaterial
|
||||
{
|
||||
public:
|
||||
|
||||
using Std3DMaterial::Std3DMaterial;
|
||||
~MaterialBillboard2DDynamicSize()=default;
|
||||
|
||||
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||
{
|
||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddOutput(VAT_UINT,"l2w_id",Interpolation::Flat);
|
||||
|
||||
vsc->SetMain(vs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CustomGeometryShader(ShaderCreateInfoGeometry *gsc) override
|
||||
{
|
||||
gsc->SetGeom(Prim::Points,Prim::TriangleStrip,4);
|
||||
|
||||
gsc->AddOutput(VAT_VEC2,"TexCoord");
|
||||
|
||||
gsc->SetMain(gs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||
{
|
||||
mci->AddSampler(VK_SHADER_STAGE_FRAGMENT_BIT,DescriptorSetType::PerMaterial,SamplerType::Sampler2D,mtl::SamplerName::BaseColor);
|
||||
|
||||
fsc->AddOutput(VAT_VEC4,"FragColor"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
||||
|
||||
fsc->SetMain(fs_main);
|
||||
return(true);
|
||||
}
|
||||
};//class MaterialBillboard2DDynamicSize:public Std3DMaterial
|
||||
}//namespace
|
||||
|
||||
MaterialCreateInfo *CreateBillboard2DDynamic(mtl::BillboardMaterialCreateConfig *cfg)
|
||||
{
|
||||
if(!cfg)
|
||||
return(nullptr);
|
||||
|
||||
cfg->shader_stage_flag_bit|=VK_SHADER_STAGE_GEOMETRY_BIT;
|
||||
|
||||
cfg->local_to_world=true;
|
||||
|
||||
MaterialBillboard2DDynamicSize mtl_billbard_2d(cfg);
|
||||
|
||||
return mtl_billbard_2d.Create();
|
||||
}
|
||||
STD_MTL_NAMESPACE_END
|
112
src/ShaderGen/3d/M_BillboardFixedSize.cpp
Normal file
112
src/ShaderGen/3d/M_BillboardFixedSize.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include"Std3DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
constexpr const char mi_codes[]="uvec2 BillboardSize;"; //材质实例代码
|
||||
constexpr const uint32_t mi_bytes=sizeof(Vector2u); //材质实例数据大小
|
||||
|
||||
constexpr const char vs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.BillboardSize=mi.BillboardSize/viewport.canvas_resolution;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
gl_Position/=gl_Position.w;
|
||||
})";
|
||||
|
||||
constexpr const char gs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
const vec2 BillboardVertex[4]=vec2[]
|
||||
(
|
||||
vec2(-0.5,-0.5),
|
||||
vec2(-0.5, 0.5),
|
||||
vec2( 0.5,-0.5),
|
||||
vec2( 0.5, 0.5)
|
||||
);
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
gl_Position=gl_in[0].gl_Position;
|
||||
gl_Position.xy+=BillboardVertex[i]*Input[0].BillboardSize;
|
||||
|
||||
Output.TexCoord=BillboardVertex[i]+vec2(0.5);
|
||||
|
||||
EmitVertex();
|
||||
}
|
||||
EndPrimitive();
|
||||
})";
|
||||
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
FragColor=texture(TextureBaseColor,Input.TexCoord);
|
||||
})";
|
||||
|
||||
class MaterialBillboard2DFixedSize:public Std3DMaterial
|
||||
{
|
||||
public:
|
||||
|
||||
using Std3DMaterial::Std3DMaterial;
|
||||
~MaterialBillboard2DFixedSize()=default;
|
||||
|
||||
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||
{
|
||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddOutput(VAT_VEC2,"BillboardSize");
|
||||
|
||||
vsc->SetMain(vs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CustomGeometryShader(ShaderCreateInfoGeometry *gsc) override
|
||||
{
|
||||
gsc->SetGeom(Prim::Points,Prim::TriangleStrip,4);
|
||||
|
||||
gsc->AddOutput(VAT_VEC2,"TexCoord");
|
||||
|
||||
gsc->SetMain(gs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||
{
|
||||
mci->AddSampler(VK_SHADER_STAGE_FRAGMENT_BIT,DescriptorSetType::PerMaterial,SamplerType::Sampler2D,mtl::SamplerName::BaseColor);
|
||||
|
||||
fsc->AddOutput(VAT_VEC4,"FragColor"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
||||
|
||||
fsc->SetMain(fs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool EndCustomShader() override
|
||||
{
|
||||
mci->SetMaterialInstance( mi_codes, //材质实例glsl代码
|
||||
mi_bytes, //材质实例数据大小
|
||||
VK_SHADER_STAGE_VERTEX_BIT); //只在Vertex Shader中使用材质实例最终数据
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class MaterialBillboard2DFixedSize:public Std3DMaterial
|
||||
}//namespace
|
||||
|
||||
MaterialCreateInfo *CreateBillboard2DFixedSize(mtl::BillboardMaterialCreateConfig *cfg)
|
||||
{
|
||||
if(!cfg)
|
||||
return(nullptr);
|
||||
|
||||
cfg->shader_stage_flag_bit|=VK_SHADER_STAGE_GEOMETRY_BIT;
|
||||
|
||||
cfg->local_to_world=true;
|
||||
|
||||
MaterialBillboard2DFixedSize mtl_billbard_2d_fixed_size(cfg);
|
||||
|
||||
return mtl_billbard_2d_fixed_size.Create();
|
||||
}
|
||||
STD_MTL_NAMESPACE_END
|
@@ -1,4 +1,4 @@
|
||||
set(SHADERGEN_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/shadergen)
|
||||
set(SHADERGEN_INCLUDE_PATH ${ROOT_INCLUDE_PATH}/hgl/shadergen)
|
||||
|
||||
SET(SHADER_CREATER_HEADER_FILES ${SHADERGEN_INCLUDE_PATH}/ShaderCreateInfo.h
|
||||
${SHADERGEN_INCLUDE_PATH}/ShaderCreateInfoMap.h
|
||||
@@ -39,6 +39,7 @@ set(STD_MTL_HEADER_PATH ${ROOT_INCLUDE_PATH}/hgl/graph/mtl)
|
||||
SET(SHADERGEN_COMMON_FILES ${STD_MTL_HEADER_PATH}/UniformBuffer.h
|
||||
${STD_MTL_HEADER_PATH}/UBOCommon.h
|
||||
${STD_MTL_HEADER_PATH}/SamplerName.h
|
||||
${STD_MTL_HEADER_PATH}/ShaderVariableType.h
|
||||
common/MFCommon.h
|
||||
common/MFGetPosition.h
|
||||
common/MFGetNormal.h
|
||||
@@ -69,6 +70,9 @@ SET(STD_MTL_3D_SOURCE_FILES ${STD_MTL_HEADER_PATH}/Material3DCreateConfig.h
|
||||
3d/Std3DMaterialLoader.cpp
|
||||
3d/M_VertexColor3D.cpp
|
||||
3d/M_VertexLum3D.cpp
|
||||
3d/M_BillboardDynamicSize.cpp
|
||||
3d/M_BillboardFixedSize.cpp
|
||||
3d/M_Billboard.cpp
|
||||
)
|
||||
|
||||
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
||||
|
@@ -58,7 +58,7 @@ bool MaterialCreateInfo::AddUBO(const VkShaderStageFlagBits flag_bit,const Descr
|
||||
|
||||
ubo->stage_flag|=flag_bit;
|
||||
|
||||
return sc->sdm->AddUBO(set_type,ubo);
|
||||
return sc->sdi->AddUBO(set_type,ubo);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -67,7 +67,7 @@ bool MaterialCreateInfo::AddUBO(const VkShaderStageFlagBits flag_bit,const Descr
|
||||
ubo->type=struct_name;
|
||||
hgl::strcpy(ubo->name,DESCRIPTOR_NAME_MAX_LENGTH,name);
|
||||
|
||||
return sc->sdm->AddUBO(set_type,mdi.AddUBO(flag_bit,set_type,ubo));
|
||||
return sc->sdi->AddUBO(set_type,mdi.AddUBO(flag_bit,set_type,ubo));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ bool MaterialCreateInfo::AddSampler(const VkShaderStageFlagBits flag_bit,const D
|
||||
|
||||
sampler->stage_flag|=flag_bit;
|
||||
|
||||
return sc->sdm->AddSampler(set_type,sampler);
|
||||
return sc->sdi->AddSampler(set_type,sampler);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -125,7 +125,7 @@ bool MaterialCreateInfo::AddSampler(const VkShaderStageFlagBits flag_bit,const D
|
||||
sampler->type=st_name;
|
||||
hgl::strcpy(sampler->name,DESCRIPTOR_NAME_MAX_LENGTH,name);
|
||||
|
||||
return sc->sdm->AddSampler(set_type,mdi.AddSampler(flag_bit,set_type,sampler));
|
||||
return sc->sdi->AddSampler(set_type,mdi.AddSampler(flag_bit,set_type,sampler));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ namespace material_file
|
||||
|
||||
struct ShaderIOAttrib
|
||||
{
|
||||
VAT vat;
|
||||
VAType vat;
|
||||
|
||||
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
|
||||
};
|
||||
|
@@ -13,7 +13,7 @@ ShaderCreateInfo::ShaderCreateInfo(VkShaderStageFlagBits ss,MaterialDescriptorIn
|
||||
{
|
||||
shader_stage=ss;
|
||||
mdi=m;
|
||||
sdm=new ShaderDescriptorInfo(ss);
|
||||
sdi=new ShaderDescriptorInfo(ss);
|
||||
|
||||
spv_data=nullptr;
|
||||
|
||||
@@ -26,7 +26,7 @@ ShaderCreateInfo::~ShaderCreateInfo()
|
||||
if(spv_data)
|
||||
FreeSPVData(spv_data);
|
||||
|
||||
delete sdm;
|
||||
delete sdi;
|
||||
}
|
||||
|
||||
bool ShaderCreateInfo::AddDefine(const AnsiString &m,const AnsiString &v)
|
||||
@@ -100,9 +100,9 @@ bool ShaderCreateInfo::ProcDefine()
|
||||
return(true);
|
||||
}
|
||||
|
||||
int ShaderCreateInfo::AddOutput(const VAT &type,const AnsiString &name,Interpolation inter)
|
||||
int ShaderCreateInfo::AddOutput(const VAType &type,const AnsiString &name,Interpolation inter)
|
||||
{
|
||||
ShaderAttribute *ss=new ShaderAttribute;
|
||||
VertexInputAttribute *ss=new VertexInputAttribute;
|
||||
|
||||
hgl::strcpy(ss->name,sizeof(ss->name),name.c_str());
|
||||
|
||||
@@ -110,12 +110,12 @@ int ShaderCreateInfo::AddOutput(const VAT &type,const AnsiString &name,Interpola
|
||||
ss->vec_size = type.vec_size;
|
||||
ss->interpolation = inter;
|
||||
|
||||
return sdm->AddOutput(ss);
|
||||
return sdi->AddOutput(ss);
|
||||
}
|
||||
|
||||
int ShaderCreateInfo::AddOutput(const AnsiString &type,const AnsiString &name,Interpolation inter)
|
||||
{
|
||||
VAT vat;
|
||||
VAType vat;
|
||||
|
||||
if(name.IsEmpty())
|
||||
return -1;
|
||||
@@ -126,9 +126,23 @@ int ShaderCreateInfo::AddOutput(const AnsiString &type,const AnsiString &name,In
|
||||
return AddOutput(vat,name,inter);
|
||||
}
|
||||
|
||||
//int ShaderCreateInfo::AddOutput(const ShaderVariableType &type,const AnsiString &name,Interpolation inter=Interpolation::Smooth)
|
||||
//{
|
||||
// VertexInputAttribute *ss=new VertexInputAttribute;
|
||||
//
|
||||
// hgl::strcpy(ss->name,sizeof(ss->name),name.c_str());
|
||||
//
|
||||
// ss->basetype =(uint8)type.base_type;
|
||||
// ss->vec_size = type.vec_size;
|
||||
// ss->interpolation = inter;
|
||||
//
|
||||
// return sdi->AddOutput(ss);
|
||||
//
|
||||
//}
|
||||
|
||||
bool ShaderCreateInfo::ProcSubpassInput()
|
||||
{
|
||||
auto sil=sdm->GetSubpassInputList();
|
||||
auto sil=sdi->GetSubpassInputList();
|
||||
|
||||
if(sil.IsEmpty())
|
||||
return(true);
|
||||
@@ -167,8 +181,8 @@ namespace
|
||||
|
||||
void ShaderCreateInfo::SetMaterialInstance(UBODescriptor *ubo,const AnsiString &mi)
|
||||
{
|
||||
sdm->AddUBO(DescriptorSetType::PerMaterial,ubo);
|
||||
sdm->AddStruct(mtl::MaterialInstanceStruct);
|
||||
sdi->AddUBO(DescriptorSetType::PerMaterial,ubo);
|
||||
sdi->AddStruct(mtl::MaterialInstanceStruct);
|
||||
|
||||
AddFunction(shader_stage==VK_SHADER_STAGE_VERTEX_BIT?MF_GetMI_VS:MF_GetMI_Other);
|
||||
|
||||
@@ -212,14 +226,14 @@ bool ShaderCreateInfo::ProcOutput()
|
||||
{
|
||||
output_struct.Clear();
|
||||
|
||||
const ShaderAttributeArray &ssd=sdm->GetShaderStageIO().output;
|
||||
const VertexInputAttributeArray &ssd=sdi->GetShaderStageIO().output;
|
||||
|
||||
if(ssd.count<=0)return(true);
|
||||
|
||||
output_struct=GetShaderStageName(shader_stage);
|
||||
output_struct+="_Output\n{\n";
|
||||
|
||||
const ShaderAttribute *ss=ssd.items;
|
||||
const VertexInputAttribute *ss=ssd.items;
|
||||
|
||||
for(uint i=0;i<ssd.count;i++)
|
||||
{
|
||||
@@ -251,7 +265,7 @@ bool ShaderCreateInfo::ProcOutput()
|
||||
|
||||
bool ShaderCreateInfo::ProcStruct()
|
||||
{
|
||||
const AnsiStringList &struct_list=sdm->GetStructList();
|
||||
const AnsiStringList &struct_list=sdi->GetStructList();
|
||||
|
||||
AnsiString codes;
|
||||
|
||||
@@ -283,7 +297,7 @@ bool ShaderCreateInfo::ProcMI()
|
||||
|
||||
bool ShaderCreateInfo::ProcUBO()
|
||||
{
|
||||
auto ubo_list=sdm->GetUBOList();
|
||||
auto ubo_list=sdi->GetUBOList();
|
||||
|
||||
const int count=ubo_list.GetCount();
|
||||
|
||||
@@ -327,7 +341,7 @@ bool ShaderCreateInfo::ProcSSBO()
|
||||
|
||||
bool ShaderCreateInfo::ProcConstantID()
|
||||
{
|
||||
auto const_list=sdm->GetConstList();
|
||||
auto const_list=sdi->GetConstList();
|
||||
|
||||
const int count=const_list.GetCount();
|
||||
|
||||
@@ -357,7 +371,7 @@ bool ShaderCreateInfo::ProcConstantID()
|
||||
|
||||
bool ShaderCreateInfo::ProcSampler()
|
||||
{
|
||||
auto sampler_list=sdm->GetSamplerList();
|
||||
auto sampler_list=sdi->GetSamplerList();
|
||||
|
||||
const int count=sampler_list.GetCount();
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/shadergen/ShaderCreateInfoFragment.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoFragment.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
@@ -7,9 +7,9 @@ using namespace hgl::graph;
|
||||
|
||||
bool ShaderCreateInfoFragment::ProcOutput()
|
||||
{
|
||||
const auto &output_list=sdm->GetShaderStageIO().output;
|
||||
const auto &output_list=sdi->GetShaderStageIO().output;
|
||||
|
||||
const ShaderAttribute *o=output_list.items;
|
||||
const VertexInputAttribute *o=output_list.items;
|
||||
|
||||
final_shader+="\n";
|
||||
|
||||
|
@@ -12,9 +12,9 @@ ShaderCreateInfoVertex::ShaderCreateInfoVertex(MaterialDescriptorInfo *m):Shader
|
||||
{
|
||||
}
|
||||
|
||||
int ShaderCreateInfoVertex::AddInput(const VAT &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
||||
int ShaderCreateInfoVertex::AddInput(const VAType &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
||||
{
|
||||
ShaderAttribute *ss=new ShaderAttribute;
|
||||
VertexInputAttribute *ss=new VertexInputAttribute;
|
||||
|
||||
hgl::strcpy(ss->name,sizeof(ss->name),name.c_str());
|
||||
|
||||
@@ -24,12 +24,12 @@ int ShaderCreateInfoVertex::AddInput(const VAT &type,const AnsiString &name,cons
|
||||
ss->input_rate =input_rate;
|
||||
ss->group =group;
|
||||
|
||||
return sdm->AddInput(ss);
|
||||
return sdi->AddInput(ss);
|
||||
}
|
||||
|
||||
int ShaderCreateInfoVertex::AddInput(const AnsiString &type,const AnsiString &name,const VkVertexInputRate input_rate,const VertexInputGroup &group)
|
||||
{
|
||||
VAT vat;
|
||||
VAType vat;
|
||||
|
||||
if(!ParseVertexAttribType(&vat,type))
|
||||
return(-2);
|
||||
@@ -39,7 +39,7 @@ int ShaderCreateInfoVertex::AddInput(const AnsiString &type,const AnsiString &na
|
||||
|
||||
int ShaderCreateInfoVertex::hasInput(const char *name)
|
||||
{
|
||||
return sdm->hasInput(name);
|
||||
return sdi->hasInput(name);
|
||||
}
|
||||
|
||||
void ShaderCreateInfoVertex::AddJoint()
|
||||
@@ -60,7 +60,7 @@ void ShaderCreateInfoVertex::AddAssign()
|
||||
|
||||
bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||
{
|
||||
const auto &input=sdm->GetShaderStageIO().input;
|
||||
const auto &input=sdi->GetShaderStageIO().input;
|
||||
|
||||
if(input.count<=0)
|
||||
{
|
||||
@@ -71,7 +71,7 @@ bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||
|
||||
final_shader+="\n";
|
||||
|
||||
const ShaderAttribute *ss=input.items;
|
||||
const VertexInputAttribute *ss=input.items;
|
||||
|
||||
for(uint i=0;i<input.count;i++)
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
|
||||
namespace hgl{namespace graph{
|
||||
ShaderDescriptorInfo::ShaderDescriptorInfo(VkShaderStageFlagBits flag_bit)
|
||||
@@ -12,7 +12,7 @@ ShaderDescriptorInfo::ShaderDescriptorInfo(VkShaderStageFlagBits flag_bit)
|
||||
|
||||
namespace
|
||||
{
|
||||
bool Find(const ShaderAttributeArray &sad,const char *name)
|
||||
bool Find(const VertexInputAttributeArray &sad,const char *name)
|
||||
{
|
||||
if(sad.count<=0)
|
||||
return(false);
|
||||
@@ -25,7 +25,7 @@ namespace
|
||||
}
|
||||
}//namespace
|
||||
|
||||
bool ShaderDescriptorInfo::AddInput(ShaderAttribute *ss)
|
||||
bool ShaderDescriptorInfo::AddInput(VertexInputAttribute *ss)
|
||||
{
|
||||
if(!ss)return(false);
|
||||
|
||||
@@ -46,7 +46,7 @@ bool ShaderDescriptorInfo::hasInput(const char *name)const
|
||||
|
||||
}
|
||||
|
||||
bool ShaderDescriptorInfo::AddOutput(ShaderAttribute *ss)
|
||||
bool ShaderDescriptorInfo::AddOutput(VertexInputAttribute *ss)
|
||||
{
|
||||
if(!ss)return(false);
|
||||
|
||||
|
Reference in New Issue
Block a user