Warning, /plasma/kwin/src/scene/shaders/debug_fractional.vert 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 uniform mat4 modelViewProjectionMatrix;
0008 uniform float fractionalPrecision;
0009 uniform vec2 screenSize;
0010 uniform vec2 geometrySize;
0011 
0012 attribute vec4 vertex;
0013 attribute vec4 texcoord;
0014 
0015 varying vec2 texcoord0;
0016 varying float vertexFractional;
0017 
0018 // This shader calculates the fractional component of the vertex position and
0019 // passes 1 to the fragment shader if it is larger than the precision we want to
0020 // measure, or 0 if it is not. The fragment shader can then use that information
0021 // to color the pixel based on that value. 0 or 1 is used instead of something
0022 // like vertex coloring because of vertex interpolation and the fragment shader
0023 // having control over the final appearance.
0024 void main(void)
0025 {
0026     float errorCorrection = 1.0 / fractionalPrecision;
0027 
0028     gl_Position = modelViewProjectionMatrix * vertex;
0029 
0030     vec2 screenPosition = ((gl_Position.xy / gl_Position.w + vec2(1.0)) / vec2(2.0)) * screenSize;
0031     // Cancel out any floating point errors below what we want to measure.
0032     screenPosition = round(screenPosition * errorCorrection) / errorCorrection;
0033 
0034     // Dermine how far off the pixel grid this vertex is.
0035     vec2 error = fract(screenPosition);
0036 
0037     vertexFractional = dot(error, vec2(1.0)) > fractionalPrecision ? 1.0 : 0.0;
0038 
0039     // Correct texture sampling for floating-point error on the vertices.
0040     // This currently assumes UV coordinates are always from 0 to 1 over an
0041     // entire triangle.
0042     texcoord0 = texcoord.xy + (error / geometrySize);
0043 }