From efc3443c61cff472f473c972df253e6e5aba6aa4 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 27 Nov 2022 12:48:51 +0900 Subject: [PATCH] [vulkan] Create a water warp output pipeline Although it works as intended (tested via hacking), it's not hooked up as the current frame buffer handling in r_screen is not readily compatible with how vulkan output is handled. This will need some thought to get working. --- libs/video/renderer/Makemodule.am | 16 ++++++++-- libs/video/renderer/vulkan/pl_output.plist | 28 +++++++++++++++++ libs/video/renderer/vulkan/shader.c | 6 ++++ .../renderer/vulkan/shader/fstrianglest.vert | 12 +++++++ .../renderer/vulkan/shader/waterwarp.frag | 31 +++++++++++++++++++ 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 libs/video/renderer/vulkan/shader/fstrianglest.vert create mode 100644 libs/video/renderer/vulkan/shader/waterwarp.frag diff --git a/libs/video/renderer/Makemodule.am b/libs/video/renderer/Makemodule.am index 39716cfcc..03f698aa9 100644 --- a/libs/video/renderer/Makemodule.am +++ b/libs/video/renderer/Makemodule.am @@ -359,8 +359,12 @@ passthrough_src = $(vkshaderpath)/passthrough.vert passthrough_c = $(vkshaderpath)/passthrough.vert.spvc fstriangle_src = $(vkshaderpath)/fstriangle.vert fstriangle_c = $(vkshaderpath)/fstriangle.vert.spvc +fstrianglest_src = $(vkshaderpath)/fstrianglest.vert +fstrianglest_c = $(vkshaderpath)/fstrianglest.vert.spvc pushcolor_src = $(vkshaderpath)/pushcolor.frag pushcolor_c = $(vkshaderpath)/pushcolor.frag.spvc +waterwarp_src = $(vkshaderpath)/waterwarp.frag +waterwarp_c = $(vkshaderpath)/waterwarp.frag.spvc $(slice_vert_c): $(slice_vert_src) @@ -432,8 +436,12 @@ $(passthrough_c): $(passthrough_src) $(fstriangle_c): $(fstriangle_src) +$(fstrianglest_c): $(fstrianglest_src) + $(pushcolor_c): $(pushcolor_src) +$(waterwarp_c): $(waterwarp_src) + vkshader_c = \ $(slice_c) \ $(glyphv_c) \ @@ -473,8 +481,10 @@ vkshader_c = \ $(output_c) \ $(passthrough_c) \ $(fstriangle_c) \ + $(fstrianglest_c) \ $(pushcolor_c) \ - $(shadow_c) + $(shadow_c) \ + $(waterwarp_c) V_VKGEN = $(V_VKGEN_@AM_V@) V_VKGEN_ = $(V_VKGEN_@AM_DEFAULT_V@) @@ -532,6 +542,7 @@ EXTRA_DIST += \ libs/video/renderer/vulkan/shader/lighting.frag \ libs/video/renderer/vulkan/shader/passthrough.vert \ libs/video/renderer/vulkan/shader/fstriangle.vert \ + libs/video/renderer/vulkan/shader/fstrianglest.vert \ libs/video/renderer/vulkan/shader/partphysics.comp \ libs/video/renderer/vulkan/shader/partupdate.comp \ libs/video/renderer/vulkan/shader/particle.vert \ @@ -547,4 +558,5 @@ EXTRA_DIST += \ libs/video/renderer/vulkan/shader/sprite_gbuf.frag \ libs/video/renderer/vulkan/shader/twod_depth.frag \ libs/video/renderer/vulkan/shader/twod.frag \ - libs/video/renderer/vulkan/shader/twod.vert + libs/video/renderer/vulkan/shader/twod.vert \ + libs/video/renderer/vulkan/shader/waterwarp.frag diff --git a/libs/video/renderer/vulkan/pl_output.plist b/libs/video/renderer/vulkan/pl_output.plist index 001b999c6..2262d53f3 100644 --- a/libs/video/renderer/vulkan/pl_output.plist +++ b/libs/video/renderer/vulkan/pl_output.plist @@ -56,6 +56,16 @@ output_layout = { setLayouts = (matrix_set, output_set); }; + waterwarp_layout = { + @inherit = $properties.pipelineLayouts.output_layout; + pushConstantRanges = ( + { + stageFlags = fragment; + offset = 0; + size = "4"; + } + ); + }; }; depthStencil = { @@ -152,6 +162,11 @@ name = main; module = $builtin/fstriangle.vert; }; + vertexStageST = { + stage = vertex; + name = main; + module = $builtin/fstrianglest.vert; + }; vertexInput = { bindings = (); attributes = (); @@ -205,5 +220,18 @@ ); layout = output_layout; }; + waterwarp = { + @inherit = $properties.pipelines.output_base; + subpass = 0; + stages = ( + $properties.fstriangle.vertexStageST, + { + stage = fragment; + name = main; + module = $builtin/waterwarp.frag; + }, + ); + layout = waterwarp_layout; + }; }; } diff --git a/libs/video/renderer/vulkan/shader.c b/libs/video/renderer/vulkan/shader.c index fb34c7e05..133f23517 100644 --- a/libs/video/renderer/vulkan/shader.c +++ b/libs/video/renderer/vulkan/shader.c @@ -115,7 +115,11 @@ static static #include "libs/video/renderer/vulkan/shader/fstriangle.vert.spvc" static +#include "libs/video/renderer/vulkan/shader/fstrianglest.vert.spvc" +static #include "libs/video/renderer/vulkan/shader/pushcolor.frag.spvc" +static +#include "libs/video/renderer/vulkan/shader/waterwarp.frag.spvc" typedef struct shaderdata_s { const char *name; @@ -162,7 +166,9 @@ static shaderdata_t builtin_shaders[] = { { "output.frag", output_frag, sizeof (output_frag) }, { "passthrough.vert", passthrough_vert, sizeof (passthrough_vert) }, { "fstriangle.vert", fstriangle_vert, sizeof (fstriangle_vert) }, + { "fstrianglest.vert", fstrianglest_vert, sizeof (fstrianglest_vert) }, { "pushcolor.frag", pushcolor_frag, sizeof (pushcolor_frag) }, + { "waterwarp.frag", waterwarp_frag, sizeof (waterwarp_frag) }, {} }; diff --git a/libs/video/renderer/vulkan/shader/fstrianglest.vert b/libs/video/renderer/vulkan/shader/fstrianglest.vert new file mode 100644 index 000000000..92a9c7d51 --- /dev/null +++ b/libs/video/renderer/vulkan/shader/fstrianglest.vert @@ -0,0 +1,12 @@ +#version 450 + +layout (location = 0) out vec2 st; + +void +main () +{ + float x = (gl_VertexIndex & 2); + float y = (gl_VertexIndex & 1); + gl_Position = vec4 (2, 4, 0, 1) * vec4 (x, y, 0, 1) - vec4 (1, 1, 0, 0); + st = vec2(1, 2) * vec2(x, y); +} diff --git a/libs/video/renderer/vulkan/shader/waterwarp.frag b/libs/video/renderer/vulkan/shader/waterwarp.frag new file mode 100644 index 000000000..c0dce195f --- /dev/null +++ b/libs/video/renderer/vulkan/shader/waterwarp.frag @@ -0,0 +1,31 @@ +#version 450 +#extension GL_GOOGLE_include_directive : enable + +layout (set = 0, binding = 0) uniform +#include "matrices.h" +; + +layout (set = 1, binding = 0) uniform sampler2D Input; + +layout (push_constant) uniform PushConstants { + float time; +}; + +layout (location = 0) in vec2 uv; + +layout (location = 0) out vec4 frag_color; + +const float S = 0.15625; +const float F = 2.5; +const float A = 0.01; +const vec2 B = vec2 (1, 1); +const float PI = 3.14159265; + +void +main (void) +{ + vec2 st; + st = uv * (1.0 - 2.0*A) + A * (B + sin ((time * S + F * uv.yx) * 2.0*PI)); + vec4 c = texture (Input, st); + frag_color = c;//vec4(uv, c.x, 1); +}