定义通用UBO属性
This commit is contained in:
parent
2ab09c6367
commit
962ed65fee
@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/graph/vulkan/VK.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
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<const SceneNode *> 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
|
||||
|
@ -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;i<count;i++)
|
||||
{
|
||||
const Matrix4f fin_mv=modelview_matrix*(*node)->GetLocalToWorldMatrix();
|
||||
const Matrix4f fin_mv=ubo_matrix.modelview*(*node)->GetLocalToWorldMatrix();
|
||||
|
||||
int sn=(*node)->RenderableList.GetCount();
|
||||
RenderableInstance **p=(*node)->RenderableList.GetData();
|
||||
|
||||
for(int j=0;j<sn;j++)
|
||||
{
|
||||
Render(*p,projection_matrix*fin_mv);
|
||||
Render(*p,ubo_matrix.projection*fin_mv);
|
||||
|
||||
p++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user