fixed Atomsphere sample.

This commit is contained in:
hyzboy 2021-09-27 10:44:35 +08:00
parent 6b6866db97
commit 689c3a7ce6
4 changed files with 32 additions and 20 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 089d4992016b39cefc399723ea162bd4de7bd310 Subproject commit eae6976f86d01b462bc12e723b902fd169382083

@ -1 +1 @@
Subproject commit 8fd61af485ae69e4a8d445992002d0a5ec6dd61e Subproject commit dfcc07773caec8b971039cf64ea6650ce868bfe6

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=512;
constexpr uint32_t SCREEN_HEIGHT=128; constexpr uint32_t SCREEN_HEIGHT=512;
struct AtmosphereData struct AtmosphereData
{ {
@ -24,7 +24,7 @@ public:
AtmosphereData() AtmosphereData()
{ {
position.Set(0,0.1f,-1.0f); position=Vector3f(0,0.1f,-1.0f);
intensity=22.0f; intensity=22.0f;
scattering_direction=0.758f; scattering_direction=0.758f;
} }
@ -34,10 +34,10 @@ class TestApp:public CameraAppFramework
{ {
private: private:
SceneNode render_root; SceneNode render_root;
RenderList render_list; RenderList * render_list=nullptr;
MaterialParameters * material_instance =nullptr; MaterialInstance * material_instance =nullptr;
Pipeline * pipeline_solid =nullptr; Pipeline * pipeline_solid =nullptr;
GPUBuffer * ubo_atomsphere =nullptr; GPUBuffer * ubo_atomsphere =nullptr;
@ -53,7 +53,7 @@ private:
if(!material_instance)return(false); if(!material_instance)return(false);
// pipeline_solid=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/sky")); // pipeline_solid=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/sky"));
pipeline_solid=CreatePipeline(material_instance,InlinePipeline::Sky); //等同上一行为Framework重载默认使用swapchain的render target pipeline_solid=CreatePipeline(material_instance,InlinePipeline::Sky,Prim::Triangles); //等同上一行为Framework重载默认使用swapchain的render target
if(!pipeline_solid)return(false); if(!pipeline_solid)return(false);
return(true); return(true);
@ -61,18 +61,24 @@ private:
bool InitUBO() bool InitUBO()
{ {
if(!material_instance->BindUBO("camera",GetCameraInfoBuffer())) // if(!material_instance->BindUBO("g_camera",GetCameraInfoBuffer()))
return(false); // return(false);
ubo_atomsphere=db->CreateUBO(sizeof(AtmosphereData),&atomsphere_data); ubo_atomsphere=db->CreateUBO(sizeof(AtmosphereData),&atomsphere_data);
if(!ubo_atomsphere) if(!ubo_atomsphere)
return(false); return(false);
if(!material_instance->BindUBO("sun",ubo_atomsphere)) {
return(false); MaterialParameters *mp=material_instance->GetMP(DescriptorSetType::Value);
material_instance->Update(); if(!mp)return(false);
if(!mp->BindUBO("sun",ubo_atomsphere))
return(false);
mp->Update();
}
return(true); return(true);
} }
@ -80,21 +86,28 @@ private:
{ {
ro_sphere=CreateRenderableSphere(db,material_instance->GetMaterial(),128); ro_sphere=CreateRenderableSphere(db,material_instance->GetMaterial(),128);
render_root.Add(db->CreateRenderableInstance(ro_sphere,material_instance,pipeline_solid),scale(100)); render_root.CreateSubNode(scale(100),db->CreateRenderableInstance(ro_sphere,material_instance,pipeline_solid));
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_root.ExpendToList(&render_list); render_list->Expend(GetCameraInfo(),&render_root);
return(true); return(true);
} }
public: public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init() bool Init()
{ {
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT)) if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false); return(false);
render_list=new RenderList(device);
if(!InitMaterial()) if(!InitMaterial())
return(false); return(false);
@ -110,10 +123,9 @@ public:
void BuildCommandBuffer(uint32_t index) override void BuildCommandBuffer(uint32_t index) override
{ {
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_list.Clear(); render_list->Expend(GetCameraInfo(),&render_root);
render_root.ExpendToList(&render_list);
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list); VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
} }
};//class TestApp:public CameraAppFramework };//class TestApp:public CameraAppFramework

2
res

@ -1 +1 @@
Subproject commit 3a693b3ec35b61a7830f6a20b3d7f25e60f91843 Subproject commit ef811956f435a9f694abd43f108f3455c4467506