From 962ed65fee46d48f8bb1d0cb835d167c03c3f0ac Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 25 May 2019 01:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=80=9A=E7=94=A8UBO?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/graph/RenderList.h | 23 +++++++++++++++++------ src/SceneGraph/RenderList.cpp | 11 ++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/inc/hgl/graph/RenderList.h b/inc/hgl/graph/RenderList.h index 831840e1..93d02489 100644 --- a/inc/hgl/graph/RenderList.h +++ b/inc/hgl/graph/RenderList.h @@ -3,6 +3,7 @@ #include #include +#include namespace hgl { namespace graph @@ -14,25 +15,30 @@ namespace hgl Matrix4f projection; Matrix4f modelview; Matrix4f mvp; + Matrix3f normal; };// struct UBOSkyLight - { - Vector4f sky_color; + { + Color4f sun_color; + Vector3f alignas(16) sun_direction; };// class RenderList { vulkan::CommandBuffer *cmd_buf; + private: + Camera camera; - Matrix4f projection_matrix, - modelview_matrix, - mvp_matrix; - Frustum frustum; + private: + + UBOMatrixData ubo_matrix; + UBOSkyLight ubo_skylight; + private: List SceneNodeList; @@ -59,6 +65,11 @@ namespace hgl void Clear () {SceneNodeList.ClearData();} void SetCamera(const Camera &); + void SetSkyLightColor(const Color4f &c,const Vector3f &d) + { + ubo_skylight.sun_color=c; + ubo_skylight.sun_direction=d; + } bool Render(); };//class RenderList diff --git a/src/SceneGraph/RenderList.cpp b/src/SceneGraph/RenderList.cpp index ab493379..831e807e 100644 --- a/src/SceneGraph/RenderList.cpp +++ b/src/SceneGraph/RenderList.cpp @@ -32,11 +32,12 @@ namespace hgl { camera=cam; - MakeCameraMatrix( &projection_matrix, - &modelview_matrix, + MakeCameraMatrix( &ubo_matrix.projection, + &ubo_matrix.modelview, &camera); - mvp_matrix=projection_matrix*modelview_matrix; + ubo_matrix.mvp =ubo_matrix.projection*ubo_matrix.modelview; + ubo_matrix.normal =ubo_matrix.modelview.Float3x3Part(); //法线矩阵为3x3 CameraToFrustum(&frustum, &camera); @@ -99,14 +100,14 @@ namespace hgl for(int i=0;iGetLocalToWorldMatrix(); + const Matrix4f fin_mv=ubo_matrix.modelview*(*node)->GetLocalToWorldMatrix(); int sn=(*node)->RenderableList.GetCount(); RenderableInstance **p=(*node)->RenderableList.GetData(); for(int j=0;j