forked from AuroraMiddleware/gtk
af917c4ade
Note: We interpolate premultiplied colors as per the CSS spec. This i different from Cairo, which interpolates unpremultiplied. So in testcases with translucent gradients, it's actually Cairo that is wrong.
90 lines
2.7 KiB
GLSL
90 lines
2.7 KiB
GLSL
#version 420 core
|
|
|
|
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(push_constant) uniform PushConstants {
|
|
mat4 mvp;
|
|
vec4 clip_bounds;
|
|
vec4 clip_widths;
|
|
vec4 clip_heights;
|
|
} push;
|
|
|
|
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) };
|
|
|
|
vec4 intersect(vec4 a, vec4 b)
|
|
{
|
|
a = vec4(a.xy, a.xy + a.zw);
|
|
b = vec4(b.xy, b.xy + b.zw);
|
|
vec4 result = vec4(max(a.xy, b.xy), min(a.zw, b.zw));
|
|
if (any (greaterThanEqual (result.xy, result.zw)))
|
|
return vec4(0.0,0.0,0.0,0.0);
|
|
return vec4(result.xy, result.zw - result.xy);
|
|
}
|
|
|
|
float
|
|
get_gradient_pos (vec2 pos)
|
|
{
|
|
pos = pos - inStart;
|
|
vec2 grad = inEnd - inStart;
|
|
|
|
return dot (pos, grad) / dot (grad, grad);
|
|
}
|
|
|
|
void main() {
|
|
vec4 rect = intersect(inRect, push.clip_bounds);
|
|
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);
|
|
}
|