updated examples.
This commit is contained in:
parent
bcd373fe6f
commit
edbecbb86d
@ -198,7 +198,7 @@ private:
|
|||||||
cam.width=extent.width;
|
cam.width=extent.width;
|
||||||
cam.height=extent.height;
|
cam.height=extent.height;
|
||||||
|
|
||||||
cam.Refresh();
|
cam.RefreshCameraInfo();
|
||||||
|
|
||||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
|
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ public:
|
|||||||
cam.width=w;
|
cam.width=w;
|
||||||
cam.height=h;
|
cam.height=h;
|
||||||
|
|
||||||
cam.Refresh();
|
cam.RefreshCameraInfo();
|
||||||
|
|
||||||
ubo_camera_info->Write(&cam.info);
|
ubo_camera_info->Write(&cam.info);
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ private:
|
|||||||
cam.width=extent.width;
|
cam.width=extent.width;
|
||||||
cam.height=extent.height;
|
cam.height=extent.height;
|
||||||
|
|
||||||
cam.Refresh();
|
cam.RefreshCameraInfo();
|
||||||
|
|
||||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
|
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public:
|
|||||||
cam.width=w;
|
cam.width=w;
|
||||||
cam.height=h;
|
cam.height=h;
|
||||||
|
|
||||||
cam.Refresh();
|
cam.RefreshCameraInfo();
|
||||||
|
|
||||||
ubo_camera_info->Write(&cam.info);
|
ubo_camera_info->Write(&cam.info);
|
||||||
|
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
// 5.SceneTree
|
// SceneTree
|
||||||
// 用于测试树形排列的场景中,每一级节点对变换矩阵的处理是否正确
|
// 用于测试树形排列的场景中,每一级节点对变换矩阵的处理是否正确,以及Instance绘制
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/InlineGeometry.h>
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
#include<hgl/graph/vulkan/VKDatabase.h>
|
|
||||||
#include<hgl/graph/RenderableInstance.h>
|
|
||||||
#include<hgl/graph/RenderList.h>
|
#include<hgl/graph/RenderList.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
|
|
||||||
@ -19,8 +17,8 @@ class TestApp:public CameraAppFramework
|
|||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
Vector4f color;
|
Color4f color;
|
||||||
Vector4f abiment;
|
Color4f abiment;
|
||||||
}color_material;
|
}color_material;
|
||||||
|
|
||||||
Vector3f sun_direction;
|
Vector3f sun_direction;
|
||||||
@ -32,15 +30,15 @@ private:
|
|||||||
SceneNode render_root;
|
SceneNode render_root;
|
||||||
RenderList render_list;
|
RenderList render_list;
|
||||||
|
|
||||||
vulkan::Material * material =nullptr;
|
Material * material =nullptr;
|
||||||
vulkan::MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
|
|
||||||
vulkan::Buffer * ubo_color =nullptr;
|
GPUBuffer * ubo_color =nullptr;
|
||||||
vulkan::Buffer * ubo_sun =nullptr;
|
GPUBuffer * ubo_sun =nullptr;
|
||||||
|
|
||||||
vulkan::Renderable * renderable_object =nullptr;
|
Renderable * renderable_object =nullptr;
|
||||||
|
|
||||||
vulkan::Pipeline * pipeline_line =nullptr;
|
Pipeline * pipeline =nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -55,35 +53,33 @@ private:
|
|||||||
|
|
||||||
bool InitMaterial()
|
bool InitMaterial()
|
||||||
{
|
{
|
||||||
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/VertexLight.vert"),
|
material=db->CreateMaterial(OS_TEXT("res/shader/VertexLight.vert"),
|
||||||
OS_TEXT("res/shader/VertexColor.frag"));
|
OS_TEXT("res/shader/VertexColor.frag"));
|
||||||
if(!material)
|
if(!material)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
material_instance=material->CreateInstance();
|
material_instance=db->CreateMaterialInstance(material);
|
||||||
|
|
||||||
db->Add(material);
|
|
||||||
db->Add(material_instance);
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateRenderObject()
|
void CreateRenderObject()
|
||||||
{
|
{
|
||||||
renderable_object=CreateRenderableSphere(db,material,40);
|
renderable_object=CreateRenderableSphere(db,material_instance->GetVAB(),40);
|
||||||
|
|
||||||
db->Add(renderable_object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitUBO()
|
bool InitUBO()
|
||||||
{
|
{
|
||||||
LCG lcg;
|
color_material.color.Set(1,1,1,1);
|
||||||
|
|
||||||
color_material.color=Vector4f(1,1,1,1.0);
|
|
||||||
color_material.abiment.Set(0.25,0.25,0.25,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_color=device->CreateUBO(sizeof(color_material),&color_material);
|
||||||
|
if(!ubo_color)return(false);
|
||||||
|
|
||||||
|
sun_direction=normalized(Vector3f(rand(),rand(),rand()));
|
||||||
|
|
||||||
ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction);
|
ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction);
|
||||||
|
if(!ubo_sun)return(false);
|
||||||
|
|
||||||
material_instance->BindUBO("world",GetCameraMatrixBuffer());
|
material_instance->BindUBO("world",GetCameraMatrixBuffer());
|
||||||
material_instance->BindUBO("color_material",ubo_color);
|
material_instance->BindUBO("color_material",ubo_color);
|
||||||
@ -98,20 +94,9 @@ private:
|
|||||||
|
|
||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
AutoDelete<vulkan::PipelineCreater>
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Triangles);
|
||||||
pipeline_creater=new vulkan::PipelineCreater(device,material,sc_render_target);
|
|
||||||
pipeline_creater->SetDepthTest(true);
|
return pipeline;
|
||||||
pipeline_creater->SetDepthWrite(true);
|
|
||||||
pipeline_creater->CloseCullFace();
|
|
||||||
pipeline_creater->SetPolygonMode(VK_POLYGON_MODE_FILL);
|
|
||||||
pipeline_creater->Set(Prim::Triangles);
|
|
||||||
|
|
||||||
pipeline_line=pipeline_creater->Create();
|
|
||||||
if(!pipeline_line)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
db->Add(pipeline_line);
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitScene()
|
bool InitScene()
|
||||||
@ -121,20 +106,20 @@ private:
|
|||||||
uint count;
|
uint count;
|
||||||
float size;
|
float size;
|
||||||
|
|
||||||
RenderableInstance *ri=db->CreateRenderableInstance(pipeline_line,material_instance,renderable_object);
|
RenderableInstance *ri=db->CreateRenderableInstance(pipeline,material_instance,renderable_object);
|
||||||
|
|
||||||
for(uint i=0;i<360;i++)
|
for(uint i=0;i<360;i++)
|
||||||
{
|
{
|
||||||
size=(i+1)/100.0f;
|
size=(i+1)/100.0f;
|
||||||
|
|
||||||
cur_node=render_root.CreateSubNode( rotate(i/5.0f,camera.up_vector)*
|
cur_node=render_root.CreateSubNode( rotate(i/5.0f,camera->world_up)*
|
||||||
translate(i/4.0f,0,0)*
|
translate(i/4.0f,0,0)*
|
||||||
scale(size));
|
scale(size));
|
||||||
|
|
||||||
count=(rand()%16)+1;
|
count=(rand()%16)+1;
|
||||||
|
|
||||||
for(uint n=0;n<count;n++)
|
for(uint n=0;n<count;n++)
|
||||||
cur_node->Add(ri,translate(0,0,size*n*1.01));
|
cur_node->CreateSubNode(translate(0,0,size*n*1.01),ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
|
@ -98,7 +98,7 @@ private:
|
|||||||
{
|
{
|
||||||
const VAB *vab=material_instance->GetVAB();
|
const VAB *vab=material_instance->GetVAB();
|
||||||
|
|
||||||
ro_skyphere=CreateRenderableSphere(db,vab,1024);
|
ro_skyphere=CreateRenderableDome(db,vab,64);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitScene()
|
bool InitScene()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user