Skip to content

Commit ffa3150

Browse files
committed
feat: move quad to tri for full screen passes
1 parent 1c023e0 commit ffa3150

File tree

12 files changed

+30
-149
lines changed

12 files changed

+30
-149
lines changed

editor/app.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ pl_app_shutdown(plAppData* ptAppData)
482482
// PL_ASSERT(gptPak->add_from_disk(ptPak, "filter_environment.comp.spv", "../out-temp/filter_environment.comp.spv",false));
483483
// PL_ASSERT(gptPak->add_from_disk(ptPak, "forward.frag.spv", "../out-temp/forward.frag.spv",false));
484484
// PL_ASSERT(gptPak->add_from_disk(ptPak, "forward.vert.spv", "../out-temp/forward.vert.spv",false));
485-
// PL_ASSERT(gptPak->add_from_disk(ptPak, "full_quad.vert.spv", "../out-temp/full_quad.vert.spv",false));
485+
// PL_ASSERT(gptPak->add_from_disk(ptPak, "full_screen.vert.spv", "../out-temp/full_screen.vert.spv",false));
486486
// PL_ASSERT(gptPak->add_from_disk(ptPak, "gbuffer_fill.frag.spv", "../out-temp/gbuffer_fill.frag.spv",false));
487487
// PL_ASSERT(gptPak->add_from_disk(ptPak, "gbuffer_fill.vert.spv", "../out-temp/gbuffer_fill.vert.spv",false));
488488
// PL_ASSERT(gptPak->add_from_disk(ptPak, "jumpfloodalgo.comp.spv", "../out-temp/jumpfloodalgo.comp.spv",false));

extensions/pl_renderer_ext.c

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -585,28 +585,6 @@ pl_renderer_initialize(plRendererSettings tSettings)
585585

586586
pl_temp_allocator_reset(&gptData->tTempAllocator);
587587

