added SkyColor example.

This commit is contained in:
2022-02-28 16:55:22 +08:00
parent 50c201de98
commit 82763c450e
2 changed files with 131 additions and 1 deletions

View File

@@ -32,9 +32,10 @@ CreateProject(05.texture_rect texture_rect.cpp)
#CreateProject(05.HQFilterTexture HQFilterTexture.cpp)
#CreateProject(06.Geometry2D Geometry2D.cpp)
CreateProject(06.Geometry3D Geometry3D.cpp)
#CreateProject(08.SceneTree SceneTree.cpp)
CreateProject(08.SceneTree SceneTree.cpp)
#CreateProject(09.LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
CreateProject(10.InlineGeometryScene InlineGeometryScene.cpp)
CreateProject(11.SkyColor SkyColor.cpp)
CreateProject(11.Atmosphere Atmosphere.cpp)
CreateProject(12.RectanglePrimitive RectanglePrimitive.cpp)

129
example/Vulkan/SkyColor.cpp Normal file
View File

@@ -0,0 +1,129 @@
#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>
using namespace hgl;
using namespace hgl::graph;
constexpr uint32_t SCREEN_WIDTH=1280;
constexpr uint32_t SCREEN_HEIGHT=720;
class TestApp:public CameraAppFramework
{
Color4f color;
GPUBuffer *ubo_color=nullptr;
private:
SceneNode render_root;
RenderList *render_list=nullptr;
Material * material =nullptr;
MaterialInstance * material_instance =nullptr;
Pipeline * pipeline =nullptr;
Renderable * ro_skyphere =nullptr;
private:
bool InitMDP()
{
material=db->CreateMaterial(OS_TEXT("res/material/SkyColor"));
if(!material)return(false);
material_instance=db->CreateMaterialInstance(material);
if(!material_instance)return(false);
pipeline=CreatePipeline(material_instance,InlinePipeline::Sky,Prim::Triangles);
if(!pipeline)
return(false);
return(true);
}
RenderableInstance *Add(Renderable *r,const Matrix4f &mat)
{
RenderableInstance *ri=db->CreateRenderableInstance(r,material_instance,pipeline);
render_root.CreateSubNode(mat,ri);
return ri;
}
void CreateRenderObject()
{
const VAB *vab=material_instance->GetVAB();
ro_skyphere=CreateRenderableDome(db,vab,32);
}
bool InitScene()
{
camera->pos=Vector3f(0,0,0);
camera_control->SetTarget(Vector3f(200,200,200));
camera_control->Refresh();
Add(ro_skyphere,scale(200));
render_root.RefreshMatrix();
render_list->Expend(camera->info,&render_root);
return(true);
}
public:
~TestApp()
{
SAFE_CLEAR(render_list);
}
bool Init()
{
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
render_list=new RenderList(device);
if(!InitMDP())
return(false);
CreateRenderObject();
if(!InitScene())
return(false);
return(true);
}
void BuildCommandBuffer(uint32 index)
{
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
}
void Resize(int w,int h)override
{
CameraAppFramework::Resize(w,h);
VulkanApplicationFramework::BuildCommandBuffer(render_list);
}
};//class TestApp:public CameraAppFramework
int main(int,char **)
{
TestApp app;
if(!app.Init())
return(-1);
while(app.Run());
return 0;
}