改进SceneTree范例,使用实体带方向光球体

This commit is contained in:
hyzboy 2020-06-16 20:01:36 +08:00
parent 80dd4f6010
commit fbac9f03c6
5 changed files with 43 additions and 20 deletions

@ -1 +1 @@
Subproject commit 06a42e93940fd2a377d5c4cbf5c4c8662d31ce3a Subproject commit bf7152aee5cffa219c6675c03d1e075b9c98c3bf

View File

@ -11,8 +11,8 @@
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=128; constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=128; constexpr uint32_t SCREEN_HEIGHT=720;
class TestApp:public CameraAppFramework class TestApp:public CameraAppFramework
{ {
@ -42,8 +42,8 @@ private:
bool InitMaterial() bool InitMaterial()
{ {
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition3D.vert.spv"), material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition3D.vert"),
OS_TEXT("res/shader/FlatColor.frag.spv")); OS_TEXT("res/shader/FlatColor.frag"));
if(!material) if(!material)
return(false); return(false);
@ -138,7 +138,7 @@ private:
material_instance->BindUBO("color_material",ubo_color); material_instance->BindUBO("color_material",ubo_color);
if(!InitCameraUBO(material_instance,"world")) if(!material_instance->BindUBO("world",GetCameraMatrixBuffer()))
return(false); return(false);
material_instance->Update(); material_instance->Update();

View File

@ -17,7 +17,13 @@ constexpr uint32_t SCREEN_HEIGHT=720;
class TestApp:public CameraAppFramework class TestApp:public CameraAppFramework
{ {
Color4f color; struct
{
Vector4f color;
Vector4f abiment;
}color_material;
Vector3f sun_direction;
private: private:
@ -30,6 +36,7 @@ private:
vulkan::MaterialInstance * material_instance =nullptr; vulkan::MaterialInstance * material_instance =nullptr;
vulkan::Buffer * ubo_color =nullptr; vulkan::Buffer * ubo_color =nullptr;
vulkan::Buffer * ubo_sun =nullptr;
vulkan::Renderable * renderable_object =nullptr; vulkan::Renderable * renderable_object =nullptr;
@ -48,8 +55,8 @@ private:
bool InitMaterial() bool InitMaterial()
{ {
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition3D.vert"), material=shader_manage->CreateMaterial(OS_TEXT("res/shader/LightPosition3D.vert"),
OS_TEXT("res/shader/FlatColor.frag")); OS_TEXT("res/shader/VertexColor.frag"));
if(!material) if(!material)
return(false); return(false);
@ -62,22 +69,30 @@ private:
void CreateRenderObject() void CreateRenderObject()
{ {
struct CubeCreateInfo cci; renderable_object=CreateRenderableSphere(db,material,40);
renderable_object=CreateRenderableCube(db,material,&cci); db->Add(renderable_object);
} }
bool InitUBO() bool InitUBO()
{ {
if(!InitCameraUBO(material_instance,"world")) LCG lcg;
return(false);
color.Set(1,1,0,1);
ubo_color=device->CreateUBO(sizeof(Color4f),&color);
color_material.color=Vector4f(1,1,1,1.0);
color_material.abiment.Set(0.25,0.25,0.25,1.0);
ubo_color=device->CreateUBO(sizeof(color_material),&color_material);
sun_direction=Vector3f::RandomDir(lcg);
ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction);
material_instance->BindUBO("world",GetCameraMatrixBuffer());
material_instance->BindUBO("color_material",ubo_color); material_instance->BindUBO("color_material",ubo_color);
material_instance->BindUBO("sun",ubo_sun);
material_instance->Update(); material_instance->Update();
db->Add(ubo_color);
db->Add(ubo_sun);
return(true); return(true);
} }
@ -88,7 +103,7 @@ private:
pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthTest(true);
pipeline_creater->SetDepthWrite(true); pipeline_creater->SetDepthWrite(true);
pipeline_creater->CloseCullFace(); pipeline_creater->CloseCullFace();
pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_LINE); pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL);
pipeline_creater->Set(PRIM_TRIANGLES); pipeline_creater->Set(PRIM_TRIANGLES);
pipeline_line=pipeline_creater->Create(); pipeline_line=pipeline_creater->Create();

View File

@ -82,6 +82,9 @@ private:
vulkan::Material * material =nullptr; vulkan::Material * material =nullptr;
vulkan::MaterialInstance * material_instance =nullptr; vulkan::MaterialInstance * material_instance =nullptr;
vulkan::Material * pbr_material =nullptr;
vulkan::MaterialInstance * pbr_material_instance =nullptr;
vulkan::Pipeline * pipeline_wireframe =nullptr; vulkan::Pipeline * pipeline_wireframe =nullptr;
vulkan::Pipeline * pipeline_lines =nullptr; vulkan::Pipeline * pipeline_lines =nullptr;
@ -100,10 +103,15 @@ private:
private: private:
bool InitPBRMaterial()
{
}
bool InitMaterial() bool InitMaterial()
{ {
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition3D.vert.spv"), material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition3D.vert"),
OS_TEXT("res/shader/FlatColor.frag.spv")); OS_TEXT("res/shader/FlatColor.frag"));
if(!material) if(!material)
return(false); return(false);

2
res

@ -1 +1 @@
Subproject commit 23685cd868ff941da4f0974035c8f4aa23594e03 Subproject commit 69343b3bc6fb464f89ec22eca52c379dec58ac68