Warning, /plasma/kwin/src/scene/shaders/debug_fractional.frag is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #version 130 compatibility
0008 
0009 uniform float fractionalPrecision;
0010 uniform vec2 geometrySize;
0011 
0012 varying vec2 texcoord0;
0013 varying float vertexFractional;
0014 
0015 // paint every time we query textures at non-integer alignments
0016 // it implies we're being upscaled in ways that will cause blurryness
0017 // 2x scaling will go through fine
0018 void main()
0019 {
0020     const float strength = 0.4;
0021 
0022     // Calculate an error correction value based on the minimum precision we
0023     // want to measure.
0024     float errorCorrection = 1.0 / fractionalPrecision;
0025 
0026     // Determine which exact pixel we are reading from the source texture.
0027     // Texture sampling happens in the middle of a pixel so we need to add 0.5.
0028     vec2 sourcePixel = texcoord0 * geometrySize + 0.5;
0029     // Cancel out any precision artifacts below what we actually want to measure.
0030     sourcePixel = round(sourcePixel * errorCorrection) / errorCorrection;
0031 
0032     // The total error is the sum of the fractional parts of the source pixel.
0033     float error = dot(fract(sourcePixel), vec2(1.0));
0034 
0035     vec4 fragColor = vec4(0.0);
0036 
0037     if (vertexFractional > 0.5) {
0038         fragColor = mix(fragColor, vec4(0.0, 0.0, 1.0, 1.0), strength);
0039     }
0040 
0041     if (error > fractionalPrecision) {
0042         fragColor = mix(fragColor, vec4(1.0, 0.0, 0.0, 1.0), strength);
0043     }
0044 
0045     gl_FragColor = fragColor;
0046 }