preparing blinnphong light sample. added codes of to load ubo.
This commit is contained in:
parent
2ce36ec26c
commit
c8b3ed0286
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
2
ShaderLibrary/Std3D/BlinnPhong/BlinnPhongSun.ubo
Normal file
@ -0,0 +1,2 @@
|
||||
vec3 direction;
|
||||
vec3 color;
|
@ -11,7 +11,7 @@ define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
|
||||
|
||||
UBO
|
||||
{
|
||||
File Sun.ubo //文件名
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Name sun //在代码中的变量名
|
||||
Stage Vertex,Fragment //会引用的shader
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -17,6 +18,12 @@ static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector3f(1,1,1),
|
||||
Vector3f(1,0.975,0.95)
|
||||
};
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
@ -26,6 +33,10 @@ private: //plane grid
|
||||
Pipeline * p_line =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
DeviceBuffer * ubo_sun =nullptr;
|
||||
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_sun_light =nullptr;
|
||||
@ -55,6 +66,16 @@ private:
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateBlinnPhongUBO()
|
||||
{
|
||||
sun_light.color=Vector3f(1,1,1);
|
||||
|
||||
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
|
||||
if(!ubo_sun)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
@ -64,8 +85,7 @@ private:
|
||||
mtl_sun_light=db->LoadMaterial("Std3D/BlinnPhong/SunLightPureColor",&cfg);
|
||||
if(!mtl_sun_light)return(false);
|
||||
|
||||
mtl_sun_light->BindUBO(DescriptorSetType::Global,"sun",sun_data,sizeof(sun_data)); //恢复SUN.UBO或是使用内嵌SUN定义也行,
|
||||
//恢复SUN.UBO的意义是让引擎支持读取外部UBO配置文件
|
||||
mtl_sun_light->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
|
||||
mi_sphere=db->CreateMaterialInstance(mtl_sun_light);
|
||||
if(!mi_sphere)return(false);
|
||||
@ -123,7 +143,7 @@ private:
|
||||
Add(prim_plane_grid,mi_plane_grid,p_line);
|
||||
Add(prim_sphere,mi_sphere,p_sphere);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera->pos=Vector3f(32,15,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
|
@ -614,11 +614,16 @@ namespace
|
||||
};
|
||||
}//namespace MaterialFile
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr const os_char HGL_SHADER_LIBRARY_FOLDER[]=OS_TEXT("ShaderLibrary");
|
||||
}//namespace
|
||||
|
||||
MaterialFileData *LoadMaterialDataFromFile(const AnsiString &mtl_filename)
|
||||
{
|
||||
const OSString mtl_osfn=ToOSString(mtl_filename+".mtl");
|
||||
|
||||
const OSString mtl_os_filename=filesystem::MergeFilename(OS_TEXT("ShaderLibrary"),mtl_osfn);
|
||||
const OSString mtl_os_filename=filesystem::MergeFilename(HGL_SHADER_LIBRARY_FOLDER,mtl_osfn);
|
||||
|
||||
if(!filesystem::FileExist(mtl_os_filename))
|
||||
return nullptr;
|
||||
@ -653,6 +658,8 @@ MaterialFileData *LoadMaterialDataFromFile(const AnsiString &mtl_filename)
|
||||
|
||||
char *data;
|
||||
int size=filesystem::LoadFileToMemory(ubo_os_filename,(void **)&data,true);
|
||||
|
||||
..//读取所有的UBO文件
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
@ -448,6 +448,7 @@ bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
//想办法存成文件或是输出行号,以方便出错了调试
|
||||
LOG_INFO(AnsiString(GetShaderStageName(shader_stage))+" shader: \n"+final_shader);
|
||||
|
||||
#endif//_DEBUG
|
||||
|
Loading…
x
Reference in New Issue
Block a user