diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-01-15 16:02:48 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-01-15 16:02:48 +0100 |
| commit | 07e316316bc7a7529c2d9b3503771eab34775bc3 (patch) | |
| tree | 5881f36c214012206ff0f75a460cac3579c8181d /shaders | |
| parent | e5b3a3e3eda98688b731ee5e59da6725315b220c (diff) | |
test with solid color onlysolidColorOnlyShader
Diffstat (limited to 'shaders')
| -rw-r--r-- | shaders/vkvg_main.vert | 8 | ||||
| -rw-r--r-- | shaders/vkvg_solid.vert | 24 | ||||
| -rw-r--r-- | shaders/vkvg_source.frag | 49 |
3 files changed, 66 insertions, 15 deletions
diff --git a/shaders/vkvg_main.vert b/shaders/vkvg_main.vert index 7466fee..e214d14 100644 --- a/shaders/vkvg_main.vert +++ b/shaders/vkvg_main.vert @@ -26,9 +26,8 @@ layout (location = 0) in vec2 inPos; layout (location = 1) in vec4 inColor; -layout (location = 2) in vec3 inUV; +//layout (location = 2) in vec3 inUV; -======= layout (location = 0) out vec4 outSrc; layout(push_constant) uniform PushConsts { @@ -51,16 +50,13 @@ layout(push_constant) uniform PushConsts { void main() { - outSrc = pc.srcType == SOLID ? inColor : pc.source; + outSrc = (pc.fullScreenQuad_srcType & SRCTYPE_MASK) == SOLID ? inColor : pc.source; if ((pc.fullScreenQuad_srcType & FULLSCREEN_BIT)==FULLSCREEN_BIT) { gl_Position = vec4(inPos, 0.0f, 1.0f); - outUV = vec3(0,0,-1); return; } - outUV = inUV; - vec2 p = vec2( pc.mat[0][0] * inPos.x + pc.mat[1][0] * inPos.y + pc.mat[2][0], pc.mat[0][1] * inPos.x + pc.mat[1][1] * inPos.y + pc.mat[2][1] diff --git a/shaders/vkvg_solid.vert b/shaders/vkvg_solid.vert index 1b08122..8c823dd 100644 --- a/shaders/vkvg_solid.vert +++ b/shaders/vkvg_solid.vert @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> + * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -28,6 +28,8 @@ layout (location = 0) in vec2 inPos; layout (location = 1) in vec4 inColor; layout (location = 0) out vec4 outSrc; +layout (location = 1) out flat float outOpacity; +layout (location = 2) out mat3x2 outMat; out gl_PerVertex { @@ -35,13 +37,15 @@ out gl_PerVertex }; layout(push_constant) uniform PushConsts { - vec4 source; - vec2 size; - int srcType; - int fullScreenQuad; - mat3x2 mat; - mat3x2 matInv; + vec4 source; + vec2 size; + int fullScreenQuad_srcType; + float opacity; + mat3x2 mat; + mat3x2 matInv; } pc; +#define FULLSCREEN_BIT 0x10000000 +#define SRCTYPE_MASK 0x000000FF #define SOLID 0 #define SURFACE 1 @@ -52,9 +56,11 @@ layout(push_constant) uniform PushConsts { void main() { - outSrc = pc.srcType == SOLID ? inColor : pc.source; + outSrc = pc.source; + outOpacity = pc.opacity; + outMat = pc.matInv; - if (pc.fullScreenQuad != 0) { + if ((pc.fullScreenQuad_srcType & FULLSCREEN_BIT)==FULLSCREEN_BIT) { gl_Position = vec4(inPos, 0.0f, 1.0f); return; } diff --git a/shaders/vkvg_source.frag b/shaders/vkvg_source.frag new file mode 100644 index 0000000..e1de6ef --- /dev/null +++ b/shaders/vkvg_source.frag @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the + * Software, and to permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable +#extension GL_EXT_scalar_block_layout : require + +layout (set=1, binding = 0) uniform sampler2D source; + +layout (location = 0) in vec4 inSrc; //source bounds or color depending on pattern type +layout (location = 1) in flat float inOpacity; +layout (location = 2) in mat3x2 inMat; + +layout (location = 0) out vec4 outFragColor; + +layout (constant_id = 0) const int NUM_SAMPLES = 8; + +void main() +{ + vec2 p = (gl_FragCoord.xy - inSrc.xy); + vec2 uv = vec2( + inMat[0][0] * p.x + inMat[1][0] * p.y + inMat[2][0], + inMat[0][1] * p.x + inMat[1][1] * p.y + inMat[2][1] + ); + + vec4 c = texture (source, uv / inSrc.zw); + c.a *= inOpacity; + outFragColor = c; +} |