588-
// create full quad
589-
const uint32_t auFullQuadIndexBuffer[] = {0, 1, 2, 0, 2, 3};
590-
const plBufferDesc tFullQuadIndexBufferDesc = {
591-
.tUsage = PL_BUFFER_USAGE_INDEX,
592-
.szByteSize = sizeof(uint32_t) * 6,
593-
.pcDebugName = "Renderer Quad Index Buffer"
594-
};
595-
gptData->tFullQuadIndexBuffer = pl__renderer_create_local_buffer(&tFullQuadIndexBufferDesc, "full quad index buffer", 0, auFullQuadIndexBuffer, tFullQuadIndexBufferDesc.szByteSize);
596-
597-
const float afFullQuadVertexBuffer[] = {
598-
-1.0f, -1.0f, 0.0f, 0.0f,
599-
-1.0f, 1.0f, 0.0f, 1.0f,
600-
1.0f, 1.0f, 1.0f, 1.0f,
601-
1.0f, -1.0f, 1.0f, 0.0f
602-
};
603-
const plBufferDesc tFullQuadVertexBufferDesc = {
604-
.tUsage = PL_BUFFER_USAGE_VERTEX,
605-
.szByteSize = sizeof(float) * 16,
606-
.pcDebugName = "Renderer Quad Vertex Buffer"
607-
};
608-
gptData->tFullQuadVertexBuffer = pl__renderer_create_local_buffer(&tFullQuadVertexBufferDesc, "full quad vertex buffer", 0, afFullQuadVertexBuffer, tFullQuadVertexBufferDesc.szByteSize);
609-
610588
// create semaphores
611589
gptData->ptClickSemaphore = gptGfx->create_semaphore(gptData->ptDevice, false);
612590
};
@@ -2710,10 +2688,6 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
27102688
.auDynamicBuffers = {
27112689
tLightingDynamicData.uBufferHandle
27122690
},
2713-
.atVertexBuffers = {
2714-
gptData->tFullQuadVertexBuffer
2715-
},
2716-
.tIndexBuffer = gptData->tFullQuadIndexBuffer,
27172691
.uIndexOffset = 0,
27182692
.uTriangleCount = 2,
27192693
.atBindGroups = {
@@ -2951,15 +2925,13 @@ pl_renderer_render_view(plView* ptView, plCamera* ptCamera, plCamera* ptCullCame
29512925
// submit nonindexed draw using basic API
29522926
plShaderHandle tUVShader = gptShaderVariant->get_shader("uvmap", NULL, NULL, NULL, &gptData->tUVRenderPassLayout);
29532927
gptGfx->bind_shader(ptUVEncoder, tUVShader);
2954-
gptGfx->bind_vertex_buffer(ptUVEncoder, gptData->tFullQuadVertexBuffer);
29552928

2956-
plDrawIndex tDraw = {
2957-
.tIndexBuffer = gptData->tFullQuadIndexBuffer,
2958-
.uIndexCount = 6,
2929+
plDraw tDraw = {
2930+
.uVertexCount = 3,
29592931
.uInstanceCount = 1,
29602932
};
29612933
*gptData->pdDrawCalls += 1.0;
2962-
gptGfx->draw_indexed(ptUVEncoder, 1, &tDraw);
2934+
gptGfx->draw(ptUVEncoder, 1, &tDraw);
29632935

29642936
// end render pass
29652937
gptGfx->end_render_pass(ptUVEncoder);

extensions/pl_renderer_internal.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,9 @@ pl__renderer_post_process_scene(plCommandBuffer* ptCommandBuffer, plView* ptView
19091909

19101910
plRenderEncoder* ptEncoder = gptGfx->begin_render_pass(ptCommandBuffer, ptView->tPostProcessRenderPass, NULL);
19111911

1912-
plDrawIndex tDraw = {
1913-
.tIndexBuffer = gptData->tFullQuadIndexBuffer,
1914-
.uIndexCount = 6,
1912+
plDraw tDraw = {
19151913
.uInstanceCount = 1,
1914+
.uVertexCount = 3
19161915
};
19171916

19181917
// create bind groups
@@ -1960,11 +1959,10 @@ pl__renderer_post_process_scene(plCommandBuffer* ptCommandBuffer, plView* ptView
19601959

19611960
plShaderHandle tTonemapShader = gptShaderVariant->get_shader("jumpfloodalgo2", NULL, NULL, NULL, &gptData->tPostProcessRenderPassLayout);
19621961
gptGfx->bind_shader(ptEncoder, tTonemapShader);
1963-
gptGfx->bind_vertex_buffer(ptEncoder, gptData->tFullQuadVertexBuffer);
19641962
plBindGroupHandle atBindGroups[] = {ptScene->atBindGroups[uFrameIdx], tJFABindGroup0};
19651963
gptGfx->bind_graphics_bind_groups(ptEncoder, tTonemapShader, 0, 2, atBindGroups, 1, &tDynamicBinding);
19661964
*gptData->pdDrawCalls += 1.0;
1967-
gptGfx->draw_indexed(ptEncoder, 1, &tDraw);
1965+
gptGfx->draw(ptEncoder, 1, &tDraw);
19681966

19691967
gptDrawBackend->submit_3d_drawlist(ptView->pt3DGizmoDrawList, ptEncoder, tDimensions.x, tDimensions.y, ptMVP, PL_DRAW_FLAG_REVERSE_Z_DEPTH | PL_DRAW_FLAG_DEPTH_TEST | PL_DRAW_FLAG_DEPTH_WRITE, 1);
19701968

@@ -3005,12 +3003,8 @@ pl__renderer_update_probes(plScene* ptScene)
30053003
.auDynamicBuffers = {
30063004
tLightingDynamicData.uBufferHandle
30073005
},
3008-
.atVertexBuffers = {
3009-
gptData->tFullQuadVertexBuffer
3010-
},
3011-
.tIndexBuffer = gptData->tFullQuadIndexBuffer,
3012-
.uIndexOffset = 0,
3013-
.uTriangleCount = 2,
3006+
.uIndexOffset = 0,
3007+
.uTriangleCount = 2,
30143008
.atBindGroups = {
30153009
ptScene->atBindGroups[uFrameIdx],
30163010
tViewBG,

extensions/pl_renderer_internal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ typedef struct _plRefRendererData
452452
plBindGroupPool* ptBindGroupPool;
453453
plBindGroupPool* aptTempGroupPools[PL_MAX_FRAMES_IN_FLIGHT];
454454

455-
// full quad
456-
plBufferHandle tFullQuadVertexBuffer;
457-
plBufferHandle tFullQuadIndexBuffer;
458-
459455
// main renderpass layout (used as a template for views)
460456
plRenderPassLayoutHandle tRenderPassLayout;
461457
plRenderPassLayoutHandle tPostProcessRenderPassLayout;

shaders/deferred_lighting.frag

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
4141

4242
layout(location = 0) out vec4 outColor;
4343

44-
// output
45-
layout(location = 0) in struct plShaderIn {
46-
vec2 tUV;
47-
} tShaderIn;
44+
layout(location = 0) in vec2 tUV;
4845

4946
#include "lighting.glsl"
5047
#include "material_info.glsl"

shaders/deferred_lighting.vert

Lines changed: 0 additions & 26 deletions
This file was deleted.

shaders/full_quad.vert

Lines changed: 0 additions & 17 deletions
This file was deleted.

shaders/full_screen.vert

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#version 450
2+
#extension GL_ARB_separate_shader_objects : enable
3+
4+
layout(location = 0) out vec2 tUV;
5+
6+
void main()
7+
{
8+
tUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
9+
gl_Position = vec4(tUV * 2.0 - 1.0, 0.0, 1.0);
10+
}

shaders/jumpfloodalgo.frag

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ layout(set = 3, binding = 0) uniform PL_DYNAMIC_DATA
2424
// [SECTION] input
2525
//-----------------------------------------------------------------------------
2626

27-
layout(location = 0) in struct plShaderOut {
28-
vec2 tUV;
29-
} tShaderIn;
27+
layout(location = 0) in vec2 tUV;
3028

3129
//-----------------------------------------------------------------------------
3230
// [SECTION] output
@@ -42,13 +40,13 @@ void
4240
main()
4341
{
4442

45-
vec4 color = texture(sampler2D(tColorTexture, tSamplerLinearRepeat), tShaderIn.tUV);
46-
vec2 closestSeed = texture(sampler2D(tMaskTexture, tSamplerLinearRepeat), tShaderIn.tUV).xy;
47-
vec2 h = closestSeed - tShaderIn.tUV;
43+
vec4 color = texture(sampler2D(tColorTexture, tSamplerLinearRepeat), tUV);
44+
vec2 closestSeed = texture(sampler2D(tMaskTexture, tSamplerLinearRepeat), tUV).xy;
45+
vec2 h = closestSeed - tUV;
4846
float xdist = h.x * float(textureSize(sampler2D(tColorTexture, tSamplerLinearRepeat),0).x);
4947
float ydist = h.y * float(textureSize(sampler2D(tColorTexture, tSamplerLinearRepeat),0).y);
5048
float tdist2 = xdist * xdist + ydist * ydist;
51-
float dist = distance(closestSeed, tShaderIn.tUV);
49+
float dist = distance(closestSeed, tUV);
5250
if (closestSeed.x > 0 && closestSeed.y > 0 && dist > 0.0001 && tdist2 < tObjectInfo.tData.fTargetWidth * tObjectInfo.tData.fTargetWidth)
5351
{
5452
color = tObjectInfo.tData.tOutlineColor;

shaders/shaders.pls

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"graphics shaders": [
166166
{
167167
"pcName": "jumpfloodalgo2",
168-
"tVertexShader": { "file": "full_quad.vert"},
168+
"tVertexShader": { "file": "full_screen.vert"},
169169
"tFragmentShader": { "file": "jumpfloodalgo.frag"},
170170
"tGraphicsState": {
171171
"ulDepthWriteEnabled": false,
@@ -181,14 +181,6 @@
181181
"ulStencilOpDepthFail": "PL_STENCIL_OP_KEEP",
182182
"ulStencilOpPass": "PL_STENCIL_OP_KEEP"
183183
},
184-
"atVertexBufferLayouts": [
185-
{
186-
"atAttributes": [
187-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" },
188-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" }
189-
]
190-
}
191-
],
192184
"uSubpassIndex": 0,
193185
"atBlendStates": [
194186
{ "bBlendEnabled": false }
@@ -324,7 +316,7 @@
324316
},
325317
{
326318
"pcName": "uvmap",
327-
"tVertexShader": { "file": "uvmap.vert"},
319+
"tVertexShader": { "file": "full_screen.vert"},
328320
"tFragmentShader": { "file": "uvmap.frag"},
329321
"tGraphicsState": {
330322
"ulDepthWriteEnabled": false,
@@ -340,14 +332,6 @@
340332
"ulStencilOpDepthFail": "PL_STENCIL_OP_KEEP",
341333
"ulStencilOpPass": "PL_STENCIL_OP_KEEP"
342334
},
343-
"atVertexBufferLayouts": [
344-
{
345-
"atAttributes": [
346-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" },
347-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" }
348-
]
349-
}
350-
],
351335
"atBlendStates": [
352336
{ "bBlendEnabled": false }
353337
]
@@ -488,7 +472,7 @@
488472
},
489473
{
490474
"pcName": "deferred_lighting",
491-
"tVertexShader": { "file": "deferred_lighting.vert"},
475+
"tVertexShader": { "file": "full_screen.vert"},
492476
"tFragmentShader": { "file": "deferred_lighting.frag"},
493477
"tGraphicsState": {
494478
"ulDepthWriteEnabled": false,
@@ -505,14 +489,6 @@
505489
"ulStencilOpPass": "PL_STENCIL_OP_KEEP"
506490
},
507491
"uSubpassIndex": 1,
508-
"atVertexBufferLayouts": [
509-
{
510-
"atAttributes": [
511-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" },
512-
{ "tFormat": "PL_VERTEX_FORMAT_FLOAT2" }
513-
]
514-
}
515-
],
516492
"atBlendStates": [
517493
{ "bBlendEnabled": false }
518494
],

0 commit comments

Comments
 (0)