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