world matrix增加viewport size
This commit is contained in:
parent
7e3b14ce17
commit
0c20f52eb8
@ -46,8 +46,7 @@ private:
|
||||
|
||||
struct DeferredGBuffer
|
||||
{
|
||||
vulkan::Semaphore *present_complete_semaphore =nullptr,
|
||||
*render_complete_semaphore =nullptr;
|
||||
vulkan::Semaphore *render_complete_semaphore =nullptr;
|
||||
|
||||
vulkan::RenderTarget *rt;
|
||||
|
||||
@ -157,7 +156,6 @@ private:
|
||||
gbuffer.extent.width =512;
|
||||
gbuffer.extent.height =512;
|
||||
|
||||
gbuffer.present_complete_semaphore =device->CreateSem();
|
||||
gbuffer.render_complete_semaphore =device->CreateSem();
|
||||
|
||||
//根据候选格式表选择格式
|
||||
@ -417,8 +415,6 @@ private:
|
||||
|
||||
gbuffer_cmd->EndRenderPass();
|
||||
gbuffer_cmd->End();
|
||||
|
||||
gbuffer.rt->Submit(*gbuffer_cmd,gbuffer.present_complete_semaphore,gbuffer.render_complete_semaphore);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -445,11 +441,13 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual void SubmitDraw(int index)
|
||||
{
|
||||
virtual void SubmitDraw(int index) override
|
||||
{
|
||||
gbuffer.rt->Submit(*gbuffer_cmd,present_complete_semaphore,gbuffer.render_complete_semaphore);
|
||||
|
||||
VkCommandBuffer cb=*cmd_buf[index];
|
||||
|
||||
sc_render_target->Submit(cb,present_complete_semaphore,render_complete_semaphore);
|
||||
sc_render_target->Submit(cb,gbuffer.render_complete_semaphore,render_complete_semaphore);
|
||||
sc_render_target->PresentBackbuffer(render_complete_semaphore);
|
||||
sc_render_target->Wait();
|
||||
}
|
||||
|
@ -10,19 +10,14 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH=128;
|
||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||
|
||||
struct WorldConfig
|
||||
{
|
||||
Matrix4f mvp;
|
||||
}world;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=4;
|
||||
|
||||
constexpr float vertex_data[VERTEX_COUNT][2]=
|
||||
{
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.25},
|
||||
{SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.75},
|
||||
{SCREEN_WIDTH*0.75, SCREEN_HEIGHT*0.75}
|
||||
{SCREEN_WIDTH*0, SCREEN_HEIGHT*0},
|
||||
{SCREEN_WIDTH*1, SCREEN_HEIGHT*0},
|
||||
{SCREEN_WIDTH*0, SCREEN_HEIGHT*1},
|
||||
{SCREEN_WIDTH*1, SCREEN_HEIGHT*1}
|
||||
};
|
||||
|
||||
constexpr uint32_t INDEX_COUNT=6;
|
||||
@ -37,6 +32,8 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
WorldMatrix wm;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
@ -65,7 +62,7 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
material=shader_manage->CreateMaterial(OS_TEXT("res/shader/OnlyPosition.vert.spv"),
|
||||
OS_TEXT("res/shader/FlatColor.frag.spv"));
|
||||
OS_TEXT("res/shader/glFragCoord.frag.spv"));
|
||||
if(!material)
|
||||
return(false);
|
||||
|
||||
@ -78,9 +75,12 @@ private:
|
||||
{
|
||||
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||
|
||||
world.mvp=ortho(extent.width,extent.height);
|
||||
wm.vp_size.x=extent.width;
|
||||
wm.vp_size.y=extent.height;
|
||||
|
||||
ubo_mvp=device->CreateUBO(sizeof(WorldConfig),&world);
|
||||
wm.ortho=ortho(extent.width,extent.height);
|
||||
|
||||
ubo_mvp=device->CreateUBO(sizeof(WorldMatrix),&wm);
|
||||
|
||||
if(!ubo_mvp)
|
||||
return(false);
|
||||
|
@ -14,11 +14,6 @@ bool LoadFromFile(const OSString &filename,VK_NAMESPACE::PipelineCreater *pc);
|
||||
constexpr uint32_t SCREEN_WIDTH=128;
|
||||
constexpr uint32_t SCREEN_HEIGHT=128;
|
||||
|
||||
struct WorldConfig
|
||||
{
|
||||
Matrix4f mvp;
|
||||
}world;
|
||||
|
||||
constexpr uint32_t VERTEX_COUNT=3;
|
||||
|
||||
constexpr float vertex_data[VERTEX_COUNT][2]=
|
||||
@ -38,6 +33,8 @@ class TestApp:public VulkanApplicationFramework
|
||||
{
|
||||
private:
|
||||
|
||||
WorldMatrix wm;
|
||||
|
||||
vulkan::Material * material =nullptr;
|
||||
vulkan::DescriptorSets * descriptor_sets =nullptr;
|
||||
vulkan::Renderable * render_obj =nullptr;
|
||||
@ -79,9 +76,12 @@ private:
|
||||
{
|
||||
const VkExtent2D extent=sc_render_target->GetExtent();
|
||||
|
||||
world.mvp=ortho(extent.width,extent.height);
|
||||
wm.vp_size.x=extent.width;
|
||||
wm.vp_size.y=extent.height;
|
||||
|
||||
ubo_mvp=device->CreateUBO(sizeof(WorldConfig),&world);
|
||||
wm.ortho=ortho(extent.width,extent.height);
|
||||
|
||||
ubo_mvp=device->CreateUBO(sizeof(WorldMatrix),&wm);
|
||||
|
||||
if(!ubo_mvp)
|
||||
return(false);
|
||||
@ -92,7 +92,7 @@ private:
|
||||
descriptor_sets->Update();
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
void InitVBO()
|
||||
{
|
||||
vertex_buffer =device->CreateVBO(FMT_RG32F, VERTEX_COUNT,vertex_data);
|
||||
@ -150,8 +150,14 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(int,int)override
|
||||
void Resize(int w,int h)override
|
||||
{
|
||||
wm.vp_size.x=w;
|
||||
wm.vp_size.y=h;
|
||||
wm.ortho=ortho(w,h);
|
||||
|
||||
ubo_mvp->Write(&wm);
|
||||
|
||||
BuildCommandBuffer(pipeline,descriptor_sets,render_obj);
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
|
@ -13,7 +13,9 @@ namespace hgl
|
||||
|
||||
struct WorldMatrix
|
||||
{
|
||||
alignas(16) Matrix4f two_dim; //2D矩阵
|
||||
alignas(8) Vector2f vp_size; //viewport尺寸
|
||||
|
||||
alignas(16) Matrix4f ortho; //2D正角视图矩阵
|
||||
|
||||
alignas(16) Matrix4f projection;
|
||||
// alignas(16) Matrix4f inverse_projection;
|
||||
|
@ -3,9 +3,14 @@
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
layout(location = 1) in vec3 Color;
|
||||
|
||||
layout(binding = 0) uniform WorldConfig
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
vec2 vp_size;
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout(location = 0) out vec4 FragmentColor;
|
||||
@ -14,5 +19,5 @@ void main()
|
||||
{
|
||||
FragmentColor=vec4(Color,1.0);
|
||||
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.mvp;
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.ortho;
|
||||
}
|
||||
|
@ -2,9 +2,14 @@
|
||||
|
||||
layout(location = 0) in vec2 Vertex;
|
||||
|
||||
layout(binding = 0) uniform WorldConfig
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
vec2 vp_size;
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout(location = 0) out vec4 FragmentColor;
|
||||
@ -13,5 +18,5 @@ void main()
|
||||
{
|
||||
FragmentColor=vec4(1.0);
|
||||
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.mvp;
|
||||
gl_Position=vec4(Vertex,0.0,1.0)*world.ortho;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ layout(location = 1) in vec4 Color;
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
mat4 two_dim;
|
||||
vec2 vp_size;
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
|
18
res/shader/glFragCoord.frag
Normal file
18
res/shader/glFragCoord.frag
Normal file
@ -0,0 +1,18 @@
|
||||
#version 450
|
||||
|
||||
layout(binding = 0) uniform WorldMatrix
|
||||
{
|
||||
vec2 vp_size;
|
||||
mat4 ortho;
|
||||
mat4 projection;
|
||||
mat4 modelview;
|
||||
mat4 mvp;
|
||||
vec4 view_pos;
|
||||
} world;
|
||||
|
||||
layout (location = 0) out vec4 outFragcolor;
|
||||
|
||||
void main()
|
||||
{
|
||||
outFragcolor = vec4(gl_FragCoord.rg/world.vp_size,0.0,1.0);
|
||||
}
|
@ -17,3 +17,5 @@ glslangValidator -V -o Atomsphere.frag.spv Atomsphere.frag
|
||||
|
||||
glslangValidator -V -o gbuffer_opaque.vert.spv gbuffer_opaque.vert
|
||||
glslangValidator -V -o gbuffer_opaque.frag.spv gbuffer_opaque.frag
|
||||
|
||||
glslangValidator -V -o glFragCoord.frag.spv glFragCoord.frag
|
@ -28,6 +28,9 @@ namespace hgl
|
||||
|
||||
void Camera::Refresh()
|
||||
{
|
||||
matrix.vp_size.x=width;
|
||||
matrix.vp_size.y=height;
|
||||
|
||||
if(type==CameraType::Perspective)
|
||||
matrix.projection=perspective(fov,width/height,znear,zfar);
|
||||
else
|
||||
@ -43,7 +46,7 @@ namespace hgl
|
||||
//注意: C++中要 projection * model_view * local_to_world * position
|
||||
//而GLSL中要 position * local_to_world * model_view * projection
|
||||
|
||||
matrix.two_dim=ortho(width,height,znear,zfar);
|
||||
matrix.ortho=ortho(width,height,znear,zfar);
|
||||
|
||||
matrix.view_pos=eye;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user