1 # From the ARB_cull_distance spec:
3 # In the fragment language, gl_CullDistance array contains linearly
4 # interpolated values for the vertex values written by a shader to the
5 # gl_CullDistance vertex output variable.
7 # This test checks proper operation of gl_CullDistance in fragment
8 # shaders by setting each element of gl_CullDistance to simple linear
9 # function of gl_Vertex (computed by taking the dot product of
10 # gl_Vertex with a uniform vector, and dividing the result by
11 # gl_Vertex's homogeneous coordinate). gl_Vertex is also passed
12 # through to the fragment shader, which uses the same dot product to
13 # verify that gl_CullDistance has been properly interpolated.
21 #extension GL_ARB_cull_distance: enable
22 uniform vec4 transform[6];
24 out float gl_CullDistance[6];
28 gl_Position = gl_Vertex;
30 // Set each value of gl_CullDistance to a linear transformation of
32 for (int i = 0; i < 6; ++i) {
33 gl_CullDistance[i] = dot(transform[i], gl_Vertex) / gl_Vertex.w;
36 // Pass through gl_Vertex to the fragment shader so that it can
37 // verify the interpolated values of gl_CullDistance.
43 #extension GL_ARB_cull_distance: enable
44 uniform vec4 transform[6];
46 in float gl_CullDistance[6];
50 bool test_passed = true;
52 // Check that each value of gl_CullDistance matches the value
53 // computed in the vertex shader.
54 for (int i = 0; i < 6; ++i) {
55 float expected_distance = dot(transform[i], vertex) / vertex.w;
56 float deviation = distance(gl_CullDistance[i], expected_distance);
57 if (deviation > 1.0e-5) {
62 // Report pass/fail as a red or green pixel.
63 gl_FragColor = test_passed ? vec4(0.0, 1.0, 0.0, 1.0)
64 : vec4(1.0, 0.0, 0.0, 1.0);
68 uniform vec4 transform[0] 1.0 1.0 0.0 0.0 # cullDistance[0] = x + y
69 uniform vec4 transform[1] 1.0 2.0 0.0 0.0 # cullDistance[1] = x + 2*y
70 uniform vec4 transform[2] 2.0 1.0 0.0 0.0 # cullDistance[2] = 2*x + y
71 uniform vec4 transform[3] 2.0 2.0 0.0 0.0 # cullDistance[3] = 2*x + 2*y
72 uniform vec4 transform[4] -1.0 -1.0 0.0 2.0 # cullDistance[4] = 2.0 - x - y
73 uniform vec4 transform[5] -1.0 1.0 0.0 1.0 # cullDistance[5] = 1.0 - x + y
76 probe all rgba 0.0 1.0 0.0 1.0