1 # From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
4 # The built-in input variable gl_ClipDistance array contains
5 # linearly interpolated values for the vertex values written by the
6 # vertex shader to the gl_ClipDistance vertex output variable. This
7 # array must be sized in the fragment shader either implicitly or
8 # explicitly to be the same size as it was sized in the vertex
9 # shader. Only elements in this array that have clipping enabled
10 # will have defined values.
12 # This test checks proper operation of gl_ClipDistance in fragment
13 # shaders by setting each element of gl_ClipDistance to simple linear
14 # function of gl_Vertex (computed by taking the dot product of
15 # gl_Vertex with a uniform vector, and dividing the result by
16 # gl_Vertex's homogeneous coordinate). gl_Vertex is also passed
17 # through to the fragment shader, which uses the same dot product to
18 # verify that gl_ClipDistance has been properly interpolated.
25 uniform vec4 transform[6];
27 out float gl_ClipDistance[6];
31 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
33 // Set each value of gl_ClipDistance to a linear transformation of
35 for (int i = 0; i < 6; ++i) {
36 gl_ClipDistance[i] = dot(transform[i], gl_Vertex) / gl_Vertex.w;
39 // Pass through gl_Vertex to the fragment shader so that it can
40 // verify the interpolated values of gl_ClipDistance.
46 uniform vec4 transform[6];
48 in float gl_ClipDistance[6];
52 bool test_passed = true;
54 // Check that each value of gl_ClipDistance matches the value
55 // computed in the vertex shader.
56 for (int i = 0; i < 6; ++i) {
57 float expected_distance = dot(transform[i], vertex) / vertex.w;
58 float deviation = distance(gl_ClipDistance[i], expected_distance);
59 if (deviation > 1.0e-5) {
64 // Report pass/fail as a red or green pixel.
65 gl_FragColor = test_passed ? vec4(0.0, 1.0, 0.0, 1.0)
66 : vec4(1.0, 0.0, 0.0, 1.0);
72 # Since the fragment shader's gl_ClipDistance array is only defined
73 # for elements that have clipping enabled, we need to enable all 6
74 # clip planes and carefully shoose the transform vectors to make sure
75 # that no pixels are actually clipped.
82 uniform vec4 transform[0] 1.0 1.0 0.0 0.0 # clipDistance[0] = x + y
83 uniform vec4 transform[1] 1.0 2.0 0.0 0.0 # clipDistance[1] = x + 2*y
84 uniform vec4 transform[2] 2.0 1.0 0.0 0.0 # clipDistance[2] = 2*x + y
85 uniform vec4 transform[3] 2.0 2.0 0.0 0.0 # clipDistance[3] = 2*x + 2*y
86 uniform vec4 transform[4] -1.0 -1.0 0.0 2.0 # clipDistance[4] = 2.0 - x - y
87 uniform vec4 transform[5] -1.0 1.0 0.0 1.0 # clipDistance[5] = 1.0 - x + y
90 probe all rgba 0.0 1.0 0.0 1.0