forked from AuroraMiddleware/gtk
vulkan: Generate clip shaders from same source
Instead of having 3 different shaders for the different clipping versions, just have one shader and use a preprocessor define to use different clip functions. That preprocessor define is set in the Makefile. Also use foo.frag and foo.vert as the file extensions instead of using foo.frag.glsl and foo.vert.glsl, as that's what glslc suggests as extension.
This commit is contained in:
parent
3768c676c6
commit
6bec7aae89
@ -62,39 +62,28 @@ gsk_private_vulkan_include_shaders = \
|
|||||||
resources/vulkan/clip.vert.glsl \
|
resources/vulkan/clip.vert.glsl \
|
||||||
resources/vulkan/constants.glsl \
|
resources/vulkan/constants.glsl \
|
||||||
resources/vulkan/rounded-rect.glsl
|
resources/vulkan/rounded-rect.glsl
|
||||||
|
gsk_private_vulkan_fragment_shaders = \
|
||||||
|
resources/vulkan/blend.frag \
|
||||||
|
resources/vulkan/border.frag \
|
||||||
|
resources/vulkan/color.frag \
|
||||||
|
resources/vulkan/color-matrix.frag \
|
||||||
|
resources/vulkan/linear.frag
|
||||||
|
gsk_private_vulkan_vertex_shaders = \
|
||||||
|
resources/vulkan/blend.vert \
|
||||||
|
resources/vulkan/border.vert \
|
||||||
|
resources/vulkan/color.vert \
|
||||||
|
resources/vulkan/color-matrix.vert \
|
||||||
|
resources/vulkan/linear.vert
|
||||||
gsk_private_vulkan_shaders = \
|
gsk_private_vulkan_shaders = \
|
||||||
resources/vulkan/blend-clip.frag.glsl \
|
$(gsk_private_vulkan_fragment_shaders) \
|
||||||
resources/vulkan/blend-clip-rounded.frag.glsl \
|
$(gsk_private_vulkan_vertex_shaders)
|
||||||
resources/vulkan/blend-clip-rounded.vert.glsl \
|
|
||||||
resources/vulkan/blend-clip.vert.glsl \
|
|
||||||
resources/vulkan/blend.frag.glsl \
|
|
||||||
resources/vulkan/blend.vert.glsl \
|
|
||||||
resources/vulkan/border-clip.frag.glsl \
|
|
||||||
resources/vulkan/border-clip.vert.glsl \
|
|
||||||
resources/vulkan/border-clip-rounded.frag.glsl \
|
|
||||||
resources/vulkan/border-clip-rounded.vert.glsl \
|
|
||||||
resources/vulkan/border.frag.glsl \
|
|
||||||
resources/vulkan/border.vert.glsl \
|
|
||||||
resources/vulkan/color-clip.frag.glsl \
|
|
||||||
resources/vulkan/color-clip-rounded.frag.glsl \
|
|
||||||
resources/vulkan/color-clip-rounded.vert.glsl \
|
|
||||||
resources/vulkan/color-clip.vert.glsl \
|
|
||||||
resources/vulkan/color.frag.glsl \
|
|
||||||
resources/vulkan/color.vert.glsl \
|
|
||||||
resources/vulkan/color-matrix-clip.frag.glsl \
|
|
||||||
resources/vulkan/color-matrix-clip-rounded.frag.glsl \
|
|
||||||
resources/vulkan/color-matrix-clip-rounded.vert.glsl \
|
|
||||||
resources/vulkan/color-matrix-clip.vert.glsl \
|
|
||||||
resources/vulkan/color-matrix.frag.glsl \
|
|
||||||
resources/vulkan/color-matrix.vert.glsl \
|
|
||||||
resources/vulkan/linear-clip.frag.glsl \
|
|
||||||
resources/vulkan/linear-clip-rounded.frag.glsl \
|
|
||||||
resources/vulkan/linear-clip-rounded.vert.glsl \
|
|
||||||
resources/vulkan/linear-clip.vert.glsl \
|
|
||||||
resources/vulkan/linear.frag.glsl \
|
|
||||||
resources/vulkan/linear.vert.glsl
|
|
||||||
gsk_private_vulkan_compiled_shaders = \
|
gsk_private_vulkan_compiled_shaders = \
|
||||||
$(gsk_private_vulkan_shaders:.glsl=.spv)
|
$(gsk_private_vulkan_fragment_shaders:.frag=.frag.spv) \
|
||||||
|
$(gsk_private_vulkan_vertex_shaders:.vert=.vert.spv) \
|
||||||
|
$(gsk_private_vulkan_fragment_shaders:.frag=-clip.frag.spv) \
|
||||||
|
$(gsk_private_vulkan_vertex_shaders:.vert=-clip.vert.spv) \
|
||||||
|
$(gsk_private_vulkan_fragment_shaders:.frag=-clip-rounded.frag.spv) \
|
||||||
|
$(gsk_private_vulkan_vertex_shaders:.vert=-clip-rounded.vert.spv)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
gsk_public_source_h = \
|
gsk_public_source_h = \
|
||||||
@ -180,13 +169,29 @@ resource_files = \
|
|||||||
$(gsk_private_vulkan_compiled_shaders) \
|
$(gsk_private_vulkan_compiled_shaders) \
|
||||||
$(gsk_private_vulkan_shaders)
|
$(gsk_private_vulkan_shaders)
|
||||||
|
|
||||||
resources/vulkan/%.frag.spv: resources/vulkan/%.frag.glsl
|
resources/vulkan/%-clip-rounded.frag.spv: resources/vulkan/%.frag
|
||||||
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
$(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -o $@.tmp $< && mv $@.tmp $@
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_ROUNDED_RECT -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
resources/vulkan/%.vert.spv: resources/vulkan/%.vert.glsl
|
resources/vulkan/%-clip-rounded.vert.spv: resources/vulkan/%.vert
|
||||||
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
$(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -o $@.tmp $< && mv $@.tmp $@
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_ROUNDED_RECT -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
|
resources/vulkan/%-clip.frag.spv: resources/vulkan/%.frag
|
||||||
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_RECT -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
|
resources/vulkan/%-clip.vert.spv: resources/vulkan/%.vert
|
||||||
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_RECT -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
|
resources/vulkan/%.frag.spv: resources/vulkan/%.frag
|
||||||
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_NONE -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
|
resources/vulkan/%.vert.spv: resources/vulkan/%.vert
|
||||||
|
@if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi
|
||||||
|
$(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_NONE -o $@.tmp $< && mv $@.tmp $@
|
||||||
|
|
||||||
gsk.resources.xml: Makefile.am
|
gsk.resources.xml: Makefile.am
|
||||||
$(AM_V_GEN) echo "<?xml version='1.0' encoding='UTF-8'?>" > $@; \
|
$(AM_V_GEN) echo "<?xml version='1.0' encoding='UTF-8'?>" > $@; \
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 inTexCoord;
|
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform sampler2D inTexture;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
color = texture (inTexture, inTexCoord);
|
|
||||||
}
|
|
Binary file not shown.
@ -1,32 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#define CLIP_RECT
|
|
||||||
#include "clip.vert.glsl"
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
|
||||||
layout(location = 1) in vec4 inTexRect;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 outTexCoord;
|
|
||||||
|
|
||||||
out gl_PerVertex {
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(1.0, 1.0) };
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 rect = clip (inRect);
|
|
||||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
|
||||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
|
||||||
|
|
||||||
vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
|
|
||||||
rect.zw / inRect.zw);
|
|
||||||
texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
|
|
||||||
inTexRect.zw * texrect.zw);
|
|
||||||
outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
|
|
||||||
}
|
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.frag.glsl"
|
#include "clip.frag.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec2 inPos;
|
layout(location = 0) in vec2 inPos;
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.vert.glsl"
|
#include "clip.vert.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
layout(location = 0) in vec4 inRect;
|
Binary file not shown.
Binary file not shown.
@ -1,103 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.vert.glsl"
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
|
||||||
layout(location = 1) in vec4 inCornerWidths;
|
|
||||||
layout(location = 2) in vec4 inCornerHeights;
|
|
||||||
layout(location = 3) in vec4 inBorderWidths;
|
|
||||||
layout(location = 4) in mat4 inBorderColors;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 outPos;
|
|
||||||
layout(location = 1) out flat vec4 outColor;
|
|
||||||
layout(location = 2) out flat vec4 outRect;
|
|
||||||
layout(location = 3) out flat vec4 outCornerWidths;
|
|
||||||
layout(location = 4) out flat vec4 outCornerHeights;
|
|
||||||
layout(location = 5) out flat vec4 outBorderWidths;
|
|
||||||
|
|
||||||
out gl_PerVertex {
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 1.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0) };
|
|
||||||
|
|
||||||
#define TOP 0
|
|
||||||
#define RIGHT 1
|
|
||||||
#define BOTTOM 2
|
|
||||||
#define LEFT 3
|
|
||||||
|
|
||||||
#define TOP_LEFT 0
|
|
||||||
#define TOP_RIGHT 1
|
|
||||||
#define BOTTOM_RIGHT 2
|
|
||||||
#define BOTTOM_LEFT 3
|
|
||||||
|
|
||||||
#define SLICE_TOP_LEFT 0
|
|
||||||
#define SLICE_TOP 1
|
|
||||||
#define SLICE_TOP_RIGHT 2
|
|
||||||
#define SLICE_RIGHT 3
|
|
||||||
#define SLICE_BOTTOM_RIGHT 4
|
|
||||||
#define SLICE_BOTTOM 5
|
|
||||||
#define SLICE_BOTTOM_LEFT 6
|
|
||||||
#define SLICE_LEFT 7
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
int slice_index = gl_VertexIndex / 6;
|
|
||||||
int vert_index = gl_VertexIndex % 6;
|
|
||||||
|
|
||||||
vec4 corner_widths = max (inCornerWidths, inBorderWidths.wyyw);
|
|
||||||
vec4 corner_heights = max (inCornerHeights, inBorderWidths.xxzz);
|
|
||||||
|
|
||||||
vec4 rect;
|
|
||||||
|
|
||||||
switch (slice_index)
|
|
||||||
{
|
|
||||||
case SLICE_TOP_LEFT:
|
|
||||||
rect = vec4(inRect.xy, corner_widths[TOP_LEFT], corner_heights[TOP_LEFT]);
|
|
||||||
vert_index = (vert_index + 3) % 6;
|
|
||||||
break;
|
|
||||||
case SLICE_TOP:
|
|
||||||
rect = vec4(inRect.x + corner_widths[TOP_LEFT], inRect.y, inRect.z - corner_widths[TOP_LEFT] - corner_widths[TOP_RIGHT], inBorderWidths[TOP]);
|
|
||||||
outColor = inBorderColors[TOP];
|
|
||||||
break;
|
|
||||||
case SLICE_TOP_RIGHT:
|
|
||||||
rect = vec4(inRect.x + inRect.z - corner_widths[TOP_RIGHT], inRect.y, corner_widths[TOP_RIGHT], corner_heights[TOP_RIGHT]);
|
|
||||||
break;
|
|
||||||
case SLICE_RIGHT:
|
|
||||||
rect = vec4(inRect.x + inRect.z - inBorderWidths[RIGHT], inRect.y + corner_heights[TOP_RIGHT], inBorderWidths[RIGHT], inRect.w - corner_heights[TOP_RIGHT] - corner_heights[BOTTOM_RIGHT]);
|
|
||||||
outColor = inBorderColors[RIGHT];
|
|
||||||
break;
|
|
||||||
case SLICE_BOTTOM_RIGHT:
|
|
||||||
rect = vec4(inRect.x + inRect.z - corner_widths[BOTTOM_RIGHT], inRect.y + inRect.w - corner_heights[BOTTOM_RIGHT], corner_widths[BOTTOM_RIGHT], corner_heights[BOTTOM_RIGHT]);
|
|
||||||
break;
|
|
||||||
case SLICE_BOTTOM:
|
|
||||||
rect = vec4(inRect.x + corner_widths[BOTTOM_LEFT], inRect.y + inRect.w - inBorderWidths[BOTTOM], inRect.z - corner_widths[BOTTOM_LEFT] - corner_widths[BOTTOM_RIGHT], inBorderWidths[BOTTOM]);
|
|
||||||
break;
|
|
||||||
case SLICE_BOTTOM_LEFT:
|
|
||||||
rect = vec4(inRect.x, inRect.y + inRect.w - corner_heights[BOTTOM_LEFT], corner_widths[BOTTOM_LEFT], corner_heights[BOTTOM_LEFT]);
|
|
||||||
vert_index = (vert_index + 3) % 6;
|
|
||||||
break;
|
|
||||||
case SLICE_LEFT:
|
|
||||||
rect = vec4(inRect.x, inRect.y + corner_heights[TOP_LEFT], inBorderWidths[LEFT], inRect.w - corner_heights[TOP_LEFT] - corner_heights[BOTTOM_LEFT]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
rect = clip (rect);
|
|
||||||
vec2 pos;
|
|
||||||
if ((slice_index % 4) != 0 || (vert_index % 3) != 2)
|
|
||||||
pos = rect.xy + rect.zw * offsets[vert_index];
|
|
||||||
else
|
|
||||||
pos = rect.xy + rect.zw * vec2(1.0 - offsets[vert_index].x, offsets[vert_index].y);
|
|
||||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
|
||||||
outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4];
|
|
||||||
outPos = pos;
|
|
||||||
outRect = inRect;
|
|
||||||
outCornerWidths = inCornerWidths;
|
|
||||||
outCornerHeights = inCornerHeights;
|
|
||||||
outBorderWidths = inBorderWidths;
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#include "rounded-rect.glsl"
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 inPos;
|
|
||||||
layout(location = 1) in flat vec4 inColor;
|
|
||||||
layout(location = 2) in flat vec4 inRect;
|
|
||||||
layout(location = 3) in flat vec4 inCornerWidths;
|
|
||||||
layout(location = 4) in flat vec4 inCornerHeights;
|
|
||||||
layout(location = 5) in flat vec4 inBorderWidths;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights);
|
|
||||||
RoundedRect rinside = rounded_rect_shrink (routside, inBorderWidths);
|
|
||||||
|
|
||||||
float alpha = clamp (rounded_rect_coverage (routside, inPos) -
|
|
||||||
rounded_rect_coverage (rinside, inPos),
|
|
||||||
0.0, 1.0);
|
|
||||||
color = inColor * alpha;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#include "constants.glsl"
|
#include "clip.frag.glsl"
|
||||||
#include "rounded-rect.glsl"
|
#include "rounded-rect.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec2 inPos;
|
layout(location = 0) in vec2 inPos;
|
||||||
@ -12,14 +12,6 @@ layout(location = 5) in vec4 inBorderWidths;
|
|||||||
|
|
||||||
layout(location = 0) out vec4 color;
|
layout(location = 0) out vec4 color;
|
||||||
|
|
||||||
vec4
|
|
||||||
clip (vec4 color)
|
|
||||||
{
|
|
||||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths, push.clip_heights);
|
|
||||||
|
|
||||||
return color * rounded_rect_coverage (r, inPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights);
|
RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights);
|
||||||
@ -28,5 +20,5 @@ void main()
|
|||||||
float alpha = clamp (rounded_rect_coverage (routside, inPos) -
|
float alpha = clamp (rounded_rect_coverage (routside, inPos) -
|
||||||
rounded_rect_coverage (rinside, inPos),
|
rounded_rect_coverage (rinside, inPos),
|
||||||
0.0, 1.0);
|
0.0, 1.0);
|
||||||
color = clip (inColor);
|
color = clip (inPos, inColor * alpha);
|
||||||
}
|
}
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_RECT
|
|
||||||
#include "clip.vert.glsl"
|
#include "clip.vert.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
layout(location = 0) in vec4 inRect;
|
Binary file not shown.
@ -1,10 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inColor;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 color;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
color = vec4(inColor.rgb * inColor.a, inColor.a);
|
|
||||||
}
|
|
Binary file not shown.
@ -1,28 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#define CLIP_RECT
|
|
||||||
#include "clip.vert.glsl"
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
|
||||||
layout(location = 1) in vec4 inColor;
|
|
||||||
|
|
||||||
out gl_PerVertex {
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(1.0, 1.0) };
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 rect = clip (inRect);
|
|
||||||
|
|
||||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
|
||||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
|
||||||
outColor = inColor;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,31 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 inTexCoord;
|
|
||||||
layout(location = 1) in flat mat4 inColorMatrix;
|
|
||||||
layout(location = 5) in flat vec4 inColorOffset;
|
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform sampler2D inTexture;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 color;
|
|
||||||
|
|
||||||
vec4
|
|
||||||
color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
|
|
||||||
{
|
|
||||||
/* unpremultiply */
|
|
||||||
if (color.a != 0.0)
|
|
||||||
color.rgb /= color.a;
|
|
||||||
|
|
||||||
color = color_matrix * color + color_offset;
|
|
||||||
color = clamp(color, 0.0, 1.0);
|
|
||||||
|
|
||||||
/* premultiply */
|
|
||||||
if (color.a != 0.0)
|
|
||||||
color.rgb *= color.a;
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset);
|
|
||||||
}
|
|
Binary file not shown.
@ -1,38 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#define CLIP_RECT
|
|
||||||
#include "clip.vert.glsl"
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
|
||||||
layout(location = 1) in vec4 inTexRect;
|
|
||||||
layout(location = 2) in mat4 inColorMatrix;
|
|
||||||
layout(location = 6) in vec4 inColorOffset;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 outTexCoord;
|
|
||||||
layout(location = 1) out flat mat4 outColorMatrix;
|
|
||||||
layout(location = 5) out flat vec4 outColorOffset;
|
|
||||||
|
|
||||||
out gl_PerVertex {
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(1.0, 1.0) };
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 rect = clip (inRect);
|
|
||||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
|
||||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
|
||||||
|
|
||||||
vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
|
|
||||||
rect.zw / inRect.zw);
|
|
||||||
texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
|
|
||||||
inTexRect.zw * texrect.zw);
|
|
||||||
outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
|
|
||||||
outColorMatrix = inColorMatrix;
|
|
||||||
outColorOffset = inColorOffset;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.frag.glsl"
|
#include "clip.frag.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec2 inPos;
|
layout(location = 0) in vec2 inPos;
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.vert.glsl"
|
#include "clip.vert.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
layout(location = 0) in vec4 inRect;
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.frag.glsl"
|
#include "clip.frag.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec2 inPos;
|
layout(location = 0) in vec2 inPos;
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.vert.glsl"
|
#include "clip.vert.glsl"
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
layout(location = 0) in vec4 inRect;
|
Binary file not shown.
@ -1,33 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
struct ColorStop {
|
|
||||||
float offset;
|
|
||||||
vec4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) in float inGradientPos;
|
|
||||||
layout(location = 1) in flat int inRepeating;
|
|
||||||
layout(location = 2) in flat int inStopCount;
|
|
||||||
layout(location = 3) in flat ColorStop inStops[8];
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
float pos;
|
|
||||||
if (inRepeating != 0)
|
|
||||||
pos = fract (inGradientPos);
|
|
||||||
else
|
|
||||||
pos = clamp (inGradientPos, 0, 1);
|
|
||||||
|
|
||||||
vec4 color = inStops[0].color;
|
|
||||||
int n = clamp (inStopCount, 2, 8);
|
|
||||||
for (int i = 1; i < n; i++)
|
|
||||||
{
|
|
||||||
if (inStops[i].offset > inStops[i-1].offset)
|
|
||||||
color = mix (color, inStops[i].color, clamp((pos - inStops[i-1].offset) / (inStops[i].offset - inStops[i-1].offset), 0, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
//outColor = vec4(pos, pos, pos, 1.0);
|
|
||||||
outColor = color;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,75 +0,0 @@
|
|||||||
#version 420 core
|
|
||||||
|
|
||||||
#define CLIP_RECT
|
|
||||||
#include "clip.vert.glsl"
|
|
||||||
|
|
||||||
struct ColorStop {
|
|
||||||
float offset;
|
|
||||||
vec4 color;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inRect;
|
|
||||||
layout(location = 1) in vec2 inStart;
|
|
||||||
layout(location = 2) in vec2 inEnd;
|
|
||||||
layout(location = 3) in int inRepeating;
|
|
||||||
layout(location = 4) in int inStopCount;
|
|
||||||
layout(location = 5) in vec4 inOffsets0;
|
|
||||||
layout(location = 6) in vec4 inOffsets1;
|
|
||||||
layout(location = 7) in vec4 inColors0;
|
|
||||||
layout(location = 8) in vec4 inColors1;
|
|
||||||
layout(location = 9) in vec4 inColors2;
|
|
||||||
layout(location = 10) in vec4 inColors3;
|
|
||||||
layout(location = 11) in vec4 inColors4;
|
|
||||||
layout(location = 12) in vec4 inColors5;
|
|
||||||
layout(location = 13) in vec4 inColors6;
|
|
||||||
layout(location = 14) in vec4 inColors7;
|
|
||||||
|
|
||||||
layout(location = 0) out float outGradientPos;
|
|
||||||
layout(location = 1) out flat int outRepeating;
|
|
||||||
layout(location = 2) out flat int outStopCount;
|
|
||||||
layout(location = 3) out flat ColorStop outStops[8];
|
|
||||||
|
|
||||||
out gl_PerVertex {
|
|
||||||
vec4 gl_Position;
|
|
||||||
};
|
|
||||||
|
|
||||||
vec2 offsets[6] = { vec2(0.0, 0.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(0.0, 1.0),
|
|
||||||
vec2(1.0, 0.0),
|
|
||||||
vec2(1.0, 1.0) };
|
|
||||||
|
|
||||||
float
|
|
||||||
get_gradient_pos (vec2 pos)
|
|
||||||
{
|
|
||||||
pos = pos - inStart;
|
|
||||||
vec2 grad = inEnd - inStart;
|
|
||||||
|
|
||||||
return dot (pos, grad) / dot (grad, grad);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 rect = clip (inRect);
|
|
||||||
vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
|
|
||||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
|
||||||
outGradientPos = get_gradient_pos (pos);
|
|
||||||
outRepeating = inRepeating;
|
|
||||||
outStopCount = inStopCount;
|
|
||||||
outStops[0].offset = inOffsets0[0];
|
|
||||||
outStops[0].color = inColors0 * vec4(inColors0.aaa, 1.0);
|
|
||||||
outStops[1].offset = inOffsets0[1];
|
|
||||||
outStops[1].color = inColors1 * vec4(inColors1.aaa, 1.0);
|
|
||||||
outStops[2].offset = inOffsets0[2];
|
|
||||||
outStops[2].color = inColors2 * vec4(inColors2.aaa, 1.0);
|
|
||||||
outStops[3].offset = inOffsets0[3];
|
|
||||||
outStops[3].color = inColors3 * vec4(inColors3.aaa, 1.0);
|
|
||||||
outStops[4].offset = inOffsets1[0];
|
|
||||||
outStops[4].color = inColors4 * vec4(inColors4.aaa, 1.0);
|
|
||||||
outStops[5].offset = inOffsets1[1];
|
|
||||||
outStops[5].color = inColors5 * vec4(inColors5.aaa, 1.0);
|
|
||||||
outStops[6].offset = inOffsets1[2];
|
|
||||||
outStops[6].color = inColors6 * vec4(inColors6.aaa, 1.0);
|
|
||||||
outStops[7].offset = inOffsets1[3];
|
|
||||||
outStops[7].color = inColors7 * vec4(inColors7.aaa, 1.0);
|
|
||||||
}
|
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.frag.glsl"
|
#include "clip.frag.glsl"
|
||||||
|
|
||||||
struct ColorStop {
|
struct ColorStop {
|
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
#version 420 core
|
#version 420 core
|
||||||
|
|
||||||
#define CLIP_ROUNDED_RECT
|
|
||||||
#include "clip.vert.glsl"
|
#include "clip.vert.glsl"
|
||||||
|
|
||||||
struct ColorStop {
|
struct ColorStop {
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user