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 // This requires "sdf.frag" which is included through SDFShader.
0009
0010 // The maximum number of segments we can support for a single pie.
0011 // This is based on OpenGL's MAX_FRAGMENT_UNIFORM_COMPONENTS.
0012 // MAX_FRAGMENT_UNIFORM_COMPONENTS is required to be at least 1024.
0013 // Assuming a segment of size 1, each segment needs
0014 // 2 (size of a vec2) * 2 (number of points) + 4 (size of vec4) + 1 (segment size)
0015 // components. We also need to leave some room for the other uniforms.
0016 #define MAX_SEGMENTS 100
0017
0018 uniform lowp float opacity;
0019 uniform lowp float innerRadius;
0020 uniform lowp float outerRadius;
0021 uniform lowp vec4 backgroundColor;
0022 uniform bool smoothEnds;
0023 uniform lowp float fromAngle;
0024 uniform lowp float toAngle;
0025
0026 uniform lowp vec2 segments[MAX_SEGMENTS];
0027 uniform lowp vec4 colors[MAX_SEGMENTS];
0028 uniform int segmentCount;
0029
0030 #ifdef LEGACY_STAGE_INOUT
0031 varying lowp vec2 uv;
0032 #else
0033 in lowp vec2 uv;
0034 out lowp vec4 out_color;
0035 #endif
0036
0037 const lowp vec2 origin = vec2(0.0, 0.0);
0038 const lowp float lineSmooth = 0.001;
0039
0040 lowp float rounded_segment(lowp float from, lowp float to, lowp float inner, lowp float outer, lowp float rounding)
0041 {
0042 return sdf_torus_segment(uv, from + rounding, to - rounding, inner + rounding, outer - rounding) - rounding;
0043 }
0044
0045 void main()
0046 {
0047 lowp vec4 color = vec4(0.0);
0048
0049 lowp float thickness = (outerRadius - innerRadius) / 2.0;
0050 lowp float rounding = smoothEnds ? thickness : 0.0;
0051
0052 // Background first, slightly smaller than the actual pie to avoid antialiasing artifacts.
0053 lowp float background_rounding = (toAngle - fromAngle) >= 2.0 * pi ? 0.001 : rounding + 0.001;
0054 lowp float background = rounded_segment(fromAngle, toAngle, innerRadius, outerRadius, background_rounding);
0055 color = sdf_render(background, color, backgroundColor);
0056
0057 for (int i = 0; i < segmentCount && i < MAX_SEGMENTS; ++i) {
0058 lowp vec2 segment = segments[i];
0059
0060 lowp float segment_sdf = rounded_segment(segment.x, segment.y, innerRadius, outerRadius, rounding);
0061 color = sdf_render(segment_sdf, color, colors[i]);
0062 }
0063
0064 #ifdef LEGACY_STAGE_INOUT
0065 gl_FragColor = color * opacity;
0066 #else
0067 out_color = color * opacity;
0068 #endif
0069 }