Warning, /frameworks/kquickcharts/src/shaders/piechart.frag is written in an unsupported language. File is not indexed.
0001 /*
0002 * This file is part of KQuickCharts
0003 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004 *
0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007
0008 #version 440
0009
0010 #extension GL_GOOGLE_include_directive: enable
0011 #include "sdf.glsl"
0012
0013 // The maximum number of segments we can support for a single pie.
0014 // This is based on OpenGL's MAX_FRAGMENT_UNIFORM_COMPONENTS.
0015 // MAX_FRAGMENT_UNIFORM_COMPONENTS is required to be at least 1024.
0016 // Assuming a segment of size 1, each segment needs
0017 // 2 (size of a vec2) * 2 (number of points) + 4 (size of vec4) + 1 (segment size)
0018 // components. We also need to leave some room for the other uniforms.
0019 #define MAX_SEGMENTS 100
0020
0021 layout(std140, binding = 0) uniform buf {
0022 highp mat4 matrix;
0023 lowp float opacity;
0024 lowp vec2 aspect;
0025 lowp float innerRadius;
0026 lowp float outerRadius;
0027 lowp vec4 backgroundColor;
0028 bool smoothEnds;
0029 lowp float fromAngle;
0030 lowp float toAngle;
0031
0032 int segmentCount;
0033 lowp vec2 segments[MAX_SEGMENTS];
0034 lowp vec4 colors[MAX_SEGMENTS];
0035 } ubuf;
0036
0037 layout (location = 0) in lowp vec2 uv;
0038 layout (location = 0) out lowp vec4 out_color;
0039
0040 const lowp vec2 origin = vec2(0.0, 0.0);
0041 const lowp float lineSmooth = 0.001;
0042
0043 lowp float rounded_segment(lowp float from, lowp float to, lowp float inner, lowp float outer, lowp float rounding)
0044 {
0045 return sdf_torus_segment(uv, from + rounding, to - rounding, inner + rounding, outer - rounding) - rounding;
0046 }
0047
0048 void main()
0049 {
0050 lowp vec4 color = vec4(0.0);
0051
0052 lowp float thickness = (ubuf.outerRadius - ubuf.innerRadius) / 2.0;
0053 lowp float rounding = ubuf.smoothEnds ? thickness : 0.0;
0054
0055 // Background first, slightly smaller than the actual pie to avoid antialiasing artifacts.
0056 lowp float background_rounding = (ubuf.toAngle - ubuf.fromAngle) >= 2.0 * pi ? 0.001 : rounding + 0.001;
0057 lowp float background = rounded_segment(ubuf.fromAngle, ubuf.toAngle, ubuf.innerRadius, ubuf.outerRadius, background_rounding);
0058 color = sdf_render(background, color, ubuf.backgroundColor);
0059
0060 for (int i = 0; i < ubuf.segmentCount && i < MAX_SEGMENTS; ++i) {
0061 lowp vec2 segment = ubuf.segments[i];
0062
0063 lowp float segment_sdf = rounded_segment(segment.x, segment.y, ubuf.innerRadius, ubuf.outerRadius, rounding);
0064 color = sdf_render(segment_sdf, color, ubuf.colors[i]);
0065 }
0066
0067 out_color = color * ubuf.opacity;
0068 }