Same work as crossfade shader pretty much.
struct _GskVulkanBlendModeInstance
{
float rect[4];
- float start_tex_rect[4];
- float end_tex_rect[4];
- guint32 start_tex_id;
- guint32 end_tex_id;
+ float top_rect[4];
+ float bottom_rect[4];
+ float top_tex_rect[4];
+ float bottom_tex_rect[4];
+ guint32 top_tex_id;
+ guint32 bottom_tex_id;
guint32 blend_mode;
};
.location = 1,
.binding = 0,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
- .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, start_tex_rect),
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_rect),
},
{
.location = 2,
.binding = 0,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
- .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, end_tex_rect),
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_rect),
},
{
.location = 3,
.binding = 0,
- .format = VK_FORMAT_R32_UINT,
- .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, start_tex_id),
+ .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_tex_rect),
},
{
.location = 4,
.binding = 0,
- .format = VK_FORMAT_R32_UINT,
- .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, end_tex_id),
+ .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_tex_rect),
},
{
.location = 5,
.binding = 0,
.format = VK_FORMAT_R32_UINT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_tex_id),
+ },
+ {
+ .location = 6,
+ .binding = 0,
+ .format = VK_FORMAT_R32_UINT,
+ .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_tex_id),
+ },
+ {
+ .location = 7,
+ .binding = 0,
+ .format = VK_FORMAT_R32_UINT,
.offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, blend_mode),
}
};
void
gsk_vulkan_blend_mode_pipeline_collect_vertex_data (GskVulkanBlendModePipeline *pipeline,
guchar *data,
- guint32 start_tex_id,
- guint32 end_tex_id,
+ guint32 top_tex_id,
+ guint32 bottom_tex_id,
const graphene_point_t *offset,
const graphene_rect_t *bounds,
- const graphene_rect_t *start_tex_rect,
- const graphene_rect_t *end_tex_rect,
+ const graphene_rect_t *top_bounds,
+ const graphene_rect_t *bottom_bounds,
+ const graphene_rect_t *top_tex_rect,
+ const graphene_rect_t *bottom_tex_rect,
GskBlendMode blend_mode)
{
GskVulkanBlendModeInstance *instance = (GskVulkanBlendModeInstance *) data;
instance->rect[2] = bounds->size.width;
instance->rect[3] = bounds->size.height;
- instance->start_tex_rect[0] = start_tex_rect->origin.x;
- instance->start_tex_rect[1] = start_tex_rect->origin.y;
- instance->start_tex_rect[2] = start_tex_rect->size.width;
- instance->start_tex_rect[3] = start_tex_rect->size.height;
+ instance->top_rect[0] = top_bounds->origin.x + offset->x;
+ instance->top_rect[1] = top_bounds->origin.y + offset->y;
+ instance->top_rect[2] = top_bounds->size.width;
+ instance->top_rect[3] = top_bounds->size.height;
+
+ instance->bottom_rect[0] = bottom_bounds->origin.x + offset->x;
+ instance->bottom_rect[1] = bottom_bounds->origin.y + offset->y;
+ instance->bottom_rect[2] = bottom_bounds->size.width;
+ instance->bottom_rect[3] = bottom_bounds->size.height;
+
+ instance->top_tex_rect[0] = top_tex_rect->origin.x;
+ instance->top_tex_rect[1] = top_tex_rect->origin.y;
+ instance->top_tex_rect[2] = top_tex_rect->size.width;
+ instance->top_tex_rect[3] = top_tex_rect->size.height;
- instance->end_tex_rect[0] = end_tex_rect->origin.x;
- instance->end_tex_rect[1] = end_tex_rect->origin.y;
- instance->end_tex_rect[2] = end_tex_rect->size.width;
- instance->end_tex_rect[3] = end_tex_rect->size.height;
+ instance->bottom_tex_rect[0] = bottom_tex_rect->origin.x;
+ instance->bottom_tex_rect[1] = bottom_tex_rect->origin.y;
+ instance->bottom_tex_rect[2] = bottom_tex_rect->size.width;
+ instance->bottom_tex_rect[3] = bottom_tex_rect->size.height;
- instance->start_tex_id = start_tex_id;
- instance->end_tex_id = end_tex_id;
+ instance->top_tex_id = top_tex_id;
+ instance->bottom_tex_id = bottom_tex_id;
instance->blend_mode = blend_mode;
}
void gsk_vulkan_blend_mode_pipeline_collect_vertex_data (GskVulkanBlendModePipeline *pipeline,
guchar *data,
- guint32 start_tex_id,
- guint32 end_tex_id,
+ guint32 top_tex_id,
+ guint32 bottom_tex_id,
const graphene_point_t *offset,
const graphene_rect_t *bounds,
- const graphene_rect_t *start_bounds,
- const graphene_rect_t *end_bounds,
+ const graphene_rect_t *top_bounds,
+ const graphene_rect_t *bottom_bounds,
+ const graphene_rect_t *top_tex_rect,
+ const graphene_rect_t *bottom_tex_rect,
GskBlendMode blend_mode);
gsize gsk_vulkan_blend_mode_pipeline_draw (GskVulkanBlendModePipeline *pipeline,
VkCommandBuffer command_buffer,
op->render.descriptor_set_index2,
&op->render.offset,
&op->render.node->bounds,
+ &gsk_blend_node_get_top_child (op->render.node)->bounds,
+ &gsk_blend_node_get_bottom_child (op->render.node)->bounds,
&op->render.source_rect,
&op->render.source2_rect,
gsk_blend_node_get_blend_mode (op->render.node));
#include "common.frag.glsl"
#include "clip.frag.glsl"
+#include "rect.frag.glsl"
layout(location = 0) in vec2 inPos;
-layout(location = 1) in vec2 inStartTexCoord;
-layout(location = 2) in vec2 inEndTexCoord;
-layout(location = 3) flat in uint inStartTexId;
-layout(location = 4) flat in uint inEndTexId;
-layout(location = 5) flat in uint inBlendMode;
+layout(location = 1) in Rect inTopRect;
+layout(location = 2) in Rect inBottomRect;
+layout(location = 3) in vec2 inTopTexCoord;
+layout(location = 4) in vec2 inBottomTexCoord;
+layout(location = 5) flat in uint inTopTexId;
+layout(location = 6) flat in uint inBottomTexId;
+layout(location = 7) flat in uint inBlendMode;
-layout(location = 0) out vec4 outColor;
+layout(location = 0) out vec4 color;
float
combine (float source, float backdrop)
}
vec4
-color (vec4 Cs, vec4 Cb)
+colorize (vec4 Cs, vec4 Cb)
{
vec3 B = set_lum (Cs.rgb, lum (Cb.rgb));
return composite (Cs, Cb, B);
void main()
{
- vec4 source = texture (textures[inStartTexId], inStartTexCoord);
- vec4 backdrop = texture (textures[inEndTexId], inEndTexCoord);
+ float source_alpha = rect_coverage (inTopRect, inPos);
+ vec4 source = texture (textures[inTopTexId], inTopTexCoord) * source_alpha;
+ //source=vec4(1); //inTopTexCoord * 100 + 100) / 255, 0, 1);
+ float backdrop_alpha = rect_coverage (inBottomRect, inPos);
+ vec4 backdrop = texture (textures[inBottomTexId], inBottomTexCoord) * backdrop_alpha;
+ //backdrop=vec4(1, 0, 0, 1) * backdrop_alpha;
vec4 result;
if (inBlendMode == 0)
else if (inBlendMode == 11)
result = exclusion (source, backdrop);
else if (inBlendMode == 12)
- result = color (source, backdrop);
+ result = colorize (source, backdrop);
else if (inBlendMode == 13)
result = hue (source, backdrop);
else if (inBlendMode == 14)
else
discard;
- outColor = clip (inPos, result);
+ color = clip_scaled (inPos, result);
}
#version 420 core
-#include "clip.vert.glsl"
+#include "common.vert.glsl"
+#include "rect.vert.glsl"
layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inStartTexRect;
-layout(location = 2) in vec4 inEndTexRect;
-layout(location = 3) in uint inStartTexId;
-layout(location = 4) in uint inEndTexId;
-layout(location = 5) in uint inBlendMode;
+layout(location = 1) in vec4 inTopRect;
+layout(location = 2) in vec4 inBottomRect;
+layout(location = 3) in vec4 inTopTexRect;
+layout(location = 4) in vec4 inBottomTexRect;
+layout(location = 5) in uint inTopTexId;
+layout(location = 6) in uint inBottomTexId;
+layout(location = 7) in uint inBlendMode;
layout(location = 0) out vec2 outPos;
-layout(location = 1) out vec2 outStartTexCoord;
-layout(location = 2) out vec2 outEndTexCoord;
-layout(location = 3) flat out uint outStartTexId;
-layout(location = 4) flat out uint outEndTexId;
-layout(location = 5) flat out uint outBlendMode;
-
-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) };
+layout(location = 1) flat out Rect outTopRect;
+layout(location = 2) flat out Rect outBottomRect;
+layout(location = 3) out vec2 outTopTexCoord;
+layout(location = 4) out vec2 outBottomTexCoord;
+layout(location = 5) flat out uint outTopTexId;
+layout(location = 6) flat out uint outBottomTexId;
+layout(location = 7) flat out uint outBlendMode;
void main() {
- vec4 rect = clip (inRect);
- vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
- gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
+ Rect r = rect_from_gsk (inRect);
+ vec2 pos = set_position_from_rect (r);
outPos = pos;
-
- vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
- rect.zw / inRect.zw);
- vec4 starttexrect = vec4(inStartTexRect.xy + inStartTexRect.zw * texrect.xy,
- inStartTexRect.zw * texrect.zw);
- vec4 endtexrect = vec4(inEndTexRect.xy + inEndTexRect.zw * texrect.xy,
- inEndTexRect.zw * texrect.zw);
-
- outStartTexCoord = starttexrect.xy + starttexrect.zw * offsets[gl_VertexIndex];
- outEndTexCoord = endtexrect.xy + endtexrect.zw * offsets[gl_VertexIndex];
- outStartTexId = inStartTexId;
- outEndTexId = inEndTexId;
+ outTopRect = rect_from_gsk (inTopRect);
+ outBottomRect = rect_from_gsk (inBottomRect);
+ outTopTexCoord = scale_tex_coord (pos, r, inTopTexRect);
+ outBottomTexCoord = scale_tex_coord (pos, r, inBottomTexRect);
+ outTopTexId = inTopTexId;
+ outBottomTexId = inBottomTexId;
outBlendMode = inBlendMode;
}