diff --git a/src/shaders/linechart.frag b/src/shaders/linechart.frag index 55a85f8..fced284 100644 --- a/src/shaders/linechart.frag +++ b/src/shaders/linechart.frag @@ -1,55 +1,69 @@ /* * This file is part of KQuickCharts * SPDX-FileCopyrightText: 2019 Arjen Hiemstra * * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ // This requires "sdf.frag" which is included through SDFShader. uniform lowp float opacity; // inherited opacity of this item uniform lowp vec4 lineColor; uniform lowp vec4 fillColor; uniform lowp float lineWidth; uniform lowp vec2 bounds; uniform lowp vec2 points[SDF_POLYGON_MAX_POINT_COUNT]; uniform int pointCount; +#ifdef LEGACY_STAGE_INOUT varying lowp vec2 uv; +#else +in lowp vec2 uv; +out lowp vec4 out_color; +#endif + void main() { lowp vec2 point = uv; lowp vec4 color = vec4(0.0, 0.0, 0.0, 0.0); // bounds.y contains the line segment's maximum value. If we are a bit above // that, we will never render anything, so just discard the pixel. if (point.y > bounds.y + 0.01) { discard; } // bounds.x contains the line segment's minimum value. If we are a bit below // that, we know we will always be inside the polygon described by points. // So just return a pixel with fillColor. if (point.y < bounds.x - 0.01) { +#ifdef LEGACY_STAGE_INOUT gl_FragColor = fillColor * opacity; +#else + out_color = fillColor * opacity; +#endif return; } #if !defined(GL_ES) || !defined(VALIDATING) // See sdf.frag line 98 lowp float polygon = sdf_polygon(point, points, pointCount); #else lowp float polygon = 0.0; #endif color = sdf_render(polygon, color, fillColor, 0.001); if (lineWidth > 0.0) { color = sdf_render(sdf_annular(sdf_outline(polygon), lineWidth), color, lineColor, 0.0002); } +#ifdef LEGACY_STAGE_INOUT gl_FragColor = color * opacity; +#else + out_color = color * opacity; +#endif } diff --git a/src/shaders/linechart.vert b/src/shaders/linechart.vert index 1f5d035..10a2f46 100644 --- a/src/shaders/linechart.vert +++ b/src/shaders/linechart.vert @@ -1,22 +1,27 @@ /* * This file is part of KQuickCharts * SPDX-FileCopyrightText: 2019 Arjen Hiemstra * * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ uniform highp mat4 matrix; uniform lowp float lineWidth; uniform lowp float aspect; +#ifdef LEGACY_STAGE_INOUT attribute highp vec4 in_vertex; attribute mediump vec2 in_uv; - varying mediump vec2 uv; +#else +in highp vec4 in_vertex; +in mediump vec2 in_uv; +out mediump vec2 uv; +#endif void main() { uv.x = in_uv.x; uv.y = in_uv.y; uv.y = (1.0 + -1.0 * uv.y) * aspect; gl_Position = matrix * in_vertex; } diff --git a/src/shaders/piechart.frag b/src/shaders/piechart.frag index 68073f0..ac28193 100644 --- a/src/shaders/piechart.frag +++ b/src/shaders/piechart.frag @@ -1,69 +1,78 @@ /* * This file is part of KQuickCharts * SPDX-FileCopyrightText: 2019 Arjen Hiemstra * * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ // This requires "sdf.frag" which is included through SDFShader. // The maximum number of segments we can support for a single pie. // This is based on OpenGL's MAX_FRAGMENT_UNIFORM_COMPONENTS. // MAX_FRAGMENT_UNIFORM_COMPONENTS is required to be at least 1024. // Assuming a segment of size 1, each segment needs // 2 (size of a vec2) * 2 (number of points) + 4 (size of vec4) + 1 (segment size) // components. We also need to leave some room for the other uniforms. #define MAX_SEGMENTS 100 uniform lowp float opacity; uniform lowp float innerRadius; uniform lowp float outerRadius; uniform lowp vec4 backgroundColor; uniform bool smoothEnds; uniform lowp vec2 triangles[MAX_SEGMENTS * 2]; uniform lowp vec4 colors[MAX_SEGMENTS]; uniform int segments[MAX_SEGMENTS]; uniform int segmentCount; +#ifdef LEGACY_STAGE_INOUT varying lowp vec2 uv; +#else +in lowp vec2 uv; +out lowp vec4 out_color; +#endif const lowp vec2 origin = vec2(0.0, 0.0); const lowp float lineSmooth = 0.001; void main() { lowp vec2 point = uv * (1.0 + lineSmooth * 2.0); lowp float thickness = (outerRadius - innerRadius) / 2.0; lowp float donut = sdf_annular(sdf_circle(point, innerRadius + thickness), thickness); lowp vec4 color = vec4(0.0); lowp float totalSegments = sdf_null; int index = 0; for (int i = 0; i < segmentCount && i < MAX_SEGMENTS; ++i) { lowp float segment = sdf_null; for(int j = 0; j < segments[i] && j < MAX_SEGMENTS; j++) { segment = sdf_union(segment, sdf_round(sdf_triangle(point, origin, triangles[index++], triangles[index++]), lineSmooth)); } totalSegments = sdf_union(totalSegments, segment); segment = smoothEnds ? sdf_intersect_smooth(donut, segment, thickness) : sdf_intersect(donut, segment); color = sdf_render(segment, color, colors[i], lineSmooth); } // Finally, render an end segment with the background color. if (smoothEnds) { lowp vec4 background = sdf_render(donut, vec4(0.0), backgroundColor, lineSmooth); color = mix(background, color, color.a); } else { lowp float segment = sdf_subtract(sdf_round(donut, lineSmooth), totalSegments); color = sdf_render(segment, color, backgroundColor, lineSmooth); } +#ifdef LEGACY_STAGE_INOUT gl_FragColor = color * opacity; +#else + out_color = color * opacity; +#endif } diff --git a/src/shaders/piechart.vert b/src/shaders/piechart.vert index 5bda423..f44c897 100644 --- a/src/shaders/piechart.vert +++ b/src/shaders/piechart.vert @@ -1,19 +1,24 @@ /* * This file is part of KQuickCharts * SPDX-FileCopyrightText: 2019 Arjen Hiemstra * * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ uniform highp mat4 matrix; uniform lowp vec2 aspect; +#ifdef LEGACY_STAGE_INOUT attribute highp vec4 in_vertex; attribute mediump vec2 in_uv; - varying mediump vec2 uv; +#else +in highp vec4 in_vertex; +in mediump vec2 in_uv; +out mediump vec2 uv; +#endif void main() { uv = (-1.0 + 2.0 * in_uv) * aspect; gl_Position = matrix * in_vertex; }