From b369a3ec4877ad9db19d68152b26ee10d9990f56 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 28 Feb 2022 17:31:12 +0800 Subject: [PATCH] improved SkyColor example. --- example/Vulkan/SkyColor.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/example/Vulkan/SkyColor.cpp b/example/Vulkan/SkyColor.cpp index 7a2631a4..3648e3aa 100644 --- a/example/Vulkan/SkyColor.cpp +++ b/example/Vulkan/SkyColor.cpp @@ -13,7 +13,7 @@ constexpr uint32_t SCREEN_HEIGHT=720; class TestApp:public CameraAppFramework { - Color4f color; + Color3f color; GPUBuffer *ubo_color=nullptr; @@ -26,6 +26,8 @@ private: MaterialInstance * material_instance =nullptr; Pipeline * pipeline =nullptr; + GPUBuffer * ubo_sky_color =nullptr; + Renderable * ro_skyphere =nullptr; private: @@ -44,6 +46,34 @@ private: return(true); } + + bool InitUBO() + { + color.Set( + //.1, .3, .6 //blue + //.18,.19,.224 //overcast + //.1, .15,.4 //dusk + .03,.2, .9 //tropical blue + //.4, .06,.01 //orange-red + //.1, .2, .01 //green + ); + + ubo_sky_color=db->CreateUBO(sizeof(Color3f),&color); + + if(!ubo_sky_color) + return(false); + + { + MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value); + + if(!mp)return(false); + + if(!mp->BindUBO("sky_color",ubo_sky_color)) + return(false); + + mp->Update(); + } + } RenderableInstance *Add(Renderable *r,const Matrix4f &mat) { @@ -92,6 +122,9 @@ public: if(!InitMDP()) return(false); + if(!InitUBO()) + return(false); + CreateRenderObject(); if(!InitScene())